From 46c55216a443f73982fd2db481a24fb1cf39ce5e Mon Sep 17 00:00:00 2001 From: ArashPartow Date: Sun, 10 May 2020 13:29:43 +1000 Subject: [PATCH] Updates to ExprTk --- bench_expr_weird.txt | 3 + exprtk/Makefile | 2 +- exprtk/exprtk.hpp | 7623 ++++++++++------- exprtk/exprtk_benchmark.cpp | 8 +- exprtk/exprtk_simple_example_01.cpp | 6 +- exprtk/exprtk_simple_example_02.cpp | 6 +- exprtk/exprtk_simple_example_03.cpp | 6 +- exprtk/exprtk_simple_example_04.cpp | 12 +- exprtk/exprtk_simple_example_05.cpp | 6 +- exprtk/exprtk_simple_example_06.cpp | 6 +- exprtk/exprtk_simple_example_07.cpp | 6 +- exprtk/exprtk_simple_example_08.cpp | 16 +- exprtk/exprtk_simple_example_09.cpp | 12 +- exprtk/exprtk_simple_example_10.cpp | 12 +- exprtk/exprtk_simple_example_11.cpp | 6 +- exprtk/exprtk_simple_example_12.cpp | 6 +- exprtk/exprtk_simple_example_13.cpp | 4 +- exprtk/exprtk_simple_example_14.cpp | 4 +- exprtk/exprtk_simple_example_15.cpp | 10 +- exprtk/exprtk_simple_example_16.cpp | 24 +- exprtk/exprtk_simple_example_17.cpp | 6 +- exprtk/exprtk_simple_example_18.cpp | 6 +- exprtk/exprtk_simple_example_19.cpp | 14 +- exprtk/exprtk_test.cpp | 601 +- exprtk/readme.txt | 68 +- ...-parser-benchmark-project_msvc2015.vcxproj | 810 +- ...benchmark-project_msvc2015.vcxproj.filters | 1802 ++-- ...-parser-benchmark-project_msvc2017.vcxproj | 848 +- ...benchmark-project_msvc2017.vcxproj.filters | 1912 ++--- math-parser-benchmark-project_msvc2015.sln | 46 +- math-parser-benchmark-project_msvc2017.sln | 46 +- 31 files changed, 7919 insertions(+), 6018 deletions(-) diff --git a/bench_expr_weird.txt b/bench_expr_weird.txt index 9ae28d6..6e59da3 100644 --- a/bench_expr_weird.txt +++ b/bench_expr_weird.txt @@ -8,6 +8,9 @@ +2+1 +2-1 -2-1 +2-+1 +2+-1 +2--1 +2-+1 +2+-1 +2--1 diff --git a/exprtk/Makefile b/exprtk/Makefile index 76d43a0..bdae9b1 100644 --- a/exprtk/Makefile +++ b/exprtk/Makefile @@ -2,7 +2,7 @@ # ************************************************************** # * C++ Mathematical Expression Toolkit Library * # * * -# * Author: Arash Partow (1999-2020) * +# * Author: Arash Partow (1999-2021) * # * URL: http://www.partow.net/programming/exprtk/index.html * # * * # * Copyright notice: * diff --git a/exprtk/exprtk.hpp b/exprtk/exprtk.hpp index 75ee0de..4ce0848 100644 --- a/exprtk/exprtk.hpp +++ b/exprtk/exprtk.hpp @@ -2,7 +2,7 @@ ****************************************************************** * C++ Mathematical Expression Toolkit Library * * * - * Author: Arash Partow (1999-2020) * + * Author: Arash Partow (1999-2021) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * @@ -35,6 +35,7 @@ #include +#include #include #include #include @@ -81,14 +82,24 @@ namespace exprtk #define exprtk_disable_fallthrough_end (void)0; #endif + #if __cplusplus >= 201103L + #define exprtk_override override + #define exprtk_final final + #else + #define exprtk_override + #define exprtk_final + #endif + namespace details { - typedef unsigned char uchar_t; - typedef char char_t; - typedef uchar_t* uchar_ptr; - typedef char_t* char_ptr; - typedef uchar_t const* uchar_cptr; - typedef char_t const* char_cptr; + typedef char char_t; + typedef char_t* char_ptr; + typedef char_t const* char_cptr; + typedef unsigned char uchar_t; + typedef uchar_t* uchar_ptr; + typedef uchar_t const* uchar_cptr; + typedef unsigned long long int _uint64_t; + typedef long long int _int64_t; inline bool is_whitespace(const char_t c) { @@ -162,6 +173,12 @@ namespace exprtk ('\'' != c); } + inline bool is_valid_string_char(const char_t c) + { + return std::isprint(static_cast(c)) || + is_whitespace(c); + } + #ifndef exprtk_disable_caseinsensitivity inline void case_normalise(std::string& s) { @@ -202,8 +219,8 @@ namespace exprtk for (std::size_t i = 0; i < length; ++i) { - const char_t c1 = static_cast(std::tolower(s1[i])); - const char_t c2 = static_cast(std::tolower(s2[i])); + const char_t c1 = static_cast(std::tolower(s1[i])); + const char_t c2 = static_cast(std::tolower(s2[i])); if (c1 > c2) return false; @@ -269,7 +286,7 @@ namespace exprtk { for ( ; i; i /= 10) { - result += '0' + char(-(i % 10)); + result += '0' + static_cast(-(i % 10)); } result += '-'; @@ -278,7 +295,7 @@ namespace exprtk { for ( ; i; i /= 10) { - result += '0' + char(i % 10); + result += '0' + static_cast(i % 10); } } @@ -304,35 +321,34 @@ namespace exprtk if (('0' <= h) && (h <= '9')) return (h - '0'); else - return static_cast(std::toupper(h) - 'A'); + return static_cast(std::toupper(h) - 'A'); } template - inline void parse_hex(Iterator& itr, Iterator end, std::string::value_type& result) + inline bool parse_hex(Iterator& itr, Iterator end, + std::string::value_type& result) { if ( - (end != (itr )) && - (end != (itr + 1)) && - (end != (itr + 2)) && - (end != (itr + 3)) && - ('0' == *(itr )) && - ( - ('x' == *(itr + 1)) || - ('X' == *(itr + 1)) - ) && - (is_hex_digit(*(itr + 2))) && - (is_hex_digit(*(itr + 3))) + (end == (itr )) || + (end == (itr + 1)) || + (end == (itr + 2)) || + (end == (itr + 3)) || + ('0' != *(itr )) || + ('X' != std::toupper(*(itr + 1))) || + (!is_hex_digit(*(itr + 2))) || + (!is_hex_digit(*(itr + 3))) ) { - result = hex_to_bin(static_cast(*(itr + 2))) << 4 | - hex_to_bin(static_cast(*(itr + 3))) ; - itr += 3; + return false; } - else - result = '\0'; + + result = hex_to_bin(static_cast(*(itr + 2))) << 4 | + hex_to_bin(static_cast(*(itr + 3))) ; + + return true; } - inline void cleanup_escapes(std::string& s) + inline bool cleanup_escapes(std::string& s) { typedef std::string::iterator str_itr_t; @@ -346,36 +362,41 @@ namespace exprtk { if ('\\' == (*itr1)) { - ++removal_count; - if (end == ++itr1) - break; - else if ('\\' != (*itr1)) { - switch (*itr1) - { - case 'n' : (*itr1) = '\n'; break; - case 'r' : (*itr1) = '\r'; break; - case 't' : (*itr1) = '\t'; break; - case '0' : parse_hex(itr1, end, (*itr1)); - removal_count += 3; - break; - } - - continue; + return false; } + else if (parse_hex(itr1, end, *itr2)) + { + itr1+= 4; + itr2+= 1; + removal_count +=4; + } + else if ('a' == (*itr1)) { (*itr2++) = '\a'; ++itr1; ++removal_count; } + else if ('b' == (*itr1)) { (*itr2++) = '\b'; ++itr1; ++removal_count; } + else if ('f' == (*itr1)) { (*itr2++) = '\f'; ++itr1; ++removal_count; } + else if ('n' == (*itr1)) { (*itr2++) = '\n'; ++itr1; ++removal_count; } + else if ('r' == (*itr1)) { (*itr2++) = '\r'; ++itr1; ++removal_count; } + else if ('t' == (*itr1)) { (*itr2++) = '\t'; ++itr1; ++removal_count; } + else if ('v' == (*itr1)) { (*itr2++) = '\v'; ++itr1; ++removal_count; } + else if ('0' == (*itr1)) { (*itr2++) = '\0'; ++itr1; ++removal_count; } + else + { + (*itr2++) = (*itr1++); + ++removal_count; + } + continue; } - - if (itr1 != itr2) - { - (*itr2) = (*itr1); - } - - ++itr1; - ++itr2; + else + (*itr2++) = (*itr1++); } + if ((removal_count > s.size()) || (0 == removal_count)) + return false; + s.resize(s.size() - removal_count); + + return true; } class build_string @@ -643,23 +664,19 @@ namespace exprtk inline bool wc_match(const std::string& wild_card, const std::string& str) { - return match_impl(wild_card.data(), - wild_card.data() + wild_card.size(), - str.data(), - str.data() + str.size(), - '*', - '?'); + return match_impl( + wild_card.data(), wild_card.data() + wild_card.size(), + str.data(), str.data() + str.size(), + '*', '?'); } inline bool wc_imatch(const std::string& wild_card, const std::string& str) { - return match_impl(wild_card.data(), - wild_card.data() + wild_card.size(), - str.data(), - str.data() + str.size(), - '*', - '?'); + return match_impl( + wild_card.data(), wild_card.data() + wild_card.size(), + str.data(), str.data() + str.size(), + '*', '?'); } inline bool sequence_match(const std::string& pattern, @@ -686,12 +703,12 @@ namespace exprtk { if ('*' == (*p_itr)) { - const char_t target = static_cast(std::toupper(*(p_itr - 1))); + const char_t target = static_cast(std::toupper(*(p_itr - 1))); if ('*' == target) { diff_index = static_cast(std::distance(str.begin(),s_itr)); - diff_value = static_cast(std::toupper(*p_itr)); + diff_value = static_cast(std::toupper(*p_itr)); return false; } @@ -714,7 +731,7 @@ namespace exprtk ) { diff_index = static_cast(std::distance(str.begin(),s_itr)); - diff_value = static_cast(std::toupper(*p_itr)); + diff_value = static_cast(std::toupper(*p_itr)); return false; } @@ -773,15 +790,15 @@ namespace exprtk }; #define exprtk_register_real_type_tag(T) \ - template<> struct number_type \ + template <> struct number_type \ { typedef real_type_tag type; number_type() {} }; \ #define exprtk_register_complex_type_tag(T) \ - template<> struct number_type > \ + template <> struct number_type > \ { typedef complex_type_tag type; number_type() {} }; \ #define exprtk_register_int_type_tag(T) \ - template<> struct number_type \ + template <> struct number_type \ { typedef int_type_tag type; number_type() {} }; \ exprtk_register_real_type_tag(double ) @@ -792,45 +809,34 @@ namespace exprtk exprtk_register_complex_type_tag(long double) exprtk_register_complex_type_tag(float ) - exprtk_register_int_type_tag(short ) - exprtk_register_int_type_tag(int ) - exprtk_register_int_type_tag(long long int ) - exprtk_register_int_type_tag(unsigned short ) - exprtk_register_int_type_tag(unsigned int ) - exprtk_register_int_type_tag(unsigned long long int) + exprtk_register_int_type_tag(short ) + exprtk_register_int_type_tag(int ) + exprtk_register_int_type_tag(_int64_t ) + exprtk_register_int_type_tag(unsigned short) + exprtk_register_int_type_tag(unsigned int ) + exprtk_register_int_type_tag(_uint64_t ) #undef exprtk_register_real_type_tag #undef exprtk_register_int_type_tag template - struct epsilon_type - { - static inline T value() - { - const T epsilon = T(0.0000000001); - return epsilon; - } - }; + struct epsilon_type {}; - template <> - struct epsilon_type - { - static inline float value() - { - const float epsilon = float(0.000001f); - return epsilon; - } - }; + #define exprtk_define_epsilon_type(Type, Epsilon) \ + template <> struct epsilon_type \ + { \ + static inline Type value() \ + { \ + const Type epsilon = static_cast(Epsilon); \ + return epsilon; \ + } \ + }; \ - template <> - struct epsilon_type - { - static inline long double value() - { - const long double epsilon = (long double)(0.000000000001); - return epsilon; - } - }; + exprtk_define_epsilon_type(float , 0.00000100000f) + exprtk_define_epsilon_type(double , 0.000000000100) + exprtk_define_epsilon_type(long double, 0.000000000001) + + #undef exprtk_define_epsilon_type template inline bool is_nan_impl(const T v, real_type_tag) @@ -845,9 +851,9 @@ namespace exprtk } template - inline long long int to_int64_impl(const T v, real_type_tag) + inline _int64_t to_int64_impl(const T v, real_type_tag) { - return static_cast(v); + return static_cast<_int64_t>(v); } template @@ -1028,7 +1034,7 @@ namespace exprtk template inline T roundn_impl(const T v0, const T v1, real_type_tag) { - const int index = std::max(0, std::min(pow10_size - 1, (int)std::floor(v1))); + const int index = std::max(0, std::min(pow10_size - 1, static_cast(std::floor(v1)))); const T p10 = T(pow10[index]); if (v0 < T(0)) @@ -1239,8 +1245,8 @@ namespace exprtk #define exprtk_define_erfc(TT,impl) \ inline TT erfc_impl(TT v) { return impl(v); } \ - exprtk_define_erfc( float,::erfcf) - exprtk_define_erfc( double,::erfc ) + exprtk_define_erfc(float ,::erfcf) + exprtk_define_erfc(double ,::erfc ) exprtk_define_erfc(long double,::erfcl) #undef exprtk_define_erfc #endif @@ -1323,8 +1329,9 @@ namespace exprtk template inline T frac_impl(const T v, real_type_tag) { return (v - static_cast(v)); } template inline T trunc_impl(const T v, real_type_tag) { return T(static_cast(v)); } - template inline T const_pi_impl(real_type_tag) { return T(numeric::constant::pi); } - template inline T const_e_impl (real_type_tag) { return T(numeric::constant::e); } + template inline T const_pi_impl (real_type_tag) { return T(numeric::constant::pi); } + template inline T const_e_impl (real_type_tag) { return T(numeric::constant::e); } + template inline T const_qnan_impl(real_type_tag) { return std::numeric_limits::quiet_NaN(); } template inline T abs_impl(const T v, int_type_tag) { return ((v >= T(0)) ? v : -v); } template inline T exp_impl(const T v, int_type_tag) { return std::exp (v); } @@ -1372,10 +1379,10 @@ namespace exprtk template struct numeric_info { enum { length = 0, size = 32, bound_length = 0, min_exp = 0, max_exp = 0 }; }; - template<> struct numeric_info { enum { length = 10, size = 16, bound_length = 9}; }; - template<> struct numeric_info { enum { min_exp = -38, max_exp = +38}; }; - template<> struct numeric_info { enum { min_exp = -308, max_exp = +308}; }; - template<> struct numeric_info { enum { min_exp = -308, max_exp = +308}; }; + template <> struct numeric_info { enum { length = 10, size = 16, bound_length = 9 }; }; + template <> struct numeric_info { enum { min_exp = -38, max_exp = +38 }; }; + template <> struct numeric_info { enum { min_exp = -308, max_exp = +308 }; }; + template <> struct numeric_info { enum { min_exp = -308, max_exp = +308 }; }; template inline int to_int32(const T v) @@ -1385,7 +1392,7 @@ namespace exprtk } template - inline long long int to_int64(const T v) + inline _int64_t to_int64(const T v) { const typename details::number_type::type num_type; return to_int64_impl(v, num_type); @@ -1548,31 +1555,31 @@ namespace exprtk while (k) { - if (k & 1) + if (1 == (k % 2)) { l *= v; --k; } v *= v; - k >>= 1; + k /= 2; } return l; } }; - template struct fast_exp { static inline T result(T v) { T v_5 = fast_exp::result(v); return v_5 * v_5; } }; - template struct fast_exp { static inline T result(T v) { return fast_exp::result(v) * v; } }; - template struct fast_exp { static inline T result(T v) { T v_4 = fast_exp::result(v); return v_4 * v_4; } }; - template struct fast_exp { static inline T result(T v) { return fast_exp::result(v) * v; } }; - template struct fast_exp { static inline T result(T v) { T v_3 = fast_exp::result(v); return v_3 * v_3; } }; - template struct fast_exp { static inline T result(T v) { return fast_exp::result(v) * v; } }; - template struct fast_exp { static inline T result(T v) { T v_2 = v * v; return v_2 * v_2; } }; - template struct fast_exp { static inline T result(T v) { return v * v * v; } }; - template struct fast_exp { static inline T result(T v) { return v * v; } }; - template struct fast_exp { static inline T result(T v) { return v; } }; - template struct fast_exp { static inline T result(T ) { return T(1); } }; + template struct fast_exp { static inline T result(const T v) { T v_5 = fast_exp::result(v); return v_5 * v_5; } }; + template struct fast_exp { static inline T result(const T v) { return fast_exp::result(v) * v; } }; + template struct fast_exp { static inline T result(const T v) { T v_4 = fast_exp::result(v); return v_4 * v_4; } }; + template struct fast_exp { static inline T result(const T v) { return fast_exp::result(v) * v; } }; + template struct fast_exp { static inline T result(const T v) { T v_3 = fast_exp::result(v); return v_3 * v_3; } }; + template struct fast_exp { static inline T result(const T v) { return fast_exp::result(v) * v; } }; + template struct fast_exp { static inline T result(const T v) { T v_2 = v * v; return v_2 * v_2; } }; + template struct fast_exp { static inline T result(const T v) { return v * v * v; } }; + template struct fast_exp { static inline T result(const T v) { return v * v; } }; + template struct fast_exp { static inline T result(const T v) { return v; } }; + template struct fast_exp { static inline T result(const T ) { return T(1); } }; #define exprtk_define_unary_function(FunctionName) \ template \ @@ -1707,7 +1714,7 @@ namespace exprtk bool return_result = true; unsigned int digit = 0; - const std::size_t length = static_cast(std::distance(itr,end)); + const std::size_t length = static_cast(std::distance(itr,end)); if (length <= 4) { @@ -1738,10 +1745,14 @@ namespace exprtk #endif - case 4 : exprtk_process_digit - case 3 : exprtk_process_digit - case 2 : exprtk_process_digit - case 1 : if ((digit = (*itr - zero))>= 10) { digit = 0; return_result = false; } + case 4 : exprtk_process_digit + case 3 : exprtk_process_digit + case 2 : exprtk_process_digit + case 1 : if ((digit = (*itr - zero))>= 10) + { + digit = 0; + return_result = false; + } #undef exprtk_process_digit } @@ -1809,7 +1820,7 @@ namespace exprtk while (end != itr) { - if (*inf_itr == static_cast(*itr)) + if (*inf_itr == static_cast(*itr)) { ++itr; ++inf_itr; @@ -1827,6 +1838,13 @@ namespace exprtk return true; } + template + inline bool valid_exponent(const int exponent, numeric::details::real_type_tag) + { + using namespace details::numeric; + return (numeric_info::min_exp <= exponent) && (exponent <= numeric_info::max_exp); + } + template inline bool string_to_real(Iterator& itr_external, const Iterator end, T& t, numeric::details::real_type_tag) { @@ -1858,7 +1876,8 @@ namespace exprtk #define parse_digit_2(d) \ if ((digit = (*itr - zero)) < 10) \ { d = d * T(10) + digit; } \ - else { break; } \ + else \ + { break; } \ ++itr; \ if ('.' != (*itr)) @@ -1867,16 +1886,9 @@ namespace exprtk while ((end != itr) && (zero == (*itr))) ++itr; - unsigned int digit; - while (end != itr) { - // Note: For 'physical' superscalar architectures it - // is advised that the following loop be: 4xPD1 and 1xPD2 - #ifdef exprtk_enable_superscalar - parse_digit_1(d) - parse_digit_1(d) - #endif + unsigned int digit; parse_digit_1(d) parse_digit_1(d) parse_digit_2(d) @@ -1892,16 +1904,11 @@ namespace exprtk if ('.' == (*itr)) { const Iterator curr = ++itr; - unsigned int digit; T tmp_d = T(0); while (end != itr) { - #ifdef exprtk_enable_superscalar - parse_digit_1(tmp_d) - parse_digit_1(tmp_d) - parse_digit_1(tmp_d) - #endif + unsigned int digit; parse_digit_1(tmp_d) parse_digit_1(tmp_d) parse_digit_2(tmp_d) @@ -1910,7 +1917,13 @@ namespace exprtk if (curr != itr) { instate = true; - d += compute_pow10(tmp_d,static_cast(-std::distance(curr,itr))); + + const int frac_exponent = static_cast(-std::distance(curr, itr)); + + if (!valid_exponent(frac_exponent, numeric::details::real_type_tag())) + return false; + + d += compute_pow10(tmp_d, frac_exponent); } #undef parse_digit_1 @@ -1981,6 +1994,8 @@ namespace exprtk if ((end != itr) || (!instate)) return false; + else if (!valid_exponent(exponent, numeric::details::real_type_tag())) + return false; else if (exponent) d = compute_pow10(d,exponent); @@ -2019,6 +2034,50 @@ namespace exprtk } // namespace details + struct loop_runtime_check + { + enum loop_types + { + e_invalid = 0, + e_for_loop = 1, + e_while_loop = 2, + e_repeat_until_loop = 4, + e_all_loops = 7 + }; + + enum violation_type + { + e_unknown = 0, + e_iteration_count = 1, + e_timeout = 2 + }; + + loop_types loop_set; + + loop_runtime_check() + : loop_set(e_invalid) + , max_loop_iterations(0) + {} + + details::_uint64_t max_loop_iterations; + + struct violation_context + { + loop_types loop; + violation_type violation; + details::_uint64_t iteration_count; + }; + + virtual void handle_runtime_violation(const violation_context&) + { + throw std::runtime_error("ExprTk Loop run-time violation."); + } + + virtual ~loop_runtime_check() {} + }; + + typedef loop_runtime_check* loop_runtime_check_ptr; + namespace lexer { struct token @@ -2042,9 +2101,9 @@ namespace exprtk }; token() - : type(e_none), - value(""), - position(std::numeric_limits::max()) + : type(e_none) + , value("") + , position(std::numeric_limits::max()) {} void clear() @@ -2199,13 +2258,13 @@ namespace exprtk typedef token token_t; typedef std::vector token_list_t; - typedef std::vector::iterator token_list_itr_t; + typedef token_list_t::iterator token_list_itr_t; typedef details::char_t char_t; generator() - : base_itr_(0), - s_itr_ (0), - s_end_ (0) + : base_itr_(0) + , s_itr_ (0) + , s_end_ (0) { clear(); } @@ -2324,7 +2383,7 @@ namespace exprtk inline std::string substr(const std::size_t& begin, const std::size_t& end) { const details::char_cptr begin_itr = ((base_itr_ + begin) < s_end_) ? (base_itr_ + begin) : s_end_; - const details::char_cptr end_itr = ((base_itr_ + end) < s_end_) ? (base_itr_ + end) : s_end_; + const details::char_cptr end_itr = ((base_itr_ + end ) < s_end_) ? (base_itr_ + end ) : s_end_; return std::string(begin_itr,end_itr); } @@ -2334,9 +2393,9 @@ namespace exprtk if (finished()) return ""; else if (token_list_.begin() != token_itr_) - return std::string(base_itr_ + (token_itr_ - 1)->position,s_end_); + return std::string(base_itr_ + (token_itr_ - 1)->position, s_end_); else - return std::string(base_itr_ + token_itr_->position,s_end_); + return std::string(base_itr_ + token_itr_->position, s_end_); } private: @@ -2346,9 +2405,9 @@ namespace exprtk return (s_end_ == itr); } + #ifndef exprtk_disable_comments inline bool is_comment_start(details::char_cptr itr) { - #ifndef exprtk_disable_comments const char_t c0 = *(itr + 0); const char_t c1 = *(itr + 1); @@ -2359,9 +2418,14 @@ namespace exprtk if (('/' == c0) && ('/' == c1)) return true; if (('/' == c0) && ('*' == c1)) return true; } - #endif return false; } + #else + inline bool is_comment_start(details::char_cptr) + { + return false; + } + #endif inline void skip_whitespace() { @@ -2637,6 +2701,7 @@ namespace exprtk { t.set_error(token::e_err_number, initial_itr, s_itr_, base_itr_); token_list_.push_back(t); + return; } @@ -2715,7 +2780,10 @@ namespace exprtk // $fdd(x,x,x) = at least 11 chars if (std::distance(s_itr_,s_end_) < 11) { - t.set_error(token::e_err_sfunc, initial_itr, s_itr_, base_itr_); + t.set_error( + token::e_err_sfunc, + initial_itr, std::min(initial_itr + 11, s_end_), + base_itr_); token_list_.push_back(t); return; @@ -2728,7 +2796,10 @@ namespace exprtk (details::is_digit(*(s_itr_ + 3)))) ) { - t.set_error(token::e_err_sfunc, initial_itr, s_itr_, base_itr_); + t.set_error( + token::e_err_sfunc, + initial_itr, std::min(initial_itr + 4, s_end_), + base_itr_); token_list_.push_back(t); return; @@ -2752,6 +2823,7 @@ namespace exprtk { t.set_error(token::e_err_string, s_itr_, s_end_, base_itr_); token_list_.push_back(t); + return; } @@ -2762,7 +2834,14 @@ namespace exprtk while (!is_end(s_itr_)) { - if (!escaped && ('\\' == *s_itr_)) + if (!details::is_valid_string_char(*s_itr_)) + { + t.set_error(token::e_err_string, initial_itr, s_itr_, base_itr_); + token_list_.push_back(t); + + return; + } + else if (!escaped && ('\\' == *s_itr_)) { escaped_found = true; escaped = true; @@ -2777,28 +2856,17 @@ namespace exprtk } else if (escaped) { - if (!is_end(s_itr_) && ('0' == *(s_itr_))) + if ( + !is_end(s_itr_) && ('0' == *(s_itr_)) && + ((s_itr_ + 4) <= s_end_) + ) { - /* - Note: The following 'awkward' conditional is - due to various broken msvc compilers. - */ - #if defined(_MSC_VER) && (_MSC_VER == 1600) - const bool within_range = !is_end(s_itr_ + 2) && - !is_end(s_itr_ + 3) ; - #else - const bool within_range = !is_end(s_itr_ + 1) && - !is_end(s_itr_ + 2) && - !is_end(s_itr_ + 3) ; - #endif - - const bool x_seperator = ('x' == *(s_itr_ + 1)) || - ('X' == *(s_itr_ + 1)) ; + const bool x_seperator = ('X' == std::toupper(*(s_itr_ + 1))); - const bool both_digits = details::is_hex_digit(*(s_itr_ + 2)) && - details::is_hex_digit(*(s_itr_ + 3)) ; + const bool both_digits = details::is_hex_digit(*(s_itr_ + 2)) && + details::is_hex_digit(*(s_itr_ + 3)) ; - if (!within_range || !x_seperator || !both_digits) + if (!(x_seperator && both_digits)) { t.set_error(token::e_err_string, initial_itr, s_itr_, base_itr_); token_list_.push_back(t); @@ -2829,7 +2897,13 @@ namespace exprtk { std::string parsed_string(initial_itr,s_itr_); - details::cleanup_escapes(parsed_string); + if (!details::cleanup_escapes(parsed_string)) + { + t.set_error(token::e_err_string, initial_itr, s_itr_, base_itr_); + token_list_.push_back(t); + + return; + } t.set_string( parsed_string, @@ -2845,10 +2919,10 @@ namespace exprtk private: - token_list_t token_list_; - token_list_itr_t token_itr_; - token_list_itr_t store_token_itr_; - token_t eof_token_; + token_list_t token_list_; + token_list_itr_t token_itr_; + token_list_itr_t store_token_itr_; + token_t eof_token_; details::char_cptr base_itr_; details::char_cptr s_itr_; details::char_cptr s_end_; @@ -2886,7 +2960,7 @@ namespace exprtk } } - inline std::size_t process(generator& g) + inline std::size_t process(generator& g) exprtk_override { if (g.token_list_.size() >= stride_) { @@ -2981,7 +3055,7 @@ namespace exprtk { public: - inline std::size_t process(generator& g) + inline std::size_t process(generator& g) exprtk_override { std::size_t changes = 0; @@ -3009,7 +3083,7 @@ namespace exprtk } } - inline std::size_t process(generator& g) + inline std::size_t process(generator& g) exprtk_override { if (g.token_list_.empty()) return 0; @@ -3018,6 +3092,10 @@ namespace exprtk std::size_t changes = 0; + typedef std::pair insert_t; + std::vector insert_list; + insert_list.reserve(10000); + for (std::size_t i = 0; i < (g.token_list_.size() - stride_ + 1); ++i) { int insert_index = -1; @@ -3041,17 +3119,36 @@ namespace exprtk break; } - typedef std::iterator_traits::difference_type diff_t; - if ((insert_index >= 0) && (insert_index <= (static_cast(stride_) + 1))) { - g.token_list_.insert( - g.token_list_.begin() + static_cast(i + static_cast(insert_index)), t); - + insert_list.push_back(insert_t(i, t)); changes++; } } + if (!insert_list.empty()) + { + generator::token_list_t token_list; + + std::size_t insert_index = 0; + + for (std::size_t i = 0; i < g.token_list_.size(); ++i) + { + token_list.push_back(g.token_list_[i]); + + if ( + (insert_index < insert_list.size()) && + (insert_list[insert_index].first == i) + ) + { + token_list.push_back(insert_list[insert_index].second); + insert_index++; + } + } + + std::swap(g.token_list_,token_list); + } + return changes; } @@ -3090,7 +3187,7 @@ namespace exprtk : stride_(stride) {} - inline std::size_t process(generator& g) + inline std::size_t process(generator& g) exprtk_override { if (g.token_list_.empty()) return 0; @@ -3110,59 +3207,86 @@ namespace exprtk inline std::size_t process_stride_2(generator& g) { - typedef std::iterator_traits::difference_type diff_t; - if (g.token_list_.size() < 2) return 0; std::size_t changes = 0; + generator::token_list_t token_list; + token_list.reserve(10000); + for (int i = 0; i < static_cast(g.token_list_.size() - 1); ++i) { token t; - while (join(g[i], g[i + 1], t)) + for ( ; ; ) { - g.token_list_[i] = t; + if (!join(g[i], g[i + 1], t)) + { + token_list.push_back(g[i]); + break; + } - g.token_list_.erase(g.token_list_.begin() + static_cast(i + 1)); + token_list.push_back(t); ++changes; - if (static_cast(i + 1) >= g.token_list_.size()) + i+=2; + + if (static_cast(i) >= (g.token_list_.size() - 1)) break; } } + token_list.push_back(g.token_list_.back()); + + assert(token_list.size() <= g.token_list_.size()); + + std::swap(token_list, g.token_list_); + return changes; } inline std::size_t process_stride_3(generator& g) { - typedef std::iterator_traits::difference_type diff_t; - if (g.token_list_.size() < 3) return 0; std::size_t changes = 0; + generator::token_list_t token_list; + token_list.reserve(10000); + for (int i = 0; i < static_cast(g.token_list_.size() - 2); ++i) { token t; - while (join(g[i], g[i + 1], g[i + 2], t)) + for ( ; ; ) { - g.token_list_[i] = t; + if (!join(g[i], g[i + 1], g[i + 2], t)) + { + token_list.push_back(g[i]); + break; + } + + token_list.push_back(t); - g.token_list_.erase(g.token_list_.begin() + static_cast(i + 1), - g.token_list_.begin() + static_cast(i + 3)); ++changes; - if (static_cast(i + 2) >= g.token_list_.size()) + i+=3; + + if (static_cast(i) >= (g.token_list_.size() - 2)) break; } } + token_list.push_back(*(g.token_list_.begin() + g.token_list_.size() - 2)); + token_list.push_back(*(g.token_list_.begin() + g.token_list_.size() - 1)); + + assert(token_list.size() <= g.token_list_.size()); + + std::swap(token_list, g.token_list_); + return changes; } @@ -3172,11 +3296,11 @@ namespace exprtk namespace helper { - inline void dump(lexer::generator& generator) + inline void dump(const lexer::generator& generator) { for (std::size_t i = 0; i < generator.size(); ++i) { - lexer::token t = generator[i]; + const lexer::token& t = generator[i]; printf("Token[%02d] @ %03d %6s --> '%s'\n", static_cast(i), static_cast(t.position), @@ -3339,7 +3463,7 @@ namespace exprtk return true; } // '! =' --> '!=' - else if ((static_cast(t0.type) == '!') && (t1.type == lexer::token::e_eq)) + else if ((static_cast(t0.type) == '!') && (t1.type == lexer::token::e_eq)) { t.type = lexer::token::e_ne; t.value = "!="; @@ -3400,7 +3524,10 @@ namespace exprtk return false; } - inline bool join(const lexer::token& t0, const lexer::token& t1, const lexer::token& t2, lexer::token& t) + inline bool join(const lexer::token& t0, + const lexer::token& t1, + const lexer::token& t2, + lexer::token& t) { // '[ * ]' --> '[*]' if ( @@ -3427,8 +3554,8 @@ namespace exprtk using lexer::token_scanner::operator(); bracket_checker() - : token_scanner(1), - state_(true) + : token_scanner(1) + , state_(true) {} bool result() @@ -3512,8 +3639,8 @@ namespace exprtk using lexer::token_scanner::operator(); numeric_checker() - : token_scanner (1), - current_index_(0) + : token_scanner (1) + , current_index_(0) {} bool result() @@ -3720,12 +3847,12 @@ namespace exprtk private: - void add_invalid(lexer::token::token_type base, lexer::token::token_type t) + void add_invalid(const lexer::token::token_type base, const lexer::token::token_type t) { invalid_comb_.insert(std::make_pair(base,t)); } - void add_invalid_set1(lexer::token::token_type t) + void add_invalid_set1(const lexer::token::token_type t) { add_invalid(t, lexer::token::e_assign); add_invalid(t, lexer::token::e_shr ); @@ -3744,9 +3871,9 @@ namespace exprtk add_invalid(t, lexer::token::e_colon ); } - bool invalid_bracket_check(lexer::token::token_type base, lexer::token::token_type t) + bool invalid_bracket_check(const lexer::token::token_type base, const lexer::token::token_type t) { - if (details::is_right_bracket(static_cast(base))) + if (details::is_right_bracket(static_cast(base))) { switch (t) { @@ -3755,11 +3882,11 @@ namespace exprtk default : return false; } } - else if (details::is_left_bracket(static_cast(base))) + else if (details::is_left_bracket(static_cast(base))) { - if (details::is_right_bracket(static_cast(t))) + if (details::is_right_bracket(static_cast(t))) return false; - else if (details::is_left_bracket(static_cast(t))) + else if (details::is_left_bracket(static_cast(t))) return false; else { @@ -3776,7 +3903,7 @@ namespace exprtk } } } - else if (details::is_right_bracket(static_cast(t))) + else if (details::is_right_bracket(static_cast(t))) { switch (base) { @@ -3789,7 +3916,7 @@ namespace exprtk default : return true ; } } - else if (details::is_left_bracket(static_cast(t))) + else if (details::is_left_bracket(static_cast(t))) { switch (base) { @@ -3822,23 +3949,23 @@ namespace exprtk sequence_validator_3tokens() : lexer::token_scanner(3) { - add_invalid(lexer::token::e_number, lexer::token::e_number, lexer::token::e_number); - add_invalid(lexer::token::e_string, lexer::token::e_string, lexer::token::e_string); - add_invalid(lexer::token::e_comma , lexer::token::e_comma , lexer::token::e_comma ); + add_invalid(lexer::token::e_number , lexer::token::e_number , lexer::token::e_number); + add_invalid(lexer::token::e_string , lexer::token::e_string , lexer::token::e_string); + add_invalid(lexer::token::e_comma , lexer::token::e_comma , lexer::token::e_comma ); - add_invalid(lexer::token::e_add , lexer::token::e_add , lexer::token::e_add ); - add_invalid(lexer::token::e_sub , lexer::token::e_sub , lexer::token::e_sub ); - add_invalid(lexer::token::e_div , lexer::token::e_div , lexer::token::e_div ); - add_invalid(lexer::token::e_mul , lexer::token::e_mul , lexer::token::e_mul ); - add_invalid(lexer::token::e_mod , lexer::token::e_mod , lexer::token::e_mod ); - add_invalid(lexer::token::e_pow , lexer::token::e_pow , lexer::token::e_pow ); + add_invalid(lexer::token::e_add , lexer::token::e_add , lexer::token::e_add ); + add_invalid(lexer::token::e_sub , lexer::token::e_sub , lexer::token::e_sub ); + add_invalid(lexer::token::e_div , lexer::token::e_div , lexer::token::e_div ); + add_invalid(lexer::token::e_mul , lexer::token::e_mul , lexer::token::e_mul ); + add_invalid(lexer::token::e_mod , lexer::token::e_mod , lexer::token::e_mod ); + add_invalid(lexer::token::e_pow , lexer::token::e_pow , lexer::token::e_pow ); - add_invalid(lexer::token::e_add , lexer::token::e_sub , lexer::token::e_add ); - add_invalid(lexer::token::e_sub , lexer::token::e_add , lexer::token::e_sub ); - add_invalid(lexer::token::e_div , lexer::token::e_mul , lexer::token::e_div ); - add_invalid(lexer::token::e_mul , lexer::token::e_div , lexer::token::e_mul ); - add_invalid(lexer::token::e_mod , lexer::token::e_pow , lexer::token::e_mod ); - add_invalid(lexer::token::e_pow , lexer::token::e_mod , lexer::token::e_pow ); + add_invalid(lexer::token::e_add , lexer::token::e_sub , lexer::token::e_add ); + add_invalid(lexer::token::e_sub , lexer::token::e_add , lexer::token::e_sub ); + add_invalid(lexer::token::e_div , lexer::token::e_mul , lexer::token::e_div ); + add_invalid(lexer::token::e_mul , lexer::token::e_div , lexer::token::e_mul ); + add_invalid(lexer::token::e_mod , lexer::token::e_pow , lexer::token::e_mod ); + add_invalid(lexer::token::e_pow , lexer::token::e_mod , lexer::token::e_pow ); } bool result() @@ -3883,7 +4010,7 @@ namespace exprtk private: - void add_invalid(token_t t0, token_t t1, token_t t2) + void add_invalid(const token_t t0, const token_t t1, const token_t t2) { invalid_comb_.insert(std::make_pair(t0,std::make_pair(t1,t2))); } @@ -4054,7 +4181,7 @@ namespace exprtk { public: - typedef token token_t; + typedef token token_t; typedef generator generator_t; inline bool init(const std::string& str) @@ -4172,15 +4299,15 @@ namespace exprtk typedef T* data_ptr_t; vector_view(data_ptr_t data, const std::size_t& size) - : size_(size), - data_(data), - data_ref_(0) + : size_(size) + , data_(data) + , data_ref_(0) {} vector_view(const vector_view& vv) - : size_(vv.size_), - data_(vv.data_), - data_ref_(0) + : size_(vv.size_) + , data_(vv.data_) + , data_ref_(0) {} inline void rebase(data_ptr_t data) @@ -4232,14 +4359,14 @@ namespace exprtk inline vector_view make_vector_view(T* data, const std::size_t size, const std::size_t offset = 0) { - return vector_view(data + offset,size); + return vector_view(data + offset, size); } template inline vector_view make_vector_view(std::vector& v, const std::size_t size, const std::size_t offset = 0) { - return vector_view(v.data() + offset,size); + return vector_view(v.data() + offset, size); } template class results_context; @@ -4256,15 +4383,15 @@ namespace exprtk }; type_store() - : data(0), - size(0), - type(e_unknown) + : data(0) + , size(0) + , type(e_unknown) {} union { - void* data; - T* vec_data; + void* data; + T* vec_data; }; std::size_t size; @@ -4274,7 +4401,7 @@ namespace exprtk { public: - parameter_list(std::vector& pl) + explicit parameter_list(std::vector& pl) : parameter_list_(pl) {} @@ -4331,14 +4458,14 @@ namespace exprtk typedef type_store type_store_t; typedef ViewType value_t; - type_view(type_store_t& ts) - : ts_(ts), - data_(reinterpret_cast(ts_.data)) + explicit type_view(type_store_t& ts) + : ts_(ts) + , data_(reinterpret_cast(ts_.data)) {} - type_view(const type_store_t& ts) - : ts_(const_cast(ts)), - data_(reinterpret_cast(ts_.data)) + explicit type_view(const type_store_t& ts) + : ts_(const_cast(ts)) + , data_(reinterpret_cast(ts_.data)) {} inline std::size_t size() const @@ -4381,11 +4508,11 @@ namespace exprtk typedef type_store type_store_t; typedef T value_t; - scalar_view(type_store_t& ts) + explicit scalar_view(type_store_t& ts) : v_(*reinterpret_cast(ts.data)) {} - scalar_view(const type_store_t& ts) + explicit scalar_view(const type_store_t& ts) : v_(*reinterpret_cast(const_cast(ts).data)) {} @@ -4573,35 +4700,41 @@ namespace exprtk { switch (opr) { - case e_add : return "+"; - case e_sub : return "-"; - case e_mul : return "*"; - case e_div : return "/"; - case e_mod : return "%"; - case e_pow : return "^"; - case e_assign : return ":="; - case e_addass : return "+="; - case e_subass : return "-="; - case e_mulass : return "*="; - case e_divass : return "/="; - case e_modass : return "%="; - case e_lt : return "<"; - case e_lte : return "<="; - case e_eq : return "=="; - case e_equal : return "="; - case e_ne : return "!="; - case e_nequal : return "<>"; - case e_gte : return ">="; - case e_gt : return ">"; - default : return"N/A"; + case e_add : return "+" ; + case e_sub : return "-" ; + case e_mul : return "*" ; + case e_div : return "/" ; + case e_mod : return "%" ; + case e_pow : return "^" ; + case e_assign : return ":=" ; + case e_addass : return "+=" ; + case e_subass : return "-=" ; + case e_mulass : return "*=" ; + case e_divass : return "/=" ; + case e_modass : return "%=" ; + case e_lt : return "<" ; + case e_lte : return "<=" ; + case e_eq : return "==" ; + case e_equal : return "=" ; + case e_ne : return "!=" ; + case e_nequal : return "<>" ; + case e_gte : return ">=" ; + case e_gt : return ">" ; + case e_and : return "and" ; + case e_or : return "or" ; + case e_xor : return "xor" ; + case e_nand : return "nand"; + case e_nor : return "nor" ; + case e_xnor : return "xnor"; + default : return "N/A" ; } } struct base_operation_t { base_operation_t(const operator_type t, const unsigned int& np) - : type(t), - num_params(np) + : type(t) + , num_params(np) {} operator_type type; @@ -4618,15 +4751,15 @@ namespace exprtk struct details { - details(const std::size_t& vsize, - const unsigned int loop_batch_size = global_loop_batch_size) - : batch_size(loop_batch_size ), - remainder (vsize % batch_size), - upper_bound(static_cast(vsize - (remainder ? loop_batch_size : 0))) + explicit details(const std::size_t& vsize, + const unsigned int loop_batch_size = global_loop_batch_size) + : batch_size(loop_batch_size ) + , remainder (vsize % batch_size) + , upper_bound(static_cast(vsize - (remainder ? loop_batch_size : 0))) {} unsigned int batch_size; - int remainder; + int remainder; int upper_bound; }; } @@ -4660,24 +4793,24 @@ namespace exprtk struct control_block { control_block() - : ref_count(1), - size (0), - data (0), - destruct (true) + : ref_count(1) + , size (0) + , data (0) + , destruct (true) {} - control_block(const std::size_t& dsize) - : ref_count(1 ), - size (dsize), - data (0 ), - destruct (true ) + explicit control_block(const std::size_t& dsize) + : ref_count(1 ) + , size (dsize) + , data (0 ) + , destruct (true ) { create_data(); } control_block(const std::size_t& dsize, data_t dptr, bool dstrct = false) - : ref_count(1 ), - size (dsize ), - data (dptr ), - destruct (dstrct) + : ref_count(1 ) + , size (dsize ) + , data (dptr ) + , destruct (dstrct) {} ~control_block() @@ -4733,8 +4866,8 @@ namespace exprtk { destruct = true; data = new T[size]; - std::fill_n(data,size,T(0)); - dump_ptr("control_block::create_data() - data",data,size); + std::fill_n(data, size, T(0)); + dump_ptr("control_block::create_data() - data", data, size); } }; @@ -4744,8 +4877,8 @@ namespace exprtk : control_block_(control_block::create(0)) {} - vec_data_store(const std::size_t& size) - : control_block_(control_block::create(size,(data_t)(0),true)) + explicit vec_data_store(const std::size_t& size) + : control_block_(control_block::create(size,reinterpret_cast(0),true)) {} vec_data_store(const std::size_t& size, data_t data, bool dstrct = false) @@ -4830,7 +4963,7 @@ namespace exprtk static inline void match_sizes(type& vds0, type& vds1) { - std::size_t size = min_size(vds0.control_block_,vds1.control_block_); + const std::size_t size = min_size(vds0.control_block_,vds1.control_block_); vds0.control_block_->size = size; vds1.control_block_->size = size; } @@ -4998,8 +5131,24 @@ namespace exprtk } } + template + struct node_collector_interface + { + typedef Node* node_ptr_t; + typedef Node** node_pp_t; + typedef std::vector noderef_list_t; + + virtual ~node_collector_interface() {} + + virtual void collect_nodes(noderef_list_t&) {} + }; + + template + struct node_depth_base; + template - class expression_node + class expression_node : public node_collector_interface >, + public node_depth_base > { public: @@ -5040,12 +5189,15 @@ namespace exprtk e_vecdefass , e_vecvalass , e_vecvecass , e_vecopvalass , e_vecopvecass , e_vecfunc , e_vecvecswap , e_vecvecineq , e_vecvalineq , e_valvecineq , e_vecvecarith , e_vecvalarith , - e_valvecarith , e_vecunaryop , e_break , e_continue , - e_swap + e_valvecarith , e_vecunaryop , e_vecondition , e_break , + e_continue , e_swap }; typedef T value_type; typedef expression_node* expression_ptr; + typedef node_collector_interface > nci_t; + typedef typename nci_t::noderef_list_t noderef_list_t; + typedef node_depth_base > ndb_t; virtual ~expression_node() {} @@ -5096,12 +5248,24 @@ namespace exprtk return std::not_equal_to()(T(0),node->value()); } + template + inline bool is_true(const std::pair*,bool>& node) + { + return std::not_equal_to()(T(0),node.first->value()); + } + template inline bool is_false(const expression_node* node) { return std::equal_to()(T(0),node->value()); } + template + inline bool is_false(const std::pair*,bool>& node) + { + return std::equal_to()(T(0),node.first->value()); + } + template inline bool is_unary_node(const expression_node* node) { @@ -5178,7 +5342,8 @@ namespace exprtk case details::expression_node::e_vecvecarith : case details::expression_node::e_vecvalarith : case details::expression_node::e_valvecarith : - case details::expression_node::e_vecunaryop : return true; + case details::expression_node::e_vecunaryop : + case details::expression_node::e_vecondition : return true; default : return false; } } @@ -5244,7 +5409,8 @@ namespace exprtk template inline bool branch_deletable(expression_node* node) { - return !is_variable_node(node) && + return (0 != node) && + !is_variable_node(node) && !is_string_node (node) ; } @@ -5302,6 +5468,76 @@ namespace exprtk return true; } + template + class node_collection_destructor + { + public: + + typedef node_collector_interface nci_t; + + typedef typename nci_t::node_ptr_t node_ptr_t; + typedef typename nci_t::node_pp_t node_pp_t; + typedef typename nci_t::noderef_list_t noderef_list_t; + + static void delete_nodes(node_ptr_t& root) + { + std::vector node_delete_list; + node_delete_list.reserve(1000); + + collect_nodes(root, node_delete_list); + + for (std::size_t i = 0; i < node_delete_list.size(); ++i) + { + node_ptr_t& node = *node_delete_list[i]; + exprtk_debug(("ncd::delete_nodes() - deleting: %p\n", static_cast(node))); + delete node; + node = reinterpret_cast(0); + } + } + + private: + + static void collect_nodes(node_ptr_t& root, noderef_list_t& node_delete_list) + { + std::deque node_list; + node_list.push_back(root); + node_delete_list.push_back(&root); + + noderef_list_t child_node_delete_list; + child_node_delete_list.reserve(1000); + + while (!node_list.empty()) + { + node_list.front()->collect_nodes(child_node_delete_list); + + if (!child_node_delete_list.empty()) + { + for (std::size_t i = 0; i < child_node_delete_list.size(); ++i) + { + node_pp_t& node = child_node_delete_list[i]; + + if (0 == (*node)) + { + exprtk_debug(("ncd::collect_nodes() - null node encountered.\n")); + } + + node_list.push_back(*node); + } + + node_delete_list.insert( + node_delete_list.end(), + child_node_delete_list.begin(), child_node_delete_list.end()); + + child_node_delete_list.clear(); + } + + node_list.pop_front(); + } + + std::reverse(node_delete_list.begin(), node_delete_list.end()); + } + }; + template inline void free_all_nodes(NodeAllocator& node_allocator, expression_node* (&b)[N]) { @@ -5326,28 +5562,242 @@ namespace exprtk } template - inline void free_node(NodeAllocator& node_allocator, expression_node*& node, const bool force_delete = false) + inline void free_node(NodeAllocator&, expression_node*& node) { - if (0 != node) + if ((0 == node) || is_variable_node(node) || is_string_node(node)) { - if ( - (is_variable_node(node) || is_string_node(node)) || - force_delete - ) - return; - - node_allocator.free(node); - node = reinterpret_cast*>(0); + return; } + + node_collection_destructor > + ::delete_nodes(node); } template inline void destroy_node(expression_node*& node) { - delete node; - node = reinterpret_cast*>(0); + if (0 != node) + { + node_collection_destructor > + ::delete_nodes(node); + } } + template + struct node_depth_base + { + typedef Node* node_ptr_t; + typedef std::pair nb_pair_t; + + node_depth_base() + : depth_set(false) + , depth(0) + {} + + virtual ~node_depth_base() {} + + virtual std::size_t node_depth() const { return 1; } + + std::size_t compute_node_depth(const Node* const& node) const + { + if (!depth_set) + { + depth = 1 + (node ? node->node_depth() : 0); + depth_set = true; + } + + return depth; + } + + std::size_t compute_node_depth(const nb_pair_t& branch) const + { + if (!depth_set) + { + depth = 1 + (branch.first ? branch.first->node_depth() : 0); + depth_set = true; + } + + return depth; + } + + template + std::size_t compute_node_depth(const nb_pair_t (&branch)[N]) const + { + if (!depth_set) + { + depth = 0; + for (std::size_t i = 0; i < N; ++i) + { + if (branch[i].first) + { + depth = std::max(depth,branch[i].first->node_depth()); + } + } + depth += 1; + depth_set = true; + } + + return depth; + } + + template + std::size_t compute_node_depth(const BranchType& n0, const BranchType& n1) const + { + if (!depth_set) + { + depth = 1 + std::max(compute_node_depth(n0), compute_node_depth(n1)); + depth_set = true; + } + + return depth; + } + + template + std::size_t compute_node_depth(const BranchType& n0, const BranchType& n1, + const BranchType& n2) const + { + if (!depth_set) + { + depth = 1 + std::max( + std::max(compute_node_depth(n0), compute_node_depth(n1)), + compute_node_depth(n2)); + depth_set = true; + } + + return depth; + } + + template + std::size_t compute_node_depth(const BranchType& n0, const BranchType& n1, + const BranchType& n2, const BranchType& n3) const + { + if (!depth_set) + { + depth = 1 + std::max( + std::max(compute_node_depth(n0), compute_node_depth(n1)), + std::max(compute_node_depth(n2), compute_node_depth(n3))); + depth_set = true; + } + + return depth; + } + + template class Sequence> + std::size_t compute_node_depth(const Sequence& branch_list) const + { + if (!depth_set) + { + for (std::size_t i = 0; i < branch_list.size(); ++i) + { + if (branch_list[i]) + { + depth = std::max(depth, compute_node_depth(branch_list[i])); + } + } + depth_set = true; + } + + return depth; + } + + template class Sequence> + std::size_t compute_node_depth(const Sequence& branch_list) const + { + if (!depth_set) + { + for (std::size_t i = 0; i < branch_list.size(); ++i) + { + if (branch_list[i].first) + { + depth = std::max(depth, compute_node_depth(branch_list[i].first)); + } + } + depth_set = true; + } + + return depth; + } + + mutable bool depth_set; + mutable std::size_t depth; + + template + void collect(node_ptr_t const& node, + const bool deletable, + NodeSequence& delete_node_list) const + { + if ((0 != node) && deletable) + { + delete_node_list.push_back(const_cast(&node)); + } + } + + template + void collect(const nb_pair_t& branch, + NodeSequence& delete_node_list) const + { + collect(branch.first, branch.second, delete_node_list); + } + + template + void collect(Node*& node, + NodeSequence& delete_node_list) const + { + collect(node, branch_deletable(node), delete_node_list); + } + + template + void collect(const nb_pair_t(&branch)[N], + NodeSequence& delete_node_list) const + { + for (std::size_t i = 0; i < N; ++i) + { + collect(branch[i].first, branch[i].second, delete_node_list); + } + } + + template class Sequence, + typename NodeSequence> + void collect(const Sequence& branch, + NodeSequence& delete_node_list) const + { + for (std::size_t i = 0; i < branch.size(); ++i) + { + collect(branch[i].first, branch[i].second, delete_node_list); + } + } + + template class Sequence, + typename NodeSequence> + void collect(const Sequence& branch_list, + NodeSequence& delete_node_list) const + { + for (std::size_t i = 0; i < branch_list.size(); ++i) + { + collect(branch_list[i], branch_deletable(branch_list[i]), delete_node_list); + } + } + + template class Sequence, + typename NodeSequence> + void collect(const Sequence& branch_list, + const Sequence& branch_deletable_list, + NodeSequence& delete_node_list) const + { + for (std::size_t i = 0; i < branch_list.size(); ++i) + { + collect(branch_list[i], branch_deletable_list[i], delete_node_list); + } + } + }; + template class vector_holder { @@ -5396,8 +5846,8 @@ namespace exprtk public: array_vector_impl(const Type* vec, const std::size_t& vec_size) - : vec_(vec), - size_(vec_size) + : vec_(vec) + , size_(vec_size) {} protected: @@ -5546,7 +5996,7 @@ namespace exprtk }; template - class null_node : public expression_node + class null_node exprtk_final : public expression_node { public: @@ -5561,30 +6011,70 @@ namespace exprtk } }; + template + inline void construct_branch_pair(std::pair*,bool> (&branch)[N], + expression_node* b, + const std::size_t& index) + { + if (b && (index < N)) + { + branch[index] = std::make_pair(b,branch_deletable(b)); + } + } + template - class null_eq_node : public expression_node + inline void construct_branch_pair(std::pair*,bool>& branch, expression_node* b) + { + if (b) + { + branch = std::make_pair(b,branch_deletable(b)); + } + } + + template + inline void init_branches(std::pair*,bool> (&branch)[N], + expression_node* b0, + expression_node* b1 = reinterpret_cast*>(0), + expression_node* b2 = reinterpret_cast*>(0), + expression_node* b3 = reinterpret_cast*>(0), + expression_node* b4 = reinterpret_cast*>(0), + expression_node* b5 = reinterpret_cast*>(0), + expression_node* b6 = reinterpret_cast*>(0), + expression_node* b7 = reinterpret_cast*>(0), + expression_node* b8 = reinterpret_cast*>(0), + expression_node* b9 = reinterpret_cast*>(0)) + { + construct_branch_pair(branch, b0, 0); + construct_branch_pair(branch, b1, 1); + construct_branch_pair(branch, b2, 2); + construct_branch_pair(branch, b3, 3); + construct_branch_pair(branch, b4, 4); + construct_branch_pair(branch, b5, 5); + construct_branch_pair(branch, b6, 6); + construct_branch_pair(branch, b7, 7); + construct_branch_pair(branch, b8, 8); + construct_branch_pair(branch, b9, 9); + } + + template + class null_eq_node exprtk_final : public expression_node { public: typedef expression_node* expression_ptr; + typedef std::pair branch_t; - null_eq_node(expression_ptr brnch, const bool equality = true) - : branch_(brnch), - branch_deletable_(branch_deletable(branch_)), - equality_(equality) - {} - - ~null_eq_node() + explicit null_eq_node(expression_ptr branch, const bool equality = true) + : equality_(equality) { - if (branch_ && branch_deletable_) - { - destroy_node(branch_); - } + construct_branch_pair(branch_, branch); } inline T value() const { - const T v = branch_->value(); + assert(branch_.first); + + const T v = branch_.first->value(); const bool result = details::numeric::is_nan(v); if (result) @@ -5605,18 +6095,27 @@ namespace exprtk inline expression_node* branch(const std::size_t&) const { - return branch_; + return branch_.first; + } + + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::collect(branch_, node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth(branch_); } private: - expression_ptr branch_; - const bool branch_deletable_; bool equality_; + branch_t branch_; }; template - class literal_node : public expression_node + class literal_node exprtk_final : public expression_node { public: @@ -5687,7 +6186,8 @@ namespace exprtk }; template - class string_literal_node : public expression_node , + class string_literal_node exprtk_final + : public expression_node , public string_base_node, public range_interface { @@ -5760,25 +6260,19 @@ namespace exprtk public: typedef expression_node* expression_ptr; + typedef std::pair branch_t; - unary_node(const operator_type& opr, - expression_ptr brnch) - : operation_(opr), - branch_(brnch), - branch_deletable_(branch_deletable(branch_)) - {} - - ~unary_node() + unary_node(const operator_type& opr, expression_ptr branch) + : operation_(opr) { - if (branch_ && branch_deletable_) - { - destroy_node(branch_); - } + construct_branch_pair(branch_,branch); } inline T value() const { - const T arg = branch_->value(); + assert(branch_.first); + + const T arg = branch_.first->value(); return numeric::process(operation_,arg); } @@ -5795,94 +6289,28 @@ namespace exprtk inline expression_node* branch(const std::size_t&) const { - return branch_; + return branch_.first; } inline void release() { - branch_deletable_ = false; + branch_.second = false; } - protected: - - operator_type operation_; - expression_ptr branch_; - bool branch_deletable_; - }; - - template - struct construct_branch_pair - { - template - static inline void process(std::pair*,bool> (&)[N], expression_node*) - {} - }; - - template - struct construct_branch_pair - { - template - static inline void process(std::pair*,bool> (&branch)[N], expression_node* b) + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) { - if (b) - { - branch[D] = std::make_pair(b,branch_deletable(b)); - } + expression_node::ndb_t::collect(branch_, node_delete_list); } - }; - template - inline void init_branches(std::pair*,bool> (&branch)[N], - expression_node* b0, - expression_node* b1 = reinterpret_cast*>(0), - expression_node* b2 = reinterpret_cast*>(0), - expression_node* b3 = reinterpret_cast*>(0), - expression_node* b4 = reinterpret_cast*>(0), - expression_node* b5 = reinterpret_cast*>(0), - expression_node* b6 = reinterpret_cast*>(0), - expression_node* b7 = reinterpret_cast*>(0), - expression_node* b8 = reinterpret_cast*>(0), - expression_node* b9 = reinterpret_cast*>(0)) - { - construct_branch_pair 0)>::process(branch,b0); - construct_branch_pair 1)>::process(branch,b1); - construct_branch_pair 2)>::process(branch,b2); - construct_branch_pair 3)>::process(branch,b3); - construct_branch_pair 4)>::process(branch,b4); - construct_branch_pair 5)>::process(branch,b5); - construct_branch_pair 6)>::process(branch,b6); - construct_branch_pair 7)>::process(branch,b7); - construct_branch_pair 8)>::process(branch,b8); - construct_branch_pair 9)>::process(branch,b9); - } - - struct cleanup_branches - { - template - static inline void execute(std::pair*,bool> (&branch)[N]) + std::size_t node_depth() const exprtk_final { - for (std::size_t i = 0; i < N; ++i) - { - if (branch[i].first && branch[i].second) - { - destroy_node(branch[i].first); - } - } + return expression_node::ndb_t::compute_node_depth(branch_); } - template class Sequence> - static inline void execute(Sequence*,bool>,Allocator>& branch) - { - for (std::size_t i = 0; i < branch.size(); ++i) - { - if (branch[i].first && branch[i].second) - { - destroy_node(branch[i].first); - } - } - } + protected: + + operator_type operation_; + branch_t branch_; }; template @@ -5901,13 +6329,11 @@ namespace exprtk init_branches<2>(branch_, branch0, branch1); } - ~binary_node() - { - cleanup_branches::execute(branch_); - } - inline T value() const { + assert(branch_[0].first); + assert(branch_[1].first); + const T arg0 = branch_[0].first->value(); const T arg1 = branch_[1].first->value(); @@ -5934,6 +6360,16 @@ namespace exprtk return reinterpret_cast(0); } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::template collect(branch_, node_delete_list); + } + + std::size_t node_depth() const exprtk_final + { + return expression_node::ndb_t::template compute_node_depth<2>(branch_); + } + protected: operator_type operation_; @@ -5941,7 +6377,7 @@ namespace exprtk }; template - class binary_ext_node : public expression_node + class binary_ext_node exprtk_final : public expression_node { public: @@ -5953,13 +6389,11 @@ namespace exprtk init_branches<2>(branch_, branch0, branch1); } - ~binary_ext_node() - { - cleanup_branches::execute(branch_); - } - inline T value() const { + assert(branch_[0].first); + assert(branch_[1].first); + const T arg0 = branch_[0].first->value(); const T arg1 = branch_[1].first->value(); @@ -5986,6 +6420,16 @@ namespace exprtk return reinterpret_cast(0); } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::template collect(branch_, node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::template compute_node_depth<2>(branch_); + } + protected: branch_t branch_[2]; @@ -6008,13 +6452,12 @@ namespace exprtk init_branches<3>(branch_, branch0, branch1, branch2); } - ~trinary_node() - { - cleanup_branches::execute(branch_); - } - inline T value() const { + assert(branch_[0].first); + assert(branch_[1].first); + assert(branch_[2].first); + const T arg0 = branch_[0].first->value(); const T arg1 = branch_[1].first->value(); const T arg2 = branch_[2].first->value(); @@ -6040,6 +6483,16 @@ namespace exprtk return expression_node::e_trinary; } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::template collect(branch_, node_delete_list); + } + + std::size_t node_depth() const exprtk_final + { + return expression_node::ndb_t::template compute_node_depth<3>(branch_); + } + protected: operator_type operation_; @@ -6064,11 +6517,6 @@ namespace exprtk init_branches<4>(branch_, branch0, branch1, branch2, branch3); } - ~quaternary_node() - { - cleanup_branches::execute(branch_); - } - inline T value() const { return std::numeric_limits::quiet_NaN(); @@ -6079,6 +6527,16 @@ namespace exprtk return expression_node::e_quaternary; } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::template collect(branch_, node_delete_list); + } + + std::size_t node_depth() const exprtk_final + { + return expression_node::ndb_t::template compute_node_depth<4>(branch_); + } + protected: operator_type operation_; @@ -6086,47 +6544,32 @@ namespace exprtk }; template - class conditional_node : public expression_node + class conditional_node exprtk_final : public expression_node { public: typedef expression_node* expression_ptr; + typedef std::pair branch_t; - conditional_node(expression_ptr test, + conditional_node(expression_ptr condition, expression_ptr consequent, expression_ptr alternative) - : test_(test), - consequent_(consequent), - alternative_(alternative), - test_deletable_(branch_deletable(test_)), - consequent_deletable_(branch_deletable(consequent_)), - alternative_deletable_(branch_deletable(alternative_)) - {} - - ~conditional_node() { - if (test_ && test_deletable_) - { - destroy_node(test_); - } - - if (consequent_ && consequent_deletable_ ) - { - destroy_node(consequent_); - } - - if (alternative_ && alternative_deletable_) - { - destroy_node(alternative_); - } + construct_branch_pair(condition_ , condition ); + construct_branch_pair(consequent_ , consequent ); + construct_branch_pair(alternative_, alternative); } inline T value() const { - if (is_true(test_)) - return consequent_->value(); + assert(condition_ .first); + assert(consequent_ .first); + assert(alternative_.first); + + if (is_true(condition_)) + return consequent_.first->value(); else - return alternative_->value(); + return alternative_.first->value(); } inline typename expression_node::node_type type() const @@ -6134,49 +6577,49 @@ namespace exprtk return expression_node::e_conditional; } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::collect(condition_ , node_delete_list); + expression_node::ndb_t::collect(consequent_ , node_delete_list); + expression_node::ndb_t::collect(alternative_ , node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth + (condition_, consequent_, alternative_); + } + private: - expression_ptr test_; - expression_ptr consequent_; - expression_ptr alternative_; - const bool test_deletable_; - const bool consequent_deletable_; - const bool alternative_deletable_; + branch_t condition_; + branch_t consequent_; + branch_t alternative_; }; template - class cons_conditional_node : public expression_node + class cons_conditional_node exprtk_final : public expression_node { public: // Consequent only conditional statement node typedef expression_node* expression_ptr; + typedef std::pair branch_t; - cons_conditional_node(expression_ptr test, + cons_conditional_node(expression_ptr condition, expression_ptr consequent) - : test_(test), - consequent_(consequent), - test_deletable_(branch_deletable(test_)), - consequent_deletable_(branch_deletable(consequent_)) - {} - - ~cons_conditional_node() { - if (test_ && test_deletable_) - { - destroy_node(test_); - } - - if (consequent_ && consequent_deletable_) - { - destroy_node(consequent_); - } + construct_branch_pair(condition_ , condition ); + construct_branch_pair(consequent_, consequent); } inline T value() const { - if (is_true(test_)) - return consequent_->value(); + assert(condition_ .first); + assert(consequent_.first); + + if (is_true(condition_)) + return consequent_.first->value(); else return std::numeric_limits::quiet_NaN(); } @@ -6186,12 +6629,22 @@ namespace exprtk return expression_node::e_conditional; } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::collect(condition_ , node_delete_list); + expression_node::ndb_t::collect(consequent_ , node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t:: + compute_node_depth(condition_, consequent_); + } + private: - expression_ptr test_; - expression_ptr consequent_; - const bool test_deletable_; - const bool consequent_deletable_; + branch_t condition_; + branch_t consequent_; }; #ifndef exprtk_disable_break_continue @@ -6200,7 +6653,7 @@ namespace exprtk { public: - break_exception(const T& v) + explicit break_exception(const T& v) : value(v) {} @@ -6211,28 +6664,26 @@ namespace exprtk {}; template - class break_node : public expression_node + class break_node exprtk_final : public expression_node { public: typedef expression_node* expression_ptr; + typedef std::pair branch_t; break_node(expression_ptr ret = expression_ptr(0)) - : return_(ret), - return_deletable_(branch_deletable(return_)) - {} - - ~break_node() { - if (return_deletable_) - { - destroy_node(return_); - } + construct_branch_pair(return_, ret); } inline T value() const { - throw break_exception(return_ ? return_->value() : std::numeric_limits::quiet_NaN()); + const T result = return_.first ? + return_.first->value() : + std::numeric_limits::quiet_NaN(); + + throw break_exception(result); + #ifndef _MSC_VER return std::numeric_limits::quiet_NaN(); #endif @@ -6243,14 +6694,23 @@ namespace exprtk return expression_node::e_break; } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::collect(return_, node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth(return_); + } + private: - expression_ptr return_; - const bool return_deletable_; + branch_t return_; }; template - class continue_node : public expression_node + class continue_node exprtk_final : public expression_node { public: @@ -6269,40 +6729,91 @@ namespace exprtk }; #endif - template - class while_loop_node : public expression_node + #ifdef exprtk_enable_runtime_checks + struct loop_runtime_checker { - public: - - typedef expression_node* expression_ptr; - - while_loop_node(expression_ptr condition, expression_ptr loop_body) - : condition_(condition), - loop_body_(loop_body), - condition_deletable_(branch_deletable(condition_)), - loop_body_deletable_(branch_deletable(loop_body_)) + loop_runtime_checker(loop_runtime_check_ptr loop_rt_chk = loop_runtime_check_ptr(0), + loop_runtime_check::loop_types lp_typ = loop_runtime_check::e_invalid) + : iteration_count_(0) + , loop_runtime_check_(loop_rt_chk) + , loop_type(lp_typ) {} - ~while_loop_node() + inline void reset(const _uint64_t initial_value = 0) const { - if (condition_ && condition_deletable_) - { - destroy_node(condition_); - } + iteration_count_ = initial_value; + } - if (loop_body_ && loop_body_deletable_) + inline bool check() const + { + if ( + (0 == loop_runtime_check_) || + (++iteration_count_ <= loop_runtime_check_->max_loop_iterations) + ) { - destroy_node(loop_body_); + return true; } + + loop_runtime_check::violation_context ctxt; + ctxt.loop = loop_type; + ctxt.violation = loop_runtime_check::e_iteration_count; + + loop_runtime_check_->handle_runtime_violation(ctxt); + + return false; + } + + mutable _uint64_t iteration_count_; + mutable loop_runtime_check_ptr loop_runtime_check_; + loop_runtime_check::loop_types loop_type; + }; + #else + struct loop_runtime_checker + { + loop_runtime_checker(loop_runtime_check_ptr, loop_runtime_check::loop_types) + {} + + inline void reset(const _uint64_t = 0) const + {} + + inline bool check() const + { + return true; + } + }; + #endif + + template + class while_loop_node exprtk_final + : public expression_node, + public loop_runtime_checker + { + public: + + typedef expression_node* expression_ptr; + typedef std::pair branch_t; + + while_loop_node(expression_ptr condition, + expression_ptr loop_body, + loop_runtime_check_ptr loop_rt_chk = loop_runtime_check_ptr(0)) + : loop_runtime_checker(loop_rt_chk,loop_runtime_check::e_while_loop) + { + construct_branch_pair(condition_, condition); + construct_branch_pair(loop_body_, loop_body); } inline T value() const { + assert(condition_.first); + assert(loop_body_.first); + T result = T(0); - while (is_true(condition_)) + loop_runtime_checker::reset(); + + while (is_true(condition_) && loop_runtime_checker::check()) { - result = loop_body_->value(); + result = loop_body_.first->value(); } return result; @@ -6313,50 +6824,56 @@ namespace exprtk return expression_node::e_while; } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::collect(condition_ , node_delete_list); + expression_node::ndb_t::collect(loop_body_ , node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth(condition_, loop_body_); + } + private: - expression_ptr condition_; - expression_ptr loop_body_; - const bool condition_deletable_; - const bool loop_body_deletable_; + branch_t condition_; + branch_t loop_body_; }; template - class repeat_until_loop_node : public expression_node + class repeat_until_loop_node exprtk_final + : public expression_node, + public loop_runtime_checker { public: typedef expression_node* expression_ptr; + typedef std::pair branch_t; - repeat_until_loop_node(expression_ptr condition, expression_ptr loop_body) - : condition_(condition), - loop_body_(loop_body), - condition_deletable_(branch_deletable(condition_)), - loop_body_deletable_(branch_deletable(loop_body_)) - {} - - ~repeat_until_loop_node() + repeat_until_loop_node(expression_ptr condition, + expression_ptr loop_body, + loop_runtime_check_ptr loop_rt_chk = loop_runtime_check_ptr(0)) + : loop_runtime_checker(loop_rt_chk, loop_runtime_check::e_repeat_until_loop) { - if (condition_ && condition_deletable_) - { - destroy_node(condition_); - } - - if (loop_body_ && loop_body_deletable_) - { - destroy_node(loop_body_); - } + construct_branch_pair(condition_, condition); + construct_branch_pair(loop_body_, loop_body); } inline T value() const { + assert(condition_.first); + assert(loop_body_.first); + T result = T(0); + loop_runtime_checker::reset(1); + do { - result = loop_body_->value(); + result = loop_body_.first->value(); } - while (is_false(condition_)); + while (is_false(condition_.first) && loop_runtime_checker::check()); return result; } @@ -6366,78 +6883,71 @@ namespace exprtk return expression_node::e_repeat; } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::collect(condition_ , node_delete_list); + expression_node::ndb_t::collect(loop_body_ , node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth(condition_, loop_body_); + } + private: - expression_ptr condition_; - expression_ptr loop_body_; - const bool condition_deletable_; - const bool loop_body_deletable_; + branch_t condition_; + branch_t loop_body_; }; template - class for_loop_node : public expression_node + class for_loop_node exprtk_final + : public expression_node, + public loop_runtime_checker { public: typedef expression_node* expression_ptr; + typedef std::pair branch_t; for_loop_node(expression_ptr initialiser, expression_ptr condition, expression_ptr incrementor, - expression_ptr loop_body) - : initialiser_(initialiser), - condition_ (condition ), - incrementor_(incrementor), - loop_body_ (loop_body ), - initialiser_deletable_(branch_deletable(initialiser_)), - condition_deletable_ (branch_deletable(condition_ )), - incrementor_deletable_(branch_deletable(incrementor_)), - loop_body_deletable_ (branch_deletable(loop_body_ )) - {} - - ~for_loop_node() + expression_ptr loop_body, + loop_runtime_check_ptr loop_rt_chk = loop_runtime_check_ptr(0)) + : loop_runtime_checker(loop_rt_chk, loop_runtime_check::e_for_loop) { - if (initialiser_ && initialiser_deletable_) - { - destroy_node(initialiser_); - } - - if (condition_ && condition_deletable_) - { - destroy_node(condition_); - } - - if (incrementor_ && incrementor_deletable_) - { - destroy_node(incrementor_); - } - - if (loop_body_ && loop_body_deletable_) - { - destroy_node(loop_body_); - } + construct_branch_pair(initialiser_, initialiser); + construct_branch_pair(condition_ , condition ); + construct_branch_pair(incrementor_, incrementor); + construct_branch_pair(loop_body_ , loop_body ); } inline T value() const { + assert(condition_.first); + assert(loop_body_.first); + T result = T(0); - if (initialiser_) - initialiser_->value(); + loop_runtime_checker::reset(); - if (incrementor_) + if (initialiser_.first) + initialiser_.first->value(); + + if (incrementor_.first) { - while (is_true(condition_)) + while (is_true(condition_) && loop_runtime_checker::check()) { - result = loop_body_->value(); - incrementor_->value(); + result = loop_body_.first->value(); + incrementor_.first->value(); } } else { - while (is_true(condition_)) + while (is_true(condition_) && loop_runtime_checker::check()) { - result = loop_body_->value(); + result = loop_body_.first->value(); } } @@ -6449,55 +6959,62 @@ namespace exprtk return expression_node::e_for; } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::collect(initialiser_ , node_delete_list); + expression_node::ndb_t::collect(condition_ , node_delete_list); + expression_node::ndb_t::collect(incrementor_ , node_delete_list); + expression_node::ndb_t::collect(loop_body_ , node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth + (initialiser_, condition_, incrementor_, loop_body_); + } + private: - expression_ptr initialiser_ ; - expression_ptr condition_ ; - expression_ptr incrementor_ ; - expression_ptr loop_body_ ; - const bool initialiser_deletable_; - const bool condition_deletable_ ; - const bool incrementor_deletable_; - const bool loop_body_deletable_ ; + branch_t initialiser_; + branch_t condition_ ; + branch_t incrementor_; + branch_t loop_body_ ; }; #ifndef exprtk_disable_break_continue template - class while_loop_bc_node : public expression_node + class while_loop_bc_node exprtk_final + : public expression_node, + public loop_runtime_checker { public: typedef expression_node* expression_ptr; + typedef std::pair branch_t; - while_loop_bc_node(expression_ptr condition, expression_ptr loop_body) - : condition_(condition), - loop_body_(loop_body), - condition_deletable_(branch_deletable(condition_)), - loop_body_deletable_(branch_deletable(loop_body_)) - {} - - ~while_loop_bc_node() + while_loop_bc_node(expression_ptr condition, + expression_ptr loop_body, + loop_runtime_check_ptr loop_rt_chk = loop_runtime_check_ptr(0)) + : loop_runtime_checker(loop_rt_chk, loop_runtime_check::e_while_loop) { - if (condition_ && condition_deletable_) - { - destroy_node(condition_); - } - - if (loop_body_ && loop_body_deletable_) - { - destroy_node(loop_body_); - } + construct_branch_pair(condition_, condition); + construct_branch_pair(loop_body_, loop_body); } inline T value() const { + assert(condition_.first); + assert(loop_body_.first); + T result = T(0); - while (is_true(condition_)) + loop_runtime_checker::reset(); + + while (is_true(condition_) && loop_runtime_checker::check()) { try { - result = loop_body_->value(); + result = loop_body_.first->value(); } catch(const break_exception& e) { @@ -6515,50 +7032,56 @@ namespace exprtk return expression_node::e_while; } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::collect(condition_ , node_delete_list); + expression_node::ndb_t::collect(loop_body_ , node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth(condition_, loop_body_); + } + private: - expression_ptr condition_; - expression_ptr loop_body_; - const bool condition_deletable_; - const bool loop_body_deletable_; + branch_t condition_; + branch_t loop_body_; }; template - class repeat_until_loop_bc_node : public expression_node + class repeat_until_loop_bc_node exprtk_final + : public expression_node, + public loop_runtime_checker { public: typedef expression_node* expression_ptr; + typedef std::pair branch_t; - repeat_until_loop_bc_node(expression_ptr condition, expression_ptr loop_body) - : condition_(condition), - loop_body_(loop_body), - condition_deletable_(branch_deletable(condition_)), - loop_body_deletable_(branch_deletable(loop_body_)) - {} - - ~repeat_until_loop_bc_node() + repeat_until_loop_bc_node(expression_ptr condition, + expression_ptr loop_body, + loop_runtime_check_ptr loop_rt_chk = loop_runtime_check_ptr(0)) + : loop_runtime_checker(loop_rt_chk, loop_runtime_check::e_repeat_until_loop) { - if (condition_ && condition_deletable_) - { - destroy_node(condition_); - } - - if (loop_body_ && loop_body_deletable_) - { - destroy_node(loop_body_); - } + construct_branch_pair(condition_, condition); + construct_branch_pair(loop_body_, loop_body); } inline T value() const { + assert(condition_.first); + assert(loop_body_.first); + T result = T(0); + loop_runtime_checker::reset(); + do { try { - result = loop_body_->value(); + result = loop_body_.first->value(); } catch(const break_exception& e) { @@ -6567,7 +7090,7 @@ namespace exprtk catch(const continue_exception&) {} } - while (is_false(condition_)); + while (is_false(condition_.first) && loop_runtime_checker::check()); return result; } @@ -6577,72 +7100,65 @@ namespace exprtk return expression_node::e_repeat; } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::collect(condition_ , node_delete_list); + expression_node::ndb_t::collect(loop_body_ , node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth(condition_, loop_body_); + } + private: - expression_ptr condition_; - expression_ptr loop_body_; - const bool condition_deletable_; - const bool loop_body_deletable_; + branch_t condition_; + branch_t loop_body_; }; template - class for_loop_bc_node : public expression_node + class for_loop_bc_node exprtk_final + : public expression_node, + public loop_runtime_checker { public: typedef expression_node* expression_ptr; + typedef std::pair branch_t; for_loop_bc_node(expression_ptr initialiser, - expression_ptr condition, - expression_ptr incrementor, - expression_ptr loop_body) - : initialiser_(initialiser), - condition_ (condition ), - incrementor_(incrementor), - loop_body_ (loop_body ), - initialiser_deletable_(branch_deletable(initialiser_)), - condition_deletable_ (branch_deletable(condition_ )), - incrementor_deletable_(branch_deletable(incrementor_)), - loop_body_deletable_ (branch_deletable(loop_body_ )) - {} - - ~for_loop_bc_node() + expression_ptr condition, + expression_ptr incrementor, + expression_ptr loop_body, + loop_runtime_check_ptr loop_rt_chk = loop_runtime_check_ptr(0)) + : loop_runtime_checker(loop_rt_chk, loop_runtime_check::e_for_loop) { - if (initialiser_ && initialiser_deletable_) - { - destroy_node(initialiser_); - } - - if (condition_ && condition_deletable_) - { - destroy_node(condition_); - } - - if (incrementor_ && incrementor_deletable_) - { - destroy_node(incrementor_); - } - - if (loop_body_ && loop_body_deletable_) - { - destroy_node(loop_body_); - } + construct_branch_pair(initialiser_, initialiser); + construct_branch_pair(condition_ , condition ); + construct_branch_pair(incrementor_, incrementor); + construct_branch_pair(loop_body_ , loop_body ); } inline T value() const { + assert(condition_.first); + assert(loop_body_.first); + T result = T(0); - if (initialiser_) - initialiser_->value(); + loop_runtime_checker::reset(); + + if (initialiser_.first) + initialiser_.first->value(); - if (incrementor_) + if (incrementor_.first) { - while (is_true(condition_)) + while (is_true(condition_) && loop_runtime_checker::check()) { try { - result = loop_body_->value(); + result = loop_body_.first->value(); } catch(const break_exception& e) { @@ -6651,16 +7167,16 @@ namespace exprtk catch(const continue_exception&) {} - incrementor_->value(); + incrementor_.first->value(); } } else { - while (is_true(condition_)) + while (is_true(condition_) && loop_runtime_checker::check()) { try { - result = loop_body_->value(); + result = loop_body_.first->value(); } catch(const break_exception& e) { @@ -6679,16 +7195,26 @@ namespace exprtk return expression_node::e_for; } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::collect(initialiser_ , node_delete_list); + expression_node::ndb_t::collect(condition_ , node_delete_list); + expression_node::ndb_t::collect(incrementor_ , node_delete_list); + expression_node::ndb_t::collect(loop_body_ , node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth + (initialiser_, condition_, incrementor_, loop_body_); + } + private: - expression_ptr initialiser_; - expression_ptr condition_ ; - expression_ptr incrementor_; - expression_ptr loop_body_ ; - const bool initialiser_deletable_; - const bool condition_deletable_ ; - const bool incrementor_deletable_; - const bool loop_body_deletable_ ; + branch_t initialiser_; + branch_t condition_ ; + branch_t incrementor_; + branch_t loop_body_ ; }; #endif @@ -6698,6 +7224,7 @@ namespace exprtk public: typedef expression_node* expression_ptr; + typedef std::pair branch_t; template class Sequence> @@ -6707,35 +7234,21 @@ namespace exprtk return; arg_list_.resize(arg_list.size()); - delete_branch_.resize(arg_list.size()); for (std::size_t i = 0; i < arg_list.size(); ++i) { if (arg_list[i]) { - arg_list_[i] = arg_list[i]; - delete_branch_[i] = static_cast(branch_deletable(arg_list_[i]) ? 1 : 0); + construct_branch_pair(arg_list_[i], arg_list[i]); } else { arg_list_.clear(); - delete_branch_.clear(); return; } } } - ~switch_node() - { - for (std::size_t i = 0; i < arg_list_.size(); ++i) - { - if (arg_list_[i] && delete_branch_[i]) - { - destroy_node(arg_list_[i]); - } - } - } - inline T value() const { if (!arg_list_.empty()) @@ -6744,8 +7257,8 @@ namespace exprtk for (std::size_t i = 0; i < upper_bound; i += 2) { - expression_ptr condition = arg_list_[i ]; - expression_ptr consequent = arg_list_[i + 1]; + expression_ptr condition = arg_list_[i ].first; + expression_ptr consequent = arg_list_[i + 1].first; if (is_true(condition)) { @@ -6753,25 +7266,34 @@ namespace exprtk } } - return arg_list_[upper_bound]->value(); + return arg_list_[upper_bound].first->value(); } else return std::numeric_limits::quiet_NaN(); } - inline typename expression_node::node_type type() const + inline typename expression_node::node_type type() const exprtk_final { return expression_node::e_switch; } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::collect(arg_list_, node_delete_list); + } + + std::size_t node_depth() const exprtk_final + { + return expression_node::ndb_t::compute_node_depth(arg_list_); + } + protected: - std::vector arg_list_; - std::vector delete_branch_; + std::vector arg_list_; }; template - class switch_n_node : public switch_node + class switch_n_node exprtk_final : public switch_node { public: @@ -6790,11 +7312,12 @@ namespace exprtk }; template - class multi_switch_node : public expression_node + class multi_switch_node exprtk_final : public expression_node { public: typedef expression_node* expression_ptr; + typedef std::pair branch_t; template class Sequence> @@ -6804,35 +7327,21 @@ namespace exprtk return; arg_list_.resize(arg_list.size()); - delete_branch_.resize(arg_list.size()); for (std::size_t i = 0; i < arg_list.size(); ++i) { if (arg_list[i]) { - arg_list_[i] = arg_list[i]; - delete_branch_[i] = static_cast(branch_deletable(arg_list_[i]) ? 1 : 0); + construct_branch_pair(arg_list_[i], arg_list[i]); } else { arg_list_.clear(); - delete_branch_.clear(); return; } } } - ~multi_switch_node() - { - for (std::size_t i = 0; i < arg_list_.size(); ++i) - { - if (arg_list_[i] && delete_branch_[i]) - { - destroy_node(arg_list_[i]); - } - } - } - inline T value() const { T result = T(0); @@ -6846,8 +7355,8 @@ namespace exprtk for (std::size_t i = 0; i < upper_bound; i += 2) { - expression_ptr condition = arg_list_[i ]; - expression_ptr consequent = arg_list_[i + 1]; + expression_ptr condition = arg_list_[i ].first; + expression_ptr consequent = arg_list_[i + 1].first; if (is_true(condition)) { @@ -6863,10 +7372,19 @@ namespace exprtk return expression_node::e_mswitch; } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::collect(arg_list_, node_delete_list); + } + + std::size_t node_depth() const exprtk_final + { + return expression_node::ndb_t::compute_node_depth(arg_list_); + } + private: - std::vector arg_list_; - std::vector delete_branch_; + std::vector arg_list_; }; template @@ -6882,7 +7400,8 @@ namespace exprtk }; template - class variable_node : public expression_node, + class variable_node exprtk_final + : public expression_node, public ivariable { public: @@ -6937,11 +7456,11 @@ namespace exprtk typedef std::pair cached_range_t; range_pack() - : n0_e (std::make_pair(false,expression_node_ptr(0))), - n1_e (std::make_pair(false,expression_node_ptr(0))), - n0_c (std::make_pair(false,0)), - n1_c (std::make_pair(false,0)), - cache(std::make_pair(0,0)) + : n0_e (std::make_pair(false,expression_node_ptr(0))) + , n1_e (std::make_pair(false,expression_node_ptr(0))) + , n0_c (std::make_pair(false,0)) + , n1_c (std::make_pair(false,0)) + , cache(std::make_pair(0,0)) {} void clear() @@ -6982,30 +7501,26 @@ namespace exprtk } } - bool const_range() + bool const_range() const { return ( n0_c.first && n1_c.first) && (!n0_e.first && !n1_e.first); } - bool var_range() + bool var_range() const { return ( n0_e.first && n1_e.first) && (!n0_c.first && !n1_c.first); } - bool operator() (std::size_t& r0, std::size_t& r1, const std::size_t& size = std::numeric_limits::max()) const + bool operator() (std::size_t& r0, std::size_t& r1, + const std::size_t& size = std::numeric_limits::max()) const { if (n0_c.first) r0 = n0_c.second; else if (n0_e.first) { - const T r0_value = n0_e.second->value(); - - if (r0_value < 0) - return false; - else - r0 = static_cast(details::numeric::to_int64(r0_value)); + r0 = static_cast(details::numeric::to_int64(n0_e.second->value())); } else return false; @@ -7014,12 +7529,7 @@ namespace exprtk r1 = n1_c.second; else if (n1_e.first) { - const T r1_value = n1_e.second->value(); - - if (r1_value < 0) - return false; - else - r1 = static_cast(details::numeric::to_int64(r1_value)); + r1 = static_cast(details::numeric::to_int64(n1_e.second->value())); } else return false; @@ -7035,7 +7545,11 @@ namespace exprtk cache.first = r0; cache.second = r1; + #ifndef exprtk_enable_runtime_checks return (r0 <= r1); + #else + return range_runtime_check(r0, r1, size); + #endif } inline std::size_t const_size() const @@ -7053,6 +7567,27 @@ namespace exprtk std::pair n0_c; std::pair n1_c; mutable cached_range_t cache; + + #ifdef exprtk_enable_runtime_checks + bool range_runtime_check(const std::size_t r0, + const std::size_t r1, + const std::size_t size) const + { + if (r0 >= size) + { + throw std::runtime_error("range error: (r0 < 0) || (r0 >= size)"); + return false; + } + + if (r1 >= size) + { + throw std::runtime_error("range error: (r1 < 0) || (r1 >= size)"); + return false; + } + + return (r0 <= r1); + } + #endif }; template @@ -7065,11 +7600,11 @@ namespace exprtk typedef string_base_node* strbase_ptr_t; range_data_type() - : range(0), - data (0), - size (0), - type_size(0), - str_node (0) + : range(0) + , data (0) + , size (0) + , type_size(0) + , str_node (0) {} range_t* range; @@ -7087,7 +7622,7 @@ namespace exprtk public: typedef vector_node* vector_node_ptr; - typedef vec_data_store vds_t; + typedef vec_data_store vds_t; virtual ~vector_interface() {} @@ -7106,8 +7641,9 @@ namespace exprtk }; template - class vector_node : public expression_node , - public vector_interface + class vector_node exprtk_final + : public expression_node + , public vector_interface { public: @@ -7117,15 +7653,15 @@ namespace exprtk typedef vec_data_store vds_t; explicit vector_node(vector_holder_t* vh) - : vector_holder_(vh), - vds_((*vector_holder_).size(),(*vector_holder_)[0]) + : vector_holder_(vh) + , vds_((*vector_holder_).size(),(*vector_holder_)[0]) { vector_holder_->set_ref(&vds_.ref()); } vector_node(const vds_t& vds, vector_holder_t* vh) - : vector_holder_(vh), - vds_(vds) + : vector_holder_(vh) + , vds_(vds) {} inline T value() const @@ -7175,43 +7711,37 @@ namespace exprtk }; template - class vector_elem_node : public expression_node, + class vector_elem_node exprtk_final + : public expression_node, public ivariable { public: - typedef expression_node* expression_ptr; - typedef vector_holder vector_holder_t; - typedef vector_holder_t* vector_holder_ptr; + typedef expression_node* expression_ptr; + typedef vector_holder vector_holder_t; + typedef vector_holder_t* vector_holder_ptr; + typedef std::pair branch_t; vector_elem_node(expression_ptr index, vector_holder_ptr vec_holder) - : index_(index), - vec_holder_(vec_holder), - vector_base_((*vec_holder)[0]), - index_deletable_(branch_deletable(index_)) - {} - - ~vector_elem_node() + : vec_holder_(vec_holder) + , vector_base_((*vec_holder)[0]) { - if (index_ && index_deletable_) - { - destroy_node(index_); - } + construct_branch_pair(index_, index); } inline T value() const { - return *(vector_base_ + static_cast(details::numeric::to_int64(index_->value()))); + return *(vector_base_ + static_cast(details::numeric::to_int64(index_.first->value()))); } inline T& ref() { - return *(vector_base_ + static_cast(details::numeric::to_int64(index_->value()))); + return *(vector_base_ + static_cast(details::numeric::to_int64(index_.first->value()))); } inline const T& ref() const { - return *(vector_base_ + static_cast(details::numeric::to_int64(index_->value()))); + return *(vector_base_ + static_cast(details::numeric::to_int64(index_.first->value()))); } inline typename expression_node::node_type type() const @@ -7224,55 +7754,57 @@ namespace exprtk return (*vec_holder_); } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::collect(index_, node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth(index_); + } + private: - expression_ptr index_; vector_holder_ptr vec_holder_; T* vector_base_; - const bool index_deletable_; + branch_t index_; }; template - class rebasevector_elem_node : public expression_node, + class rebasevector_elem_node exprtk_final + : public expression_node, public ivariable { public: - typedef expression_node* expression_ptr; - typedef vector_holder vector_holder_t; - typedef vector_holder_t* vector_holder_ptr; - typedef vec_data_store vds_t; + typedef expression_node* expression_ptr; + typedef vector_holder vector_holder_t; + typedef vector_holder_t* vector_holder_ptr; + typedef vec_data_store vds_t; + typedef std::pair branch_t; rebasevector_elem_node(expression_ptr index, vector_holder_ptr vec_holder) - : index_(index), - index_deletable_(branch_deletable(index_)), - vector_holder_(vec_holder), - vds_((*vector_holder_).size(),(*vector_holder_)[0]) + : vector_holder_(vec_holder) + , vds_((*vector_holder_).size(),(*vector_holder_)[0]) { vector_holder_->set_ref(&vds_.ref()); - } - - ~rebasevector_elem_node() - { - if (index_ && index_deletable_) - { - destroy_node(index_); - } + construct_branch_pair(index_, index); } inline T value() const { - return *(vds_.data() + static_cast(details::numeric::to_int64(index_->value()))); + return *(vds_.data() + static_cast(details::numeric::to_int64(index_.first->value()))); } inline T& ref() { - return *(vds_.data() + static_cast(details::numeric::to_int64(index_->value()))); + return *(vds_.data() + static_cast(details::numeric::to_int64(index_.first->value()))); } inline const T& ref() const { - return *(vds_.data() + static_cast(details::numeric::to_int64(index_->value()))); + return *(vds_.data() + static_cast(details::numeric::to_int64(index_.first->value()))); } inline typename expression_node::node_type type() const @@ -7285,16 +7817,26 @@ namespace exprtk return (*vector_holder_); } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::template collect(index_, node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth(index_); + } + private: - expression_ptr index_; - const bool index_deletable_; vector_holder_ptr vector_holder_; vds_t vds_; + branch_t index_; }; template - class rebasevector_celem_node : public expression_node, + class rebasevector_celem_node exprtk_final + : public expression_node, public ivariable { public: @@ -7305,9 +7847,9 @@ namespace exprtk typedef vec_data_store vds_t; rebasevector_celem_node(const std::size_t index, vector_holder_ptr vec_holder) - : index_(index), - vector_holder_(vec_holder), - vds_((*vector_holder_).size(),(*vector_holder_)[0]) + : index_(index) + , vector_holder_(vec_holder) + , vds_((*vector_holder_).size(),(*vector_holder_)[0]) { vector_holder_->set_ref(&vds_.ref()); } @@ -7345,7 +7887,7 @@ namespace exprtk }; template - class vector_assignment_node : public expression_node + class vector_assignment_node exprtk_final : public expression_node { public: @@ -7355,23 +7897,12 @@ namespace exprtk const std::size_t& size, const std::vector& initialiser_list, const bool single_value_initialse) - : vector_base_(vector_base), - initialiser_list_(initialiser_list), - size_(size), - single_value_initialse_(single_value_initialse) + : vector_base_(vector_base) + , initialiser_list_(initialiser_list) + , size_(size) + , single_value_initialse_(single_value_initialse) {} - ~vector_assignment_node() - { - for (std::size_t i = 0; i < initialiser_list_.size(); ++i) - { - if (branch_deletable(initialiser_list_[i])) - { - destroy_node(initialiser_list_[i]); - } - } - } - inline T value() const { if (single_value_initialse_) @@ -7407,6 +7938,16 @@ namespace exprtk return expression_node::e_vecdefass; } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::collect(initialiser_list_, node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth(initialiser_list_); + } + private: vector_assignment_node& operator=(const vector_assignment_node&); @@ -7418,7 +7959,7 @@ namespace exprtk }; template - class swap_node : public expression_node + class swap_node exprtk_final : public expression_node { public: @@ -7426,8 +7967,8 @@ namespace exprtk typedef variable_node* variable_node_ptr; swap_node(variable_node_ptr var0, variable_node_ptr var1) - : var0_(var0), - var1_(var1) + : var0_(var0) + , var1_(var1) {} inline T value() const @@ -7448,17 +7989,17 @@ namespace exprtk }; template - class swap_generic_node : public binary_node + class swap_generic_node exprtk_final : public binary_node { public: typedef expression_node* expression_ptr; - typedef ivariable* ivariable_ptr; + typedef ivariable* ivariable_ptr; swap_generic_node(expression_ptr var0, expression_ptr var1) - : binary_node(details::e_swap, var0, var1), - var0_(dynamic_cast(var0)), - var1_(dynamic_cast(var1)) + : binary_node(details::e_swap, var0, var1) + , var0_(dynamic_cast(var0)) + , var1_(dynamic_cast(var1)) {} inline T value() const @@ -7479,22 +8020,23 @@ namespace exprtk }; template - class swap_vecvec_node : public binary_node , - public vector_interface + class swap_vecvec_node exprtk_final + : public binary_node + , public vector_interface { public: - typedef expression_node* expression_ptr; - typedef vector_node* vector_node_ptr; - typedef vec_data_store vds_t; + typedef expression_node* expression_ptr; + typedef vector_node * vector_node_ptr; + typedef vec_data_store vds_t; swap_vecvec_node(expression_ptr branch0, expression_ptr branch1) - : binary_node(details::e_swap, branch0, branch1), - vec0_node_ptr_(0), - vec1_node_ptr_(0), - vec_size_ (0), - initialised_ (false) + : binary_node(details::e_swap, branch0, branch1) + , vec0_node_ptr_(0) + , vec1_node_ptr_(0) + , vec_size_ (0) + , initialised_ (false) { if (is_ivector_node(binary_node::branch_[0].first)) { @@ -7524,12 +8066,17 @@ namespace exprtk initialised_ = true; } + + assert(initialised_); } inline T value() const { if (initialised_) { + assert(binary_node::branch_[0].first); + assert(binary_node::branch_[1].first); + binary_node::branch_[0].first->value(); binary_node::branch_[1].first->value(); @@ -7588,7 +8135,8 @@ namespace exprtk #ifndef exprtk_disable_string_capabilities template - class stringvar_node : public expression_node , + class stringvar_node exprtk_final + : public expression_node , public string_base_node, public range_interface { @@ -7674,7 +8222,8 @@ namespace exprtk std::string stringvar_node::null_value = std::string(""); template - class string_range_node : public expression_node , + class string_range_node exprtk_final + : public expression_node , public string_base_node, public range_interface { @@ -7685,8 +8234,8 @@ namespace exprtk static std::string null_value; explicit string_range_node(std::string& v, const range_t& rp) - : value_(&v), - rp_(rp) + : value_(&v) + , rp_(rp) {} virtual ~string_range_node() @@ -7759,7 +8308,8 @@ namespace exprtk std::string string_range_node::null_value = std::string(""); template - class const_string_range_node : public expression_node , + class const_string_range_node exprtk_final + : public expression_node , public string_base_node, public range_interface { @@ -7768,8 +8318,8 @@ namespace exprtk typedef range_pack range_t; explicit const_string_range_node(const std::string& v, const range_t& rp) - : value_(v), - rp_(rp) + : value_(v) + , rp_(rp) {} ~const_string_range_node() @@ -7826,64 +8376,66 @@ namespace exprtk }; template - class generic_string_range_node : public expression_node , + class generic_string_range_node exprtk_final + : public expression_node , public string_base_node, public range_interface { public: - typedef expression_node * expression_ptr; + typedef expression_node * expression_ptr; typedef stringvar_node * strvar_node_ptr; - typedef string_base_node* str_base_ptr; - typedef range_pack range_t; - typedef range_t* range_ptr; - typedef range_interface irange_t; - typedef irange_t* irange_ptr; + typedef string_base_node* str_base_ptr; + typedef range_pack range_t; + typedef range_t* range_ptr; + typedef range_interface irange_t; + typedef irange_t* irange_ptr; + typedef std::pair branch_t; + generic_string_range_node(expression_ptr str_branch, const range_t& brange) - : initialised_(false), - branch_(str_branch), - branch_deletable_(branch_deletable(branch_)), - str_base_ptr_ (0), - str_range_ptr_(0), - base_range_(brange) + : initialised_(false) + , str_base_ptr_ (0) + , str_range_ptr_(0) + , base_range_(brange) { range_.n0_c = std::make_pair(true,0); range_.n1_c = std::make_pair(true,0); range_.cache.first = range_.n0_c.second; range_.cache.second = range_.n1_c.second; - if (is_generally_string_node(branch_)) + construct_branch_pair(branch_, str_branch); + + if (is_generally_string_node(branch_.first)) { - str_base_ptr_ = dynamic_cast(branch_); + str_base_ptr_ = dynamic_cast(branch_.first); if (0 == str_base_ptr_) return; - str_range_ptr_ = dynamic_cast(branch_); + str_range_ptr_ = dynamic_cast(branch_.first); if (0 == str_range_ptr_) return; } initialised_ = (str_base_ptr_ && str_range_ptr_); + + assert(initialised_); } ~generic_string_range_node() { base_range_.free(); - - if (branch_ && branch_deletable_) - { - destroy_node(branch_); - } } inline T value() const { if (initialised_) { - branch_->value(); + assert(branch_.first); + + branch_.first->value(); std::size_t str_r0 = 0; std::size_t str_r1 = 0; @@ -7891,13 +8443,13 @@ namespace exprtk std::size_t r0 = 0; std::size_t r1 = 0; - range_t& range = str_range_ptr_->range_ref(); + const range_t& range = str_range_ptr_->range_ref(); const std::size_t base_str_size = str_base_ptr_->size(); if ( - range (str_r0,str_r1,base_str_size) && - base_range_( r0, r1,base_str_size) + range (str_r0, str_r1, base_str_size) && + base_range_( r0, r1, base_str_size - str_r0) ) { const std::size_t size = (r1 - r0) + 1; @@ -7942,41 +8494,51 @@ namespace exprtk return expression_node::e_strgenrange; } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::collect(branch_, node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth(branch_); + } + private: bool initialised_; - expression_ptr branch_; - const bool branch_deletable_; - str_base_ptr str_base_ptr_; - irange_ptr str_range_ptr_; - mutable range_t base_range_; - mutable range_t range_; - mutable std::string value_; + branch_t branch_; + str_base_ptr str_base_ptr_; + irange_ptr str_range_ptr_; + mutable range_t base_range_; + mutable range_t range_; + mutable std::string value_; }; template - class string_concat_node : public binary_node , + class string_concat_node exprtk_final + : public binary_node , public string_base_node, public range_interface { public: - typedef expression_node * expression_ptr; - typedef string_base_node* str_base_ptr; - typedef range_pack range_t; - typedef range_t* range_ptr; - typedef range_interface irange_t; - typedef irange_t* irange_ptr; + typedef expression_node * expression_ptr; + typedef string_base_node* str_base_ptr; + typedef range_pack range_t; + typedef range_t* range_ptr; + typedef range_interface irange_t; + typedef irange_t* irange_ptr; string_concat_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr, branch0, branch1), - initialised_(false), - str0_base_ptr_ (0), - str1_base_ptr_ (0), - str0_range_ptr_(0), - str1_range_ptr_(0) + : binary_node(opr, branch0, branch1) + , initialised_(false) + , str0_base_ptr_ (0) + , str1_base_ptr_ (0) + , str0_range_ptr_(0) + , str1_range_ptr_(0) { range_.n0_c = std::make_pair(true,0); range_.n1_c = std::make_pair(true,0); @@ -8014,12 +8576,17 @@ namespace exprtk str1_base_ptr_ && str0_range_ptr_ && str1_range_ptr_ ; + + assert(initialised_); } inline T value() const { if (initialised_) { + assert(binary_node::branch_[0].first); + assert(binary_node::branch_[1].first); + binary_node::branch_[0].first->value(); binary_node::branch_[1].first->value(); @@ -8029,8 +8596,8 @@ namespace exprtk std::size_t str1_r0 = 0; std::size_t str1_r1 = 0; - range_t& range0 = str0_range_ptr_->range_ref(); - range_t& range1 = str1_range_ptr_->range_ref(); + const range_t& range0 = str0_range_ptr_->range_ref(); + const range_t& range1 = str1_range_ptr_->range_ref(); if ( range0(str0_r0, str0_r1, str0_base_ptr_->size()) && @@ -8083,29 +8650,30 @@ namespace exprtk private: - bool initialised_; - str_base_ptr str0_base_ptr_; - str_base_ptr str1_base_ptr_; - irange_ptr str0_range_ptr_; - irange_ptr str1_range_ptr_; + bool initialised_; + str_base_ptr str0_base_ptr_; + str_base_ptr str1_base_ptr_; + irange_ptr str0_range_ptr_; + irange_ptr str1_range_ptr_; mutable range_t range_; mutable std::string value_; }; template - class swap_string_node : public binary_node , + class swap_string_node exprtk_final + : public binary_node , public string_base_node, public range_interface { public: - typedef expression_node * expression_ptr; + typedef expression_node * expression_ptr; typedef stringvar_node * strvar_node_ptr; - typedef string_base_node* str_base_ptr; - typedef range_pack range_t; - typedef range_t* range_ptr; - typedef range_interface irange_t; - typedef irange_t* irange_ptr; + typedef string_base_node* str_base_ptr; + typedef range_pack range_t; + typedef range_t* range_ptr; + typedef range_interface irange_t; + typedef irange_t* irange_ptr; swap_string_node(expression_ptr branch0, expression_ptr branch1) : binary_node(details::e_swap, branch0, branch1), @@ -8124,16 +8692,21 @@ namespace exprtk } initialised_ = (str0_node_ptr_ && str1_node_ptr_); + + assert(initialised_); } inline T value() const { if (initialised_) { + assert(binary_node::branch_[0].first); + assert(binary_node::branch_[1].first); + binary_node::branch_[0].first->value(); binary_node::branch_[1].first->value(); - std::swap(str0_node_ptr_->ref(),str1_node_ptr_->ref()); + std::swap(str0_node_ptr_->ref(), str1_node_ptr_->ref()); } return std::numeric_limits::quiet_NaN(); @@ -8177,25 +8750,25 @@ namespace exprtk }; template - class swap_genstrings_node : public binary_node + class swap_genstrings_node exprtk_final : public binary_node { public: typedef expression_node * expression_ptr; - typedef string_base_node* str_base_ptr; - typedef range_pack range_t; - typedef range_t* range_ptr; - typedef range_interface irange_t; - typedef irange_t* irange_ptr; + typedef string_base_node* str_base_ptr; + typedef range_pack range_t; + typedef range_t* range_ptr; + typedef range_interface irange_t; + typedef irange_t* irange_ptr; swap_genstrings_node(expression_ptr branch0, expression_ptr branch1) - : binary_node(details::e_default, branch0, branch1), - str0_base_ptr_ (0), - str1_base_ptr_ (0), - str0_range_ptr_(0), - str1_range_ptr_(0), - initialised_(false) + : binary_node(details::e_default, branch0, branch1) + , str0_base_ptr_ (0) + , str1_base_ptr_ (0) + , str0_range_ptr_(0) + , str1_range_ptr_(0) + , initialised_(false) { if (is_generally_string_node(binary_node::branch_[0].first)) { @@ -8231,12 +8804,17 @@ namespace exprtk str1_base_ptr_ && str0_range_ptr_ && str1_range_ptr_ ; + + assert(initialised_); } inline T value() const { if (initialised_) { + assert(binary_node::branch_[0].first); + assert(binary_node::branch_[1].first); + binary_node::branch_[0].first->value(); binary_node::branch_[1].first->value(); @@ -8246,8 +8824,8 @@ namespace exprtk std::size_t str1_r0 = 0; std::size_t str1_r1 = 0; - range_t& range0 = (*str0_range_ptr_); - range_t& range1 = (*str1_range_ptr_); + const range_t& range0 = (*str0_range_ptr_); + const range_t& range1 = (*str1_range_ptr_); if ( range0(str0_r0, str0_r1, str0_base_ptr_->size()) && @@ -8289,8 +8867,8 @@ namespace exprtk exprtk_disable_fallthrough_begin switch (lud.remainder) { - #define case_stmt(N) \ - case N : { std::swap(s0[i],s1[i]); ++i; } \ + #define case_stmt(N) \ + case N : { std::swap(s0[i], s1[i]); ++i; } \ #ifndef exprtk_disable_superscalar_unroll case_stmt(15) case_stmt(14) @@ -8331,7 +8909,7 @@ namespace exprtk }; template - class stringvar_size_node : public expression_node + class stringvar_size_node exprtk_final : public expression_node { public: @@ -8364,42 +8942,35 @@ namespace exprtk std::string stringvar_size_node::null_value = std::string(""); template - class string_size_node : public expression_node + class string_size_node exprtk_final : public expression_node { public: typedef expression_node * expression_ptr; - typedef string_base_node* str_base_ptr; + typedef string_base_node* str_base_ptr; + typedef std::pair branch_t; - explicit string_size_node(expression_ptr brnch) - : branch_(brnch), - branch_deletable_(branch_deletable(branch_)), - str_base_ptr_(0) + explicit string_size_node(expression_ptr branch) + : str_base_ptr_(0) { - if (is_generally_string_node(branch_)) + construct_branch_pair(branch_, branch); + + if (is_generally_string_node(branch_.first)) { - str_base_ptr_ = dynamic_cast(branch_); + str_base_ptr_ = dynamic_cast(branch_.first); if (0 == str_base_ptr_) return; } } - ~string_size_node() - { - if (branch_ && branch_deletable_) - { - destroy_node(branch_); - } - } - inline T value() const { T result = std::numeric_limits::quiet_NaN(); if (str_base_ptr_) { - branch_->value(); + branch_.first->value(); result = T(str_base_ptr_->size()); } @@ -8411,11 +8982,20 @@ namespace exprtk return expression_node::e_stringsize; } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::collect(branch_, node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth(branch_); + } + private: - expression_ptr branch_; - const bool branch_deletable_; - str_base_ptr str_base_ptr_; + branch_t branch_; + str_base_ptr str_base_ptr_; }; struct asn_assignment @@ -8431,29 +9011,30 @@ namespace exprtk }; template - class assignment_string_node : public binary_node , + class assignment_string_node exprtk_final + : public binary_node , public string_base_node, public range_interface { public: - typedef expression_node * expression_ptr; + typedef expression_node * expression_ptr; typedef stringvar_node * strvar_node_ptr; - typedef string_base_node* str_base_ptr; - typedef range_pack range_t; - typedef range_t* range_ptr; - typedef range_interface irange_t; - typedef irange_t* irange_ptr; + typedef string_base_node* str_base_ptr; + typedef range_pack range_t; + typedef range_t* range_ptr; + typedef range_interface irange_t; + typedef irange_t* irange_ptr; assignment_string_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr, branch0, branch1), - initialised_(false), - str0_base_ptr_ (0), - str1_base_ptr_ (0), - str0_node_ptr_ (0), - str1_range_ptr_(0) + : binary_node(opr, branch0, branch1) + , initialised_(false) + , str0_base_ptr_ (0) + , str1_base_ptr_ (0) + , str0_node_ptr_ (0) + , str1_range_ptr_(0) { if (is_string_node(binary_node::branch_[0].first)) { @@ -8481,18 +9062,23 @@ namespace exprtk str1_base_ptr_ && str0_node_ptr_ && str1_range_ptr_ ; + + assert(initialised_); } inline T value() const { if (initialised_) { + assert(binary_node::branch_[0].first); + assert(binary_node::branch_[1].first); + binary_node::branch_[1].first->value(); std::size_t r0 = 0; std::size_t r1 = 0; - range_t& range = (*str1_range_ptr_); + const range_t& range = (*str1_range_ptr_); if (range(r0, r1, str1_base_ptr_->size())) { @@ -8547,34 +9133,36 @@ namespace exprtk }; template - class assignment_string_range_node : public binary_node , + class assignment_string_range_node exprtk_final + : public binary_node , public string_base_node, public range_interface { public: - typedef expression_node * expression_ptr; - typedef stringvar_node * strvar_node_ptr; - typedef string_base_node* str_base_ptr; - typedef range_pack range_t; - typedef range_t* range_ptr; - typedef range_interface irange_t; - typedef irange_t* irange_ptr; + typedef expression_node * expression_ptr; + typedef stringvar_node * strvar_node_ptr; + typedef string_range_node* str_rng_node_ptr; + typedef string_base_node * str_base_ptr; + typedef range_pack range_t; + typedef range_t* range_ptr; + typedef range_interface irange_t; + typedef irange_t* irange_ptr; assignment_string_range_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr, branch0, branch1), - initialised_(false), - str0_base_ptr_ (0), - str1_base_ptr_ (0), - str0_node_ptr_ (0), - str0_range_ptr_(0), - str1_range_ptr_(0) + : binary_node(opr, branch0, branch1) + , initialised_(false) + , str0_base_ptr_ (0) + , str1_base_ptr_ (0) + , str0_rng_node_ptr_(0) + , str0_range_ptr_ (0) + , str1_range_ptr_ (0) { if (is_string_range_node(binary_node::branch_[0].first)) { - str0_node_ptr_ = static_cast(binary_node::branch_[0].first); + str0_rng_node_ptr_ = static_cast(binary_node::branch_[0].first); str0_base_ptr_ = dynamic_cast(binary_node::branch_[0].first); @@ -8601,17 +9189,22 @@ namespace exprtk str1_range_ptr_ = &(range->range_ref()); } - initialised_ = str0_base_ptr_ && - str1_base_ptr_ && - str0_node_ptr_ && - str0_range_ptr_ && - str1_range_ptr_ ; + initialised_ = str0_base_ptr_ && + str1_base_ptr_ && + str0_rng_node_ptr_ && + str0_range_ptr_ && + str1_range_ptr_ ; + + assert(initialised_); } inline T value() const { if (initialised_) { + assert(binary_node::branch_[0].first); + assert(binary_node::branch_[1].first); + binary_node::branch_[0].first->value(); binary_node::branch_[1].first->value(); @@ -8621,15 +9214,15 @@ namespace exprtk std::size_t s1_r0 = 0; std::size_t s1_r1 = 0; - range_t& range0 = (*str0_range_ptr_); - range_t& range1 = (*str1_range_ptr_); + const range_t& range0 = (*str0_range_ptr_); + const range_t& range1 = (*str1_range_ptr_); if ( range0(s0_r0, s0_r1, str0_base_ptr_->size()) && range1(s1_r0, s1_r1, str1_base_ptr_->size()) ) { - std::size_t size = std::min((s0_r1 - s0_r0),(s1_r1 - s1_r0)) + 1; + const std::size_t size = std::min((s0_r1 - s0_r0), (s1_r1 - s1_r0)) + 1; std::copy(str1_base_ptr_->base() + s1_r0, str1_base_ptr_->base() + s1_r0 + size, @@ -8642,27 +9235,27 @@ namespace exprtk std::string str() const { - return str0_node_ptr_->str(); + return str0_base_ptr_->str(); } char_cptr base() const { - return str0_node_ptr_->base(); + return str0_base_ptr_->base(); } std::size_t size() const { - return str0_node_ptr_->size(); + return str0_base_ptr_->size(); } range_t& range_ref() { - return str0_node_ptr_->range_ref(); + return str0_rng_node_ptr_->range_ref(); } const range_t& range_ref() const { - return str0_node_ptr_->range_ref(); + return str0_rng_node_ptr_->range_ref(); } inline typename expression_node::node_type type() const @@ -8672,40 +9265,41 @@ namespace exprtk private: - bool initialised_; - str_base_ptr str0_base_ptr_; - str_base_ptr str1_base_ptr_; - strvar_node_ptr str0_node_ptr_; - range_ptr str0_range_ptr_; - range_ptr str1_range_ptr_; + bool initialised_; + str_base_ptr str0_base_ptr_; + str_base_ptr str1_base_ptr_; + str_rng_node_ptr str0_rng_node_ptr_; + range_ptr str0_range_ptr_; + range_ptr str1_range_ptr_; }; template - class conditional_string_node : public trinary_node , + class conditional_string_node exprtk_final + : public trinary_node , public string_base_node, public range_interface { public: typedef expression_node * expression_ptr; - typedef string_base_node* str_base_ptr; - typedef range_pack range_t; - typedef range_t* range_ptr; - typedef range_interface irange_t; - typedef irange_t* irange_ptr; + typedef string_base_node* str_base_ptr; + typedef range_pack range_t; + typedef range_t* range_ptr; + typedef range_interface irange_t; + typedef irange_t* irange_ptr; - conditional_string_node(expression_ptr test, + conditional_string_node(expression_ptr condition, expression_ptr consequent, expression_ptr alternative) - : trinary_node(details::e_default,consequent,alternative,test), - initialised_(false), - str0_base_ptr_ (0), - str1_base_ptr_ (0), - str0_range_ptr_(0), - str1_range_ptr_(0), - test_ (test), - consequent_ (consequent), - alternative_(alternative) + : trinary_node(details::e_default,consequent,alternative,condition) + , initialised_(false) + , str0_base_ptr_ (0) + , str1_base_ptr_ (0) + , str0_range_ptr_(0) + , str1_range_ptr_(0) + , condition_ (condition ) + , consequent_ (consequent ) + , alternative_(alternative) { range_.n0_c = std::make_pair(true,0); range_.n1_c = std::make_pair(true,0); @@ -8744,20 +9338,25 @@ namespace exprtk str0_range_ptr_ && str1_range_ptr_ ; + assert(initialised_); } inline T value() const { if (initialised_) { + assert(condition_ ); + assert(consequent_ ); + assert(alternative_); + std::size_t r0 = 0; std::size_t r1 = 0; - if (is_true(test_)) + if (is_true(condition_)) { consequent_->value(); - range_t& range = str0_range_ptr_->range_ref(); + const range_t& range = str0_range_ptr_->range_ref(); if (range(r0, r1, str0_base_ptr_->size())) { @@ -8775,7 +9374,7 @@ namespace exprtk { alternative_->value(); - range_t& range = str1_range_ptr_->range_ref(); + const range_t& range = str1_range_ptr_->range_ref(); if (range(r0, r1, str1_base_ptr_->size())) { @@ -8834,33 +9433,34 @@ namespace exprtk mutable range_t range_; mutable std::string value_; - expression_ptr test_; + expression_ptr condition_; expression_ptr consequent_; expression_ptr alternative_; }; template - class cons_conditional_str_node : public binary_node , + class cons_conditional_str_node exprtk_final + : public binary_node , public string_base_node, public range_interface { public: typedef expression_node * expression_ptr; - typedef string_base_node* str_base_ptr; - typedef range_pack range_t; - typedef range_t* range_ptr; - typedef range_interface irange_t; - typedef irange_t* irange_ptr; + typedef string_base_node* str_base_ptr; + typedef range_pack range_t; + typedef range_t* range_ptr; + typedef range_interface irange_t; + typedef irange_t* irange_ptr; - cons_conditional_str_node(expression_ptr test, + cons_conditional_str_node(expression_ptr condition, expression_ptr consequent) - : binary_node(details::e_default, consequent, test), - initialised_(false), - str0_base_ptr_ (0), - str0_range_ptr_(0), - test_ (test), - consequent_(consequent) + : binary_node(details::e_default, consequent, condition) + , initialised_(false) + , str0_base_ptr_ (0) + , str0_range_ptr_(0) + , condition_ (condition ) + , consequent_(consequent) { range_.n0_c = std::make_pair(true,0); range_.n1_c = std::make_pair(true,0); @@ -8882,17 +9482,22 @@ namespace exprtk } initialised_ = str0_base_ptr_ && str0_range_ptr_ ; + + assert(initialised_); } inline T value() const { if (initialised_) { - if (is_true(test_)) + assert(condition_ ); + assert(consequent_); + + if (is_true(condition_)) { consequent_->value(); - range_t& range = str0_range_ptr_->range_ref(); + const range_t& range = str0_range_ptr_->range_ref(); std::size_t r0 = 0; std::size_t r1 = 0; @@ -8952,44 +9557,46 @@ namespace exprtk mutable range_t range_; mutable std::string value_; - expression_ptr test_; + expression_ptr condition_; expression_ptr consequent_; }; template - class str_vararg_node : public expression_node , - public string_base_node, - public range_interface + class str_vararg_node exprtk_final + : public expression_node , + public string_base_node, + public range_interface { public: - typedef expression_node * expression_ptr; - typedef string_base_node* str_base_ptr; - typedef range_pack range_t; - typedef range_t* range_ptr; - typedef range_interface irange_t; - typedef irange_t* irange_ptr; + typedef expression_node * expression_ptr; + typedef string_base_node* str_base_ptr; + typedef range_pack range_t; + typedef range_t* range_ptr; + typedef range_interface irange_t; + typedef irange_t* irange_ptr; + typedef std::pair branch_t; template class Sequence> explicit str_vararg_node(const Sequence& arg_list) - : final_node_(arg_list.back()), - final_deletable_(branch_deletable(final_node_)), - initialised_(false), - str_base_ptr_ (0), - str_range_ptr_(0) + : initialised_(false) + , str_base_ptr_ (0) + , str_range_ptr_(0) { - if (0 == final_node_) + construct_branch_pair(final_node_, const_cast(arg_list.back())); + + if (0 == final_node_.first) return; - else if (!is_generally_string_node(final_node_)) + else if (!is_generally_string_node(final_node_.first)) return; - str_base_ptr_ = dynamic_cast(final_node_); + str_base_ptr_ = dynamic_cast(final_node_.first); if (0 == str_base_ptr_) return; - str_range_ptr_ = dynamic_cast(final_node_); + str_range_ptr_ = dynamic_cast(final_node_.first); if (0 == str_range_ptr_) return; @@ -9001,41 +9608,22 @@ namespace exprtk const std::size_t arg_list_size = arg_list.size() - 1; arg_list_.resize(arg_list_size); - delete_branch_.resize(arg_list_size); for (std::size_t i = 0; i < arg_list_size; ++i) { if (arg_list[i]) { - arg_list_[i] = arg_list[i]; - delete_branch_[i] = static_cast(branch_deletable(arg_list_[i]) ? 1 : 0); + construct_branch_pair(arg_list_[i], arg_list[i]); } else { - arg_list_ .clear(); - delete_branch_.clear(); + arg_list_.clear(); return; } } } } - ~str_vararg_node() - { - if (final_node_ && final_deletable_) - { - destroy_node(final_node_); - } - - for (std::size_t i = 0; i < arg_list_.size(); ++i) - { - if (arg_list_[i] && delete_branch_[i]) - { - destroy_node(arg_list_[i]); - } - } - } - inline T value() const { if (!arg_list_.empty()) @@ -9043,7 +9631,7 @@ namespace exprtk VarArgFunction::process(arg_list_); } - final_node_->value(); + final_node_.first->value(); return std::numeric_limits::quiet_NaN(); } @@ -9078,27 +9666,38 @@ namespace exprtk return expression_node::e_stringvararg; } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::collect(final_node_ , node_delete_list); + expression_node::ndb_t::collect(arg_list_ , node_delete_list); + } + + std::size_t node_depth() const + { + return std::max( + expression_node::ndb_t::compute_node_depth(final_node_), + expression_node::ndb_t::compute_node_depth(arg_list_ )); + } + private: - expression_ptr final_node_; - bool final_deletable_; - bool initialised_; - str_base_ptr str_base_ptr_; - irange_ptr str_range_ptr_; - std::vector arg_list_; - std::vector delete_branch_; + bool initialised_; + branch_t final_node_; + str_base_ptr str_base_ptr_; + irange_ptr str_range_ptr_; + std::vector arg_list_; }; #endif template - inline T axn(T a, T x) + inline T axn(const T a, const T x) { // a*x^n return a * exprtk::details::numeric::fast_exp::result(x); } template - inline T axnb(T a, T x, T b) + inline T axnb(const T a, const T x, const T b) { // a*x^n+b return a * exprtk::details::numeric::fast_exp::result(x) + b; @@ -9110,23 +9709,23 @@ namespace exprtk typedef typename details::functor_t::Type Type; typedef typename details::functor_t functor_t; typedef typename functor_t::qfunc_t quaternary_functor_t; - typedef typename functor_t::tfunc_t trinary_functor_t; - typedef typename functor_t::bfunc_t binary_functor_t; - typedef typename functor_t::ufunc_t unary_functor_t; + typedef typename functor_t::tfunc_t trinary_functor_t; + typedef typename functor_t::bfunc_t binary_functor_t; + typedef typename functor_t::ufunc_t unary_functor_t; }; #define define_sfop3(NN,OP0,OP1) \ template \ struct sf##NN##_op : public sf_base \ { \ - typedef typename sf_base::Type Type; \ + typedef typename sf_base::Type const Type; \ static inline T process(Type x, Type y, Type z) \ { \ return (OP0); \ } \ static inline std::string id() \ { \ - return OP1; \ + return (OP1); \ } \ }; \ @@ -9183,12 +9782,15 @@ namespace exprtk template \ struct sf##NN##_op : public sf_base \ { \ - typedef typename sf_base::Type Type; \ + typedef typename sf_base::Type const Type; \ static inline T process(Type x, Type y, Type z, Type w) \ { \ return (OP0); \ } \ - static inline std::string id() { return OP1; } \ + static inline std::string id() \ + { \ + return (OP1); \ + } \ }; \ define_sfop4(48,(x + ((y + z) / w)),"t+((t+t)/t)") @@ -9312,7 +9914,7 @@ namespace exprtk #undef define_sfop4 template - class sf3_node : public trinary_node + class sf3_node exprtk_final : public trinary_node { public: @@ -9327,6 +9929,10 @@ namespace exprtk inline T value() const { + assert(trinary_node::branch_[0].first); + assert(trinary_node::branch_[1].first); + assert(trinary_node::branch_[2].first); + const T x = trinary_node::branch_[0].first->value(); const T y = trinary_node::branch_[1].first->value(); const T z = trinary_node::branch_[2].first->value(); @@ -9336,7 +9942,7 @@ namespace exprtk }; template - class sf4_node : public quaternary_node + class sf4_node exprtk_final : public quaternary_node { public: @@ -9352,6 +9958,11 @@ namespace exprtk inline T value() const { + assert(quaternary_node::branch_[0].first); + assert(quaternary_node::branch_[1].first); + assert(quaternary_node::branch_[2].first); + assert(quaternary_node::branch_[3].first); + const T x = quaternary_node::branch_[0].first->value(); const T y = quaternary_node::branch_[1].first->value(); const T z = quaternary_node::branch_[2].first->value(); @@ -9362,16 +9973,16 @@ namespace exprtk }; template - class sf3_var_node : public expression_node + class sf3_var_node exprtk_final : public expression_node { public: typedef expression_node* expression_ptr; sf3_var_node(const T& v0, const T& v1, const T& v2) - : v0_(v0), - v1_(v1), - v2_(v2) + : v0_(v0) + , v1_(v1) + , v2_(v2) {} inline T value() const @@ -9395,17 +10006,17 @@ namespace exprtk }; template - class sf4_var_node : public expression_node + class sf4_var_node exprtk_final : public expression_node { public: typedef expression_node* expression_ptr; sf4_var_node(const T& v0, const T& v1, const T& v2, const T& v3) - : v0_(v0), - v1_(v1), - v2_(v2), - v3_(v3) + : v0_(v0) + , v1_(v1) + , v2_(v2) + , v3_(v3) {} inline T value() const @@ -9430,46 +10041,33 @@ namespace exprtk }; template - class vararg_node : public expression_node + class vararg_node exprtk_final : public expression_node { public: typedef expression_node* expression_ptr; + typedef std::pair branch_t; template class Sequence> explicit vararg_node(const Sequence& arg_list) { - arg_list_ .resize(arg_list.size()); - delete_branch_.resize(arg_list.size()); + arg_list_.resize(arg_list.size()); for (std::size_t i = 0; i < arg_list.size(); ++i) { if (arg_list[i]) { - arg_list_[i] = arg_list[i]; - delete_branch_[i] = static_cast(branch_deletable(arg_list_[i]) ? 1 : 0); + construct_branch_pair(arg_list_[i],arg_list[i]); } else { arg_list_.clear(); - delete_branch_.clear(); return; } } } - ~vararg_node() - { - for (std::size_t i = 0; i < arg_list_.size(); ++i) - { - if (arg_list_[i] && delete_branch_[i]) - { - destroy_node(arg_list_[i]); - } - } - } - inline T value() const { return VarArgFunction::process(arg_list_); @@ -9480,14 +10078,23 @@ namespace exprtk return expression_node::e_vararg; } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::collect(arg_list_, node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth(arg_list_); + } + private: - std::vector arg_list_; - std::vector delete_branch_; + std::vector arg_list_; }; template - class vararg_varnode : public expression_node + class vararg_varnode exprtk_final : public expression_node { public: @@ -9533,38 +10140,34 @@ namespace exprtk }; template - class vectorize_node : public expression_node + class vectorize_node exprtk_final : public expression_node { public: typedef expression_node* expression_ptr; + typedef std::pair branch_t; explicit vectorize_node(const expression_ptr v) - : ivec_ptr_(0), - v_(v), - v_deletable_(branch_deletable(v_)) + : ivec_ptr_(0) { - if (is_ivector_node(v)) + construct_branch_pair(v_, v); + + if (is_ivector_node(v_.first)) { - ivec_ptr_ = dynamic_cast*>(v); + ivec_ptr_ = dynamic_cast*>(v_.first); } else ivec_ptr_ = 0; } - ~vectorize_node() - { - if (v_ && v_deletable_) - { - destroy_node(v_); - } - } - inline T value() const { if (ivec_ptr_) { - v_->value(); + assert(v_.first); + + v_.first->value(); + return VecFunction::process(ivec_ptr_); } else @@ -9576,15 +10179,24 @@ namespace exprtk return expression_node::e_vecfunc; } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::collect(v_, node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth(v_); + } + private: vector_interface* ivec_ptr_; - expression_ptr v_; - const bool v_deletable_; + branch_t v_; }; template - class assignment_node : public binary_node + class assignment_node exprtk_final : public binary_node { public: @@ -9593,8 +10205,8 @@ namespace exprtk assignment_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr, branch0, branch1), - var_node_ptr_(0) + : binary_node(opr, branch0, branch1) + , var_node_ptr_(0) { if (is_variable_node(binary_node::branch_[0].first)) { @@ -9606,6 +10218,8 @@ namespace exprtk { if (var_node_ptr_) { + assert(binary_node::branch_[1].first); + T& result = var_node_ptr_->ref(); result = binary_node::branch_[1].first->value(); @@ -9622,7 +10236,7 @@ namespace exprtk }; template - class assignment_vec_elem_node : public binary_node + class assignment_vec_elem_node exprtk_final : public binary_node { public: @@ -9631,8 +10245,8 @@ namespace exprtk assignment_vec_elem_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr, branch0, branch1), - vec_node_ptr_(0) + : binary_node(opr, branch0, branch1) + , vec_node_ptr_(0) { if (is_vector_elem_node(binary_node::branch_[0].first)) { @@ -9644,6 +10258,8 @@ namespace exprtk { if (vec_node_ptr_) { + assert(binary_node::branch_[1].first); + T& result = vec_node_ptr_->ref(); result = binary_node::branch_[1].first->value(); @@ -9660,7 +10276,7 @@ namespace exprtk }; template - class assignment_rebasevec_elem_node : public binary_node + class assignment_rebasevec_elem_node exprtk_final : public binary_node { public: @@ -9669,8 +10285,8 @@ namespace exprtk assignment_rebasevec_elem_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr, branch0, branch1), - rbvec_node_ptr_(0) + : binary_node(opr, branch0, branch1) + , rbvec_node_ptr_(0) { if (is_rebasevector_elem_node(binary_node::branch_[0].first)) { @@ -9682,6 +10298,8 @@ namespace exprtk { if (rbvec_node_ptr_) { + assert(binary_node::branch_[1].first); + T& result = rbvec_node_ptr_->ref(); result = binary_node::branch_[1].first->value(); @@ -9698,7 +10316,7 @@ namespace exprtk }; template - class assignment_rebasevec_celem_node : public binary_node + class assignment_rebasevec_celem_node exprtk_final : public binary_node { public: @@ -9707,8 +10325,8 @@ namespace exprtk assignment_rebasevec_celem_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr, branch0, branch1), - rbvec_node_ptr_(0) + : binary_node(opr, branch0, branch1) + , rbvec_node_ptr_(0) { if (is_rebasevector_celem_node(binary_node::branch_[0].first)) { @@ -9720,6 +10338,8 @@ namespace exprtk { if (rbvec_node_ptr_) { + assert(binary_node::branch_[1].first); + T& result = rbvec_node_ptr_->ref(); result = binary_node::branch_[1].first->value(); @@ -9736,20 +10356,21 @@ namespace exprtk }; template - class assignment_vec_node : public binary_node , - public vector_interface + class assignment_vec_node exprtk_final + : public binary_node + , public vector_interface { public: typedef expression_node* expression_ptr; - typedef vector_node* vector_node_ptr; - typedef vec_data_store vds_t; + typedef vector_node* vector_node_ptr; + typedef vec_data_store vds_t; assignment_vec_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr, branch0, branch1), - vec_node_ptr_(0) + : binary_node(opr, branch0, branch1) + , vec_node_ptr_(0) { if (is_vector_node(binary_node::branch_[0].first)) { @@ -9762,6 +10383,8 @@ namespace exprtk { if (vec_node_ptr_) { + assert(binary_node::branch_[1].first); + const T v = binary_node::branch_[1].first->value(); T* vec = vds().data(); @@ -9853,23 +10476,24 @@ namespace exprtk }; template - class assignment_vecvec_node : public binary_node , - public vector_interface + class assignment_vecvec_node exprtk_final + : public binary_node + , public vector_interface { public: - typedef expression_node* expression_ptr; + typedef expression_node* expression_ptr; typedef vector_node* vector_node_ptr; - typedef vec_data_store vds_t; + typedef vec_data_store vds_t; assignment_vecvec_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr, branch0, branch1), - vec0_node_ptr_(0), - vec1_node_ptr_(0), - initialised_(false), - src_is_ivec_(false) + : binary_node(opr, branch0, branch1) + , vec0_node_ptr_(0) + , vec1_node_ptr_(0) + , initialised_(false) + , src_is_ivec_(false) { if (is_vector_node(binary_node::branch_[0].first)) { @@ -9901,12 +10525,16 @@ namespace exprtk } initialised_ = (vec0_node_ptr_ && vec1_node_ptr_); + + assert(initialised_); } inline T value() const { if (initialised_) { + assert(binary_node::branch_[1].first); + binary_node::branch_[1].first->value(); if (src_is_ivec_) @@ -10006,7 +10634,7 @@ namespace exprtk }; template - class assignment_op_node : public binary_node + class assignment_op_node exprtk_final : public binary_node { public: @@ -10015,8 +10643,8 @@ namespace exprtk assignment_op_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr, branch0, branch1), - var_node_ptr_(0) + : binary_node(opr, branch0, branch1) + , var_node_ptr_(0) { if (is_variable_node(binary_node::branch_[0].first)) { @@ -10028,6 +10656,8 @@ namespace exprtk { if (var_node_ptr_) { + assert(binary_node::branch_[1].first); + T& v = var_node_ptr_->ref(); v = Operation::process(v,binary_node::branch_[1].first->value()); @@ -10043,7 +10673,7 @@ namespace exprtk }; template - class assignment_vec_elem_op_node : public binary_node + class assignment_vec_elem_op_node exprtk_final : public binary_node { public: @@ -10052,8 +10682,8 @@ namespace exprtk assignment_vec_elem_op_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr, branch0, branch1), - vec_node_ptr_(0) + : binary_node(opr, branch0, branch1) + , vec_node_ptr_(0) { if (is_vector_elem_node(binary_node::branch_[0].first)) { @@ -10065,6 +10695,8 @@ namespace exprtk { if (vec_node_ptr_) { + assert(binary_node::branch_[1].first); + T& v = vec_node_ptr_->ref(); v = Operation::process(v,binary_node::branch_[1].first->value()); @@ -10080,7 +10712,7 @@ namespace exprtk }; template - class assignment_rebasevec_elem_op_node : public binary_node + class assignment_rebasevec_elem_op_node exprtk_final : public binary_node { public: @@ -10089,8 +10721,8 @@ namespace exprtk assignment_rebasevec_elem_op_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr, branch0, branch1), - rbvec_node_ptr_(0) + : binary_node(opr, branch0, branch1) + , rbvec_node_ptr_(0) { if (is_rebasevector_elem_node(binary_node::branch_[0].first)) { @@ -10102,6 +10734,8 @@ namespace exprtk { if (rbvec_node_ptr_) { + assert(binary_node::branch_[1].first); + T& v = rbvec_node_ptr_->ref(); v = Operation::process(v,binary_node::branch_[1].first->value()); @@ -10117,7 +10751,7 @@ namespace exprtk }; template - class assignment_rebasevec_celem_op_node : public binary_node + class assignment_rebasevec_celem_op_node exprtk_final : public binary_node { public: @@ -10126,8 +10760,8 @@ namespace exprtk assignment_rebasevec_celem_op_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr, branch0, branch1), - rbvec_node_ptr_(0) + : binary_node(opr, branch0, branch1) + , rbvec_node_ptr_(0) { if (is_rebasevector_celem_node(binary_node::branch_[0].first)) { @@ -10139,6 +10773,8 @@ namespace exprtk { if (rbvec_node_ptr_) { + assert(binary_node::branch_[1].first); + T& v = rbvec_node_ptr_->ref(); v = Operation::process(v,binary_node::branch_[1].first->value()); @@ -10154,20 +10790,21 @@ namespace exprtk }; template - class assignment_vec_op_node : public binary_node , - public vector_interface + class assignment_vec_op_node exprtk_final + : public binary_node + , public vector_interface { public: - typedef expression_node* expression_ptr; + typedef expression_node* expression_ptr; typedef vector_node* vector_node_ptr; - typedef vec_data_store vds_t; + typedef vec_data_store vds_t; assignment_vec_op_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr, branch0, branch1), - vec_node_ptr_(0) + : binary_node(opr, branch0, branch1) + , vec_node_ptr_(0) { if (is_vector_node(binary_node::branch_[0].first)) { @@ -10180,6 +10817,8 @@ namespace exprtk { if (vec_node_ptr_) { + assert(binary_node::branch_[1].first); + const T v = binary_node::branch_[1].first->value(); T* vec = vds().data(); @@ -10277,22 +10916,23 @@ namespace exprtk }; template - class assignment_vecvec_op_node : public binary_node , - public vector_interface + class assignment_vecvec_op_node exprtk_final + : public binary_node + , public vector_interface { public: - typedef expression_node* expression_ptr; + typedef expression_node* expression_ptr; typedef vector_node* vector_node_ptr; - typedef vec_data_store vds_t; + typedef vec_data_store vds_t; assignment_vecvec_op_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr, branch0, branch1), - vec0_node_ptr_(0), - vec1_node_ptr_(0), - initialised_(false) + : binary_node(opr, branch0, branch1) + , vec0_node_ptr_(0) + , vec1_node_ptr_(0) + , initialised_(false) { if (is_vector_node(binary_node::branch_[0].first)) { @@ -10319,12 +10959,17 @@ namespace exprtk } initialised_ = (vec0_node_ptr_ && vec1_node_ptr_); + + assert(initialised_); } inline T value() const { if (initialised_) { + assert(binary_node::branch_[0].first); + assert(binary_node::branch_[1].first); + binary_node::branch_[0].first->value(); binary_node::branch_[1].first->value(); @@ -10428,25 +11073,26 @@ namespace exprtk }; template - class vec_binop_vecvec_node : public binary_node , - public vector_interface + class vec_binop_vecvec_node exprtk_final + : public binary_node + , public vector_interface { public: - typedef expression_node* expression_ptr; - typedef vector_node* vector_node_ptr; + typedef expression_node* expression_ptr; + typedef vector_node* vector_node_ptr; typedef vector_holder* vector_holder_ptr; - typedef vec_data_store vds_t; + typedef vec_data_store vds_t; vec_binop_vecvec_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr, branch0, branch1), - vec0_node_ptr_(0), - vec1_node_ptr_(0), - temp_ (0), - temp_vec_node_(0), - initialised_(false) + : binary_node(opr, branch0, branch1) + , vec0_node_ptr_(0) + , vec1_node_ptr_(0) + , temp_ (0) + , temp_vec_node_(0) + , initialised_(false) { bool v0_is_ivec = false; bool v1_is_ivec = false; @@ -10494,10 +11140,12 @@ namespace exprtk vds_ = vds_t(std::min(vec0.size(),vec1.size())); temp_ = new vector_holder(vds().data(),vds().size()); - temp_vec_node_ = new vector_node (vds(),temp_); + temp_vec_node_ = new vector_node (vds(),temp_); initialised_ = true; } + + assert(initialised_); } ~vec_binop_vecvec_node() @@ -10510,6 +11158,9 @@ namespace exprtk { if (initialised_) { + assert(binary_node::branch_[0].first); + assert(binary_node::branch_[1].first); + binary_node::branch_[0].first->value(); binary_node::branch_[1].first->value(); @@ -10612,23 +11263,24 @@ namespace exprtk }; template - class vec_binop_vecval_node : public binary_node , - public vector_interface + class vec_binop_vecval_node exprtk_final + : public binary_node + , public vector_interface { public: - typedef expression_node* expression_ptr; - typedef vector_node* vector_node_ptr; + typedef expression_node* expression_ptr; + typedef vector_node* vector_node_ptr; typedef vector_holder* vector_holder_ptr; - typedef vec_data_store vds_t; + typedef vec_data_store vds_t; vec_binop_vecval_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr, branch0, branch1), - vec0_node_ptr_(0), - temp_ (0), - temp_vec_node_(0) + : binary_node(opr, branch0, branch1) + , vec0_node_ptr_(0) + , temp_ (0) + , temp_vec_node_(0) { bool v0_is_ivec = false; @@ -10655,7 +11307,7 @@ namespace exprtk vds() = vds_t(vec0_node_ptr_->size()); temp_ = new vector_holder(vds()); - temp_vec_node_ = new vector_node (vds(),temp_); + temp_vec_node_ = new vector_node (vds(),temp_); } } @@ -10669,6 +11321,9 @@ namespace exprtk { if (vec0_node_ptr_) { + assert(binary_node::branch_[0].first); + assert(binary_node::branch_[1].first); + binary_node::branch_[0].first->value(); const T v = binary_node::branch_[1].first->value(); @@ -10767,23 +11422,24 @@ namespace exprtk }; template - class vec_binop_valvec_node : public binary_node , - public vector_interface + class vec_binop_valvec_node exprtk_final + : public binary_node + , public vector_interface { public: - typedef expression_node* expression_ptr; - typedef vector_node* vector_node_ptr; + typedef expression_node* expression_ptr; + typedef vector_node* vector_node_ptr; typedef vector_holder* vector_holder_ptr; - typedef vec_data_store vds_t; + typedef vec_data_store vds_t; vec_binop_valvec_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr, branch0, branch1), - vec1_node_ptr_(0), - temp_ (0), - temp_vec_node_(0) + : binary_node(opr, branch0, branch1) + , vec1_node_ptr_(0) + , temp_ (0) + , temp_vec_node_(0) { bool v1_is_ivec = false; @@ -10810,7 +11466,7 @@ namespace exprtk vds() = vds_t(vec1_node_ptr_->size()); temp_ = new vector_holder(vds()); - temp_vec_node_ = new vector_node (vds(),temp_); + temp_vec_node_ = new vector_node (vds(),temp_); } } @@ -10824,6 +11480,9 @@ namespace exprtk { if (vec1_node_ptr_) { + assert(binary_node::branch_[0].first); + assert(binary_node::branch_[1].first); + const T v = binary_node::branch_[0].first->value(); binary_node::branch_[1].first->value(); @@ -10922,33 +11581,34 @@ namespace exprtk }; template - class unary_vector_node : public unary_node , - public vector_interface + class unary_vector_node exprtk_final + : public unary_node + , public vector_interface { public: - typedef expression_node* expression_ptr; - typedef vector_node* vector_node_ptr; + typedef expression_node* expression_ptr; + typedef vector_node* vector_node_ptr; typedef vector_holder* vector_holder_ptr; - typedef vec_data_store vds_t; + typedef vec_data_store vds_t; unary_vector_node(const operator_type& opr, expression_ptr branch0) - : unary_node(opr, branch0), - vec0_node_ptr_(0), - temp_ (0), - temp_vec_node_(0) + : unary_node(opr, branch0) + , vec0_node_ptr_(0) + , temp_ (0) + , temp_vec_node_(0) { bool vec0_is_ivec = false; - if (is_vector_node(unary_node::branch_)) + if (is_vector_node(unary_node::branch_.first)) { - vec0_node_ptr_ = static_cast(unary_node::branch_); + vec0_node_ptr_ = static_cast(unary_node::branch_.first); } - else if (is_ivector_node(unary_node::branch_)) + else if (is_ivector_node(unary_node::branch_.first)) { vector_interface* vi = reinterpret_cast*>(0); - if (0 != (vi = dynamic_cast*>(unary_node::branch_))) + if (0 != (vi = dynamic_cast*>(unary_node::branch_.first))) { vec0_node_ptr_ = vi->vec(); vec0_is_ivec = true; @@ -10963,7 +11623,7 @@ namespace exprtk vds_ = vds_t(vec0_node_ptr_->size()); temp_ = new vector_holder(vds()); - temp_vec_node_ = new vector_node (vds(),temp_); + temp_vec_node_ = new vector_node (vds(),temp_); } } @@ -10975,7 +11635,9 @@ namespace exprtk inline T value() const { - unary_node::branch_->value(); + assert(unary_node::branch_.first); + + unary_node::branch_.first->value(); if (vec0_node_ptr_) { @@ -11074,7 +11736,167 @@ namespace exprtk }; template - class scand_node : public binary_node + class conditional_vector_node exprtk_final + : public expression_node + , public vector_interface + { + public: + + typedef expression_node * expression_ptr; + typedef vector_interface* vec_interface_ptr; + typedef vector_node * vector_node_ptr; + typedef vector_holder * vector_holder_ptr; + typedef vec_data_store vds_t; + typedef std::pair branch_t; + + conditional_vector_node(expression_ptr condition, + expression_ptr consequent, + expression_ptr alternative) + : consequent_node_ptr_ (0) + , alternative_node_ptr_(0) + , temp_vec_node_ (0) + , temp_ (0) + , vec_size_ (0) + , initialised_ (false) + { + construct_branch_pair(condition_ , condition ); + construct_branch_pair(consequent_ , consequent ); + construct_branch_pair(alternative_, alternative); + + if (details::is_ivector_node(consequent_.first)) + { + vec_interface_ptr ivec_ptr = dynamic_cast(consequent_.first); + + if (0 != ivec_ptr) + { + consequent_node_ptr_ = ivec_ptr->vec(); + } + } + + if (details::is_ivector_node(alternative_.first)) + { + vec_interface_ptr ivec_ptr = dynamic_cast(alternative_.first); + + if (0 != ivec_ptr) + { + alternative_node_ptr_ = ivec_ptr->vec(); + } + } + + if (consequent_node_ptr_ && alternative_node_ptr_) + { + vec_size_ = std::min(consequent_node_ptr_ ->vds().size(), + alternative_node_ptr_->vds().size()); + + vds_ = vds_t(vec_size_); + temp_ = new vector_holder(vds_); + temp_vec_node_ = new vector_node (vds(),temp_); + + initialised_ = true; + } + + assert(initialised_ && (vec_size_ > 0)); + } + + ~conditional_vector_node() + { + delete temp_; + delete temp_vec_node_; + } + + inline T value() const + { + if (initialised_) + { + assert(condition_ .first); + assert(consequent_ .first); + assert(alternative_.first); + + T result = T(0); + T* source_vector = 0; + T* result_vector = vds().data(); + + if (is_true(condition_)) + { + result = consequent_.first->value(); + source_vector = consequent_node_ptr_->vds().data(); + } + else + { + result = alternative_.first->value(); + source_vector = alternative_node_ptr_->vds().data(); + } + + for (std::size_t i = 0; i < vec_size_; ++i) + { + result_vector[i] = source_vector[i]; + } + + return result; + } + + return std::numeric_limits::quiet_NaN(); + } + + vector_node_ptr vec() const + { + return temp_vec_node_; + } + + vector_node_ptr vec() + { + return temp_vec_node_; + } + + inline typename expression_node::node_type type() const + { + return expression_node::e_vecondition; + } + + std::size_t size() const + { + return vec_size_; + } + + vds_t& vds() + { + return vds_; + } + + const vds_t& vds() const + { + return vds_; + } + + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::collect(condition_ , node_delete_list); + expression_node::ndb_t::collect(consequent_ , node_delete_list); + expression_node::ndb_t::collect(alternative_ , node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth + (condition_, consequent_, alternative_); + } + + private: + + branch_t condition_; + branch_t consequent_; + branch_t alternative_; + vector_node_ptr consequent_node_ptr_; + vector_node_ptr alternative_node_ptr_; + vector_node_ptr temp_vec_node_; + vector_holder_ptr temp_; + vds_t vds_; + std::size_t vec_size_; + bool initialised_; + }; + + template + class scand_node exprtk_final : public binary_node { public: @@ -11088,6 +11910,9 @@ namespace exprtk inline T value() const { + assert(binary_node::branch_[0].first); + assert(binary_node::branch_[1].first); + return ( std::not_equal_to() (T(0),binary_node::branch_[0].first->value()) && @@ -11098,7 +11923,7 @@ namespace exprtk }; template - class scor_node : public binary_node + class scor_node exprtk_final : public binary_node { public: @@ -11112,6 +11937,9 @@ namespace exprtk inline T value() const { + assert(binary_node::branch_[0].first); + assert(binary_node::branch_[1].first); + return ( std::not_equal_to() (T(0),binary_node::branch_[0].first->value()) || @@ -11122,7 +11950,7 @@ namespace exprtk }; template - class function_N_node : public expression_node + class function_N_node exprtk_final : public expression_node { public: @@ -11132,15 +11960,10 @@ namespace exprtk typedef IFunction ifunction; explicit function_N_node(ifunction* func) - : function_((N == func->param_count) ? func : reinterpret_cast(0)), - parameter_count_(func->param_count) + : function_((N == func->param_count) ? func : reinterpret_cast(0)) + , parameter_count_(func->param_count) {} - ~function_N_node() - { - cleanup_branches::execute(branch_); - } - template bool init_branches(expression_ptr (&b)[NumBranches]) { @@ -11192,6 +12015,21 @@ namespace exprtk #endif } + inline typename expression_node::node_type type() const + { + return expression_node::e_function; + } + + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::template collect(branch_, node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::template compute_node_depth(branch_); + } + template struct evaluate_branches { @@ -11280,119 +12118,119 @@ namespace exprtk struct invoke { static inline T_ execute(ifunction& f, T_ (&v)[18]) - { return f(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9],v[10],v[11],v[12],v[13],v[14],v[15],v[16],v[17]); } + { return f(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11], v[12], v[13], v[14], v[15], v[16], v[17]); } }; template struct invoke { static inline T_ execute(ifunction& f, T_ (&v)[17]) - { return f(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9],v[10],v[11],v[12],v[13],v[14],v[15],v[16]); } + { return f(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11], v[12], v[13], v[14], v[15], v[16]); } }; template struct invoke { static inline T_ execute(ifunction& f, T_ (&v)[16]) - { return f(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9],v[10],v[11],v[12],v[13],v[14],v[15]); } + { return f(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11], v[12], v[13], v[14], v[15]); } }; template struct invoke { static inline T_ execute(ifunction& f, T_ (&v)[15]) - { return f(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9],v[10],v[11],v[12],v[13],v[14]); } + { return f(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11], v[12], v[13], v[14]); } }; template struct invoke { static inline T_ execute(ifunction& f, T_ (&v)[14]) - { return f(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9],v[10],v[11],v[12],v[13]); } + { return f(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11], v[12], v[13]); } }; template struct invoke { static inline T_ execute(ifunction& f, T_ (&v)[13]) - { return f(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9],v[10],v[11],v[12]); } + { return f(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11], v[12]); } }; template struct invoke { static inline T_ execute(ifunction& f, T_ (&v)[12]) - { return f(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9],v[10],v[11]); } + { return f(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11]); } }; template struct invoke { static inline T_ execute(ifunction& f, T_ (&v)[11]) - { return f(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9],v[10]); } + { return f(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10]); } }; template struct invoke { static inline T_ execute(ifunction& f, T_ (&v)[10]) - { return f(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9]); } + { return f(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9]); } }; template struct invoke { static inline T_ execute(ifunction& f, T_ (&v)[9]) - { return f(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8]); } + { return f(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8]); } }; template struct invoke { static inline T_ execute(ifunction& f, T_ (&v)[8]) - { return f(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7]); } + { return f(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]); } }; template struct invoke { static inline T_ execute(ifunction& f, T_ (&v)[7]) - { return f(v[0],v[1],v[2],v[3],v[4],v[5],v[6]); } + { return f(v[0], v[1], v[2], v[3], v[4], v[5], v[6]); } }; template struct invoke { static inline T_ execute(ifunction& f, T_ (&v)[6]) - { return f(v[0],v[1],v[2],v[3],v[4],v[5]); } + { return f(v[0], v[1], v[2], v[3], v[4], v[5]); } }; template struct invoke { static inline T_ execute(ifunction& f, T_ (&v)[5]) - { return f(v[0],v[1],v[2],v[3],v[4]); } + { return f(v[0], v[1], v[2], v[3], v[4]); } }; template struct invoke { static inline T_ execute(ifunction& f, T_ (&v)[4]) - { return f(v[0],v[1],v[2],v[3]); } + { return f(v[0], v[1], v[2], v[3]); } }; template struct invoke { static inline T_ execute(ifunction& f, T_ (&v)[3]) - { return f(v[0],v[1],v[2]); } + { return f(v[0], v[1], v[2]); } }; template struct invoke { static inline T_ execute(ifunction& f, T_ (&v)[2]) - { return f(v[0],v[1]); } + { return f(v[0], v[1]); } }; template @@ -11402,11 +12240,6 @@ namespace exprtk { return f(v[0]); } }; - inline typename expression_node::node_type type() const - { - return expression_node::e_function; - } - private: ifunction* function_; @@ -11415,7 +12248,7 @@ namespace exprtk }; template - class function_N_node : public expression_node + class function_N_node exprtk_final : public expression_node { public: @@ -11450,7 +12283,7 @@ namespace exprtk }; template - class vararg_function_node : public expression_node + class vararg_function_node exprtk_final : public expression_node { public: @@ -11458,23 +12291,12 @@ namespace exprtk vararg_function_node(VarArgFunction* func, const std::vector& arg_list) - : function_(func), - arg_list_(arg_list) + : function_(func) + , arg_list_(arg_list) { value_list_.resize(arg_list.size(),std::numeric_limits::quiet_NaN()); } - ~vararg_function_node() - { - for (std::size_t i = 0; i < arg_list_.size(); ++i) - { - if (arg_list_[i] && !details::is_variable_node(arg_list_[i])) - { - destroy_node(arg_list_[i]); - } - } - } - inline bool operator <(const vararg_function_node& fn) const { return this < (&fn); @@ -11496,6 +12318,22 @@ namespace exprtk return expression_node::e_vafunction; } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + for (std::size_t i = 0; i < arg_list_.size(); ++i) + { + if (arg_list_[i] && !details::is_variable_node(arg_list_[i])) + { + node_delete_list.push_back(&arg_list_[i]); + } + } + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth(arg_list_); + } + private: inline void populate_value_list() const @@ -11516,30 +12354,40 @@ namespace exprtk { public: - typedef type_store type_store_t; - typedef expression_node* expression_ptr; - typedef variable_node variable_node_t; - typedef vector_node vector_node_t; - typedef variable_node_t* variable_node_ptr_t; - typedef vector_node_t* vector_node_ptr_t; - typedef range_interface range_interface_t; - typedef range_data_type range_data_type_t; - typedef range_pack range_t; - typedef std::pair branch_t; - typedef std::pair void_t; - typedef std::vector tmp_vs_t; - typedef std::vector typestore_list_t; - typedef std::vector range_list_t; - - generic_function_node(const std::vector& arg_list, - GenericFunction* func = (GenericFunction*)(0)) - : function_(func), - arg_list_(arg_list) + typedef type_store type_store_t; + typedef expression_node* expression_ptr; + typedef variable_node variable_node_t; + typedef vector_node vector_node_t; + typedef variable_node_t* variable_node_ptr_t; + typedef vector_node_t* vector_node_ptr_t; + typedef range_interface range_interface_t; + typedef range_data_type range_data_type_t; + typedef range_pack range_t; + + typedef std::pair branch_t; + typedef std::pair void_t; + + typedef std::vector tmp_vs_t; + typedef std::vector typestore_list_t; + typedef std::vector range_list_t; + + explicit generic_function_node(const std::vector& arg_list, + GenericFunction* func = reinterpret_cast(0)) + : function_(func) + , arg_list_(arg_list) {} virtual ~generic_function_node() + {} + + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) { - cleanup_branches::execute(branch_); + expression_node::ndb_t::collect(branch_, node_delete_list); + } + + std::size_t node_depth() const exprtk_final + { + return expression_node::ndb_t::compute_node_depth(branch_); } virtual bool init_branches() @@ -11547,7 +12395,7 @@ namespace exprtk expr_as_vec1_store_.resize(arg_list_.size(),T(0) ); typestore_list_ .resize(arg_list_.size(),type_store_t() ); range_list_ .resize(arg_list_.size(),range_data_type_t()); - branch_ .resize(arg_list_.size(),branch_t((expression_ptr)0,false)); + branch_ .resize(arg_list_.size(),branch_t(reinterpret_cast(0),false)); for (std::size_t i = 0; i < arg_list_.size(); ++i) { @@ -11589,7 +12437,7 @@ namespace exprtk if (0 == (ri = dynamic_cast(arg_list_[i]))) return false; - range_t& rp = ri->range_ref(); + const range_t& rp = ri->range_ref(); if ( rp.const_range() && @@ -11668,11 +12516,11 @@ namespace exprtk if (rdt.range) { - range_t& rp = (*rdt.range); - std::size_t r0 = 0; - std::size_t r1 = 0; + const range_t& rp = (*rdt.range); + std::size_t r0 = 0; + std::size_t r1 = 0; - if (rp(r0,r1,rdt.size)) + if (rp(r0, r1, rdt.size)) { type_store_t& ts = typestore_list_[i]; @@ -11738,7 +12586,10 @@ namespace exprtk typedef typename StringFunction::parameter_list_t parameter_list_t; const T result = (*gen_function_t::function_) - (ret_string_, parameter_list_t(gen_function_t::typestore_list_)); + ( + ret_string_, + parameter_list_t(gen_function_t::typestore_list_) + ); range_.n1_c.second = ret_string_.size() - 1; range_.cache.second = range_.n1_c.second; @@ -11798,8 +12649,8 @@ namespace exprtk multimode_genfunction_node(GenericFunction* func, const std::size_t& param_seq_index, const std::vector& arg_list) - : gen_function_t(arg_list,func), - param_seq_index_(param_seq_index) + : gen_function_t(arg_list,func) + , param_seq_index_(param_seq_index) {} inline T value() const @@ -11810,15 +12661,18 @@ namespace exprtk { typedef typename GenericFunction::parameter_list_t parameter_list_t; - return (*gen_function_t::function_)(param_seq_index_, - parameter_list_t(gen_function_t::typestore_list_)); + return (*gen_function_t::function_) + ( + param_seq_index_, + parameter_list_t(gen_function_t::typestore_list_) + ); } } return std::numeric_limits::quiet_NaN(); } - inline typename expression_node::node_type type() const + inline typename expression_node::node_type type() const exprtk_final { return expression_node::e_genfunction; } @@ -11830,7 +12684,7 @@ namespace exprtk #ifndef exprtk_disable_string_capabilities template - class multimode_strfunction_node : public string_function_node + class multimode_strfunction_node exprtk_final : public string_function_node { public: @@ -11840,8 +12694,8 @@ namespace exprtk multimode_strfunction_node(StringFunction* func, const std::size_t& param_seq_index, const std::vector& arg_list) - : str_function_t(func,arg_list), - param_seq_index_(param_seq_index) + : str_function_t(func,arg_list) + , param_seq_index_(param_seq_index) {} inline T value() const @@ -11852,9 +12706,12 @@ namespace exprtk { typedef typename StringFunction::parameter_list_t parameter_list_t; - const T result = (*str_function_t::function_)(param_seq_index_, - str_function_t::ret_string_, - parameter_list_t(str_function_t::typestore_list_)); + const T result = (*str_function_t::function_) + ( + param_seq_index_, + str_function_t::ret_string_, + parameter_list_t(str_function_t::typestore_list_) + ); str_function_t::range_.n1_c.second = str_function_t::ret_string_.size() - 1; str_function_t::range_.cache.second = str_function_t::range_.n1_c.second; @@ -11899,7 +12756,7 @@ namespace exprtk #ifndef exprtk_disable_return_statement template - class return_node : public generic_function_node > + class return_node exprtk_final : public generic_function_node > { public: @@ -11910,8 +12767,8 @@ namespace exprtk return_node(const std::vector& arg_list, results_context_t& rc) - : gen_function_t (arg_list), - results_context_(&rc) + : gen_function_t (arg_list) + , results_context_(&rc) {} inline T value() const @@ -11943,36 +12800,31 @@ namespace exprtk }; template - class return_envelope_node : public expression_node + class return_envelope_node exprtk_final : public expression_node { public: typedef expression_node* expression_ptr; typedef results_context results_context_t; + typedef std::pair branch_t; return_envelope_node(expression_ptr body, results_context_t& rc) - : results_context_(&rc ), - return_invoked_ (false), - body_ (body ), - body_deletable_ (branch_deletable(body_)) - {} - - ~return_envelope_node() + : results_context_(&rc ) + , return_invoked_ (false) { - if (body_ && body_deletable_) - { - destroy_node(body_); - } + construct_branch_pair(body_, body); } inline T value() const { + assert(body_.first); + try { return_invoked_ = false; results_context_->clear(); - return body_->value(); + return body_.first->value(); } catch(const return_exception&) { @@ -11991,12 +12843,21 @@ namespace exprtk return &return_invoked_; } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::collect(body_, node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth(body_); + } + private: results_context_t* results_context_; - mutable bool return_invoked_; - expression_ptr body_; - const bool body_deletable_; + mutable bool return_invoked_; + branch_t body_; }; #endif @@ -12070,11 +12931,11 @@ namespace exprtk { typedef typename details::functor_t::Type Type; typedef typename details::functor_t::RefType RefType; - typedef typename details::functor_t functor_t; - typedef typename functor_t::qfunc_t quaternary_functor_t; - typedef typename functor_t::tfunc_t trinary_functor_t; - typedef typename functor_t::bfunc_t binary_functor_t; - typedef typename functor_t::ufunc_t unary_functor_t; + typedef typename details::functor_t functor_t; + typedef typename functor_t::qfunc_t quaternary_functor_t; + typedef typename functor_t::tfunc_t trinary_functor_t; + typedef typename functor_t::bfunc_t binary_functor_t; + typedef typename functor_t::ufunc_t unary_functor_t; }; template @@ -12343,11 +13204,23 @@ namespace exprtk } template - inline T value(T* t) + inline T value(std::pair*,bool> n) + { + return n.first->value(); + } + + template + inline T value(const T* t) { return (*t); } + template + inline T value(const T& t) + { + return t; + } + template struct vararg_add_op : public opr_base { @@ -12595,16 +13468,16 @@ namespace exprtk static inline T process_4(const Sequence& arg_list) { return std::min( - std::min(value(arg_list[0]),value(arg_list[1])), - std::min(value(arg_list[2]),value(arg_list[3]))); + std::min(value(arg_list[0]), value(arg_list[1])), + std::min(value(arg_list[2]), value(arg_list[3]))); } template static inline T process_5(const Sequence& arg_list) { return std::min( - std::min(std::min(value(arg_list[0]),value(arg_list[1])), - std::min(value(arg_list[2]),value(arg_list[3]))), + std::min(std::min(value(arg_list[0]), value(arg_list[1])), + std::min(value(arg_list[2]), value(arg_list[3]))), value(arg_list[4])); } }; @@ -12666,16 +13539,16 @@ namespace exprtk static inline T process_4(const Sequence& arg_list) { return std::max( - std::max(value(arg_list[0]),value(arg_list[1])), - std::max(value(arg_list[2]),value(arg_list[3]))); + std::max(value(arg_list[0]), value(arg_list[1])), + std::max(value(arg_list[2]), value(arg_list[3]))); } template static inline T process_5(const Sequence& arg_list) { return std::max( - std::max(std::max(value(arg_list[0]),value(arg_list[1])), - std::max(value(arg_list[2]),value(arg_list[3]))), + std::max(std::max(value(arg_list[0]), value(arg_list[1])), + std::max(value(arg_list[2]), value(arg_list[3]))), value(arg_list[4])); } }; @@ -13179,7 +14052,7 @@ namespace exprtk for (std::size_t i = 1; i < vec_size; ++i) { - T v_i = vec[i]; + const T v_i = vec[i]; if (v_i < result) result = v_i; @@ -13203,7 +14076,7 @@ namespace exprtk for (std::size_t i = 1; i < vec_size; ++i) { - T v_i = vec[i]; + const T v_i = vec[i]; if (v_i > result) result = v_i; @@ -13294,8 +14167,8 @@ namespace exprtk { public: - virtual ~cob_base_node() - {} + virtual ~cob_base_node() + {} inline virtual operator_type operation() const { @@ -13396,7 +14269,7 @@ namespace exprtk }; template - class unary_variable_node : public uv_base_node + class unary_variable_node exprtk_final : public uv_base_node { public: @@ -13436,24 +14309,23 @@ namespace exprtk }; template - class uvouv_node : public expression_node + class uvouv_node exprtk_final : public expression_node { public: // UOpr1(v0) Op UOpr2(v1) - - typedef expression_node* expression_ptr; typedef typename details::functor_t functor_t; - typedef typename functor_t::bfunc_t bfunc_t; - typedef typename functor_t::ufunc_t ufunc_t; + typedef typename functor_t::bfunc_t bfunc_t; + typedef typename functor_t::ufunc_t ufunc_t; + typedef expression_node* expression_ptr; explicit uvouv_node(const T& var0,const T& var1, ufunc_t uf0, ufunc_t uf1, bfunc_t bf) - : v0_(var0), - v1_(var1), - u0_(uf0 ), - u1_(uf1 ), - f_ (bf ) + : v0_(var0) + , v1_(var1) + , u0_(uf0 ) + , u1_(uf1 ) + , f_ (bf ) {} inline T value() const @@ -13509,29 +14381,22 @@ namespace exprtk }; template - class unary_branch_node : public expression_node + class unary_branch_node exprtk_final : public expression_node { public: typedef expression_node* expression_ptr; + typedef std::pair branch_t; typedef Operation operation_t; - explicit unary_branch_node(expression_ptr brnch) - : branch_(brnch), - branch_deletable_(branch_deletable(branch_)) - {} - - ~unary_branch_node() + explicit unary_branch_node(expression_ptr branch) { - if (branch_ && branch_deletable_) - { - destroy_node(branch_); - } + construct_branch_pair(branch_, branch); } inline T value() const { - return Operation::process(branch_->value()); + return Operation::process(branch_.first->value()); } inline typename expression_node::node_type type() const @@ -13546,12 +14411,22 @@ namespace exprtk inline expression_node* branch(const std::size_t&) const { - return branch_; + return branch_.first; } inline void release() { - branch_deletable_ = false; + branch_.second = false; + } + + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::collect(branch_, node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth(branch_); } private: @@ -13559,8 +14434,7 @@ namespace exprtk unary_branch_node(unary_branch_node&); unary_branch_node& operator=(unary_branch_node&); - expression_ptr branch_; - bool branch_deletable_; + branch_t branch_; }; template struct is_const { enum {result = 0}; }; @@ -13584,7 +14458,7 @@ namespace exprtk struct T0oT1oT2process { typedef typename details::functor_t functor_t; - typedef typename functor_t::bfunc_t bfunc_t; + typedef typename functor_t::bfunc_t bfunc_t; struct mode0 { @@ -13627,7 +14501,7 @@ namespace exprtk struct T0oT1oT20T3process { typedef typename details::functor_t functor_t; - typedef typename functor_t::bfunc_t bfunc_t; + typedef typename functor_t::bfunc_t bfunc_t; struct mode0 { @@ -13810,19 +14684,19 @@ namespace exprtk #undef synthesis_node_type_define template - class T0oT1 : public expression_node + class T0oT1 exprtk_final : public expression_node { public: typedef typename details::functor_t functor_t; - typedef typename functor_t::bfunc_t bfunc_t; + typedef typename functor_t::bfunc_t bfunc_t; typedef T value_type; typedef T0oT1 node_type; T0oT1(T0 p0, T1 p1, const bfunc_t p2) - : t0_(p0), - t1_(p1), - f_ (p2) + : t0_(p0) + , t1_(p1) + , f_ (p2) {} inline typename expression_node::node_type type() const @@ -13877,22 +14751,22 @@ namespace exprtk }; template - class T0oT1oT2 : public T0oT1oT2_base_node + class T0oT1oT2 exprtk_final : public T0oT1oT2_base_node { public: typedef typename details::functor_t functor_t; - typedef typename functor_t::bfunc_t bfunc_t; + typedef typename functor_t::bfunc_t bfunc_t; typedef T value_type; typedef T0oT1oT2 node_type; typedef ProcessMode process_mode_t; T0oT1oT2(T0 p0, T1 p1, T2 p2, const bfunc_t p3, const bfunc_t p4) - : t0_(p0), - t1_(p1), - t2_(p2), - f0_(p3), - f1_(p4) + : t0_(p0) + , t1_(p1) + , t2_(p2) + , f0_(p3) + , f1_(p4) {} inline typename expression_node::node_type type() const @@ -13967,12 +14841,12 @@ namespace exprtk }; template - class T0oT1oT2oT3 : public T0oT1oT2oT3_base_node + class T0oT1oT2oT3 exprtk_final : public T0oT1oT2oT3_base_node { public: typedef typename details::functor_t functor_t; - typedef typename functor_t::bfunc_t bfunc_t; + typedef typename functor_t::bfunc_t bfunc_t; typedef T value_type; typedef T0_ T0; typedef T1_ T1; @@ -13982,13 +14856,13 @@ namespace exprtk typedef ProcessMode process_mode_t; T0oT1oT2oT3(T0 p0, T1 p1, T2 p2, T3 p3, bfunc_t p4, bfunc_t p5, bfunc_t p6) - : t0_(p0), - t1_(p1), - t2_(p2), - t3_(p3), - f0_(p4), - f1_(p5), - f2_(p6) + : t0_(p0) + , t1_(p1) + , t2_(p2) + , t3_(p3) + , f0_(p4) + , f1_(p5) + , f2_(p6) {} inline T value() const @@ -14066,20 +14940,20 @@ namespace exprtk }; template - class T0oT1oT2_sf3 : public T0oT1oT2_base_node + class T0oT1oT2_sf3 exprtk_final : public T0oT1oT2_base_node { public: typedef typename details::functor_t functor_t; - typedef typename functor_t::tfunc_t tfunc_t; + typedef typename functor_t::tfunc_t tfunc_t; typedef T value_type; typedef T0oT1oT2_sf3 node_type; T0oT1oT2_sf3(T0 p0, T1 p1, T2 p2, const tfunc_t p3) - : t0_(p0), - t1_(p1), - t2_(p2), - f_ (p3) + : t0_(p0) + , t1_(p1) + , t2_(p2) + , f_ (p3) {} inline typename expression_node::node_type type() const @@ -14163,19 +15037,19 @@ namespace exprtk }; template - class T0oT1oT2_sf3ext : public sf3ext_type_node + class T0oT1oT2_sf3ext exprtk_final : public sf3ext_type_node { public: typedef typename details::functor_t functor_t; - typedef typename functor_t::tfunc_t tfunc_t; + typedef typename functor_t::tfunc_t tfunc_t; typedef T value_type; typedef T0oT1oT2_sf3ext node_type; T0oT1oT2_sf3ext(T0 p0, T1 p1, T2 p2) - : t0_(p0), - t1_(p1), - t2_(p2) + : t0_(p0) + , t1_(p1) + , t2_(p2) {} inline typename expression_node::node_type type() const @@ -14252,21 +15126,21 @@ namespace exprtk } template - class T0oT1oT2oT3_sf4 : public T0oT1oT2_base_node + class T0oT1oT2oT3_sf4 exprtk_final : public T0oT1oT2_base_node { public: typedef typename details::functor_t functor_t; - typedef typename functor_t::qfunc_t qfunc_t; + typedef typename functor_t::qfunc_t qfunc_t; typedef T value_type; typedef T0oT1oT2oT3_sf4 node_type; T0oT1oT2oT3_sf4(T0 p0, T1 p1, T2 p2, T3 p3, const qfunc_t p4) - : t0_(p0), - t1_(p1), - t2_(p2), - t3_(p3), - f_ (p4) + : t0_(p0) + , t1_(p1) + , t2_(p2) + , t3_(p3) + , f_ (p4) {} inline typename expression_node::node_type type() const @@ -14341,20 +15215,20 @@ namespace exprtk }; template - class T0oT1oT2oT3_sf4ext : public T0oT1oT2oT3_base_node + class T0oT1oT2oT3_sf4ext exprtk_final : public T0oT1oT2oT3_base_node { public: typedef typename details::functor_t functor_t; - typedef typename functor_t::tfunc_t tfunc_t; + typedef typename functor_t::tfunc_t tfunc_t; typedef T value_type; typedef T0oT1oT2oT3_sf4ext node_type; T0oT1oT2oT3_sf4ext(T0 p0, T1 p1, T2 p2, T3 p3) - : t0_(p0), - t1_(p1), - t2_(p2), - t3_(p3) + : t0_(p0) + , t1_(p1) + , t2_(p2) + , t3_(p3) {} inline typename expression_node::node_type type() const @@ -14467,7 +15341,7 @@ namespace exprtk }; template - class vov_node : public vov_base_node + class vov_node exprtk_final : public vov_base_node { public: @@ -14476,8 +15350,8 @@ namespace exprtk // variable op variable node explicit vov_node(const T& var0, const T& var1) - : v0_(var0), - v1_(var1) + : v0_(var0) + , v1_(var1) {} inline T value() const @@ -14517,7 +15391,7 @@ namespace exprtk }; template - class cov_node : public cov_base_node + class cov_node exprtk_final : public cov_base_node { public: @@ -14526,8 +15400,8 @@ namespace exprtk // constant op variable node explicit cov_node(const T& const_var, const T& var) - : c_(const_var), - v_(var) + : c_(const_var) + , v_(var) {} inline T value() const @@ -14567,7 +15441,7 @@ namespace exprtk }; template - class voc_node : public voc_base_node + class voc_node exprtk_final : public voc_base_node { public: @@ -14576,8 +15450,8 @@ namespace exprtk // variable op constant node explicit voc_node(const T& var, const T& const_var) - : v_(var), - c_(const_var) + : v_(var) + , c_(const_var) {} inline T value() const @@ -14612,7 +15486,7 @@ namespace exprtk }; template - class vob_node : public vob_base_node + class vob_node exprtk_final : public vob_base_node { public: @@ -14621,20 +15495,16 @@ namespace exprtk typedef Operation operation_t; // variable op constant node - explicit vob_node(const T& var, const expression_ptr brnch) + explicit vob_node(const T& var, const expression_ptr branch) : v_(var) { - init_branches<1>(branch_,brnch); - } - - ~vob_node() - { - cleanup_branches::execute(branch_); + construct_branch_pair(branch_, branch); } inline T value() const { - return Operation::process(v_,branch_[0].first->value()); + assert(branch_.first); + return Operation::process(v_,branch_.first->value()); } inline operator_type operation() const @@ -14649,7 +15519,17 @@ namespace exprtk inline expression_node* branch(const std::size_t&) const { - return branch_[0].first; + return branch_.first; + } + + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::template collect(branch_, node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth(branch_); } private: @@ -14658,11 +15538,11 @@ namespace exprtk vob_node& operator=(const vob_node&); const T& v_; - branch_t branch_[1]; + branch_t branch_; }; template - class bov_node : public bov_base_node + class bov_node exprtk_final : public bov_base_node { public: @@ -14671,20 +15551,16 @@ namespace exprtk typedef Operation operation_t; // variable op constant node - explicit bov_node(const expression_ptr brnch, const T& var) + explicit bov_node(const expression_ptr branch, const T& var) : v_(var) { - init_branches<1>(branch_,brnch); - } - - ~bov_node() - { - cleanup_branches::execute(branch_); + construct_branch_pair(branch_, branch); } inline T value() const { - return Operation::process(branch_[0].first->value(),v_); + assert(branch_.first); + return Operation::process(branch_.first->value(),v_); } inline operator_type operation() const @@ -14699,7 +15575,17 @@ namespace exprtk inline expression_node* branch(const std::size_t&) const { - return branch_[0].first; + return branch_.first; + } + + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::template collect(branch_, node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth(branch_); } private: @@ -14708,11 +15594,11 @@ namespace exprtk bov_node& operator=(const bov_node&); const T& v_; - branch_t branch_[1]; + branch_t branch_; }; template - class cob_node : public cob_base_node + class cob_node exprtk_final : public cob_base_node { public: @@ -14721,20 +15607,16 @@ namespace exprtk typedef Operation operation_t; // variable op constant node - explicit cob_node(const T const_var, const expression_ptr brnch) + explicit cob_node(const T const_var, const expression_ptr branch) : c_(const_var) { - init_branches<1>(branch_,brnch); - } - - ~cob_node() - { - cleanup_branches::execute(branch_); + construct_branch_pair(branch_, branch); } inline T value() const { - return Operation::process(c_,branch_[0].first->value()); + assert(branch_.first); + return Operation::process(c_,branch_.first->value()); } inline operator_type operation() const @@ -14754,13 +15636,23 @@ namespace exprtk inline expression_node* branch(const std::size_t&) const { - return branch_[0].first; + return branch_.first; } inline expression_node* move_branch(const std::size_t&) { - branch_[0].second = false; - return branch_[0].first; + branch_.second = false; + return branch_.first; + } + + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::template collect(branch_, node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth(branch_); } private: @@ -14769,11 +15661,11 @@ namespace exprtk cob_node& operator=(const cob_node&); const T c_; - branch_t branch_[1]; + branch_t branch_; }; template - class boc_node : public boc_base_node + class boc_node exprtk_final : public boc_base_node { public: @@ -14782,20 +15674,16 @@ namespace exprtk typedef Operation operation_t; // variable op constant node - explicit boc_node(const expression_ptr brnch, const T const_var) + explicit boc_node(const expression_ptr branch, const T const_var) : c_(const_var) { - init_branches<1>(branch_,brnch); - } - - ~boc_node() - { - cleanup_branches::execute(branch_); + construct_branch_pair(branch_, branch); } inline T value() const { - return Operation::process(branch_[0].first->value(),c_); + assert(branch_.first); + return Operation::process(branch_.first->value(),c_); } inline operator_type operation() const @@ -14815,13 +15703,23 @@ namespace exprtk inline expression_node* branch(const std::size_t&) const { - return branch_[0].first; + return branch_.first; } inline expression_node* move_branch(const std::size_t&) { - branch_[0].second = false; - return branch_[0].first; + branch_.second = false; + return branch_.first; + } + + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::template collect(branch_, node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth(branch_); } private: @@ -14830,12 +15728,12 @@ namespace exprtk boc_node& operator=(const boc_node&); const T c_; - branch_t branch_[1]; + branch_t branch_; }; #ifndef exprtk_disable_string_capabilities template - class sos_node : public sos_base_node + class sos_node exprtk_final : public sos_base_node { public: @@ -14844,8 +15742,8 @@ namespace exprtk // string op string node explicit sos_node(SType0 p0, SType1 p1) - : s0_(p0), - s1_(p1) + : s0_(p0) + , s1_(p1) {} inline T value() const @@ -14885,7 +15783,7 @@ namespace exprtk }; template - class str_xrox_node : public sos_base_node + class str_xrox_node exprtk_final : public sos_base_node { public: @@ -14894,9 +15792,9 @@ namespace exprtk // string-range op string node explicit str_xrox_node(SType0 p0, SType1 p1, RangePack rp0) - : s0_ (p0 ), - s1_ (p1 ), - rp0_(rp0) + : s0_ (p0 ) + , s1_ (p1 ) + , rp0_(rp0) {} ~str_xrox_node() @@ -14948,7 +15846,7 @@ namespace exprtk }; template - class str_xoxr_node : public sos_base_node + class str_xoxr_node exprtk_final : public sos_base_node { public: @@ -14957,9 +15855,9 @@ namespace exprtk // string op string range node explicit str_xoxr_node(SType0 p0, SType1 p1, RangePack rp1) - : s0_ (p0 ), - s1_ (p1 ), - rp1_(rp1) + : s0_ (p0 ) + , s1_ (p1 ) + , rp1_(rp1) {} ~str_xoxr_node() @@ -15011,7 +15909,7 @@ namespace exprtk }; template - class str_xroxr_node : public sos_base_node + class str_xroxr_node exprtk_final : public sos_base_node { public: @@ -15020,10 +15918,10 @@ namespace exprtk // string-range op string-range node explicit str_xroxr_node(SType0 p0, SType1 p1, RangePack rp0, RangePack rp1) - : s0_ (p0 ), - s1_ (p1 ), - rp0_(rp0), - rp1_(rp1) + : s0_ (p0 ) + , s1_ (p1 ) + , rp0_(rp0) + , rp1_(rp1) {} ~str_xroxr_node() @@ -15087,25 +15985,25 @@ namespace exprtk }; template - class str_sogens_node : public binary_node + class str_sogens_node exprtk_final : public binary_node { public: typedef expression_node * expression_ptr; - typedef string_base_node* str_base_ptr; - typedef range_pack range_t; - typedef range_t* range_ptr; - typedef range_interface irange_t; - typedef irange_t* irange_ptr; + typedef string_base_node* str_base_ptr; + typedef range_pack range_t; + typedef range_t* range_ptr; + typedef range_interface irange_t; + typedef irange_t* irange_ptr; str_sogens_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr, branch0, branch1), - str0_base_ptr_ (0), - str1_base_ptr_ (0), - str0_range_ptr_(0), - str1_range_ptr_(0) + : binary_node(opr, branch0, branch1) + , str0_base_ptr_ (0) + , str1_base_ptr_ (0) + , str0_range_ptr_(0) + , str1_range_ptr_(0) { if (is_generally_string_node(binary_node::branch_[0].first)) { @@ -15156,8 +16054,8 @@ namespace exprtk std::size_t str1_r0 = 0; std::size_t str1_r1 = 0; - range_t& range0 = (*str0_range_ptr_); - range_t& range1 = (*str1_range_ptr_); + const range_t& range0 = (*str0_range_ptr_); + const range_t& range1 = (*str1_range_ptr_); if ( range0(str0_r0, str0_r1, str0_base_ptr_->size()) && @@ -15196,7 +16094,7 @@ namespace exprtk }; template - class sosos_node : public sosos_base_node + class sosos_node exprtk_final : public sosos_base_node { public: @@ -15205,14 +16103,14 @@ namespace exprtk // variable op variable node explicit sosos_node(SType0 p0, SType1 p1, SType2 p2) - : s0_(p0), - s1_(p1), - s2_(p2) + : s0_(p0) + , s1_(p1) + , s2_(p2) {} inline T value() const { - return Operation::process(s0_,s1_,s2_); + return Operation::process(s0_, s1_, s2_); } inline typename expression_node::node_type type() const @@ -15248,13 +16146,13 @@ namespace exprtk private: - sosos_node(sosos_node&); - sosos_node& operator=(sosos_node&); + sosos_node(sosos_node&); + sosos_node& operator=(sosos_node&); }; #endif template - class ipow_node : public expression_node + class ipow_node exprtk_final: public expression_node { public: @@ -15284,7 +16182,7 @@ namespace exprtk }; template - class bipow_node : public expression_node + class bipow_node exprtk_final : public expression_node { public: @@ -15292,19 +16190,15 @@ namespace exprtk typedef std::pair branch_t; typedef PowOp operation_t; - explicit bipow_node(expression_ptr brnch) + explicit bipow_node(expression_ptr branch) { - init_branches<1>(branch_, brnch); - } - - ~bipow_node() - { - cleanup_branches::execute(branch_); + construct_branch_pair(branch_, branch); } inline T value() const { - return PowOp::result(branch_[0].first->value()); + assert(branch_.first); + return PowOp::result(branch_.first->value()); } inline typename expression_node::node_type type() const @@ -15312,16 +16206,26 @@ namespace exprtk return expression_node::e_ipow; } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::collect(branch_, node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth(branch_); + } + private: bipow_node(const bipow_node&); bipow_node& operator=(const bipow_node&); - branch_t branch_[1]; + branch_t branch_; }; template - class ipowinv_node : public expression_node + class ipowinv_node exprtk_final : public expression_node { public: @@ -15351,7 +16255,7 @@ namespace exprtk }; template - class bipowninv_node : public expression_node + class bipowninv_node exprtk_final : public expression_node { public: @@ -15359,19 +16263,15 @@ namespace exprtk typedef std::pair branch_t; typedef PowOp operation_t; - explicit bipowninv_node(expression_ptr brnch) + explicit bipowninv_node(expression_ptr branch) { - init_branches<1>(branch_, brnch); - } - - ~bipowninv_node() - { - cleanup_branches::execute(branch_); + construct_branch_pair(branch_, branch); } inline T value() const { - return (T(1) / PowOp::result(branch_[0].first->value())); + assert(branch_.first); + return (T(1) / PowOp::result(branch_.first->value())); } inline typename expression_node::node_type type() const @@ -15379,12 +16279,22 @@ namespace exprtk return expression_node::e_ipowinv; } + void collect_nodes(typename expression_node::noderef_list_t& node_delete_list) + { + expression_node::ndb_t::template collect(branch_, node_delete_list); + } + + std::size_t node_depth() const + { + return expression_node::ndb_t::compute_node_depth(branch_); + } + private: bipowninv_node(const bipowninv_node&); bipowninv_node& operator=(const bipowninv_node&); - branch_t branch_[1]; + branch_t branch_; }; template @@ -15533,37 +16443,55 @@ namespace exprtk template inline expression_node* allocate(OpType& operation, ExprNode (&branch)[1]) { - return allocate(operation, branch[0]); + expression_node* result = + allocate(operation, branch[0]); + result->node_depth(); + return result; } template inline expression_node* allocate(OpType& operation, ExprNode (&branch)[2]) { - return allocate(operation, branch[0], branch[1]); + expression_node* result = + allocate(operation, branch[0], branch[1]); + result->node_depth(); + return result; } template inline expression_node* allocate(OpType& operation, ExprNode (&branch)[3]) { - return allocate(operation, branch[0], branch[1], branch[2]); + expression_node* result = + allocate(operation, branch[0], branch[1], branch[2]); + result->node_depth(); + return result; } template inline expression_node* allocate(OpType& operation, ExprNode (&branch)[4]) { - return allocate(operation, branch[0], branch[1], branch[2], branch[3]); + expression_node* result = + allocate(operation, branch[0], branch[1], branch[2], branch[3]); + result->node_depth(); + return result; } template inline expression_node* allocate(OpType& operation, ExprNode (&branch)[5]) { - return allocate(operation, branch[0],branch[1], branch[2], branch[3], branch[4]); + expression_node* result = + allocate(operation, branch[0],branch[1], branch[2], branch[3], branch[4]); + result->node_depth(); + return result; } template inline expression_node* allocate(OpType& operation, ExprNode (&branch)[6]) { - return allocate(operation, branch[0], branch[1], branch[2], branch[3], branch[4], branch[5]); + expression_node* result = + allocate(operation, branch[0], branch[1], branch[2], branch[3], branch[4], branch[5]); + result->node_depth(); + return result; } template @@ -15578,89 +16506,128 @@ namespace exprtk template class Sequence> inline expression_node* allocate(const Sequence& seq) const { - return (new node_type(seq)); + expression_node* + result = (new node_type(seq)); + result->node_depth(); + return result; } template inline expression_node* allocate(T1& t1) const { - return (new node_type(t1)); + expression_node* + result = (new node_type(t1)); + result->node_depth(); + return result; } template inline expression_node* allocate_c(const T1& t1) const { - return (new node_type(t1)); + expression_node* + result = (new node_type(t1)); + result->node_depth(); + return result; } template inline expression_node* allocate(const T1& t1, const T2& t2) const { - return (new node_type(t1, t2)); + expression_node* + result = (new node_type(t1, t2)); + result->node_depth(); + return result; } template inline expression_node* allocate_cr(const T1& t1, T2& t2) const { - return (new node_type(t1, t2)); + expression_node* + result = (new node_type(t1, t2)); + result->node_depth(); + return result; } template inline expression_node* allocate_rc(T1& t1, const T2& t2) const { - return (new node_type(t1, t2)); + expression_node* + result = (new node_type(t1, t2)); + result->node_depth(); + return result; } template inline expression_node* allocate_rr(T1& t1, T2& t2) const { - return (new node_type(t1, t2)); + expression_node* + result = (new node_type(t1, t2)); + result->node_depth(); + return result; } template inline expression_node* allocate_tt(T1 t1, T2 t2) const { - return (new node_type(t1, t2)); + expression_node* + result = (new node_type(t1, t2)); + result->node_depth(); + return result; } template inline expression_node* allocate_ttt(T1 t1, T2 t2, T3 t3) const { - return (new node_type(t1, t2, t3)); + expression_node* + result = (new node_type(t1, t2, t3)); + result->node_depth(); + return result; } template inline expression_node* allocate_tttt(T1 t1, T2 t2, T3 t3, T4 t4) const { - return (new node_type(t1, t2, t3, t4)); + expression_node* + result = (new node_type(t1, t2, t3, t4)); + result->node_depth(); + return result; } template inline expression_node* allocate_rrr(T1& t1, T2& t2, T3& t3) const { - return (new node_type(t1, t2, t3)); + expression_node* + result = (new node_type(t1, t2, t3)); + result->node_depth(); + return result; } template inline expression_node* allocate_rrrr(T1& t1, T2& t2, T3& t3, T4& t4) const { - return (new node_type(t1, t2, t3, t4)); + expression_node* + result = (new node_type(t1, t2, t3, t4)); + result->node_depth(); + return result; } template inline expression_node* allocate_rrrrr(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5) const { - return (new node_type(t1, t2, t3, t4, t5)); + expression_node* + result = (new node_type(t1, t2, t3, t4, t5)); + result->node_depth(); + return result; } template * allocate(const T1& t1, const T2& t2, const T3& t3) const { - return (new node_type(t1, t2, t3)); + expression_node* + result = (new node_type(t1, t2, t3)); + result->node_depth(); + return result; } template * allocate(const T1& t1, const T2& t2, const T3& t3, const T4& t4) const { - return (new node_type(t1, t2, t3, t4)); + expression_node* + result = (new node_type(t1, t2, t3, t4)); + result->node_depth(); + return result; } template * + result = (new node_type(t1, t2, t3, t4, t5)); + result->node_depth(); + return result; } template * + result = (new node_type(t1, t2, t3, t4, t5, t6)); + result->node_depth(); + return result; } template * + result = (new node_type(t1, t2, t3, t4, t5, t6, t7)); + result->node_depth(); + return result; } template * + result = (new node_type(t1, t2, t3, t4, t5, t6, t7, t8)); + result->node_depth(); + return result; } template * + result = (new node_type(t1, t2, t3, t4, t5, t6, t7, t8, t9)); + result->node_depth(); + return result; } template * + result = (new node_type(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10)); + result->node_depth(); + return result; } template inline expression_node* allocate_type(T1 t1, T2 t2, T3 t3) const { - return (new node_type(t1, t2, t3)); + expression_node* + result = (new node_type(t1, t2, t3)); + result->node_depth(); + return result; } template * allocate_type(T1 t1, T2 t2, T3 t3, T4 t4) const { - return (new node_type(t1, t2, t3, t4)); + expression_node* + result = (new node_type(t1, t2, t3, t4)); + result->node_depth(); + return result; } template * + result = (new node_type(t1, t2, t3, t4, t5)); + result->node_depth(); + return result; } template * + result = (new node_type(t1, t2, t3, t4, t5, t6)); + result->node_depth(); + return result; } template * + result = (new node_type(t1, t2, t3, t4, t5, t6, t7)); + result->node_depth(); + return result; } template void inline free(expression_node*& e) const { + exprtk_debug(("node_allocator::free() - deleting expression_node " + "type: %03d addr: %p\n", + static_cast(e->type()), + reinterpret_cast(e))); delete e; e = 0; } @@ -15817,58 +16827,58 @@ namespace exprtk #define register_op(Symbol,Type,Args) \ m.insert(std::make_pair(std::string(Symbol),details::base_operation_t(Type,Args))); \ - register_op( "abs", e_abs , 1) - register_op( "acos", e_acos , 1) - register_op( "acosh", e_acosh , 1) - register_op( "asin", e_asin , 1) - register_op( "asinh", e_asinh , 1) - register_op( "atan", e_atan , 1) - register_op( "atanh", e_atanh , 1) - register_op( "ceil", e_ceil , 1) - register_op( "cos", e_cos , 1) - register_op( "cosh", e_cosh , 1) - register_op( "exp", e_exp , 1) - register_op( "expm1", e_expm1 , 1) - register_op( "floor", e_floor , 1) - register_op( "log", e_log , 1) - register_op( "log10", e_log10 , 1) - register_op( "log2", e_log2 , 1) - register_op( "log1p", e_log1p , 1) - register_op( "round", e_round , 1) - register_op( "sin", e_sin , 1) - register_op( "sinc", e_sinc , 1) - register_op( "sinh", e_sinh , 1) - register_op( "sec", e_sec , 1) - register_op( "csc", e_csc , 1) - register_op( "sqrt", e_sqrt , 1) - register_op( "tan", e_tan , 1) - register_op( "tanh", e_tanh , 1) - register_op( "cot", e_cot , 1) - register_op( "rad2deg", e_r2d , 1) - register_op( "deg2rad", e_d2r , 1) - register_op( "deg2grad", e_d2g , 1) - register_op( "grad2deg", e_g2d , 1) - register_op( "sgn", e_sgn , 1) - register_op( "not", e_notl , 1) - register_op( "erf", e_erf , 1) - register_op( "erfc", e_erfc , 1) - register_op( "ncdf", e_ncdf , 1) - register_op( "frac", e_frac , 1) - register_op( "trunc", e_trunc , 1) - register_op( "atan2", e_atan2 , 2) - register_op( "mod", e_mod , 2) - register_op( "logn", e_logn , 2) - register_op( "pow", e_pow , 2) - register_op( "root", e_root , 2) - register_op( "roundn", e_roundn , 2) - register_op( "equal", e_equal , 2) - register_op("not_equal", e_nequal , 2) - register_op( "hypot", e_hypot , 2) - register_op( "shr", e_shr , 2) - register_op( "shl", e_shl , 2) - register_op( "clamp", e_clamp , 3) - register_op( "iclamp", e_iclamp , 3) - register_op( "inrange", e_inrange , 3) + register_op("abs" , e_abs , 1) + register_op("acos" , e_acos , 1) + register_op("acosh" , e_acosh , 1) + register_op("asin" , e_asin , 1) + register_op("asinh" , e_asinh , 1) + register_op("atan" , e_atan , 1) + register_op("atanh" , e_atanh , 1) + register_op("ceil" , e_ceil , 1) + register_op("cos" , e_cos , 1) + register_op("cosh" , e_cosh , 1) + register_op("exp" , e_exp , 1) + register_op("expm1" , e_expm1 , 1) + register_op("floor" , e_floor , 1) + register_op("log" , e_log , 1) + register_op("log10" , e_log10 , 1) + register_op("log2" , e_log2 , 1) + register_op("log1p" , e_log1p , 1) + register_op("round" , e_round , 1) + register_op("sin" , e_sin , 1) + register_op("sinc" , e_sinc , 1) + register_op("sinh" , e_sinh , 1) + register_op("sec" , e_sec , 1) + register_op("csc" , e_csc , 1) + register_op("sqrt" , e_sqrt , 1) + register_op("tan" , e_tan , 1) + register_op("tanh" , e_tanh , 1) + register_op("cot" , e_cot , 1) + register_op("rad2deg" , e_r2d , 1) + register_op("deg2rad" , e_d2r , 1) + register_op("deg2grad" , e_d2g , 1) + register_op("grad2deg" , e_g2d , 1) + register_op("sgn" , e_sgn , 1) + register_op("not" , e_notl , 1) + register_op("erf" , e_erf , 1) + register_op("erfc" , e_erfc , 1) + register_op("ncdf" , e_ncdf , 1) + register_op("frac" , e_frac , 1) + register_op("trunc" , e_trunc , 1) + register_op("atan2" , e_atan2 , 2) + register_op("mod" , e_mod , 2) + register_op("logn" , e_logn , 2) + register_op("pow" , e_pow , 2) + register_op("root" , e_root , 2) + register_op("roundn" , e_roundn , 2) + register_op("equal" , e_equal , 2) + register_op("not_equal" , e_nequal , 2) + register_op("hypot" , e_hypot , 2) + register_op("shr" , e_shr , 2) + register_op("shl" , e_shl , 2) + register_op("clamp" , e_clamp , 3) + register_op("iclamp" , e_iclamp , 3) + register_op("inrange" , e_inrange , 3) #undef register_op } @@ -15879,10 +16889,10 @@ namespace exprtk public: function_traits() - : allow_zero_parameters_(false), - has_side_effects_(true), - min_num_args_(0), - max_num_args_(std::numeric_limits::max()) + : allow_zero_parameters_(false) + , has_side_effects_(true) + , min_num_args_(0) + , max_num_args_(std::numeric_limits::max()) {} inline bool& allow_zero_parameters() @@ -15969,83 +16979,84 @@ namespace exprtk virtual ~ifunction() {} - #define empty_method_body \ + #define empty_method_body(N) \ { \ + exprtk_debug(("ifunction::operator() - Operator(" #N ") has not been overridden\n")); \ return std::numeric_limits::quiet_NaN(); \ } \ inline virtual T operator() () - empty_method_body + empty_method_body(0) - inline virtual T operator() (const T&) - empty_method_body + inline virtual T operator() (const T&) + empty_method_body(1) - inline virtual T operator() (const T&,const T&) - empty_method_body + inline virtual T operator() (const T&,const T&) + empty_method_body(2) - inline virtual T operator() (const T&, const T&, const T&) - empty_method_body + inline virtual T operator() (const T&, const T&, const T&) + empty_method_body(3) inline virtual T operator() (const T&, const T&, const T&, const T&) - empty_method_body + empty_method_body(4) inline virtual T operator() (const T&, const T&, const T&, const T&, const T&) - empty_method_body + empty_method_body(5) inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&) - empty_method_body + empty_method_body(6) inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&) - empty_method_body + empty_method_body(7) inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&) - empty_method_body + empty_method_body(8) inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&) - empty_method_body + empty_method_body(9) inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&) - empty_method_body + empty_method_body(10) inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, - const T&) - empty_method_body + const T&) + empty_method_body(11) inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&) - empty_method_body + empty_method_body(12) inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&) - empty_method_body + empty_method_body(13) inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&) - empty_method_body + empty_method_body(14) inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&) - empty_method_body + empty_method_body(15) inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&) - empty_method_body + empty_method_body(16) inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&) - empty_method_body + empty_method_body(17) inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&) - empty_method_body + empty_method_body(18) inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&) - empty_method_body + empty_method_body(19) inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&) - empty_method_body + empty_method_body(20) #undef empty_method_body @@ -16062,7 +17073,7 @@ namespace exprtk inline virtual T operator() (const std::vector&) { - exprtk_debug(("ivararg_function::operator() - Operator has not been overridden.\n")); + exprtk_debug(("ivararg_function::operator() - Operator has not been overridden\n")); return std::numeric_limits::quiet_NaN(); } }; @@ -16084,8 +17095,8 @@ namespace exprtk typedef typename generic_type::parameter_list parameter_list_t; igeneric_function(const std::string& param_seq = "", const return_type rtr_type = e_rtrn_scalar) - : parameter_sequence(param_seq), - rtrn_type(rtr_type) + : parameter_sequence(param_seq) + , rtrn_type(rtr_type) {} virtual ~igeneric_function() @@ -16093,7 +17104,7 @@ namespace exprtk #define igeneric_function_empty_body(N) \ { \ - exprtk_debug(("igeneric_function::operator() - Operator has not been overridden. ["#N"]\n")); \ + exprtk_debug(("igeneric_function::operator() - Operator(" #N ") has not been overridden\n")); \ return std::numeric_limits::quiet_NaN(); \ } \ @@ -16346,6 +17357,27 @@ namespace exprtk : size(0) {} + struct deleter + { + #define exprtk_define_process(Type) \ + static inline void process(std::pair& n) \ + { \ + delete n.second; \ + } \ + + exprtk_define_process(variable_node_t ) + exprtk_define_process(vector_t ) + #ifndef exprtk_disable_string_capabilities + exprtk_define_process(stringvar_node_t) + #endif + + #undef exprtk_define_process + + template + static inline void process(std::pair&) + {} + }; + inline bool symbol_exists(const std::string& symbol_name) const { if (symbol_name.empty()) @@ -16484,19 +17516,19 @@ namespace exprtk (symbol_name, v, is_const); } - inline bool add(const std::string& symbol_name, RawType& t, const bool is_const = false) + inline bool add(const std::string& symbol_name, RawType& t_, const bool is_const = false) { struct tie { - static inline std::pair make(T& t,const bool is_const = false) + static inline std::pair make(T& t, const bool is_constant = false) { - return std::make_pair(is_const, new variable_node_t(t)); + return std::make_pair(is_constant, new variable_node_t(t)); } #ifndef exprtk_disable_string_capabilities - static inline std::pair make(std::string& t,const bool is_const = false) + static inline std::pair make(std::string& t, const bool is_constant = false) { - return std::make_pair(is_const, new stringvar_node_t(t)); + return std::make_pair(is_constant, new stringvar_node_t(t)); } #endif @@ -16505,9 +17537,9 @@ namespace exprtk return std::make_pair(is_constant,&t); } - static inline std::pair make(vararg_function_t& t, const bool is_const = false) + static inline std::pair make(vararg_function_t& t, const bool is_constant = false) { - return std::make_pair(is_const,&t); + return std::make_pair(is_constant,&t); } static inline std::pair make(generic_function_t& t, const bool is_constant = false) @@ -16520,7 +17552,7 @@ namespace exprtk if (map.end() == itr) { - map[symbol_name] = tie::make(t,is_const); + map[symbol_name] = tie::make(t_,is_const); ++size; } @@ -16581,16 +17613,6 @@ namespace exprtk if (map.end() != itr) { - struct deleter - { - static inline void process(std::pair& n) { delete n.second; } - static inline void process(std::pair& n) { delete n.second; } - #ifndef exprtk_disable_string_capabilities - static inline void process(std::pair& n) { delete n.second; } - #endif - static inline void process(std::pair&) { } - }; - if (delete_node) { deleter::process((*itr).second); @@ -16627,16 +17649,6 @@ namespace exprtk inline void clear(const bool delete_node = true) { - struct deleter - { - static inline void process(std::pair& n) { delete n.second; } - static inline void process(std::pair& n) { delete n.second; } - static inline void process(std::pair&) { } - #ifndef exprtk_disable_string_capabilities - static inline void process(std::pair& n) { delete n.second; } - #endif - }; - if (!map.empty()) { if (delete_node) @@ -16702,20 +17714,20 @@ namespace exprtk } }; - typedef details::expression_node* expression_ptr; - typedef typename details::variable_node variable_t; - typedef typename details::vector_holder vector_holder_t; - typedef variable_t* variable_ptr; + typedef details::expression_node* expression_ptr; + typedef typename details::variable_node variable_t; + typedef typename details::vector_holder vector_holder_t; + typedef variable_t* variable_ptr; #ifndef exprtk_disable_string_capabilities typedef typename details::stringvar_node stringvar_t; - typedef stringvar_t* stringvar_ptr; + typedef stringvar_t* stringvar_ptr; #endif - typedef ifunction function_t; - typedef ivararg_function vararg_function_t; - typedef igeneric_function generic_function_t; - typedef function_t* function_ptr; - typedef vararg_function_t* vararg_function_ptr; - typedef generic_function_t* generic_function_ptr; + typedef ifunction function_t; + typedef ivararg_function vararg_function_t; + typedef igeneric_function generic_function_t; + typedef function_t* function_ptr; + typedef vararg_function_t* vararg_function_ptr; + typedef generic_function_t* generic_function_ptr; static const std::size_t lut_size = 256; @@ -16724,16 +17736,16 @@ namespace exprtk { struct st_data { - type_store,T> variable_store; + type_store variable_store; + type_store function_store; + type_store vararg_function_store; + type_store generic_function_store; + type_store string_function_store; + type_store overload_function_store; + type_store vector_store; #ifndef exprtk_disable_string_capabilities - type_store,std::string> stringvar_store; + type_store stringvar_store; #endif - type_store,ifunction > function_store; - type_store,ivararg_function > vararg_function_store; - type_store,igeneric_function > generic_function_store; - type_store,igeneric_function > string_function_store; - type_store,igeneric_function > overload_function_store; - type_store vector_store; st_data() { @@ -16779,13 +17791,13 @@ namespace exprtk }; control_block() - : ref_count(1), - data_(st_data::create()) + : ref_count(1) + , data_(st_data::create()) {} explicit control_block(st_data* data) - : ref_count(1), - data_(data) + : ref_count(1) + , data_(data) {} ~control_block() @@ -17115,7 +18127,7 @@ namespace exprtk else if (symbol_exists(variable_name)) return false; else - return local_data().variable_store.add(variable_name,t,is_constant); + return local_data().variable_store.add(variable_name, t, is_constant); } inline bool add_constant(const std::string& constant_name, const T& value) @@ -17130,7 +18142,7 @@ namespace exprtk local_data().local_symbol_list_.push_back(value); T& t = local_data().local_symbol_list_.back(); - return add_variable(constant_name,t,true); + return add_variable(constant_name, t, true); } #ifndef exprtk_disable_string_capabilities @@ -17143,7 +18155,7 @@ namespace exprtk else if (symbol_exists(stringvar_name)) return false; else - return local_data().stringvar_store.add(stringvar_name,s,is_constant); + return local_data().stringvar_store.add(stringvar_name, s, is_constant); } #endif @@ -17179,30 +18191,22 @@ namespace exprtk return false; else if (symbol_exists(function_name)) return false; - else if ( - ( - (generic_function_t::e_rtrn_scalar == function.rtrn_type) || - (generic_function_t::e_rtrn_string == function.rtrn_type) - ) && - std::string::npos != function.parameter_sequence.find_first_not_of("STVZ*?|") - ) - return false; - else if ( - (generic_function_t::e_rtrn_overload == function.rtrn_type) && - std::string::npos != function.parameter_sequence.find_first_not_of("STVZ*?|:") - ) - return false; - - switch (function.rtrn_type) + else { - case generic_function_t::e_rtrn_scalar : - return local_data().generic_function_store.add(function_name,function); + switch (function.rtrn_type) + { + case generic_function_t::e_rtrn_scalar : + return (std::string::npos == function.parameter_sequence.find_first_not_of("STVZ*?|")) ? + local_data().generic_function_store.add(function_name,function) : false; - case generic_function_t::e_rtrn_string : - return local_data().string_function_store.add(function_name,function); + case generic_function_t::e_rtrn_string : + return (std::string::npos == function.parameter_sequence.find_first_not_of("STVZ*?|")) ? + local_data().string_function_store.add(function_name,function) : false; - case generic_function_t::e_rtrn_overload : - return local_data().overload_function_store.add(function_name,function); + case generic_function_t::e_rtrn_overload : + return (std::string::npos == function.parameter_sequence.find_first_not_of("STVZ*?|:")) ? + local_data().overload_function_store.add(function_name,function) : false; + } } return false; @@ -17268,30 +18272,22 @@ namespace exprtk return false; else if (symbol_exists(function_name,false)) return false; - else if ( - ( - (generic_function_t::e_rtrn_scalar == function.rtrn_type) || - (generic_function_t::e_rtrn_string == function.rtrn_type) - ) && - std::string::npos != function.parameter_sequence.find_first_not_of("STV*?|") - ) - return false; - else if ( - generic_function_t::e_rtrn_overload && - std::string::npos != function.parameter_sequence.find_first_not_of("STV*?|:") - ) - return false; - - switch (function.rtrn_type) + else { - case generic_function_t::e_rtrn_scalar : - return local_data().generic_function_store.add(function_name,function); + switch (function.rtrn_type) + { + case generic_function_t::e_rtrn_scalar : + return (std::string::npos == function.parameter_sequence.find_first_not_of("STVZ*?|")) ? + local_data().generic_function_store.add(function_name,function) : false; - case generic_function_t::e_rtrn_string : - return local_data().string_function_store.add(function_name,function); + case generic_function_t::e_rtrn_string : + return (std::string::npos == function.parameter_sequence.find_first_not_of("STVZ*?|")) ? + local_data().string_function_store.add(function_name,function) : false; - case generic_function_t::e_rtrn_overload : - return local_data().overload_function_store.add(function_name,function); + case generic_function_t::e_rtrn_overload : + return (std::string::npos == function.parameter_sequence.find_first_not_of("STVZ*?|:")) ? + local_data().overload_function_store.add(function_name,function) : false; + } } return false; @@ -17321,7 +18317,7 @@ namespace exprtk else if (0 == v_size) return false; else - return local_data().vector_store.add(vector_name,v,v_size); + return local_data().vector_store.add(vector_name, v, v_size); } template @@ -17684,7 +18680,7 @@ namespace exprtk ('_' != symbol[i]) ) { - if (('.' == symbol[i]) && (i < (symbol.size() - 1))) + if ((i < (symbol.size() - 1)) && ('.' == symbol[i])) continue; else return false; @@ -17710,7 +18706,7 @@ namespace exprtk ('_' != symbol[i]) ) { - if (('.' == symbol[i]) && (i < (symbol.size() - 1))) + if ((i < (symbol.size() - 1)) && ('.' == symbol[i])) continue; else return false; @@ -17765,15 +18761,15 @@ namespace exprtk struct data_pack { data_pack() - : pointer(0), - type(e_unknown), - size(0) + : pointer(0) + , type(e_unknown) + , size(0) {} data_pack(void* ptr, const data_type dt, const std::size_t sz = 0) - : pointer(ptr), - type(dt), - size(sz) + : pointer(ptr) + , type(dt) + , size(sz) {} void* pointer; @@ -17783,21 +18779,22 @@ namespace exprtk typedef std::vector local_data_list_t; typedef results_context results_context_t; + typedef control_block* cntrl_blck_ptr_t; control_block() - : ref_count(0), - expr (0), - results (0), - retinv_null(false), - return_invoked(&retinv_null) + : ref_count(0) + , expr (0) + , results (0) + , retinv_null(false) + , return_invoked(&retinv_null) {} explicit control_block(expression_ptr e) - : ref_count(1), - expr (e), - results (0), - retinv_null(false), - return_invoked(&retinv_null) + : ref_count(1) + , expr (e) + , results (0) + , retinv_null(false) + , return_invoked(&retinv_null) {} ~control_block() @@ -17819,13 +18816,13 @@ namespace exprtk case e_vecholder : delete reinterpret_cast(local_data_list[i].pointer); break; - case e_data : delete (T*)(local_data_list[i].pointer); + case e_data : delete reinterpret_cast(local_data_list[i].pointer); break; - case e_vecdata : delete [] (T*)(local_data_list[i].pointer); + case e_vecdata : delete [] reinterpret_cast(local_data_list[i].pointer); break; - case e_string : delete (std::string*)(local_data_list[i].pointer); + case e_string : delete reinterpret_cast(local_data_list[i].pointer); break; default : break; @@ -17839,12 +18836,12 @@ namespace exprtk } } - static inline control_block* create(expression_ptr e) + static inline cntrl_blck_ptr_t create(expression_ptr e) { return new control_block(e); } - static inline void destroy(control_block*& cntrl_blck) + static inline void destroy(cntrl_blck_ptr_t& cntrl_blck) { if (cntrl_blck) { @@ -17879,8 +18876,8 @@ namespace exprtk } expression(const expression& e) - : control_block_ (e.control_block_ ), - symbol_table_list_(e.symbol_table_list_) + : control_block_ (e.control_block_ ) + , symbol_table_list_(e.symbol_table_list_) { control_block_->ref_count++; } @@ -17944,6 +18941,9 @@ namespace exprtk inline T value() const { + assert(control_block_ ); + assert(control_block_->expr); + return control_block_->expr->value(); } @@ -18101,7 +19101,7 @@ namespace exprtk } control_block* control_block_; - symtab_list_t symbol_table_list_; + symtab_list_t symbol_table_list_; friend class parser; friend class expression_helper; @@ -18160,15 +19160,16 @@ namespace exprtk e_numeric = 4, e_symtab = 5, e_lexer = 6, - e_helper = 7 + e_helper = 7, + e_parser = 8 }; struct type { type() - : mode(parser_error::e_unknown), - line_no (0), - column_no(0) + : mode(parser_error::e_unknown) + , line_no (0) + , column_no(0) {} lexer::token token; @@ -18199,9 +19200,9 @@ namespace exprtk const std::string& src_location = "") { type t; - t.mode = mode; - t.token = tk; - t.diagnostic = diagnostic; + t.mode = mode; + t.token = tk; + t.diagnostic = diagnostic; t.src_location = src_location; exprtk_debug(("%s\n",diagnostic .c_str())); return t; @@ -18218,6 +19219,7 @@ namespace exprtk case e_symtab : return std::string("Symbol Error" ); case e_lexer : return std::string("Lexer Error" ); case e_helper : return std::string("Helper Error" ); + case e_parser : return std::string("Parser Error" ); default : return std::string("Unknown Error"); } } @@ -18289,92 +19291,81 @@ namespace exprtk enum precedence_level { - e_level00, - e_level01, - e_level02, - e_level03, - e_level04, - e_level05, - e_level06, - e_level07, - e_level08, - e_level09, - e_level10, - e_level11, - e_level12, - e_level13, - e_level14 - }; - - typedef const T& cref_t; - typedef const T const_t; - typedef ifunction F; - typedef ivararg_function VAF; - typedef igeneric_function GF; - typedef ifunction ifunction_t; - typedef ivararg_function ivararg_function_t; - typedef igeneric_function igeneric_function_t; - typedef details::expression_node expression_node_t; - typedef details::literal_node literal_node_t; - typedef details::unary_node unary_node_t; - typedef details::binary_node binary_node_t; - typedef details::trinary_node trinary_node_t; - typedef details::quaternary_node quaternary_node_t; - typedef details::conditional_node conditional_node_t; - typedef details::cons_conditional_node cons_conditional_node_t; - typedef details::while_loop_node while_loop_node_t; - typedef details::repeat_until_loop_node repeat_until_loop_node_t; - typedef details::for_loop_node for_loop_node_t; + e_level00, e_level01, e_level02, e_level03, e_level04, + e_level05, e_level06, e_level07, e_level08, e_level09, + e_level10, e_level11, e_level12, e_level13, e_level14 + }; + + typedef const T& cref_t; + typedef const T const_t; + typedef ifunction F; + typedef ivararg_function VAF; + typedef igeneric_function GF; + typedef ifunction ifunction_t; + typedef ivararg_function ivararg_function_t; + typedef igeneric_function igeneric_function_t; + typedef details::expression_node expression_node_t; + typedef details::literal_node literal_node_t; + typedef details::unary_node unary_node_t; + typedef details::binary_node binary_node_t; + typedef details::trinary_node trinary_node_t; + typedef details::quaternary_node quaternary_node_t; + typedef details::conditional_node conditional_node_t; + typedef details::cons_conditional_node cons_conditional_node_t; + typedef details::while_loop_node while_loop_node_t; + typedef details::repeat_until_loop_node repeat_until_loop_node_t; + typedef details::for_loop_node for_loop_node_t; #ifndef exprtk_disable_break_continue - typedef details::while_loop_bc_node while_loop_bc_node_t; - typedef details::repeat_until_loop_bc_node repeat_until_loop_bc_node_t; - typedef details::for_loop_bc_node for_loop_bc_node_t; + typedef details::while_loop_bc_node while_loop_bc_node_t; + typedef details::repeat_until_loop_bc_node repeat_until_loop_bc_node_t; + typedef details::for_loop_bc_node for_loop_bc_node_t; #endif - typedef details::switch_node switch_node_t; - typedef details::variable_node variable_node_t; - typedef details::vector_elem_node vector_elem_node_t; - typedef details::rebasevector_elem_node rebasevector_elem_node_t; - typedef details::rebasevector_celem_node rebasevector_celem_node_t; - typedef details::vector_node vector_node_t; - typedef details::range_pack range_t; + typedef details::switch_node switch_node_t; + typedef details::variable_node variable_node_t; + typedef details::vector_elem_node vector_elem_node_t; + typedef details::rebasevector_elem_node rebasevector_elem_node_t; + typedef details::rebasevector_celem_node rebasevector_celem_node_t; + typedef details::vector_node vector_node_t; + typedef details::range_pack range_t; #ifndef exprtk_disable_string_capabilities - typedef details::stringvar_node stringvar_node_t; - typedef details::string_literal_node string_literal_node_t; - typedef details::string_range_node string_range_node_t; - typedef details::const_string_range_node const_string_range_node_t; - typedef details::generic_string_range_node generic_string_range_node_t; - typedef details::string_concat_node string_concat_node_t; - typedef details::assignment_string_node assignment_string_node_t; - typedef details::assignment_string_range_node assignment_string_range_node_t; - typedef details::conditional_string_node conditional_string_node_t; - typedef details::cons_conditional_str_node cons_conditional_str_node_t; + typedef details::stringvar_node stringvar_node_t; + typedef details::string_literal_node string_literal_node_t; + typedef details::string_range_node string_range_node_t; + typedef details::const_string_range_node const_string_range_node_t; + typedef details::generic_string_range_node generic_string_range_node_t; + typedef details::string_concat_node string_concat_node_t; + typedef details::assignment_string_node assignment_string_node_t; + typedef details::assignment_string_range_node assignment_string_range_node_t; + typedef details::conditional_string_node conditional_string_node_t; + typedef details::cons_conditional_str_node cons_conditional_str_node_t; #endif typedef details::assignment_node assignment_node_t; - typedef details::assignment_vec_elem_node assignment_vec_elem_node_t; - typedef details::assignment_rebasevec_elem_node assignment_rebasevec_elem_node_t; + typedef details::assignment_vec_elem_node assignment_vec_elem_node_t; + typedef details::assignment_rebasevec_elem_node assignment_rebasevec_elem_node_t; typedef details::assignment_rebasevec_celem_node assignment_rebasevec_celem_node_t; - typedef details::assignment_vec_node assignment_vec_node_t; - typedef details::assignment_vecvec_node assignment_vecvec_node_t; - typedef details::scand_node scand_node_t; - typedef details::scor_node scor_node_t; - typedef lexer::token token_t; - typedef expression_node_t* expression_node_ptr; - typedef expression expression_t; - typedef symbol_table symbol_table_t; - typedef typename expression::symtab_list_t symbol_table_list_t; + typedef details::assignment_vec_node assignment_vec_node_t; + typedef details::assignment_vecvec_node assignment_vecvec_node_t; + typedef details::conditional_vector_node conditional_vector_node_t; + typedef details::scand_node scand_node_t; + typedef details::scor_node scor_node_t; + typedef lexer::token token_t; + typedef expression_node_t* expression_node_ptr; + typedef expression expression_t; + typedef symbol_table symbol_table_t; + typedef typename expression::symtab_list_t symbol_table_list_t; typedef details::vector_holder* vector_holder_ptr; - typedef typename details::functor_t functor_t; - typedef typename functor_t::qfunc_t quaternary_functor_t; - typedef typename functor_t::tfunc_t trinary_functor_t; - typedef typename functor_t::bfunc_t binary_functor_t; - typedef typename functor_t::ufunc_t unary_functor_t; + typedef typename details::functor_t functor_t; + typedef typename functor_t::qfunc_t quaternary_functor_t; + typedef typename functor_t::tfunc_t trinary_functor_t; + typedef typename functor_t::bfunc_t binary_functor_t; + typedef typename functor_t::ufunc_t unary_functor_t; typedef details::operator_type operator_t; - typedef std::map unary_op_map_t; - typedef std::map binary_op_map_t; - typedef std::map trinary_op_map_t; + typedef std::map unary_op_map_t; + typedef std::map binary_op_map_t; + typedef std::map trinary_op_map_t; typedef std::map > sf3_map_t; typedef std::map > sf4_map_t; @@ -18383,28 +19374,28 @@ namespace exprtk typedef std::multimap base_ops_map_t; typedef std::set disabled_func_set_t; - typedef details::T0oT1_define vov_t; - typedef details::T0oT1_define cov_t; - typedef details::T0oT1_define voc_t; - - typedef details::T0oT1oT2_define vovov_t; - typedef details::T0oT1oT2_define vovoc_t; - typedef details::T0oT1oT2_define vocov_t; - typedef details::T0oT1oT2_define covov_t; - typedef details::T0oT1oT2_define covoc_t; - typedef details::T0oT1oT2_define cocov_t; - typedef details::T0oT1oT2_define vococ_t; - - typedef details::T0oT1oT2oT3_define vovovov_t; - typedef details::T0oT1oT2oT3_define vovovoc_t; - typedef details::T0oT1oT2oT3_define vovocov_t; - typedef details::T0oT1oT2oT3_define vocovov_t; - typedef details::T0oT1oT2oT3_define covovov_t; - - typedef details::T0oT1oT2oT3_define covocov_t; - typedef details::T0oT1oT2oT3_define vocovoc_t; - typedef details::T0oT1oT2oT3_define covovoc_t; - typedef details::T0oT1oT2oT3_define vococov_t; + typedef details::T0oT1_define vov_t; + typedef details::T0oT1_define cov_t; + typedef details::T0oT1_define voc_t; + + typedef details::T0oT1oT2_define vovov_t; + typedef details::T0oT1oT2_define vovoc_t; + typedef details::T0oT1oT2_define vocov_t; + typedef details::T0oT1oT2_define covov_t; + typedef details::T0oT1oT2_define covoc_t; + typedef details::T0oT1oT2_define cocov_t; + typedef details::T0oT1oT2_define vococ_t; + + typedef details::T0oT1oT2oT3_define vovovov_t; + typedef details::T0oT1oT2oT3_define vovovoc_t; + typedef details::T0oT1oT2oT3_define vovocov_t; + typedef details::T0oT1oT2oT3_define vocovov_t; + typedef details::T0oT1oT2oT3_define covovov_t; + + typedef details::T0oT1oT2oT3_define covocov_t; + typedef details::T0oT1oT2oT3_define vocovoc_t; + typedef details::T0oT1oT2oT3_define covovoc_t; + typedef details::T0oT1oT2oT3_define vococov_t; typedef results_context results_context_t; @@ -18422,28 +19413,28 @@ namespace exprtk }; typedef details::vector_holder vector_holder_t; - typedef variable_node_t* variable_node_ptr; - typedef vector_holder_t* vector_holder_ptr; - typedef expression_node_t* expression_node_ptr; + typedef variable_node_t* variable_node_ptr; + typedef vector_holder_t* vector_holder_ptr; + typedef expression_node_t* expression_node_ptr; #ifndef exprtk_disable_string_capabilities - typedef stringvar_node_t* stringvar_node_ptr; + typedef stringvar_node_t* stringvar_node_ptr; #endif scope_element() - : name("???"), - size (std::numeric_limits::max()), - index(std::numeric_limits::max()), - depth(std::numeric_limits::max()), - ref_count(0), - ip_index (0), - type (e_none), - active(false), - data (0), - var_node(0), - vec_node(0) - #ifndef exprtk_disable_string_capabilities - ,str_node(0) - #endif + : name("???") + , size (std::numeric_limits::max()) + , index(std::numeric_limits::max()) + , depth(std::numeric_limits::max()) + , ref_count(0) + , ip_index (0) + , type (e_none) + , active(false) + , data (0) + , var_node (0) + , vec_node (0) + #ifndef exprtk_disable_string_capabilities + , str_node(0) + #endif {} bool operator < (const scope_element& se) const @@ -18503,12 +19494,12 @@ namespace exprtk public: typedef expression_node_t* expression_node_ptr; - typedef variable_node_t* variable_node_ptr; - typedef parser parser_t; + typedef variable_node_t* variable_node_ptr; + typedef parser parser_t; explicit scope_element_manager(parser& p) - : parser_(p), - input_param_cnt_(0) + : parser_(p) + , input_param_cnt_(0) {} inline std::size_t size() const @@ -18617,26 +19608,24 @@ namespace exprtk inline void free_element(scope_element& se) { - #ifdef exprtk_enable_debugging exprtk_debug(("free_element() - se[%s]\n", se.name.c_str())); - #endif switch (se.type) { - case scope_element::e_variable : if (se.data ) delete (T*) se.data; - if (se.var_node) delete se.var_node; + case scope_element::e_variable : delete reinterpret_cast(se.data); + delete se.var_node; break; - case scope_element::e_vector : if (se.data ) delete[] (T*) se.data; - if (se.vec_node) delete se.vec_node; + case scope_element::e_vector : delete[] reinterpret_cast(se.data); + delete se.vec_node; break; - case scope_element::e_vecelem : if (se.var_node) delete se.var_node; + case scope_element::e_vecelem : delete se.var_node; break; #ifndef exprtk_disable_string_capabilities - case scope_element::e_string : if (se.data ) delete (std::string*) se.data; - if (se.str_node) delete se.str_node; + case scope_element::e_string : delete reinterpret_cast(se.data); + delete se.str_node; break; #endif @@ -18734,6 +19723,45 @@ namespace exprtk parser_t& parser_; }; + class stack_limit_handler + { + public: + + typedef parser parser_t; + + explicit stack_limit_handler(parser& p) + : parser_(p) + , limit_exceeded_(false) + { + if (++parser_.state_.stack_depth > parser_.settings_.max_stack_depth_) + { + limit_exceeded_ = true; + parser_.set_error( + make_error(parser_error::e_parser, + "ERR000 - Current stack depth " + details::to_str(parser_.state_.stack_depth) + + " exceeds maximum allowed stack depth of " + details::to_str(parser_.settings_.max_stack_depth_), + exprtk_error_location)); + } + } + + ~stack_limit_handler() + { + parser_.state_.stack_depth--; + } + + bool operator!() + { + return limit_exceeded_; + } + + private: + + stack_limit_handler& operator=(const stack_limit_handler&); + + parser_t& parser_; + bool limit_exceeded_; + }; + struct symtab_store { symbol_table_list_t symtab_list_; @@ -19004,7 +20032,7 @@ namespace exprtk continue; else if (!local_data(i).stringvar_store.symbol_exists(symbol_name)) continue; - else if ( local_data(i).stringvar_store.is_constant(symbol_name)) + else if (local_data(i).stringvar_store.is_constant(symbol_name)) return true; } @@ -19177,11 +20205,13 @@ namespace exprtk void reset() { - parsing_return_stmt = false; - parsing_break_stmt = false; - return_stmt_present = false; - side_effect_present = false; - scope_depth = 0; + parsing_return_stmt = false; + parsing_break_stmt = false; + return_stmt_present = false; + side_effect_present = false; + scope_depth = 0; + stack_depth = 0; + parsing_loop_stmt_count = 0; } #ifndef exprtk_enable_debugging @@ -19204,6 +20234,8 @@ namespace exprtk bool side_effect_present; bool type_check_enabled; std::size_t scope_depth; + std::size_t stack_depth; + std::size_t parsing_loop_stmt_count; }; public: @@ -19285,12 +20317,12 @@ namespace exprtk typedef std::vector symbol_list_t; dependent_entity_collector(const std::size_t options = e_ct_none) - : options_(options), - collect_variables_ ((options_ & e_ct_variables ) == e_ct_variables ), - collect_functions_ ((options_ & e_ct_functions ) == e_ct_functions ), - collect_assignments_((options_ & e_ct_assignments) == e_ct_assignments), - return_present_ (false), - final_stmt_return_(false) + : options_(options) + , collect_variables_ ((options_ & e_ct_variables ) == e_ct_variables ) + , collect_functions_ ((options_ & e_ct_functions ) == e_ct_functions ) + , collect_assignments_((options_ & e_ct_assignments) == e_ct_assignments) + , return_present_ (false) + , final_stmt_return_(false) {} template "; case details::e_gte : return ">="; - case details::e_gt : return ">"; - default : return ""; + case details::e_gt : return ">" ; + default : return "" ; + } + } + + std::string logic_opr_to_string(details::operator_type opr) const + { + switch (opr) + { + case details::e_and : return "and" ; + case details::e_or : return "or" ; + case details::e_xor : return "xor" ; + case details::e_nand : return "nand"; + case details::e_nor : return "nor" ; + case details::e_xnor : return "xnor"; + case details::e_notl : return "not" ; + default : return "" ; } } @@ -20021,26 +21090,30 @@ namespace exprtk disabled_entity_set_t disabled_assignment_set_; disabled_entity_set_t disabled_inequality_set_; + std::size_t max_stack_depth_; + std::size_t max_node_depth_; + friend class parser; }; typedef settings_store settings_t; parser(const settings_t& settings = settings_t()) - : settings_(settings), - resolve_unknown_symbol_(false), - results_context_(0), - unknown_symbol_resolver_(reinterpret_cast(0)), + : settings_(settings) + , resolve_unknown_symbol_(false) + , results_context_(0) + , unknown_symbol_resolver_(reinterpret_cast(0)) #ifdef _MSC_VER #pragma warning(push) #pragma warning (disable:4355) #endif - sem_(*this), + , sem_(*this) #ifdef _MSC_VER #pragma warning(pop) #endif - operator_joiner_2_(2), - operator_joiner_3_(3) + , operator_joiner_2_(2) + , operator_joiner_3_(3) + , loop_runtime_check_(0) { init_precompilation(); @@ -20066,20 +21139,20 @@ namespace exprtk inline void init_precompilation() { - if (settings_.collect_variables_enabled()) - dec_.collect_variables() = true; + dec_.collect_variables() = + settings_.collect_variables_enabled(); - if (settings_.collect_functions_enabled()) - dec_.collect_functions() = true; + dec_.collect_functions() = + settings_.collect_functions_enabled(); - if (settings_.collect_assignments_enabled()) - dec_.collect_assignments() = true; + dec_.collect_assignments() = + settings_.collect_assignments_enabled(); if (settings_.replacer_enabled()) { symbol_replacer_.clear(); - symbol_replacer_.add_replace("true" ,"1",lexer::token::e_number); - symbol_replacer_.add_replace("false","0",lexer::token::e_number); + symbol_replacer_.add_replace("true" , "1", lexer::token::e_number); + symbol_replacer_.add_replace("false", "0", lexer::token::e_number); helper_assembly_.token_modifier_list.clear(); helper_assembly_.register_modifier(&symbol_replacer_); } @@ -20144,7 +21217,7 @@ namespace exprtk { set_error( make_error(parser_error::e_syntax, - "ERR000 - Empty expression!", + "ERR001 - Empty expression!", exprtk_error_location)); return false; @@ -20160,7 +21233,7 @@ namespace exprtk { set_error( make_error(parser_error::e_syntax, - "ERR001 - Empty expression!", + "ERR002 - Empty expression!", exprtk_error_location)); return false; @@ -20207,7 +21280,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR002 - Invalid expression encountered", + "ERR003 - Invalid expression encountered", exprtk_error_location)); } @@ -20226,13 +21299,13 @@ namespace exprtk inline expression_t compile(const std::string& expression_string, symbol_table_t& symtab) { - expression_t expr; + expression_t expression; - expr.register_symbol_table(symtab); + expression.register_symbol_table(symtab); - compile(expression_string,expr); + compile(expression_string,expression); - return expr; + return expression; } void process_lexer_errors() @@ -20241,7 +21314,7 @@ namespace exprtk { if (lexer()[i].is_error()) { - std::string diagnostic = "ERR003 - "; + std::string diagnostic = "ERR004 - "; switch (lexer()[i].type) { @@ -20309,7 +21382,7 @@ namespace exprtk set_error( make_error(parser_error::e_token, bracket_checker_ptr->error_token(), - "ERR004 - Mismatched brackets: '" + bracket_checker_ptr->error_token().value + "'", + "ERR005 - Mismatched brackets: '" + bracket_checker_ptr->error_token().value + "'", exprtk_error_location)); } else if (0 != (numeric_checker_ptr = dynamic_cast(helper_assembly_.error_token_scanner))) @@ -20321,7 +21394,7 @@ namespace exprtk set_error( make_error(parser_error::e_token, error_token, - "ERR005 - Invalid numeric token: '" + error_token.value + "'", + "ERR006 - Invalid numeric token: '" + error_token.value + "'", exprtk_error_location)); } @@ -20339,7 +21412,7 @@ namespace exprtk set_error( make_error(parser_error::e_token, error_token.first, - "ERR006 - Invalid token sequence: '" + + "ERR007 - Invalid token sequence: '" + error_token.first.value + "' and '" + error_token.second.value + "'", exprtk_error_location)); @@ -20359,7 +21432,7 @@ namespace exprtk set_error( make_error(parser_error::e_token, error_token.first, - "ERR007 - Invalid token sequence: '" + + "ERR008 - Invalid token sequence: '" + error_token.first.value + "' and '" + error_token.second.value + "'", exprtk_error_location)); @@ -20453,6 +21526,16 @@ namespace exprtk unknown_symbol_resolver_ = &default_usr_; } + inline void register_loop_runtime_check(loop_runtime_check& lrtchk) + { + loop_runtime_check_ = &lrtchk; + } + + inline void clear_loop_runtime_check() + { + loop_runtime_check_ = loop_runtime_check_ptr(0); + } + private: inline bool valid_base_operation(const std::string& symbol) const @@ -20496,6 +21579,11 @@ namespace exprtk settings_.function_enabled(symbol); } + bool is_invalid_logic_operation(const details::operator_type operation) const + { + return settings_.logic_disabled(operation); + } + bool is_invalid_arithmetic_operation(const details::operator_type operation) const { return settings_.arithmetic_disabled(operation); @@ -20515,13 +21603,17 @@ namespace exprtk inline void next_token() { const std::string ct_str = current_token().value; + const std::size_t ct_pos = current_token().position; parser_helper::next_token(); const std::string depth(2 * state_.scope_depth,' '); exprtk_debug(("%s" - "prev[%s] --> curr[%s]\n", + "prev[%s | %04d] --> curr[%s | %04d] stack_level: %3d\n", depth.c_str(), ct_str.c_str(), - current_token().value.c_str())); + static_cast(ct_pos), + current_token().value.c_str(), + static_cast(current_token().position), + static_cast(state_.stack_depth))); } #endif @@ -20550,7 +21642,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR008 - Invalid expression encountered", + "ERR009 - Invalid expression encountered", exprtk_error_location)); } @@ -20642,6 +21734,13 @@ namespace exprtk inline expression_node_ptr parse_expression(precedence_level precedence = e_level00) { + stack_limit_handler slh(*this); + + if (!slh) + { + return error_node(); + } + expression_node_ptr expression = parse_branch(precedence); if (0 == expression) @@ -20659,39 +21758,39 @@ namespace exprtk switch (current_token().type) { - case token_t::e_assign : current_state.set(e_level00,e_level00, details::e_assign); break; - case token_t::e_addass : current_state.set(e_level00,e_level00, details::e_addass); break; - case token_t::e_subass : current_state.set(e_level00,e_level00, details::e_subass); break; - case token_t::e_mulass : current_state.set(e_level00,e_level00, details::e_mulass); break; - case token_t::e_divass : current_state.set(e_level00,e_level00, details::e_divass); break; - case token_t::e_modass : current_state.set(e_level00,e_level00, details::e_modass); break; - case token_t::e_swap : current_state.set(e_level00,e_level00, details::e_swap ); break; - case token_t::e_lt : current_state.set(e_level05,e_level06, details:: e_lt); break; - case token_t::e_lte : current_state.set(e_level05,e_level06, details:: e_lte); break; - case token_t::e_eq : current_state.set(e_level05,e_level06, details:: e_eq); break; - case token_t::e_ne : current_state.set(e_level05,e_level06, details:: e_ne); break; - case token_t::e_gte : current_state.set(e_level05,e_level06, details:: e_gte); break; - case token_t::e_gt : current_state.set(e_level05,e_level06, details:: e_gt); break; - case token_t::e_add : current_state.set(e_level07,e_level08, details:: e_add); break; - case token_t::e_sub : current_state.set(e_level07,e_level08, details:: e_sub); break; - case token_t::e_div : current_state.set(e_level10,e_level11, details:: e_div); break; - case token_t::e_mul : current_state.set(e_level10,e_level11, details:: e_mul); break; - case token_t::e_mod : current_state.set(e_level10,e_level11, details:: e_mod); break; - case token_t::e_pow : current_state.set(e_level12,e_level12, details:: e_pow); break; + case token_t::e_assign : current_state.set(e_level00, e_level00, details::e_assign); break; + case token_t::e_addass : current_state.set(e_level00, e_level00, details::e_addass); break; + case token_t::e_subass : current_state.set(e_level00, e_level00, details::e_subass); break; + case token_t::e_mulass : current_state.set(e_level00, e_level00, details::e_mulass); break; + case token_t::e_divass : current_state.set(e_level00, e_level00, details::e_divass); break; + case token_t::e_modass : current_state.set(e_level00, e_level00, details::e_modass); break; + case token_t::e_swap : current_state.set(e_level00, e_level00, details::e_swap ); break; + case token_t::e_lt : current_state.set(e_level05, e_level06, details::e_lt ); break; + case token_t::e_lte : current_state.set(e_level05, e_level06, details::e_lte ); break; + case token_t::e_eq : current_state.set(e_level05, e_level06, details::e_eq ); break; + case token_t::e_ne : current_state.set(e_level05, e_level06, details::e_ne ); break; + case token_t::e_gte : current_state.set(e_level05, e_level06, details::e_gte ); break; + case token_t::e_gt : current_state.set(e_level05, e_level06, details::e_gt ); break; + case token_t::e_add : current_state.set(e_level07, e_level08, details::e_add ); break; + case token_t::e_sub : current_state.set(e_level07, e_level08, details::e_sub ); break; + case token_t::e_div : current_state.set(e_level10, e_level11, details::e_div ); break; + case token_t::e_mul : current_state.set(e_level10, e_level11, details::e_mul ); break; + case token_t::e_mod : current_state.set(e_level10, e_level11, details::e_mod ); break; + case token_t::e_pow : current_state.set(e_level12, e_level12, details::e_pow ); break; default : if (token_t::e_symbol == current_token().type) { - static const std::string s_and = "and"; - static const std::string s_nand = "nand"; - static const std::string s_or = "or"; - static const std::string s_nor = "nor"; - static const std::string s_xor = "xor"; - static const std::string s_xnor = "xnor"; - static const std::string s_in = "in"; - static const std::string s_like = "like"; + static const std::string s_and = "and" ; + static const std::string s_nand = "nand" ; + static const std::string s_or = "or" ; + static const std::string s_nor = "nor" ; + static const std::string s_xor = "xor" ; + static const std::string s_xnor = "xnor" ; + static const std::string s_in = "in" ; + static const std::string s_like = "like" ; static const std::string s_ilike = "ilike"; - static const std::string s_and1 = "&"; - static const std::string s_or1 = "|"; - static const std::string s_not = "not"; + static const std::string s_and1 = "&" ; + static const std::string s_or1 = "|" ; + static const std::string s_not = "not" ; if (details::imatch(current_token().value,s_and)) { @@ -20780,14 +21879,26 @@ namespace exprtk expression_node_ptr right_branch = error_node(); expression_node_ptr new_expression = error_node(); - if (is_invalid_arithmetic_operation(current_state.operation)) + if (is_invalid_logic_operation(current_state.operation)) + { + free_node(node_allocator_,expression); + + set_error( + make_error(parser_error::e_syntax, + prev_token, + "ERR010 - Invalid or disabled logic operation '" + details::to_str(current_state.operation) + "'", + exprtk_error_location)); + + return error_node(); + } + else if (is_invalid_arithmetic_operation(current_state.operation)) { free_node(node_allocator_,expression); set_error( make_error(parser_error::e_syntax, prev_token, - "ERR009 - Invalid arithmetic operation '" + details::to_str(current_state.operation) + "'", + "ERR011 - Invalid or disabled arithmetic operation '" + details::to_str(current_state.operation) + "'", exprtk_error_location)); return error_node(); @@ -20799,7 +21910,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, prev_token, - "ERR010 - Invalid inequality operation '" + details::to_str(current_state.operation) + "'", + "ERR012 - Invalid inequality operation '" + details::to_str(current_state.operation) + "'", exprtk_error_location)); return error_node(); @@ -20811,7 +21922,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, prev_token, - "ERR011 - Invalid assignment operation '" + details::to_str(current_state.operation) + "'", + "ERR013 - Invalid or disabled assignment operation '" + details::to_str(current_state.operation) + "'", exprtk_error_location)); return error_node(); @@ -20820,17 +21931,17 @@ namespace exprtk if (0 != (right_branch = parse_expression(current_state.right))) { if ( - details::is_return_node( expression) || + details::is_return_node(expression ) || details::is_return_node(right_branch) ) { - free_node(node_allocator_, expression); + free_node(node_allocator_, expression ); free_node(node_allocator_, right_branch); set_error( make_error(parser_error::e_syntax, prev_token, - "ERR012 - Return statements cannot be part of sub-expressions", + "ERR014 - Return statements cannot be part of sub-expressions", exprtk_error_location)); return error_node(); @@ -20853,11 +21964,11 @@ namespace exprtk prev_token, !synthesis_error_.empty() ? synthesis_error_ : - "ERR013 - General parsing error at token: '" + prev_token.value + "'", + "ERR015 - General parsing error at token: '" + prev_token.value + "'", exprtk_error_location)); } - free_node(node_allocator_, expression); + free_node(node_allocator_, expression ); free_node(node_allocator_, right_branch); return error_node(); @@ -20866,7 +21977,7 @@ namespace exprtk { if ( token_is(token_t::e_ternary,prsrhlpr_t::e_hold) && - (precedence == e_level00) + (e_level00 == precedence) ) { expression = parse_ternary_conditional_statement(new_expression); @@ -20878,6 +21989,20 @@ namespace exprtk } } + if ((0 != expression) && (expression->node_depth() > settings_.max_node_depth_)) + { + set_error( + make_error(parser_error::e_syntax, + current_token(), + "ERR016 - Expression depth of " + details::to_str(static_cast(expression->node_depth())) + + " exceeds maximum allowed expression depth of " + details::to_str(static_cast(settings_.max_node_depth_)), + exprtk_error_location)); + + free_node(node_allocator_,expression); + + return error_node(); + } + return expression; } @@ -20923,7 +22048,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR014 - Failed to find variable node in symbol table", + "ERR017 - Failed to find variable node in symbol table", exprtk_error_location)); free_node(node_allocator_,node); @@ -20941,21 +22066,46 @@ namespace exprtk return reinterpret_cast(0); } + struct scoped_expression_delete + { + scoped_expression_delete(parser& pr, expression_node_ptr& expression) + : delete_ptr(true) + , parser_(pr) + , expression_(expression) + {} + + ~scoped_expression_delete() + { + if (delete_ptr) + { + free_node(parser_.node_allocator_, expression_); + } + } + + bool delete_ptr; + parser& parser_; + expression_node_ptr& expression_; + + private: + + scoped_expression_delete& operator=(const scoped_expression_delete&); + }; + template struct scoped_delete { typedef Type* ptr_t; scoped_delete(parser& pr, ptr_t& p) - : delete_ptr(true), - parser_(pr), - p_(&p) + : delete_ptr(true) + , parser_(pr) + , p_(&p) {} scoped_delete(parser& pr, ptr_t (&p)[N]) - : delete_ptr(true), - parser_(pr), - p_(&p[0]) + : delete_ptr(true) + , parser_(pr) + , p_(&p[0]) {} ~scoped_delete() @@ -20964,7 +22114,7 @@ namespace exprtk { for (std::size_t i = 0; i < N; ++i) { - free_node(parser_.node_allocator_,p_[i]); + free_node(parser_.node_allocator_, p_[i]); } } } @@ -20984,9 +22134,9 @@ namespace exprtk typedef Type* ptr_t; scoped_deq_delete(parser& pr, std::deque& deq) - : delete_ptr(true), - parser_(pr), - deq_(deq) + : delete_ptr(true) + , parser_(pr) + , deq_(deq) {} ~scoped_deq_delete() @@ -21017,9 +22167,9 @@ namespace exprtk typedef Type* ptr_t; scoped_vec_delete(parser& pr, std::vector& vec) - : delete_ptr(true), - parser_(pr), - vec_(vec) + : delete_ptr(true) + , parser_(pr) + , vec_(vec) {} ~scoped_vec_delete() @@ -21059,8 +22209,8 @@ namespace exprtk struct scoped_bool_or_restorer { explicit scoped_bool_or_restorer(bool& bb) - : b(bb), - original_value_(bb) + : b(bb) + , original_value_(bb) {} ~scoped_bool_or_restorer() @@ -21072,6 +22222,21 @@ namespace exprtk bool original_value_; }; + struct scoped_inc_dec + { + explicit scoped_inc_dec(std::size_t& v) + : v_(v) + { ++v_; } + + ~scoped_inc_dec() + { + assert(v_ > 0); + --v_; + } + + std::size_t& v_; + }; + inline expression_node_ptr parse_function_invocation(ifunction* function, const std::string& function_name) { expression_node_ptr func_node = reinterpret_cast(0); @@ -21103,7 +22268,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR015 - Invalid number of parameters for function: '" + function_name + "'", + "ERR018 - Invalid number of parameters for function: '" + function_name + "'", exprtk_error_location)); return error_node(); @@ -21117,7 +22282,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR016 - Failed to generate call to function: '" + function_name + "'", + "ERR019 - Failed to generate call to function: '" + function_name + "'", exprtk_error_location)); return error_node(); @@ -21136,7 +22301,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR017 - Expecting ifunction '" + function_name + "' to have non-zero parameter count", + "ERR020 - Expecting ifunction '" + function_name + "' to have non-zero parameter count", exprtk_error_location)); return error_node(); @@ -21159,7 +22324,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR018 - Expecting argument list for function: '" + function_name + "'", + "ERR021 - Expecting argument list for function: '" + function_name + "'", exprtk_error_location)); return error_node(); @@ -21174,7 +22339,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR019 - Failed to parse argument " + details::to_str(i) + " for function: '" + function_name + "'", + "ERR022 - Failed to parse argument " + details::to_str(i) + " for function: '" + function_name + "'", exprtk_error_location)); return error_node(); @@ -21186,7 +22351,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR020 - Invalid number of arguments for function: '" + function_name + "'", + "ERR023 - Invalid number of arguments for function: '" + function_name + "'", exprtk_error_location)); return error_node(); @@ -21199,7 +22364,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR021 - Invalid number of arguments for function: '" + function_name + "'", + "ERR024 - Invalid number of arguments for function: '" + function_name + "'", exprtk_error_location)); return error_node(); @@ -21207,7 +22372,7 @@ namespace exprtk else result = expression_generator_.function(function,branch); - sd.delete_ptr = false; + sd.delete_ptr = (0 == result); return result; } @@ -21228,7 +22393,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR022 - Expecting '()' to proceed call to function: '" + function_name + "'", + "ERR025 - Expecting '()' to proceed call to function: '" + function_name + "'", exprtk_error_location)); free_node(node_allocator_,result); @@ -21253,7 +22418,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR023 - Expected a '(' at start of function call to '" + function_name + + "ERR026 - Expected a '(' at start of function call to '" + function_name + "', instead got: '" + current_token().value + "'", exprtk_error_location)); @@ -21265,7 +22430,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR024 - Expected at least one input parameter for function call '" + function_name + "'", + "ERR027 - Expected at least one input parameter for function call '" + function_name + "'", exprtk_error_location)); return 0; @@ -21291,7 +22456,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR025 - Expected a ',' between function input parameters, instead got: '" + current_token().value + "'", + "ERR028 - Expected a ',' between function input parameters, instead got: '" + current_token().value + "'", exprtk_error_location)); return 0; @@ -21303,7 +22468,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR026 - Invalid number of input parameters passed to function '" + function_name + "'", + "ERR029 - Invalid number of input parameters passed to function '" + function_name + "'", exprtk_error_location)); return 0; @@ -21326,7 +22491,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, diagnostic_token, - "ERR027 - No entry found for base operation: " + operation_name, + "ERR030 - No entry found for base operation: " + operation_name, exprtk_error_location)); return error_node(); @@ -21373,7 +22538,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, diagnostic_token, - "ERR028 - Invalid number of input parameters for call to function: '" + operation_name + "'", + "ERR031 - Invalid number of input parameters for call to function: '" + operation_name + "'", exprtk_error_location)); return error_node(); @@ -21393,7 +22558,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR029 - Expected ',' between if-statement condition and consequent", + "ERR032 - Expected ',' between if-statement condition and consequent", exprtk_error_location)); result = false; } @@ -21402,7 +22567,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR030 - Failed to parse consequent for if-statement", + "ERR033 - Failed to parse consequent for if-statement", exprtk_error_location)); result = false; } @@ -21411,7 +22576,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR031 - Expected ',' between if-statement consequent and alternative", + "ERR034 - Expected ',' between if-statement consequent and alternative", exprtk_error_location)); result = false; } @@ -21420,7 +22585,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR032 - Failed to parse alternative for if-statement", + "ERR035 - Failed to parse alternative for if-statement", exprtk_error_location)); result = false; } @@ -21429,7 +22594,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR033 - Expected ')' at the end of if-statement", + "ERR036 - Expected ')' at the end of if-statement", exprtk_error_location)); result = false; } @@ -21437,7 +22602,7 @@ namespace exprtk #ifndef exprtk_disable_string_capabilities if (result) { - const bool consq_is_str = is_generally_string_node( consequent); + const bool consq_is_str = is_generally_string_node(consequent ); const bool alter_is_str = is_generally_string_node(alternative); if (consq_is_str || alter_is_str) @@ -21445,13 +22610,13 @@ namespace exprtk if (consq_is_str && alter_is_str) { return expression_generator_ - .conditional_string(condition,consequent,alternative); + .conditional_string(condition, consequent, alternative); } set_error( make_error(parser_error::e_syntax, current_token(), - "ERR034 - Return types of ternary if-statement differ", + "ERR037 - Return types of if-statement differ: string/non-string", exprtk_error_location)); result = false; @@ -21459,17 +22624,40 @@ namespace exprtk } #endif + if (result) + { + const bool consq_is_vec = is_ivector_node(consequent ); + const bool alter_is_vec = is_ivector_node(alternative); + + if (consq_is_vec || alter_is_vec) + { + if (consq_is_vec && alter_is_vec) + { + return expression_generator_ + .conditional_vector(condition, consequent, alternative); + } + + set_error( + make_error(parser_error::e_syntax, + current_token(), + "ERR038 - Return types of if-statement differ: vector/non-vector", + exprtk_error_location)); + + result = false; + } + } + if (!result) { - free_node(node_allocator_, condition); - free_node(node_allocator_, consequent); - free_node(node_allocator_,alternative); + free_node(node_allocator_, condition ); + free_node(node_allocator_, consequent ); + free_node(node_allocator_, alternative); return error_node(); } else return expression_generator_ - .conditional(condition,consequent,alternative); + .conditional(condition, consequent, alternative); } inline expression_node_ptr parse_conditional_statement_02(expression_node_ptr condition) @@ -21486,7 +22674,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR035 - Failed to parse body of consequent for if-statement", + "ERR039 - Failed to parse body of consequent for if-statement", exprtk_error_location)); result = false; @@ -21509,7 +22697,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR036 - Expected ';' at the end of the consequent for if-statement", + "ERR040 - Expected ';' at the end of the consequent for if-statement", exprtk_error_location)); result = false; @@ -21520,7 +22708,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR037 - Failed to parse body of consequent for if-statement", + "ERR041 - Failed to parse body of consequent for if-statement", exprtk_error_location)); result = false; @@ -21540,7 +22728,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR038 - Failed to parse body of the 'else' for if-statement", + "ERR042 - Failed to parse body of the 'else' for if-statement", exprtk_error_location)); result = false; @@ -21553,7 +22741,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR039 - Failed to parse body of if-else statement", + "ERR043 - Failed to parse body of if-else statement", exprtk_error_location)); result = false; @@ -21566,7 +22754,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR040 - Expected ';' at the end of the 'else-if' for the if-statement", + "ERR044 - Expected ';' at the end of the 'else-if' for the if-statement", exprtk_error_location)); result = false; @@ -21577,7 +22765,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR041 - Failed to parse body of the 'else' for if-statement", + "ERR045 - Failed to parse body of the 'else' for if-statement", exprtk_error_location)); result = false; @@ -21588,7 +22776,7 @@ namespace exprtk #ifndef exprtk_disable_string_capabilities if (result) { - const bool consq_is_str = is_generally_string_node( consequent); + const bool consq_is_str = is_generally_string_node(consequent ); const bool alter_is_str = is_generally_string_node(alternative); if (consq_is_str || alter_is_str) @@ -21602,7 +22790,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR042 - Return types of ternary if-statement differ", + "ERR046 - Return types of if-statement differ: string/non-string", exprtk_error_location)); result = false; @@ -21610,10 +22798,33 @@ namespace exprtk } #endif + if (result) + { + const bool consq_is_vec = is_ivector_node(consequent ); + const bool alter_is_vec = is_ivector_node(alternative); + + if (consq_is_vec || alter_is_vec) + { + if (consq_is_vec && alter_is_vec) + { + return expression_generator_ + .conditional_vector(condition, consequent, alternative); + } + + set_error( + make_error(parser_error::e_syntax, + current_token(), + "ERR047 - Return types of if-statement differ: vector/non-vector", + exprtk_error_location)); + + result = false; + } + } + if (!result) { - free_node(node_allocator_, condition); - free_node(node_allocator_, consequent); + free_node(node_allocator_, condition ); + free_node(node_allocator_, consequent ); free_node(node_allocator_, alternative); return error_node(); @@ -21634,7 +22845,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR043 - Expected '(' at start of if-statement, instead got: '" + current_token().value + "'", + "ERR048 - Expected '(' at start of if-statement, instead got: '" + current_token().value + "'", exprtk_error_location)); return error_node(); @@ -21644,7 +22855,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR044 - Failed to parse condition for if-statement", + "ERR049 - Failed to parse condition for if-statement", exprtk_error_location)); return error_node(); @@ -21676,7 +22887,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR045 - Invalid if-statement", + "ERR050 - Invalid if-statement", exprtk_error_location)); free_node(node_allocator_,condition); @@ -21697,7 +22908,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR046 - Encountered invalid condition branch for ternary if-statement", + "ERR051 - Encountered invalid condition branch for ternary if-statement", exprtk_error_location)); return error_node(); @@ -21707,7 +22918,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR047 - Expected '?' after condition of ternary if-statement", + "ERR052 - Expected '?' after condition of ternary if-statement", exprtk_error_location)); result = false; @@ -21717,7 +22928,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR048 - Failed to parse consequent for ternary if-statement", + "ERR053 - Failed to parse consequent for ternary if-statement", exprtk_error_location)); result = false; @@ -21727,7 +22938,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR049 - Expected ':' between ternary if-statement consequent and alternative", + "ERR054 - Expected ':' between ternary if-statement consequent and alternative", exprtk_error_location)); result = false; @@ -21737,7 +22948,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR050 - Failed to parse alternative for ternary if-statement", + "ERR055 - Failed to parse alternative for ternary if-statement", exprtk_error_location)); result = false; @@ -21746,7 +22957,7 @@ namespace exprtk #ifndef exprtk_disable_string_capabilities if (result) { - const bool consq_is_str = is_generally_string_node( consequent); + const bool consq_is_str = is_generally_string_node(consequent ); const bool alter_is_str = is_generally_string_node(alternative); if (consq_is_str || alter_is_str) @@ -21760,7 +22971,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR051 - Return types of ternary if-statement differ", + "ERR056 - Return types of ternary differ: string/non-string", exprtk_error_location)); result = false; @@ -21768,10 +22979,33 @@ namespace exprtk } #endif + if (result) + { + const bool consq_is_vec = is_ivector_node(consequent ); + const bool alter_is_vec = is_ivector_node(alternative); + + if (consq_is_vec || alter_is_vec) + { + if (consq_is_vec && alter_is_vec) + { + return expression_generator_ + .conditional_vector(condition, consequent, alternative); + } + + set_error( + make_error(parser_error::e_syntax, + current_token(), + "ERR057 - Return types of ternary differ: vector/non-vector", + exprtk_error_location)); + + result = false; + } + } + if (!result) { - free_node(node_allocator_, condition); - free_node(node_allocator_, consequent); + free_node(node_allocator_, condition ); + free_node(node_allocator_, consequent ); free_node(node_allocator_, alternative); return error_node(); @@ -21781,6 +23015,22 @@ namespace exprtk .conditional(condition, consequent, alternative); } + inline expression_node_ptr parse_not_statement() + { + if (settings_.logic_disabled("not")) + { + set_error( + make_error(parser_error::e_syntax, + current_token(), + "ERR058 - Invalid or disabled logic operation 'not'", + exprtk_error_location)); + + return error_node(); + } + + return parse_base_operation(); + } + inline expression_node_ptr parse_while_loop() { // Parse: [while][(][test expr][)][{][expression][}] @@ -21797,7 +23047,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR052 - Expected '(' at start of while-loop condition statement", + "ERR059 - Expected '(' at start of while-loop condition statement", exprtk_error_location)); return error_node(); @@ -21807,7 +23057,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR053 - Failed to parse condition for while-loop", + "ERR060 - Failed to parse condition for while-loop", exprtk_error_location)); return error_node(); @@ -21817,7 +23067,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR054 - Expected ')' at end of while-loop condition statement", + "ERR061 - Expected ')' at end of while-loop condition statement", exprtk_error_location)); result = false; @@ -21827,12 +23077,14 @@ namespace exprtk if (result) { + scoped_inc_dec sid(state_.parsing_loop_stmt_count); + if (0 == (branch = parse_multi_sequence("while-loop"))) { set_error( make_error(parser_error::e_syntax, current_token(), - "ERR055 - Failed to parse body of while-loop")); + "ERR062 - Failed to parse body of while-loop")); result = false; } else if (0 == (result_node = expression_generator_.while_loop(condition, @@ -21842,7 +23094,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR056 - Failed to synthesize while-loop", + "ERR063 - Failed to synthesize while-loop", exprtk_error_location)); result = false; @@ -21851,8 +23103,8 @@ namespace exprtk if (!result) { - free_node(node_allocator_, branch); - free_node(node_allocator_, condition); + free_node(node_allocator_, branch ); + free_node(node_allocator_, condition ); free_node(node_allocator_, result_node); brkcnt_list_.pop_front(); @@ -21890,6 +23142,8 @@ namespace exprtk scoped_bool_or_restorer sbr(state_.side_effect_present); + scoped_inc_dec sid(state_.parsing_loop_stmt_count); + for ( ; ; ) { state_.side_effect_present = false; @@ -21918,7 +23172,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR057 - Expected '" + token_t::to_str(seperator) + "' in body of repeat until loop", + "ERR064 - Expected '" + token_t::to_str(seperator) + "' in body of repeat until loop", exprtk_error_location)); return error_node(); @@ -21942,7 +23196,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR058 - Failed to parse body of repeat until loop", + "ERR065 - Failed to parse body of repeat until loop", exprtk_error_location)); return error_node(); @@ -21956,7 +23210,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR059 - Expected '(' before condition statement of repeat until loop", + "ERR066 - Expected '(' before condition statement of repeat until loop", exprtk_error_location)); free_node(node_allocator_,branch); @@ -21970,7 +23224,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR060 - Failed to parse condition for repeat until loop", + "ERR067 - Failed to parse condition for repeat until loop", exprtk_error_location)); free_node(node_allocator_,branch); @@ -21982,10 +23236,10 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR061 - Expected ')' after condition of repeat until loop", + "ERR068 - Expected ')' after condition of repeat until loop", exprtk_error_location)); - free_node(node_allocator_, branch); + free_node(node_allocator_, branch ); free_node(node_allocator_, condition); brkcnt_list_.pop_front(); @@ -22003,7 +23257,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR062 - Failed to synthesize repeat until loop", + "ERR069 - Failed to synthesize repeat until loop", exprtk_error_location)); free_node(node_allocator_,condition); @@ -22038,7 +23292,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR063 - Expected '(' at start of for-loop", + "ERR070 - Expected '(' at start of for-loop", exprtk_error_location)); return error_node(); @@ -22058,7 +23312,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR064 - Expected a variable at the start of initialiser section of for-loop", + "ERR071 - Expected a variable at the start of initialiser section of for-loop", exprtk_error_location)); return error_node(); @@ -22068,7 +23322,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR065 - Expected variable assignment of initialiser section of for-loop", + "ERR072 - Expected variable assignment of initialiser section of for-loop", exprtk_error_location)); return error_node(); @@ -22083,7 +23337,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR066 - For-loop variable '" + loop_counter_symbol+ "' is being shadowed by a previous declaration", + "ERR073 - For-loop variable '" + loop_counter_symbol+ "' is being shadowed by a previous declaration", exprtk_error_location)); return error_node(); @@ -22093,7 +23347,7 @@ namespace exprtk if ( !se->active && (se->name == loop_counter_symbol) && - (se->type == scope_element::e_variable) + (se->type == scope_element::e_variable) ) { se->active = true; @@ -22108,14 +23362,14 @@ namespace exprtk nse.type = scope_element::e_variable; nse.depth = state_.scope_depth; nse.data = new T(T(0)); - nse.var_node = node_allocator_.allocate(*(T*)(nse.data)); + nse.var_node = node_allocator_.allocate(*reinterpret_cast(nse.data)); if (!sem_.add_element(nse)) { set_error( make_error(parser_error::e_syntax, current_token(), - "ERR067 - Failed to add new local variable '" + loop_counter_symbol + "' to SEM", + "ERR074 - Failed to add new local variable '" + loop_counter_symbol + "' to SEM", exprtk_error_location)); sem_.free_element(nse); @@ -22137,7 +23391,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR068 - Failed to parse initialiser of for-loop", + "ERR075 - Failed to parse initialiser of for-loop", exprtk_error_location)); result = false; @@ -22147,7 +23401,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR069 - Expected ';' after initialiser of for-loop", + "ERR076 - Expected ';' after initialiser of for-loop", exprtk_error_location)); result = false; @@ -22161,7 +23415,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR070 - Failed to parse condition of for-loop", + "ERR077 - Failed to parse condition of for-loop", exprtk_error_location)); result = false; @@ -22171,7 +23425,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR071 - Expected ';' after condition section of for-loop", + "ERR078 - Expected ';' after condition section of for-loop", exprtk_error_location)); result = false; @@ -22185,7 +23439,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR072 - Failed to parse incrementor of for-loop", + "ERR079 - Failed to parse incrementor of for-loop", exprtk_error_location)); result = false; @@ -22195,7 +23449,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR073 - Expected ')' after incrementor section of for-loop", + "ERR080 - Expected ')' after incrementor section of for-loop", exprtk_error_location)); result = false; @@ -22206,12 +23460,14 @@ namespace exprtk { brkcnt_list_.push_front(false); + scoped_inc_dec sid(state_.parsing_loop_stmt_count); + if (0 == (loop_body = parse_multi_sequence("for-loop"))) { set_error( make_error(parser_error::e_syntax, current_token(), - "ERR074 - Failed to parse body of for-loop", + "ERR081 - Failed to parse body of for-loop", exprtk_error_location)); result = false; @@ -22226,9 +23482,9 @@ namespace exprtk } free_node(node_allocator_, initialiser); - free_node(node_allocator_, condition); + free_node(node_allocator_, condition ); free_node(node_allocator_, incrementor); - free_node(node_allocator_, loop_body); + free_node(node_allocator_, loop_body ); if (!brkcnt_list_.empty()) { @@ -22261,7 +23517,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR075 - Expected keyword 'switch'", + "ERR082 - Expected keyword 'switch'", exprtk_error_location)); return error_node(); @@ -22276,85 +23532,100 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR076 - Expected '{' for call to switch statement", + "ERR083 - Expected '{' for call to switch statement", exprtk_error_location)); return error_node(); } + expression_node_ptr default_statement = error_node(); + + scoped_expression_delete defstmt_delete((*this), default_statement); + for ( ; ; ) { - if (!details::imatch("case",current_token().value)) + if (details::imatch("case",current_token().value)) { - set_error( - make_error(parser_error::e_syntax, - current_token(), - "ERR077 - Expected either a 'case' or 'default' statement", - exprtk_error_location)); + next_token(); - return error_node(); - } + expression_node_ptr condition = parse_expression(); - next_token(); + if (0 == condition) + return error_node(); + else if (!token_is(token_t::e_colon)) + { + set_error( + make_error(parser_error::e_syntax, + current_token(), + "ERR084 - Expected ':' for case of switch statement", + exprtk_error_location)); - expression_node_ptr condition = parse_expression(); + free_node(node_allocator_, condition); - if (0 == condition) - return error_node(); - else if (!token_is(token_t::e_colon)) - { - set_error( - make_error(parser_error::e_syntax, - current_token(), - "ERR078 - Expected ':' for case of switch statement", - exprtk_error_location)); + return error_node(); + } - return error_node(); - } + expression_node_ptr consequent = parse_expression(); - expression_node_ptr consequent = parse_expression(); + if (0 == consequent) + { + free_node(node_allocator_, condition); - if (0 == consequent) - return error_node(); - else if (!token_is(token_t::e_eof)) - { - set_error( - make_error(parser_error::e_syntax, - current_token(), - "ERR079 - Expected ';' at end of case for switch statement", - exprtk_error_location)); + return error_node(); + } + else if (!token_is(token_t::e_eof)) + { + set_error( + make_error(parser_error::e_syntax, + current_token(), + "ERR085 - Expected ';' at end of case for switch statement", + exprtk_error_location)); - return error_node(); - } + free_node(node_allocator_, condition ); + free_node(node_allocator_, consequent); + + return error_node(); + } + + // Can we optimise away the case statement? + if (is_constant_node(condition) && is_false(condition)) + { + free_node(node_allocator_, condition ); + free_node(node_allocator_, consequent); + } + else + { + arg_list.push_back(condition ); + arg_list.push_back(consequent); + } - // Can we optimise away the case statement? - if (is_constant_node(condition) && is_false(condition)) - { - free_node(node_allocator_, condition); - free_node(node_allocator_, consequent); } - else + else if (details::imatch("default",current_token().value)) { - arg_list.push_back( condition); - arg_list.push_back(consequent); - } + if (0 != default_statement) + { + set_error( + make_error(parser_error::e_syntax, + current_token(), + "ERR086 - Multiple default cases for switch statement", + exprtk_error_location)); + + return error_node(); + } - if (details::imatch("default",current_token().value)) - { next_token(); + if (!token_is(token_t::e_colon)) { set_error( make_error(parser_error::e_syntax, current_token(), - "ERR080 - Expected ':' for default of switch statement", + "ERR087 - Expected ':' for default of switch statement", exprtk_error_location)); return error_node(); } - expression_node_ptr default_statement = error_node(); - if (token_is(token_t::e_lcrlbracket,prsrhlpr_t::e_hold)) default_statement = parse_multi_sequence("switch-default"); else @@ -22364,36 +23635,40 @@ namespace exprtk return error_node(); else if (!token_is(token_t::e_eof)) { - free_node(node_allocator_,default_statement); - set_error( make_error(parser_error::e_syntax, current_token(), - "ERR081 - Expected ';' at end of default for switch statement", + "ERR088 - Expected ';' at end of default for switch statement", exprtk_error_location)); return error_node(); } - - arg_list.push_back(default_statement); + } + else if (token_is(token_t::e_rcrlbracket)) break; + else + { + set_error( + make_error(parser_error::e_syntax, + current_token(), + "ERR089 - Expected '}' at end of switch statement", + exprtk_error_location)); + + return error_node(); } } - if (!token_is(token_t::e_rcrlbracket)) - { - set_error( - make_error(parser_error::e_syntax, - current_token(), - "ERR082 - Expected '}' at end of switch statement", - exprtk_error_location)); + const bool default_statement_present = (0 != default_statement); - return error_node(); + if (default_statement_present) + { + arg_list.push_back(default_statement); } - result = expression_generator_.switch_statement(arg_list); + result = expression_generator_.switch_statement(arg_list, (0 != default_statement)); svd.delete_ptr = (0 == result); + defstmt_delete.delete_ptr = (0 == result); return result; } @@ -22407,7 +23682,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR083 - Expected token '[*]'", + "ERR090 - Expected token '[*]'", exprtk_error_location)); return error_node(); @@ -22422,7 +23697,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR084 - Expected '{' for call to [*] statement", + "ERR091 - Expected '{' for call to [*] statement", exprtk_error_location)); return error_node(); @@ -22435,7 +23710,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR085 - Expected a 'case' statement for multi-switch", + "ERR092 - Expected a 'case' statement for multi-switch", exprtk_error_location)); return error_node(); @@ -22453,7 +23728,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR086 - Expected ':' for case of [*] statement", + "ERR093 - Expected ':' for case of [*] statement", exprtk_error_location)); return error_node(); @@ -22469,7 +23744,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR087 - Expected ';' at end of case for [*] statement", + "ERR094 - Expected ';' at end of case for [*] statement", exprtk_error_location)); return error_node(); @@ -22478,12 +23753,12 @@ namespace exprtk // Can we optimise away the case statement? if (is_constant_node(condition) && is_false(condition)) { - free_node(node_allocator_, condition); + free_node(node_allocator_, condition ); free_node(node_allocator_, consequent); } else { - arg_list.push_back( condition); + arg_list.push_back(condition ); arg_list.push_back(consequent); } @@ -22498,7 +23773,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR088 - Expected '}' at end of [*] statement", + "ERR095 - Expected '}' at end of [*] statement", exprtk_error_location)); return error_node(); @@ -22539,7 +23814,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR089 - Unsupported vararg function: " + symbol, + "ERR096 - Unsupported vararg function: " + symbol, exprtk_error_location)); return error_node(); @@ -22556,7 +23831,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR090 - Expected '(' for call to vararg function: " + symbol, + "ERR097 - Expected '(' for call to vararg function: " + symbol, exprtk_error_location)); return error_node(); @@ -22578,7 +23853,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR091 - Expected ',' for call to vararg function: " + symbol, + "ERR098 - Expected ',' for call to vararg function: " + symbol, exprtk_error_location)); return error_node(); @@ -22599,7 +23874,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR092 - Expected '[' as start of string range definition", + "ERR099 - Expected '[' as start of string range definition", exprtk_error_location)); free_node(node_allocator_,expression); @@ -22627,10 +23902,11 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR093 - Failed to generate string range node", + "ERR100 - Failed to generate string range node", exprtk_error_location)); free_node(node_allocator_,expression); + rp.free(); } rp.clear(); @@ -22732,8 +24008,8 @@ namespace exprtk } if ( - return_node_present || - side_effect_list.back() || + return_node_present || + side_effect_list.back() || (expression_list.size() > 1) ) state_.activate_side_effect("simplify()"); @@ -22763,7 +24039,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR094 - Expected '" + token_t::to_str(close_bracket) + "' for call to multi-sequence" + + "ERR101 - Expected '" + token_t::to_str(close_bracket) + "' for call to multi-sequence" + ((!source.empty()) ? std::string(" section of " + source): ""), exprtk_error_location)); @@ -22810,7 +24086,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR095 - Expected '" + details::to_str(seperator) + "' for call to multi-sequence section of " + source, + "ERR102 - Expected '" + details::to_str(seperator) + "' for call to multi-sequence section of " + source, exprtk_error_location)); return error_node(); @@ -22844,7 +24120,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR096 - Expected '[' for start of range", + "ERR103 - Expected '[' for start of range", exprtk_error_location)); return false; @@ -22865,7 +24141,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR097 - Failed parse begin section of range", + "ERR104 - Failed parse begin section of range", exprtk_error_location)); return false; @@ -22888,7 +24164,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR098 - Range lower bound less than zero! Constraint: r0 >= 0", + "ERR105 - Range lower bound less than zero! Constraint: r0 >= 0", exprtk_error_location)); return false; @@ -22905,7 +24181,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR099 - Expected ':' for break in range", + "ERR106 - Expected ':' for break in range", exprtk_error_location)); rp.free(); @@ -22928,7 +24204,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR100 - Failed parse end section of range", + "ERR107 - Failed parse end section of range", exprtk_error_location)); rp.free(); @@ -22953,9 +24229,11 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR101 - Range upper bound less than zero! Constraint: r1 >= 0", + "ERR108 - Range upper bound less than zero! Constraint: r1 >= 0", exprtk_error_location)); + rp.free(); + return false; } } @@ -22970,7 +24248,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR102 - Expected ']' for start of range", + "ERR109 - Expected ']' for start of range", exprtk_error_location)); rp.free(); @@ -22984,14 +24262,21 @@ namespace exprtk std::size_t r0 = 0; std::size_t r1 = 0; - const bool rp_result = rp(r0,r1); + bool rp_result = false; + + try + { + rp_result = rp(r0, r1); + } + catch (std::runtime_error&) + {} if (!rp_result || (r0 > r1)) { set_error( make_error(parser_error::e_syntax, current_token(), - "ERR103 - Invalid range, Constraint: r0 <= r1", + "ERR110 - Invalid range, Constraint: r0 <= r1", exprtk_error_location)); return false; @@ -23032,7 +24317,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR104 - Unknown string symbol", + "ERR111 - Unknown string symbol", exprtk_error_location)); return error_node(); @@ -23126,6 +24411,7 @@ namespace exprtk if (!parse_range(rp)) { free_node(node_allocator_,result); + rp.free(); return error_node(); } @@ -23146,11 +24432,13 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR105 - Overflow in range for string: '" + const_str + "'[" + + "ERR112 - Overflow in range for string: '" + const_str + "'[" + (rp.n0_c.first ? details::to_str(static_cast(rp.n0_c.second)) : "?") + ":" + (rp.n1_c.first ? details::to_str(static_cast(rp.n1_c.second)) : "?") + "]", exprtk_error_location)); + rp.free(); + return error_node(); } @@ -23190,7 +24478,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR106 - Symbol '" + symbol+ " not a vector", + "ERR113 - Symbol '" + symbol+ " not a vector", exprtk_error_location)); return error_node(); @@ -23216,7 +24504,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR107 - Failed to parse index for vector: '" + symbol + "'", + "ERR114 - Failed to parse index for vector: '" + symbol + "'", exprtk_error_location)); return error_node(); @@ -23226,7 +24514,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR108 - Expected ']' for index of vector: '" + symbol + "'", + "ERR115 - Expected ']' for index of vector: '" + symbol + "'", exprtk_error_location)); free_node(node_allocator_,index_expr); @@ -23245,7 +24533,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR109 - Index of " + details::to_str(index) + " out of range for " + "ERR116 - Index of " + details::to_str(index) + " out of range for " "vector '" + symbol + "' of size " + details::to_str(vec_size), exprtk_error_location)); @@ -23255,7 +24543,7 @@ namespace exprtk } } - return expression_generator_.vector_element(symbol,vec,index_expr); + return expression_generator_.vector_element(symbol, vec, index_expr); } inline expression_node_ptr parse_vararg_function_call(ivararg_function* vararg_function, const std::string& vararg_function_name) @@ -23277,7 +24565,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR110 - Zero parameter call to vararg function: " + "ERR117 - Zero parameter call to vararg function: " + vararg_function_name + " not allowed", exprtk_error_location)); @@ -23302,7 +24590,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR111 - Expected ',' for call to vararg function: " + "ERR118 - Expected ',' for call to vararg function: " + vararg_function_name, exprtk_error_location)); @@ -23316,7 +24604,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR112 - Zero parameter call to vararg function: " + "ERR119 - Zero parameter call to vararg function: " + vararg_function_name + " not allowed", exprtk_error_location)); @@ -23328,7 +24616,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR113 - Invalid number of parameters to call to vararg function: " + "ERR120 - Invalid number of parameters to call to vararg function: " + vararg_function_name + ", require at least " + details::to_str(static_cast(vararg_function->min_num_args())) + " parameters", exprtk_error_location)); @@ -23340,7 +24628,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR114 - Invalid number of parameters to call to vararg function: " + "ERR121 - Invalid number of parameters to call to vararg function: " + vararg_function_name + ", require no more than " + details::to_str(static_cast(vararg_function->max_num_args())) + " parameters", exprtk_error_location)); @@ -23379,19 +24667,14 @@ namespace exprtk const std::string& func_name, const std::string& func_prototypes, const return_type_t default_return_type) - : invalid_state_(true), - parser_(p), - function_name_(func_name), - default_return_type_(default_return_type) + : invalid_state_(true) + , parser_(p) + , function_name_(func_name) + , default_return_type_(default_return_type) { parse_function_prototypes(func_prototypes); } - void set_default_return_type(const std::string& return_type) - { - default_return_type_ = return_type; - } - bool verify(const std::string& param_seq, std::size_t& pseq_index) { if (function_definition_list_.empty()) @@ -23423,9 +24706,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, parser_.current_token(), - "ERR115 - Failed parameter type check for function '" + function_name_ + "', " + "ERR122 - Failed parameter type check for function '" + function_name_ + "', " "Expected '" + function_definition_list_[0].param_seq + - "' call set: '" + param_seq + "'", + "' call set: '" + param_seq + "'", exprtk_error_location)); } else @@ -23445,9 +24728,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, parser_.current_token(), - "ERR116 - Failed parameter type check for function '" + function_name_ + "', " + "ERR123 - Failed parameter type check for function '" + function_name_ + "', " "Best match: '" + function_definition_list_[max_diff_index].param_seq + - "' call set: '" + param_seq + "'", + "' call set: '" + param_seq + "'", exprtk_error_location)); } @@ -23587,7 +24870,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, parser_.current_token(), - "ERR117 - Invalid parameter sequence of '" + param_seq_list[i] + + "ERR124 - Invalid parameter sequence of '" + param_seq_list[i] + "' for function: " + function_name_, exprtk_error_location)); return; @@ -23603,7 +24886,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, parser_.current_token(), - "ERR118 - Function '" + function_name_ + "' has a parameter sequence conflict between " + + "ERR125 - Function '" + function_name_ + "' has a parameter sequence conflict between " + "pseq_idx[" + details::to_str(seq_itr->second) + "] and" + "pseq_idx[" + details::to_str(i) + "] " + "param seq: " + param_seq_list[i], @@ -23642,7 +24925,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR119 - Type checker instantiation failure for generic function: " + function_name, + "ERR126 - Type checker instantiation failure for generic function: " + function_name, exprtk_error_location)); return error_node(); @@ -23660,7 +24943,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR120 - Zero parameter call to generic function: " + "ERR127 - Zero parameter call to generic function: " + function_name + " not allowed", exprtk_error_location)); @@ -23692,7 +24975,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR121 - Expected ',' for call to generic function: " + function_name, + "ERR128 - Expected ',' for call to generic function: " + function_name, exprtk_error_location)); return error_node(); @@ -23709,7 +24992,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR122 - Zero parameter call to generic function: " + "ERR129 - Zero parameter call to generic function: " + function_name + " not allowed", exprtk_error_location)); @@ -23726,7 +25009,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR123 - Invalid input parameter sequence for call to generic function: " + function_name, + "ERR130 - Invalid input parameter sequence for call to generic function: " + function_name, exprtk_error_location)); return error_node(); @@ -23748,7 +25031,7 @@ namespace exprtk inline bool parse_igeneric_function_params(std::string& param_type_list, std::vector& arg_list, - const std::string function_name, + const std::string& function_name, igeneric_function* function, const type_checker& tc) { @@ -23764,7 +25047,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR124 - Zero parameter call to generic function: " + "ERR131 - Zero parameter call to generic function: " + function_name + " not allowed", exprtk_error_location)); @@ -23796,7 +25079,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR125 - Expected ',' for call to string function: " + function_name, + "ERR132 - Expected ',' for call to string function: " + function_name, exprtk_error_location)); return false; @@ -23843,7 +25126,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR126 - Invalid input parameter sequence for call to string function: " + function_name, + "ERR133 - Invalid input parameter sequence for call to string function: " + function_name, exprtk_error_location)); return error_node(); @@ -23895,7 +25178,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR127 - Invalid input parameter sequence for call to overloaded function: " + function_name, + "ERR134 - Invalid input parameter sequence for call to overloaded function: " + function_name, exprtk_error_location)); return error_node(); @@ -23926,7 +25209,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR128 - Invalid return type for call to overloaded function: " + function_name, + "ERR135 - Invalid return type for call to overloaded function: " + function_name, exprtk_error_location)); } @@ -23938,12 +25221,12 @@ namespace exprtk template struct parse_special_function_impl { - static inline expression_node_ptr process(parser& p,const details::operator_type opt_type, const std::string& sf_name) + static inline expression_node_ptr process(parser& p, const details::operator_type opt_type, const std::string& sf_name) { expression_node_ptr branch[NumberOfParameters]; - expression_node_ptr result = error_node(); + expression_node_ptr result = error_node(); - std::fill_n(branch,NumberOfParameters,reinterpret_cast(0)); + std::fill_n(branch, NumberOfParameters, reinterpret_cast(0)); scoped_delete sd(p,branch); @@ -23954,7 +25237,7 @@ namespace exprtk p.set_error( make_error(parser_error::e_syntax, p.current_token(), - "ERR129 - Expected '(' for special function '" + sf_name + "'", + "ERR136 - Expected '(' for special function '" + sf_name + "'", exprtk_error_location)); return error_node(); @@ -23975,7 +25258,7 @@ namespace exprtk p.set_error( make_error(parser_error::e_syntax, p.current_token(), - "ERR130 - Expected ',' before next parameter of special function '" + sf_name + "'", + "ERR137 - Expected ',' before next parameter of special function '" + sf_name + "'", exprtk_error_location)); return p.error_node(); @@ -23988,7 +25271,7 @@ namespace exprtk p.set_error( make_error(parser_error::e_syntax, p.current_token(), - "ERR131 - Invalid number of parameters for special function '" + sf_name + "'", + "ERR138 - Invalid number of parameters for special function '" + sf_name + "'", exprtk_error_location)); return p.error_node(); @@ -24015,7 +25298,7 @@ namespace exprtk set_error( make_error(parser_error::e_token, current_token(), - "ERR132 - Invalid special function[1]: " + sf_name, + "ERR139 - Invalid special function[1]: " + sf_name, exprtk_error_location)); return error_node(); @@ -24029,7 +25312,7 @@ namespace exprtk set_error( make_error(parser_error::e_token, current_token(), - "ERR133 - Invalid special function[2]: " + sf_name, + "ERR140 - Invalid special function[2]: " + sf_name, exprtk_error_location)); return error_node(); @@ -24061,7 +25344,17 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR134 - Break call within a break call is not allowed", + "ERR141 - Invoking 'break' within a break call is not allowed", + exprtk_error_location)); + + return error_node(); + } + else if (0 == state_.parsing_loop_stmt_count) + { + set_error( + make_error(parser_error::e_syntax, + current_token(), + "ERR142 - Invalid use of 'break', allowed only in the scope of a loop", exprtk_error_location)); return error_node(); @@ -24084,7 +25377,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR135 - Failed to parse return expression for 'break' statement", + "ERR143 - Failed to parse return expression for 'break' statement", exprtk_error_location)); return error_node(); @@ -24094,7 +25387,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR136 - Expected ']' at the completion of break's return expression", + "ERR144 - Expected ']' at the completion of break's return expression", exprtk_error_location)); free_node(node_allocator_,return_expr); @@ -24112,7 +25405,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR137 - Invalid use of 'break', allowed only in the scope of a loop", + "ERR145 - Invalid use of 'break', allowed only in the scope of a loop", exprtk_error_location)); } @@ -24121,25 +25414,25 @@ namespace exprtk inline expression_node_ptr parse_continue_statement() { - if (!brkcnt_list_.empty()) - { - next_token(); - - brkcnt_list_.front() = true; - state_.activate_side_effect("parse_continue_statement()"); - - return node_allocator_.allocate >(); - } - else + if (0 == state_.parsing_loop_stmt_count) { set_error( make_error(parser_error::e_syntax, current_token(), - "ERR138 - Invalid use of 'continue', allowed only in the scope of a loop", + "ERR146 - Invalid use of 'continue', allowed only in the scope of a loop", exprtk_error_location)); return error_node(); } + else + { + next_token(); + + brkcnt_list_.front() = true; + state_.activate_side_effect("parse_continue_statement()"); + + return node_allocator_.allocate >(); + } } #endif @@ -24152,7 +25445,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR139 - Expected '[' as part of vector size definition", + "ERR147 - Expected '[' as part of vector size definition", exprtk_error_location)); return error_node(); @@ -24162,7 +25455,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR140 - Failed to determine size of vector '" + vec_name + "'", + "ERR148 - Failed to determine size of vector '" + vec_name + "'", exprtk_error_location)); return error_node(); @@ -24174,13 +25467,13 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR141 - Expected a literal number as size of vector '" + vec_name + "'", + "ERR149 - Expected a literal number as size of vector '" + vec_name + "'", exprtk_error_location)); return error_node(); } - T vector_size = size_expr->value(); + const T vector_size = size_expr->value(); free_node(node_allocator_,size_expr); @@ -24196,7 +25489,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR142 - Invalid vector size. Must be an integer in the range [0,2e9], size: " + + "ERR150 - Invalid vector size. Must be an integer in the range [0,2e9], size: " + details::to_str(details::numeric::to_int32(vector_size)), exprtk_error_location)); @@ -24216,7 +25509,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR143 - Expected ']' as part of vector size definition", + "ERR151 - Expected ']' as part of vector size definition", exprtk_error_location)); return error_node(); @@ -24228,7 +25521,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR144 - Expected ':=' as part of vector definition", + "ERR152 - Expected ':=' as part of vector definition", exprtk_error_location)); return error_node(); @@ -24242,7 +25535,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR145 - Failed to parse single vector initialiser", + "ERR153 - Failed to parse single vector initialiser", exprtk_error_location)); return error_node(); @@ -24255,7 +25548,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR146 - Expected ']' to close single value vector initialiser", + "ERR154 - Expected ']' to close single value vector initialiser", exprtk_error_location)); return error_node(); @@ -24271,7 +25564,7 @@ namespace exprtk if (token_t::e_symbol == current_token().type) { // Is it a locally defined vector? - scope_element& se = sem_.get_active_element(current_token().value); + const scope_element& se = sem_.get_active_element(current_token().value); if (scope_element::e_vector == se.type) { @@ -24302,7 +25595,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR147 - Expected '{' as part of vector initialiser list", + "ERR155 - Expected '{' as part of vector initialiser list", exprtk_error_location)); return error_node(); @@ -24322,7 +25615,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR148 - Expected '{' as part of vector initialiser list", + "ERR156 - Expected '{' as part of vector initialiser list", exprtk_error_location)); return error_node(); @@ -24340,7 +25633,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR149 - Expected ',' between vector initialisers", + "ERR157 - Expected ',' between vector initialisers", exprtk_error_location)); return error_node(); @@ -24362,7 +25655,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR150 - Expected ';' at end of vector definition", + "ERR158 - Expected ';' at end of vector definition", exprtk_error_location)); return error_node(); @@ -24374,7 +25667,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR151 - Initialiser list larger than the number of elements in the vector: '" + vec_name + "'", + "ERR159 - Initialiser list larger than the number of elements in the vector: '" + vec_name + "'", exprtk_error_location)); return error_node(); @@ -24394,7 +25687,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR152 - Illegal redefinition of local vector: '" + vec_name + "'", + "ERR160 - Illegal redefinition of local vector: '" + vec_name + "'", exprtk_error_location)); return error_node(); @@ -24421,14 +25714,14 @@ namespace exprtk nse.depth = state_.scope_depth; nse.size = vec_size; nse.data = new T[vec_size]; - nse.vec_node = new typename scope_element::vector_holder_t((T*)(nse.data),nse.size); + nse.vec_node = new typename scope_element::vector_holder_t(reinterpret_cast(nse.data),nse.size); if (!sem_.add_element(nse)) { set_error( make_error(parser_error::e_syntax, current_token(), - "ERR153 - Failed to add new local vector '" + vec_name + "' to SEM", + "ERR161 - Failed to add new local vector '" + vec_name + "' to SEM", exprtk_error_location)); sem_.free_element(nse); @@ -24487,7 +25780,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR154 - Illegal redefinition of local variable: '" + str_name + "'", + "ERR162 - Illegal redefinition of local variable: '" + str_name + "'", exprtk_error_location)); free_node(node_allocator_,initialisation_expression); @@ -24512,14 +25805,14 @@ namespace exprtk nse.type = scope_element::e_string; nse.depth = state_.scope_depth; nse.data = new std::string; - nse.str_node = new stringvar_node_t(*(std::string*)(nse.data)); + nse.str_node = new stringvar_node_t(*reinterpret_cast(nse.data)); if (!sem_.add_element(nse)) { set_error( make_error(parser_error::e_syntax, current_token(), - "ERR155 - Failed to add new local string variable '" + str_name + "' to SEM", + "ERR163 - Failed to add new local string variable '" + str_name + "' to SEM", exprtk_error_location)); free_node(node_allocator_,initialisation_expression); @@ -24565,7 +25858,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR156 - Illegal variable definition", + "ERR164 - Illegal variable definition", exprtk_error_location)); return error_node(); @@ -24586,7 +25879,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR157 - Expected a symbol for variable definition", + "ERR165 - Expected a symbol for variable definition", exprtk_error_location)); return error_node(); @@ -24596,7 +25889,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR158 - Illegal redefinition of reserved keyword: '" + var_name + "'", + "ERR166 - Illegal redefinition of reserved keyword: '" + var_name + "'", exprtk_error_location)); return error_node(); @@ -24606,7 +25899,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR159 - Illegal redefinition of variable '" + var_name + "'", + "ERR167 - Illegal redefinition of variable '" + var_name + "'", exprtk_error_location)); return error_node(); @@ -24616,7 +25909,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR160 - Illegal redefinition of local variable: '" + var_name + "'", + "ERR168 - Illegal redefinition of local variable: '" + var_name + "'", exprtk_error_location)); return error_node(); @@ -24636,7 +25929,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR161 - Failed to parse initialisation expression", + "ERR169 - Failed to parse initialisation expression", exprtk_error_location)); return error_node(); @@ -24654,7 +25947,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR162 - Expected ';' after variable definition", + "ERR170 - Expected ';' after variable definition", exprtk_error_location)); free_node(node_allocator_,initialisation_expression); @@ -24682,7 +25975,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR163 - Illegal redefinition of local variable: '" + var_name + "'", + "ERR171 - Illegal redefinition of local variable: '" + var_name + "'", exprtk_error_location)); free_node(node_allocator_, initialisation_expression); @@ -24707,14 +26000,14 @@ namespace exprtk nse.type = scope_element::e_variable; nse.depth = state_.scope_depth; nse.data = new T(T(0)); - nse.var_node = node_allocator_.allocate(*(T*)(nse.data)); + nse.var_node = node_allocator_.allocate(*reinterpret_cast(nse.data)); if (!sem_.add_element(nse)) { set_error( make_error(parser_error::e_syntax, current_token(), - "ERR164 - Failed to add new local variable '" + var_name + "' to SEM", + "ERR172 - Failed to add new local variable '" + var_name + "' to SEM", exprtk_error_location)); free_node(node_allocator_, initialisation_expression); @@ -24751,7 +26044,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR165 - Expected a '{}' for uninitialised var definition", + "ERR173 - Expected a '{}' for uninitialised var definition", exprtk_error_location)); return error_node(); @@ -24761,7 +26054,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR166 - Expected ';' after uninitialised variable definition", + "ERR174 - Expected ';' after uninitialised variable definition", exprtk_error_location)); return error_node(); @@ -24778,7 +26071,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR167 - Illegal redefinition of local variable: '" + var_name + "'", + "ERR175 - Illegal redefinition of local variable: '" + var_name + "'", exprtk_error_location)); return error_node(); @@ -24801,14 +26094,14 @@ namespace exprtk nse.depth = state_.scope_depth; nse.ip_index = sem_.next_ip_index(); nse.data = new T(T(0)); - nse.var_node = node_allocator_.allocate(*(T*)(nse.data)); + nse.var_node = node_allocator_.allocate(*reinterpret_cast(nse.data)); if (!sem_.add_element(nse)) { set_error( make_error(parser_error::e_syntax, current_token(), - "ERR168 - Failed to add new local variable '" + var_name + "' to SEM", + "ERR176 - Failed to add new local variable '" + var_name + "' to SEM", exprtk_error_location)); sem_.free_element(nse); @@ -24841,7 +26134,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR169 - Expected '(' at start of swap statement", + "ERR177 - Expected '(' at start of swap statement", exprtk_error_location)); return error_node(); @@ -24860,7 +26153,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR170 - Expected a symbol for variable or vector element definition", + "ERR178 - Expected a symbol for variable or vector element definition", exprtk_error_location)); return error_node(); @@ -24872,7 +26165,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR171 - First parameter to swap is an invalid vector element: '" + var0_name + "'", + "ERR179 - First parameter to swap is an invalid vector element: '" + var0_name + "'", exprtk_error_location)); return error_node(); @@ -24887,7 +26180,7 @@ namespace exprtk variable0 = symtab_store_.get_variable(var0_name); } - scope_element& se = sem_.get_element(var0_name); + const scope_element& se = sem_.get_element(var0_name); if ( (se.active) && @@ -24905,7 +26198,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR172 - First parameter to swap is an invalid variable: '" + var0_name + "'", + "ERR180 - First parameter to swap is an invalid variable: '" + var0_name + "'", exprtk_error_location)); return error_node(); @@ -24919,7 +26212,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR173 - Expected ',' between parameters to swap", + "ERR181 - Expected ',' between parameters to swap", exprtk_error_location)); if (variable0_generated) @@ -24937,7 +26230,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR174 - Expected a symbol for variable or vector element definition", + "ERR182 - Expected a symbol for variable or vector element definition", exprtk_error_location)); if (variable0_generated) @@ -24954,7 +26247,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR175 - Second parameter to swap is an invalid vector element: '" + var1_name + "'", + "ERR183 - Second parameter to swap is an invalid vector element: '" + var1_name + "'", exprtk_error_location)); if (variable0_generated) @@ -24974,7 +26267,7 @@ namespace exprtk variable1 = symtab_store_.get_variable(var1_name); } - scope_element& se = sem_.get_element(var1_name); + const scope_element& se = sem_.get_element(var1_name); if ( (se.active) && @@ -24992,7 +26285,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR176 - Second parameter to swap is an invalid variable: '" + var1_name + "'", + "ERR184 - Second parameter to swap is an invalid variable: '" + var1_name + "'", exprtk_error_location)); if (variable0_generated) @@ -25011,7 +26304,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR177 - Expected ')' at end of swap statement", + "ERR185 - Expected ')' at end of swap statement", exprtk_error_location)); if (variable0_generated) @@ -25068,7 +26361,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR178 - Return call within a return call is not allowed", + "ERR186 - Return call within a return call is not allowed", exprtk_error_location)); return error_node(); @@ -25092,7 +26385,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR179 - Expected '[' at start of return statement", + "ERR187 - Expected '[' at start of return statement", exprtk_error_location)); return error_node(); @@ -25115,7 +26408,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR180 - Expected ',' between values during call to return", + "ERR188 - Expected ',' between values during call to return", exprtk_error_location)); return error_node(); @@ -25127,7 +26420,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR181 - Zero parameter return statement not allowed", + "ERR189 - Zero parameter return statement not allowed", exprtk_error_location)); return error_node(); @@ -25142,7 +26435,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, prev_token, - "ERR182 - Invalid ']' found during return call", + "ERR190 - Invalid ']' found during return call", exprtk_error_location)); return error_node(); @@ -25195,7 +26488,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR183 - Invalid sequence of variable '"+ symbol + "' and bracket", + "ERR191 - Invalid sequence of variable '"+ symbol + "' and bracket", exprtk_error_location)); return false; @@ -25243,7 +26536,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR184 - Invalid sequence of brackets", + "ERR192 - Invalid sequence of brackets", exprtk_error_location)); return false; @@ -25340,7 +26633,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR185 - Failed to generate node for function: '" + symbol + "'", + "ERR193 - Failed to generate node for function: '" + symbol + "'", exprtk_error_location)); return error_node(); @@ -25366,7 +26659,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR186 - Failed to generate node for vararg function: '" + symbol + "'", + "ERR194 - Failed to generate node for vararg function: '" + symbol + "'", exprtk_error_location)); return error_node(); @@ -25392,7 +26685,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR187 - Failed to generate node for generic function: '" + symbol + "'", + "ERR195 - Failed to generate node for generic function: '" + symbol + "'", exprtk_error_location)); return error_node(); @@ -25419,7 +26712,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR188 - Failed to generate node for string function: '" + symbol + "'", + "ERR196 - Failed to generate node for string function: '" + symbol + "'", exprtk_error_location)); return error_node(); @@ -25445,7 +26738,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR189 - Failed to generate node for overload function: '" + symbol + "'", + "ERR197 - Failed to generate node for overload function: '" + symbol + "'", exprtk_error_location)); return error_node(); @@ -25471,7 +26764,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR190 - Invalid use of reserved symbol '" + symbol + "'", + "ERR198 - Invalid use of reserved symbol '" + symbol + "'", exprtk_error_location)); return error_node(); @@ -25534,7 +26827,7 @@ namespace exprtk set_error( make_error(parser_error::e_symtab, current_token(), - "ERR191 - Failed to create variable: '" + symbol + "'" + + "ERR199 - Failed to create variable: '" + symbol + "'" + (error_message.empty() ? "" : " - " + error_message), exprtk_error_location)); @@ -25554,7 +26847,7 @@ namespace exprtk set_error( make_error(parser_error::e_symtab, current_token(), - "ERR192 - Failed to resolve symbol: '" + symbol + "'" + + "ERR200 - Failed to resolve symbol: '" + symbol + "'" + (error_message.empty() ? "" : " - " + error_message), exprtk_error_location)); } @@ -25566,7 +26859,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR193 - Undefined symbol: '" + symbol + "'", + "ERR201 - Undefined symbol: '" + symbol + "'", exprtk_error_location)); return error_node(); @@ -25585,11 +26878,16 @@ namespace exprtk static const std::string symbol_var = "var" ; static const std::string symbol_swap = "swap" ; static const std::string symbol_return = "return" ; + static const std::string symbol_not = "not" ; if (valid_vararg_operation(current_token().value)) { return parse_vararg_function(); } + else if (details::imatch(current_token().value, symbol_not)) + { + return parse_not_statement(); + } else if (valid_base_operation(current_token().value)) { return parse_base_operation(); @@ -25673,7 +26971,7 @@ namespace exprtk set_error( make_error(parser_error::e_symtab, current_token(), - "ERR194 - Variable or function detected, yet symbol-table is invalid, Symbol: " + current_token().value, + "ERR202 - Variable or function detected, yet symbol-table is invalid, Symbol: " + current_token().value, exprtk_error_location)); return error_node(); @@ -25682,6 +26980,13 @@ namespace exprtk inline expression_node_ptr parse_branch(precedence_level precedence = e_level00) { + stack_limit_handler slh(*this); + + if (!slh) + { + return error_node(); + } + expression_node_ptr branch = error_node(); if (token_t::e_number == current_token().type) @@ -25697,7 +27002,7 @@ namespace exprtk set_error( make_error(parser_error::e_numeric, current_token(), - "ERR195 - Failed generate node for scalar: '" + current_token().value + "'", + "ERR203 - Failed generate node for scalar: '" + current_token().value + "'", exprtk_error_location)); return error_node(); @@ -25711,7 +27016,7 @@ namespace exprtk set_error( make_error(parser_error::e_numeric, current_token(), - "ERR196 - Failed to convert '" + current_token().value + "' to a number", + "ERR204 - Failed to convert '" + current_token().value + "' to a number", exprtk_error_location)); return error_node(); @@ -25738,7 +27043,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR197 - Expected ')' instead of: '" + current_token().value + "'", + "ERR205 - Expected ')' instead of: '" + current_token().value + "'", exprtk_error_location)); free_node(node_allocator_,branch); @@ -25763,7 +27068,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR198 - Expected ']' instead of: '" + current_token().value + "'", + "ERR206 - Expected ']' instead of: '" + current_token().value + "'", exprtk_error_location)); free_node(node_allocator_,branch); @@ -25788,7 +27093,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR199 - Expected '}' instead of: '" + current_token().value + "'", + "ERR207 - Expected '}' instead of: '" + current_token().value + "'", exprtk_error_location)); free_node(node_allocator_,branch); @@ -25815,7 +27120,16 @@ namespace exprtk ) ) { - branch = expression_generator_(details::e_neg,branch); + expression_node_ptr result = expression_generator_(details::e_neg,branch); + + if (0 == result) + { + free_node(node_allocator_,branch); + + return error_node(); + } + else + branch = result; } } else if (token_t::e_add == current_token().type) @@ -25828,7 +27142,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR200 - Premature end of expression[1]", + "ERR208 - Premature end of expression[1]", exprtk_error_location)); return error_node(); @@ -25838,7 +27152,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR201 - Premature end of expression[2]", + "ERR209 - Premature end of expression[2]", exprtk_error_location)); return error_node(); @@ -26540,9 +27854,9 @@ namespace exprtk (details::e_equal == operation) || (details::e_and == operation) || (details::e_nand == operation) || - (details:: e_or == operation) || - (details:: e_nor == operation) || - (details:: e_xor == operation) || + (details::e_or == operation) || + (details::e_nor == operation) || + (details::e_xor == operation) || (details::e_xnor == operation) ); } @@ -26741,8 +28055,8 @@ namespace exprtk { if ((0 == condition) || (0 == consequent)) { - free_node(*node_allocator_, condition); - free_node(*node_allocator_, consequent); + free_node(*node_allocator_, condition ); + free_node(*node_allocator_, consequent ); free_node(*node_allocator_, alternative); return error_node(); @@ -26753,7 +28067,7 @@ namespace exprtk // True branch if (details::is_true(condition)) { - free_node(*node_allocator_, condition); + free_node(*node_allocator_, condition ); free_node(*node_allocator_, alternative); return consequent; @@ -26761,7 +28075,7 @@ namespace exprtk // False branch else { - free_node(*node_allocator_, condition); + free_node(*node_allocator_, condition ); free_node(*node_allocator_, consequent); if (alternative) @@ -26787,8 +28101,8 @@ namespace exprtk { if ((0 == condition) || (0 == consequent)) { - free_node(*node_allocator_, condition); - free_node(*node_allocator_, consequent); + free_node(*node_allocator_, condition ); + free_node(*node_allocator_, consequent ); free_node(*node_allocator_, alternative); return error_node(); @@ -26799,7 +28113,7 @@ namespace exprtk // True branch if (details::is_true(condition)) { - free_node(*node_allocator_, condition); + free_node(*node_allocator_, condition ); free_node(*node_allocator_, alternative); return consequent; @@ -26807,7 +28121,7 @@ namespace exprtk // False branch else { - free_node(*node_allocator_, condition); + free_node(*node_allocator_, condition ); free_node(*node_allocator_, consequent); if (alternative) @@ -26832,6 +28146,64 @@ namespace exprtk } #endif + inline expression_node_ptr conditional_vector(expression_node_ptr condition, + expression_node_ptr consequent, + expression_node_ptr alternative) const + { + if ((0 == condition) || (0 == consequent)) + { + free_node(*node_allocator_, condition ); + free_node(*node_allocator_, consequent ); + free_node(*node_allocator_, alternative); + + return error_node(); + } + // Can the condition be immediately evaluated? if so optimise. + else if (details::is_constant_node(condition)) + { + // True branch + if (details::is_true(condition)) + { + free_node(*node_allocator_, condition ); + free_node(*node_allocator_, alternative); + + return consequent; + } + // False branch + else + { + free_node(*node_allocator_, condition ); + free_node(*node_allocator_, consequent); + + if (alternative) + return alternative; + else + return node_allocator_->allocate >(); + + } + } + else if ((0 != consequent) && (0 != alternative)) + { + return node_allocator_-> + allocate(condition, consequent, alternative); + } + else + return error_node(); + } + + inline loop_runtime_check_ptr get_loop_runtime_check(const loop_runtime_check::loop_types loop_type) const + { + if ( + parser_->loop_runtime_check_ && + (loop_type == (parser_->loop_runtime_check_->loop_set & loop_type)) + ) + { + return parser_->loop_runtime_check_; + } + + return loop_runtime_check_ptr(0); + } + inline expression_node_ptr while_loop(expression_node_ptr& condition, expression_node_ptr& branch, const bool brkcont = false) const @@ -26846,7 +28218,7 @@ namespace exprtk result = node_allocator_->allocate >(); free_node(*node_allocator_, condition); - free_node(*node_allocator_, branch); + free_node(*node_allocator_, branch ); return result; } @@ -26857,10 +28229,20 @@ namespace exprtk return branch; } else if (!brkcont) - return node_allocator_->allocate(condition,branch); + return node_allocator_->allocate + ( + condition, + branch, + get_loop_runtime_check(loop_runtime_check::e_while_loop) + ); #ifndef exprtk_disable_break_continue else - return node_allocator_->allocate(condition,branch); + return node_allocator_->allocate + ( + condition, + branch, + get_loop_runtime_check(loop_runtime_check::e_while_loop) + ); #else return error_node(); #endif @@ -26883,7 +28265,7 @@ namespace exprtk } free_node(*node_allocator_, condition); - free_node(*node_allocator_, branch); + free_node(*node_allocator_, branch ); return error_node(); } @@ -26894,10 +28276,20 @@ namespace exprtk return branch; } else if (!brkcont) - return node_allocator_->allocate(condition,branch); + return node_allocator_->allocate + ( + condition, + branch, + get_loop_runtime_check(loop_runtime_check::e_repeat_until_loop) + ); #ifndef exprtk_disable_break_continue else - return node_allocator_->allocate(condition,branch); + return node_allocator_->allocate + ( + condition, + branch, + get_loop_runtime_check(loop_runtime_check::e_repeat_until_loop) + ); #else return error_node(); #endif @@ -26920,16 +28312,16 @@ namespace exprtk result = node_allocator_->allocate >(); free_node(*node_allocator_, initialiser); - free_node(*node_allocator_, condition); + free_node(*node_allocator_, condition ); free_node(*node_allocator_, incrementor); - free_node(*node_allocator_, loop_body); + free_node(*node_allocator_, loop_body ); return result; } else if (details::is_null_node(condition) || (0 == condition)) { free_node(*node_allocator_, initialiser); - free_node(*node_allocator_, condition); + free_node(*node_allocator_, condition ); free_node(*node_allocator_, incrementor); return loop_body; @@ -26940,7 +28332,8 @@ namespace exprtk initialiser, condition, incrementor, - loop_body + loop_body, + get_loop_runtime_check(loop_runtime_check::e_for_loop) ); #ifndef exprtk_disable_break_continue @@ -26950,7 +28343,8 @@ namespace exprtk initialiser, condition, incrementor, - loop_body + loop_body, + get_loop_runtime_check(loop_runtime_check::e_for_loop) ); #else return error_node(); @@ -27031,54 +28425,62 @@ namespace exprtk struct switch_nodes { - typedef std::vector arg_list_t; + typedef std::vector > arg_list_t; - #define case_stmt(N) \ - if (is_true(arg[(2 * N)])) { return arg[(2 * N) + 1]->value(); } \ + #define case_stmt(N) \ + if (is_true(arg[(2 * N)].first)) { return arg[(2 * N) + 1].first->value(); } \ - struct switch_1 + struct switch_impl_1 { static inline T process(const arg_list_t& arg) { case_stmt(0) - return arg.back()->value(); + assert(arg.size() == ((2 * 1) + 1)); + + return arg.back().first->value(); } }; - struct switch_2 + struct switch_impl_2 { static inline T process(const arg_list_t& arg) { case_stmt(0) case_stmt(1) - return arg.back()->value(); + assert(arg.size() == ((2 * 2) + 1)); + + return arg.back().first->value(); } }; - struct switch_3 + struct switch_impl_3 { static inline T process(const arg_list_t& arg) { case_stmt(0) case_stmt(1) case_stmt(2) - return arg.back()->value(); + assert(arg.size() == ((2 * 3) + 1)); + + return arg.back().first->value(); } }; - struct switch_4 + struct switch_impl_4 { static inline T process(const arg_list_t& arg) { case_stmt(0) case_stmt(1) case_stmt(2) case_stmt(3) - return arg.back()->value(); + assert(arg.size() == ((2 * 4) + 1)); + + return arg.back().first->value(); } }; - struct switch_5 + struct switch_impl_5 { static inline T process(const arg_list_t& arg) { @@ -27086,11 +28488,13 @@ namespace exprtk case_stmt(2) case_stmt(3) case_stmt(4) - return arg.back()->value(); + assert(arg.size() == ((2 * 5) + 1)); + + return arg.back().first->value(); } }; - struct switch_6 + struct switch_impl_6 { static inline T process(const arg_list_t& arg) { @@ -27098,11 +28502,13 @@ namespace exprtk case_stmt(2) case_stmt(3) case_stmt(4) case_stmt(5) - return arg.back()->value(); + assert(arg.size() == ((2 * 6) + 1)); + + return arg.back().first->value(); } }; - struct switch_7 + struct switch_impl_7 { static inline T process(const arg_list_t& arg) { @@ -27111,7 +28517,9 @@ namespace exprtk case_stmt(4) case_stmt(5) case_stmt(6) - return arg.back()->value(); + assert(arg.size() == ((2 * 7) + 1)); + + return arg.back().first->value(); } }; @@ -27120,14 +28528,13 @@ namespace exprtk template class Sequence> - inline expression_node_ptr switch_statement(Sequence& arg_list) + inline expression_node_ptr switch_statement(Sequence& arg_list, const bool default_statement_present) { if (arg_list.empty()) return error_node(); else if ( - !all_nodes_valid(arg_list) || - (arg_list.size() < 3) || - ((arg_list.size() % 2) != 1) + !all_nodes_valid(arg_list) || + (!default_statement_present && (arg_list.size() < 2)) ) { details::free_all_nodes(*node_allocator_,arg_list); @@ -27139,11 +28546,11 @@ namespace exprtk switch ((arg_list.size() - 1) / 2) { - #define case_stmt(N) \ - case N : \ - return node_allocator_-> \ - allocate >(arg_list); \ + #define case_stmt(N) \ + case N : \ + return node_allocator_-> \ + allocate >(arg_list); \ case_stmt(1) case_stmt(2) @@ -27174,47 +28581,47 @@ namespace exprtk return node_allocator_->allocate >(arg_list); } - #define unary_opr_switch_statements \ - case_stmt(details:: e_abs, details:: abs_op) \ - case_stmt(details:: e_acos, details:: acos_op) \ - case_stmt(details::e_acosh, details::acosh_op) \ - case_stmt(details:: e_asin, details:: asin_op) \ - case_stmt(details::e_asinh, details::asinh_op) \ - case_stmt(details:: e_atan, details:: atan_op) \ - case_stmt(details::e_atanh, details::atanh_op) \ - case_stmt(details:: e_ceil, details:: ceil_op) \ - case_stmt(details:: e_cos, details:: cos_op) \ - case_stmt(details:: e_cosh, details:: cosh_op) \ - case_stmt(details:: e_exp, details:: exp_op) \ - case_stmt(details::e_expm1, details::expm1_op) \ - case_stmt(details::e_floor, details::floor_op) \ - case_stmt(details:: e_log, details:: log_op) \ - case_stmt(details::e_log10, details::log10_op) \ - case_stmt(details:: e_log2, details:: log2_op) \ - case_stmt(details::e_log1p, details::log1p_op) \ - case_stmt(details:: e_neg, details:: neg_op) \ - case_stmt(details:: e_pos, details:: pos_op) \ - case_stmt(details::e_round, details::round_op) \ - case_stmt(details:: e_sin, details:: sin_op) \ - case_stmt(details:: e_sinc, details:: sinc_op) \ - case_stmt(details:: e_sinh, details:: sinh_op) \ - case_stmt(details:: e_sqrt, details:: sqrt_op) \ - case_stmt(details:: e_tan, details:: tan_op) \ - case_stmt(details:: e_tanh, details:: tanh_op) \ - case_stmt(details:: e_cot, details:: cot_op) \ - case_stmt(details:: e_sec, details:: sec_op) \ - case_stmt(details:: e_csc, details:: csc_op) \ - case_stmt(details:: e_r2d, details:: r2d_op) \ - case_stmt(details:: e_d2r, details:: d2r_op) \ - case_stmt(details:: e_d2g, details:: d2g_op) \ - case_stmt(details:: e_g2d, details:: g2d_op) \ - case_stmt(details:: e_notl, details:: notl_op) \ - case_stmt(details:: e_sgn, details:: sgn_op) \ - case_stmt(details:: e_erf, details:: erf_op) \ - case_stmt(details:: e_erfc, details:: erfc_op) \ - case_stmt(details:: e_ncdf, details:: ncdf_op) \ - case_stmt(details:: e_frac, details:: frac_op) \ - case_stmt(details::e_trunc, details::trunc_op) \ + #define unary_opr_switch_statements \ + case_stmt(details::e_abs , details::abs_op ) \ + case_stmt(details::e_acos , details::acos_op ) \ + case_stmt(details::e_acosh , details::acosh_op) \ + case_stmt(details::e_asin , details::asin_op ) \ + case_stmt(details::e_asinh , details::asinh_op) \ + case_stmt(details::e_atan , details::atan_op ) \ + case_stmt(details::e_atanh , details::atanh_op) \ + case_stmt(details::e_ceil , details::ceil_op ) \ + case_stmt(details::e_cos , details::cos_op ) \ + case_stmt(details::e_cosh , details::cosh_op ) \ + case_stmt(details::e_exp , details::exp_op ) \ + case_stmt(details::e_expm1 , details::expm1_op) \ + case_stmt(details::e_floor , details::floor_op) \ + case_stmt(details::e_log , details::log_op ) \ + case_stmt(details::e_log10 , details::log10_op) \ + case_stmt(details::e_log2 , details::log2_op ) \ + case_stmt(details::e_log1p , details::log1p_op) \ + case_stmt(details::e_neg , details::neg_op ) \ + case_stmt(details::e_pos , details::pos_op ) \ + case_stmt(details::e_round , details::round_op) \ + case_stmt(details::e_sin , details::sin_op ) \ + case_stmt(details::e_sinc , details::sinc_op ) \ + case_stmt(details::e_sinh , details::sinh_op ) \ + case_stmt(details::e_sqrt , details::sqrt_op ) \ + case_stmt(details::e_tan , details::tan_op ) \ + case_stmt(details::e_tanh , details::tanh_op ) \ + case_stmt(details::e_cot , details::cot_op ) \ + case_stmt(details::e_sec , details::sec_op ) \ + case_stmt(details::e_csc , details::csc_op ) \ + case_stmt(details::e_r2d , details::r2d_op ) \ + case_stmt(details::e_d2r , details::d2r_op ) \ + case_stmt(details::e_d2g , details::d2g_op ) \ + case_stmt(details::e_g2d , details::g2d_op ) \ + case_stmt(details::e_notl , details::notl_op ) \ + case_stmt(details::e_sgn , details::sgn_op ) \ + case_stmt(details::e_erf , details::erf_op ) \ + case_stmt(details::e_erfc , details::erfc_op ) \ + case_stmt(details::e_ncdf , details::ncdf_op ) \ + case_stmt(details::e_frac , details::frac_op ) \ + case_stmt(details::e_trunc , details::trunc_op) \ inline expression_node_ptr synthesize_uv_expression(const details::operator_type& operation, expression_node_ptr (&branch)[1]) @@ -27624,24 +29031,31 @@ namespace exprtk if (details::is_constant_node(result)) return result; else if (!all_nodes_valid(b)) + { + details::free_node(*node_allocator_,result); + std::fill_n(b, N, reinterpret_cast(0)); + return error_node(); + } else if (N != f->param_count) { - details::free_all_nodes(*node_allocator_,b); + details::free_node(*node_allocator_,result); + std::fill_n(b, N, reinterpret_cast(0)); return error_node(); } - function_N_node_t* func_node_ptr = static_cast(result); + function_N_node_t* func_node_ptr = reinterpret_cast(result); - if (func_node_ptr->init_branches(b)) - return result; - else + if (!func_node_ptr->init_branches(b)) { - details::free_all_nodes(*node_allocator_,b); + details::free_node(*node_allocator_,result); + std::fill_n(b, N, reinterpret_cast(0)); return error_node(); } + + return result; } } @@ -27865,7 +29279,7 @@ namespace exprtk return node_allocator_->allocate(i,vector_base); } - scope_element& se = parser_->sem_.get_element(symbol,i); + const scope_element& se = parser_->sem_.get_element(symbol,i); if (se.index == i) { @@ -28060,11 +29474,11 @@ namespace exprtk template allocate_rrr > > \ (operation, branch[0], branch[1]); \ - case_stmt(details::e_addass,details::add_op) - case_stmt(details::e_subass,details::sub_op) - case_stmt(details::e_mulass,details::mul_op) - case_stmt(details::e_divass,details::div_op) - case_stmt(details::e_modass,details::mod_op) + case_stmt(details::e_addass , details::add_op) + case_stmt(details::e_subass , details::sub_op) + case_stmt(details::e_mulass , details::mul_op) + case_stmt(details::e_divass , details::div_op) + case_stmt(details::e_modass , details::mod_op) #undef case_stmt default : return error_node(); } @@ -28080,11 +29494,11 @@ namespace exprtk template allocate_rrr > > \ (operation, branch[0], branch[1]); \ - case_stmt(details::e_addass,details::add_op) - case_stmt(details::e_subass,details::sub_op) - case_stmt(details::e_mulass,details::mul_op) - case_stmt(details::e_divass,details::div_op) - case_stmt(details::e_modass,details::mod_op) + case_stmt(details::e_addass , details::add_op) + case_stmt(details::e_subass , details::sub_op) + case_stmt(details::e_mulass , details::mul_op) + case_stmt(details::e_divass , details::div_op) + case_stmt(details::e_modass , details::mod_op) #undef case_stmt default : return error_node(); } @@ -28100,11 +29514,11 @@ namespace exprtk template allocate_rrr > > \ (operation, branch[0], branch[1]); \ - case_stmt(details::e_addass,details::add_op) - case_stmt(details::e_subass,details::sub_op) - case_stmt(details::e_mulass,details::mul_op) - case_stmt(details::e_divass,details::div_op) - case_stmt(details::e_modass,details::mod_op) + case_stmt(details::e_addass , details::add_op) + case_stmt(details::e_subass , details::sub_op) + case_stmt(details::e_mulass , details::mul_op) + case_stmt(details::e_divass , details::div_op) + case_stmt(details::e_modass , details::mod_op) #undef case_stmt default : return error_node(); } @@ -28120,11 +29534,11 @@ namespace exprtk template allocate_rrr > > \ (operation, branch[0], branch[1]); \ - case_stmt(details::e_addass,details::add_op) - case_stmt(details::e_subass,details::sub_op) - case_stmt(details::e_mulass,details::mul_op) - case_stmt(details::e_divass,details::div_op) - case_stmt(details::e_modass,details::mod_op) + case_stmt(details::e_addass , details::add_op) + case_stmt(details::e_subass , details::sub_op) + case_stmt(details::e_mulass , details::mul_op) + case_stmt(details::e_divass , details::div_op) + case_stmt(details::e_modass , details::mod_op) #undef case_stmt default : return error_node(); } @@ -28142,11 +29556,11 @@ namespace exprtk template allocate_rrr > > \ (operation, branch[0], branch[1]); \ - case_stmt(details::e_addass,details::add_op) - case_stmt(details::e_subass,details::sub_op) - case_stmt(details::e_mulass,details::mul_op) - case_stmt(details::e_divass,details::div_op) - case_stmt(details::e_modass,details::mod_op) + case_stmt(details::e_addass , details::add_op) + case_stmt(details::e_subass , details::sub_op) + case_stmt(details::e_mulass , details::mul_op) + case_stmt(details::e_divass , details::div_op) + case_stmt(details::e_modass , details::mod_op) #undef case_stmt default : return error_node(); } @@ -28160,11 +29574,11 @@ namespace exprtk template allocate_rrr > > \ (operation, branch[0], branch[1]); \ - case_stmt(details::e_addass,details::add_op) - case_stmt(details::e_subass,details::sub_op) - case_stmt(details::e_mulass,details::mul_op) - case_stmt(details::e_divass,details::div_op) - case_stmt(details::e_modass,details::mod_op) + case_stmt(details::e_addass , details::add_op) + case_stmt(details::e_subass , details::sub_op) + case_stmt(details::e_mulass , details::mul_op) + case_stmt(details::e_divass , details::div_op) + case_stmt(details::e_modass , details::mod_op) #undef case_stmt default : return error_node(); } @@ -28197,20 +29611,20 @@ namespace exprtk const bool is_b0_ivec = details::is_ivector_node(branch[0]); const bool is_b1_ivec = details::is_ivector_node(branch[1]); - #define batch_eqineq_logic_case \ - case_stmt(details:: e_lt, details:: lt_op) \ - case_stmt(details:: e_lte, details:: lte_op) \ - case_stmt(details:: e_gt, details:: gt_op) \ - case_stmt(details:: e_gte, details:: gte_op) \ - case_stmt(details:: e_eq, details:: eq_op) \ - case_stmt(details:: e_ne, details:: ne_op) \ - case_stmt(details::e_equal, details::equal_op) \ - case_stmt(details:: e_and, details:: and_op) \ - case_stmt(details:: e_nand, details:: nand_op) \ - case_stmt(details:: e_or, details:: or_op) \ - case_stmt(details:: e_nor, details:: nor_op) \ - case_stmt(details:: e_xor, details:: xor_op) \ - case_stmt(details:: e_xnor, details:: xnor_op) \ + #define batch_eqineq_logic_case \ + case_stmt(details::e_lt , details::lt_op ) \ + case_stmt(details::e_lte , details::lte_op ) \ + case_stmt(details::e_gt , details::gt_op ) \ + case_stmt(details::e_gte , details::gte_op ) \ + case_stmt(details::e_eq , details::eq_op ) \ + case_stmt(details::e_ne , details::ne_op ) \ + case_stmt(details::e_equal , details::equal_op) \ + case_stmt(details::e_and , details::and_op ) \ + case_stmt(details::e_nand , details::nand_op ) \ + case_stmt(details::e_or , details::or_op ) \ + case_stmt(details::e_nor , details::nor_op ) \ + case_stmt(details::e_xor , details::xor_op ) \ + case_stmt(details::e_xnor , details::xnor_op ) \ if (is_b0_ivec && is_b1_ivec) { @@ -28266,12 +29680,12 @@ namespace exprtk const bool is_b0_ivec = details::is_ivector_node(branch[0]); const bool is_b1_ivec = details::is_ivector_node(branch[1]); - #define vector_ops \ - case_stmt(details::e_add,details::add_op) \ - case_stmt(details::e_sub,details::sub_op) \ - case_stmt(details::e_mul,details::mul_op) \ - case_stmt(details::e_div,details::div_op) \ - case_stmt(details::e_mod,details::mod_op) \ + #define vector_ops \ + case_stmt(details::e_add , details::add_op) \ + case_stmt(details::e_sub , details::sub_op) \ + case_stmt(details::e_mul , details::mul_op) \ + case_stmt(details::e_div , details::div_op) \ + case_stmt(details::e_mod , details::mod_op) \ if (is_b0_ivec && is_b1_ivec) { @@ -28440,27 +29854,27 @@ namespace exprtk } #endif - #define basic_opr_switch_statements \ - case_stmt(details::e_add, details::add_op) \ - case_stmt(details::e_sub, details::sub_op) \ - case_stmt(details::e_mul, details::mul_op) \ - case_stmt(details::e_div, details::div_op) \ - case_stmt(details::e_mod, details::mod_op) \ - case_stmt(details::e_pow, details::pow_op) \ - - #define extended_opr_switch_statements \ - case_stmt(details:: e_lt, details:: lt_op) \ - case_stmt(details:: e_lte, details:: lte_op) \ - case_stmt(details:: e_gt, details:: gt_op) \ - case_stmt(details:: e_gte, details:: gte_op) \ - case_stmt(details:: e_eq, details:: eq_op) \ - case_stmt(details:: e_ne, details:: ne_op) \ - case_stmt(details:: e_and, details:: and_op) \ - case_stmt(details::e_nand, details::nand_op) \ - case_stmt(details:: e_or, details:: or_op) \ - case_stmt(details:: e_nor, details:: nor_op) \ - case_stmt(details:: e_xor, details:: xor_op) \ - case_stmt(details::e_xnor, details::xnor_op) \ + #define basic_opr_switch_statements \ + case_stmt(details::e_add , details::add_op) \ + case_stmt(details::e_sub , details::sub_op) \ + case_stmt(details::e_mul , details::mul_op) \ + case_stmt(details::e_div , details::div_op) \ + case_stmt(details::e_mod , details::mod_op) \ + case_stmt(details::e_pow , details::pow_op) \ + + #define extended_opr_switch_statements \ + case_stmt(details::e_lt , details::lt_op ) \ + case_stmt(details::e_lte , details::lte_op ) \ + case_stmt(details::e_gt , details::gt_op ) \ + case_stmt(details::e_gte , details::gte_op ) \ + case_stmt(details::e_eq , details::eq_op ) \ + case_stmt(details::e_ne , details::ne_op ) \ + case_stmt(details::e_and , details::and_op ) \ + case_stmt(details::e_nand , details::nand_op) \ + case_stmt(details::e_or , details::or_op ) \ + case_stmt(details::e_nor , details::nor_op ) \ + case_stmt(details::e_xor , details::xor_op ) \ + case_stmt(details::e_xnor , details::xnor_op) \ #ifndef exprtk_disable_cardinal_pow_optimisation template class IPowNode> @@ -28717,8 +30131,9 @@ namespace exprtk { expression_node_ptr result = error_node(); - const bool synthesis_result = synthesize_sf4ext_expression::template compile_right - (expr_gen, v, operation, branch[1], result); + const bool synthesis_result = + synthesize_sf4ext_expression::template compile_right + (expr_gen, v, operation, branch[1], result); if (synthesis_result) { @@ -28791,8 +30206,9 @@ namespace exprtk { expression_node_ptr result = error_node(); - const bool synthesis_result = synthesize_sf4ext_expression::template compile_left - (expr_gen, v, operation, branch[0], result); + const bool synthesis_result = + synthesize_sf4ext_expression::template compile_left + (expr_gen, v, operation, branch[0], result); if (synthesis_result) { @@ -28896,8 +30312,8 @@ namespace exprtk // 1. (1 * (2 * (3 * (4 * (5 * (6 * (7 * (8 * (9 + x))))))))) --> 40320 * (9 + x) // 2. (1 + (2 + (3 + (4 + (5 + (6 + (7 + (8 + (9 + x))))))))) --> 45 + x if ( - (operation == details::e_mul) || - (operation == details::e_add) + (details::e_mul == operation) || + (details::e_add == operation) ) { details::cob_base_node* cobnode = static_cast*>(branch[1]); @@ -28973,7 +30389,11 @@ namespace exprtk { expression_node_ptr result = error_node(); - if (synthesize_sf4ext_expression::template compile_right(expr_gen,c,operation,branch[1],result)) + const bool synthesis_result = + synthesize_sf4ext_expression::template compile_right + (expr_gen, c, operation, branch[1], result); + + if (synthesis_result) { free_node(*expr_gen.node_allocator_,branch[1]); @@ -29030,8 +30450,8 @@ namespace exprtk // 1. (((((((((x + 9) * 8) * 7) * 6) * 5) * 4) * 3) * 2) * 1) --> (x + 9) * 40320 // 2. (((((((((x + 9) + 8) + 7) + 6) + 5) + 4) + 3) + 2) + 1) --> x + 45 if ( - (operation == details::e_mul) || - (operation == details::e_add) + (details::e_mul == operation) || + (details::e_add == operation) ) { details::boc_base_node* bocnode = static_cast*>(branch[0]); @@ -29088,8 +30508,9 @@ namespace exprtk { expression_node_ptr result = error_node(); - const bool synthesis_result = synthesize_sf4ext_expression::template compile_left - (expr_gen, c, operation, branch[0], result); + const bool synthesis_result = + synthesize_sf4ext_expression::template compile_left + (expr_gen, c, operation, branch[0], result); if (synthesis_result) { @@ -29860,9 +31281,6 @@ namespace exprtk const details::operator_type o0 = vov->operation(); const details::operator_type o1 = operation; - binary_functor_t f0 = reinterpret_cast(0); - binary_functor_t f1 = reinterpret_cast(0); - details::free_node(*(expr_gen.node_allocator_),branch[0]); expression_node_ptr result = error_node(); @@ -29874,7 +31292,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "t/(t*t)", v0, v1, v2, result); + template compile(expr_gen, "t/(t*t)", v0, v1, v2, result); exprtk_debug(("(v0 / v1) / v2 --> (vovov) v0 / (v1 * v2)\n")); @@ -29888,7 +31306,11 @@ namespace exprtk if (synthesis_result) return result; - else if (!expr_gen.valid_operator(o0,f0)) + + binary_functor_t f0 = reinterpret_cast(0); + binary_functor_t f1 = reinterpret_cast(0); + + if (!expr_gen.valid_operator(o0,f0)) return error_node(); else if (!expr_gen.valid_operator(o1,f1)) return error_node(); @@ -29897,7 +31319,8 @@ namespace exprtk } static inline std::string id(expression_generator& expr_gen, - const details::operator_type o0, const details::operator_type o1) + const details::operator_type o0, + const details::operator_type o1) { return details::build_string() << "(t" << expr_gen.to_str(o0) @@ -29923,9 +31346,6 @@ namespace exprtk const details::operator_type o0 = operation; const details::operator_type o1 = vov->operation(); - binary_functor_t f0 = reinterpret_cast(0); - binary_functor_t f1 = reinterpret_cast(0); - details::free_node(*(expr_gen.node_allocator_),branch[1]); expression_node_ptr result = error_node(); @@ -29937,7 +31357,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t*t)/t", v0, v2, v1, result); + template compile(expr_gen, "(t*t)/t", v0, v2, v1, result); exprtk_debug(("v0 / (v1 / v2) --> (vovov) (v0 * v2) / v1\n")); @@ -29951,7 +31371,11 @@ namespace exprtk if (synthesis_result) return result; - else if (!expr_gen.valid_operator(o0,f0)) + + binary_functor_t f0 = reinterpret_cast(0); + binary_functor_t f1 = reinterpret_cast(0); + + if (!expr_gen.valid_operator(o0,f0)) return error_node(); else if (!expr_gen.valid_operator(o1,f1)) return error_node(); @@ -29960,7 +31384,8 @@ namespace exprtk } static inline std::string id(expression_generator& expr_gen, - const details::operator_type o0, const details::operator_type o1) + const details::operator_type o0, + const details::operator_type o1) { return details::build_string() << "t" << expr_gen.to_str(o0) @@ -29986,9 +31411,6 @@ namespace exprtk const details::operator_type o0 = vov->operation(); const details::operator_type o1 = operation; - binary_functor_t f0 = reinterpret_cast(0); - binary_functor_t f1 = reinterpret_cast(0); - details::free_node(*(expr_gen.node_allocator_),branch[0]); details::free_node(*(expr_gen.node_allocator_),branch[1]); @@ -30001,7 +31423,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "t/(t*t)", v0, v1, c, result); + template compile(expr_gen, "t/(t*t)", v0, v1, c, result); exprtk_debug(("(v0 / v1) / c --> (vovoc) v0 / (v1 * c)\n")); @@ -30015,7 +31437,11 @@ namespace exprtk if (synthesis_result) return result; - else if (!expr_gen.valid_operator(o0,f0)) + + binary_functor_t f0 = reinterpret_cast(0); + binary_functor_t f1 = reinterpret_cast(0); + + if (!expr_gen.valid_operator(o0,f0)) return error_node(); else if (!expr_gen.valid_operator(o1,f1)) return error_node(); @@ -30024,7 +31450,8 @@ namespace exprtk } static inline std::string id(expression_generator& expr_gen, - const details::operator_type o0, const details::operator_type o1) + const details::operator_type o0, + const details::operator_type o1) { return details::build_string() << "(t" << expr_gen.to_str(o0) @@ -30050,9 +31477,6 @@ namespace exprtk const details::operator_type o0 = operation; const details::operator_type o1 = voc->operation(); - binary_functor_t f0 = reinterpret_cast(0); - binary_functor_t f1 = reinterpret_cast(0); - details::free_node(*(expr_gen.node_allocator_),branch[1]); expression_node_ptr result = error_node(); @@ -30064,7 +31488,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t*t)/t", v0, c, v1, result); + template compile(expr_gen, "(t*t)/t", v0, c, v1, result); exprtk_debug(("v0 / (v1 / c) --> (vocov) (v0 * c) / v1\n")); @@ -30078,7 +31502,11 @@ namespace exprtk if (synthesis_result) return result; - else if (!expr_gen.valid_operator(o0,f0)) + + binary_functor_t f0 = reinterpret_cast(0); + binary_functor_t f1 = reinterpret_cast(0); + + if (!expr_gen.valid_operator(o0,f0)) return error_node(); else if (!expr_gen.valid_operator(o1,f1)) return error_node(); @@ -30087,7 +31515,8 @@ namespace exprtk } static inline std::string id(expression_generator& expr_gen, - const details::operator_type o0, const details::operator_type o1) + const details::operator_type o0, + const details::operator_type o1) { return details::build_string() << "t" << expr_gen.to_str(o0) @@ -30113,9 +31542,6 @@ namespace exprtk const details::operator_type o0 = voc->operation(); const details::operator_type o1 = operation; - binary_functor_t f0 = reinterpret_cast(0); - binary_functor_t f1 = reinterpret_cast(0); - details::free_node(*(expr_gen.node_allocator_),branch[0]); expression_node_ptr result = error_node(); @@ -30127,7 +31553,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "t/(t*t)", v0, v1, c, result); + template compile(expr_gen, "t/(t*t)", v0, v1, c, result); exprtk_debug(("(v0 / c) / v1 --> (vovoc) v0 / (v1 * c)\n")); @@ -30141,7 +31567,11 @@ namespace exprtk if (synthesis_result) return result; - else if (!expr_gen.valid_operator(o0,f0)) + + binary_functor_t f0 = reinterpret_cast(0); + binary_functor_t f1 = reinterpret_cast(0); + + if (!expr_gen.valid_operator(o0,f0)) return error_node(); else if (!expr_gen.valid_operator(o1,f1)) return error_node(); @@ -30150,7 +31580,8 @@ namespace exprtk } static inline std::string id(expression_generator& expr_gen, - const details::operator_type o0, const details::operator_type o1) + const details::operator_type o0, + const details::operator_type o1) { return details::build_string() << "(t" << expr_gen.to_str(o0) @@ -30176,9 +31607,6 @@ namespace exprtk const details::operator_type o0 = operation; const details::operator_type o1 = cov->operation(); - binary_functor_t f0 = reinterpret_cast(0); - binary_functor_t f1 = reinterpret_cast(0); - details::free_node(*(expr_gen.node_allocator_),branch[1]); expression_node_ptr result = error_node(); @@ -30204,7 +31632,11 @@ namespace exprtk if (synthesis_result) return result; - else if (!expr_gen.valid_operator(o0,f0)) + + binary_functor_t f0 = reinterpret_cast(0); + binary_functor_t f1 = reinterpret_cast(0); + + if (!expr_gen.valid_operator(o0,f0)) return error_node(); else if (!expr_gen.valid_operator(o1,f1)) return error_node(); @@ -30213,7 +31645,8 @@ namespace exprtk } static inline std::string id(expression_generator& expr_gen, - const details::operator_type o0, const details::operator_type o1) + const details::operator_type o0, + const details::operator_type o1) { return details::build_string() << "t" << expr_gen.to_str(o0) @@ -30239,9 +31672,6 @@ namespace exprtk const details::operator_type o0 = cov->operation(); const details::operator_type o1 = operation; - binary_functor_t f0 = reinterpret_cast(0); - binary_functor_t f1 = reinterpret_cast(0); - details::free_node(*(expr_gen.node_allocator_),branch[0]); expression_node_ptr result = error_node(); @@ -30267,7 +31697,11 @@ namespace exprtk if (synthesis_result) return result; - else if (!expr_gen.valid_operator(o0,f0)) + + binary_functor_t f0 = reinterpret_cast(0); + binary_functor_t f1 = reinterpret_cast(0); + + if (!expr_gen.valid_operator(o0,f0)) return error_node(); else if (!expr_gen.valid_operator(o1,f1)) return error_node(); @@ -30276,7 +31710,8 @@ namespace exprtk } static inline std::string id(expression_generator& expr_gen, - const details::operator_type o0, const details::operator_type o1) + const details::operator_type o0, + const details::operator_type o1) { return details::build_string() << "(t" << expr_gen.to_str(o0) @@ -30302,9 +31737,6 @@ namespace exprtk const details::operator_type o0 = operation; const details::operator_type o1 = vov->operation(); - binary_functor_t f0 = reinterpret_cast(0); - binary_functor_t f1 = reinterpret_cast(0); - details::free_node(*(expr_gen.node_allocator_),branch[0]); details::free_node(*(expr_gen.node_allocator_),branch[1]); @@ -30331,7 +31763,11 @@ namespace exprtk if (synthesis_result) return result; - else if (!expr_gen.valid_operator(o0,f0)) + + binary_functor_t f0 = reinterpret_cast(0); + binary_functor_t f1 = reinterpret_cast(0); + + if (!expr_gen.valid_operator(o0,f0)) return error_node(); else if (!expr_gen.valid_operator(o1,f1)) return error_node(); @@ -30339,7 +31775,9 @@ namespace exprtk return node_type::allocate(*(expr_gen.node_allocator_), c, v0, v1, f0, f1); } - static inline std::string id(expression_generator& expr_gen, const details::operator_type o0, const details::operator_type o1) + static inline std::string id(expression_generator& expr_gen, + const details::operator_type o0, + const details::operator_type o1) { return details::build_string() << "t" << expr_gen.to_str(o0) @@ -30365,9 +31803,6 @@ namespace exprtk const details::operator_type o0 = cov->operation(); const details::operator_type o1 = operation; - binary_functor_t f0 = reinterpret_cast(0); - binary_functor_t f1 = reinterpret_cast(0); - details::free_node(*(expr_gen.node_allocator_),branch[0]); details::free_node(*(expr_gen.node_allocator_),branch[1]); @@ -30447,7 +31882,11 @@ namespace exprtk if (synthesis_result) return result; - else if (!expr_gen.valid_operator(o0,f0)) + + binary_functor_t f0 = reinterpret_cast(0); + binary_functor_t f1 = reinterpret_cast(0); + + if (!expr_gen.valid_operator(o0,f0)) return error_node(); else if (!expr_gen.valid_operator(o1,f1)) return error_node(); @@ -30456,7 +31895,8 @@ namespace exprtk } static inline std::string id(expression_generator& expr_gen, - const details::operator_type o0, const details::operator_type o1) + const details::operator_type o0, + const details::operator_type o1) { return details::build_string() << "(t" << expr_gen.to_str(o0) @@ -30482,9 +31922,6 @@ namespace exprtk const details::operator_type o0 = operation; const details::operator_type o1 = voc->operation(); - binary_functor_t f0 = reinterpret_cast(0); - binary_functor_t f1 = reinterpret_cast(0); - details::free_node(*(expr_gen.node_allocator_),branch[0]); details::free_node(*(expr_gen.node_allocator_),branch[1]); @@ -30564,7 +32001,11 @@ namespace exprtk if (synthesis_result) return result; - else if (!expr_gen.valid_operator(o0,f0)) + + binary_functor_t f0 = reinterpret_cast(0); + binary_functor_t f1 = reinterpret_cast(0); + + if (!expr_gen.valid_operator(o0,f0)) return error_node(); else if (!expr_gen.valid_operator(o1,f1)) return error_node(); @@ -30573,7 +32014,8 @@ namespace exprtk } static inline std::string id(expression_generator& expr_gen, - const details::operator_type o0, const details::operator_type o1) + const details::operator_type o0, + const details::operator_type o1) { return details::build_string() << "t" << expr_gen.to_str(o0) @@ -30609,9 +32051,6 @@ namespace exprtk const details::operator_type o0 = operation; const details::operator_type o1 = cov->operation(); - binary_functor_t f0 = reinterpret_cast(0); - binary_functor_t f1 = reinterpret_cast(0); - details::free_node(*(expr_gen.node_allocator_),branch[0]); details::free_node(*(expr_gen.node_allocator_),branch[1]); @@ -30691,7 +32130,11 @@ namespace exprtk if (synthesis_result) return result; - else if (!expr_gen.valid_operator(o0,f0)) + + binary_functor_t f0 = reinterpret_cast(0); + binary_functor_t f1 = reinterpret_cast(0); + + if (!expr_gen.valid_operator(o0,f0)) return error_node(); else if (!expr_gen.valid_operator(o1,f1)) return error_node(); @@ -30699,7 +32142,9 @@ namespace exprtk return node_type::allocate(*(expr_gen.node_allocator_), c0, c1, v, f0, f1); } - static inline std::string id(expression_generator& expr_gen, const details::operator_type o0, const details::operator_type o1) + static inline std::string id(expression_generator& expr_gen, + const details::operator_type o0, + const details::operator_type o1) { return details::build_string() << "t" << expr_gen.to_str(o0) @@ -30725,9 +32170,6 @@ namespace exprtk const details::operator_type o0 = voc->operation(); const details::operator_type o1 = operation; - binary_functor_t f0 = reinterpret_cast(0); - binary_functor_t f1 = reinterpret_cast(0); - details::free_node(*(expr_gen.node_allocator_),branch[0]); details::free_node(*(expr_gen.node_allocator_),branch[1]); @@ -30815,7 +32257,11 @@ namespace exprtk if (synthesis_result) return result; - else if (!expr_gen.valid_operator(o0,f0)) + + binary_functor_t f0 = reinterpret_cast(0); + binary_functor_t f1 = reinterpret_cast(0); + + if (!expr_gen.valid_operator(o0,f0)) return error_node(); else if (!expr_gen.valid_operator(o1,f1)) return error_node(); @@ -30824,7 +32270,8 @@ namespace exprtk } static inline std::string id(expression_generator& expr_gen, - const details::operator_type o0, const details::operator_type o1) + const details::operator_type o0, + const details::operator_type o1) { return details::build_string() << "(t" << expr_gen.to_str(o0) @@ -30869,10 +32316,6 @@ namespace exprtk const details::operator_type o1 = operation; const details::operator_type o2 = vov1->operation(); - binary_functor_t f0 = reinterpret_cast(0); - binary_functor_t f1 = reinterpret_cast(0); - binary_functor_t f2 = reinterpret_cast(0); - details::free_node(*(expr_gen.node_allocator_),branch[0]); details::free_node(*(expr_gen.node_allocator_),branch[1]); @@ -30885,7 +32328,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf4ext_expression:: - template compile(expr_gen, "(t*t)/(t*t)", v0, v2, v1, v3, result); + template compile(expr_gen, "(t*t)/(t*t)", v0, v2, v1, v3, result); exprtk_debug(("(v0 / v1) * (v2 / v3) --> (vovovov) (v0 * v2) / (v1 * v3)\n")); @@ -30896,7 +32339,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf4ext_expression:: - template compile(expr_gen, "(t*t)/(t*t)", v0, v3, v1, v2, result); + template compile(expr_gen, "(t*t)/(t*t)", v0, v3, v1, v2, result); exprtk_debug(("(v0 / v1) / (v2 / v3) --> (vovovov) (v0 * v3) / (v1 * v2)\n")); @@ -30907,7 +32350,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf4ext_expression:: - template compile(expr_gen, "(t+t)*(t/t)", v0, v1, v3, v2, result); + template compile(expr_gen, "(t+t)*(t/t)", v0, v1, v3, v2, result); exprtk_debug(("(v0 + v1) / (v2 / v3) --> (vovovov) (v0 + v1) * (v3 / v2)\n")); @@ -30918,7 +32361,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf4ext_expression:: - template compile(expr_gen, "(t-t)*(t/t)", v0, v1, v3, v2, result); + template compile(expr_gen, "(t-t)*(t/t)", v0, v1, v3, v2, result); exprtk_debug(("(v0 - v1) / (v2 / v3) --> (vovovov) (v0 - v1) * (v3 / v2)\n")); @@ -30929,7 +32372,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf4ext_expression:: - template compile(expr_gen, "((t*t)*t)/t", v0, v1, v3, v2, result); + template compile(expr_gen, "((t*t)*t)/t", v0, v1, v3, v2, result); exprtk_debug(("(v0 * v1) / (v2 / v3) --> (vovovov) ((v0 * v1) * v3) / v2\n")); @@ -30943,7 +32386,12 @@ namespace exprtk if (synthesis_result) return result; - else if (!expr_gen.valid_operator(o0,f0)) + + binary_functor_t f0 = reinterpret_cast(0); + binary_functor_t f1 = reinterpret_cast(0); + binary_functor_t f2 = reinterpret_cast(0); + + if (!expr_gen.valid_operator(o0,f0)) return error_node(); else if (!expr_gen.valid_operator(o1,f1)) return error_node(); @@ -30990,10 +32438,6 @@ namespace exprtk const details::operator_type o1 = operation; const details::operator_type o2 = voc->operation(); - binary_functor_t f0 = reinterpret_cast(0); - binary_functor_t f1 = reinterpret_cast(0); - binary_functor_t f2 = reinterpret_cast(0); - details::free_node(*(expr_gen.node_allocator_),branch[0]); details::free_node(*(expr_gen.node_allocator_),branch[1]); @@ -31006,7 +32450,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf4ext_expression:: - template compile(expr_gen, "(t*t)/(t*t)", v0, v2, v1, c, result); + template compile(expr_gen, "(t*t)/(t*t)", v0, v2, v1, c, result); exprtk_debug(("(v0 / v1) * (v2 / c) --> (vovovoc) (v0 * v2) / (v1 * c)\n")); @@ -31017,7 +32461,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf4ext_expression:: - template compile(expr_gen, "(t*t)/(t*t)", v0, c, v1, v2, result); + template compile(expr_gen, "(t*t)/(t*t)", v0, c, v1, v2, result); exprtk_debug(("(v0 / v1) / (v2 / c) --> (vocovov) (v0 * c) / (v1 * v2)\n")); @@ -31031,7 +32475,12 @@ namespace exprtk if (synthesis_result) return result; - else if (!expr_gen.valid_operator(o0,f0)) + + binary_functor_t f0 = reinterpret_cast(0); + binary_functor_t f1 = reinterpret_cast(0); + binary_functor_t f2 = reinterpret_cast(0); + + if (!expr_gen.valid_operator(o0,f0)) return error_node(); else if (!expr_gen.valid_operator(o1,f1)) return error_node(); @@ -31078,10 +32527,6 @@ namespace exprtk const details::operator_type o1 = operation; const details::operator_type o2 = cov->operation(); - binary_functor_t f0 = reinterpret_cast(0); - binary_functor_t f1 = reinterpret_cast(0); - binary_functor_t f2 = reinterpret_cast(0); - details::free_node(*(expr_gen.node_allocator_),branch[0]); details::free_node(*(expr_gen.node_allocator_),branch[1]); @@ -31094,7 +32539,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf4ext_expression:: - template compile(expr_gen, "(t*t)/(t*t)", v0, c, v1, v2, result); + template compile(expr_gen, "(t*t)/(t*t)", v0, c, v1, v2, result); exprtk_debug(("(v0 / v1) * (c / v2) --> (vocovov) (v0 * c) / (v1 * v2)\n")); @@ -31105,7 +32550,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf4ext_expression:: - template compile(expr_gen, "(t*t)/(t*t)", v0, v2, v1, c, result); + template compile(expr_gen, "(t*t)/(t*t)", v0, v2, v1, c, result); exprtk_debug(("(v0 / v1) / (c / v2) --> (vovovoc) (v0 * v2) / (v1 * c)\n")); @@ -31119,7 +32564,12 @@ namespace exprtk if (synthesis_result) return result; - else if (!expr_gen.valid_operator(o0,f0)) + + binary_functor_t f0 = reinterpret_cast(0); + binary_functor_t f1 = reinterpret_cast(0); + binary_functor_t f2 = reinterpret_cast(0); + + if (!expr_gen.valid_operator(o0,f0)) return error_node(); else if (!expr_gen.valid_operator(o1,f1)) return error_node(); @@ -31166,10 +32616,6 @@ namespace exprtk const details::operator_type o1 = operation; const details::operator_type o2 = vov->operation(); - binary_functor_t f0 = reinterpret_cast(0); - binary_functor_t f1 = reinterpret_cast(0); - binary_functor_t f2 = reinterpret_cast(0); - details::free_node(*(expr_gen.node_allocator_),branch[0]); details::free_node(*(expr_gen.node_allocator_),branch[1]); @@ -31182,7 +32628,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf4ext_expression:: - template compile(expr_gen, "(t*t)/(t*t)", v0, v1, c, v2, result); + template compile(expr_gen, "(t*t)/(t*t)", v0, v1, c, v2, result); exprtk_debug(("(v0 / c) * (v1 / v2) --> (vovocov) (v0 * v1) / (c * v2)\n")); @@ -31193,7 +32639,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf4ext_expression:: - template compile(expr_gen, "(t*t)/(t*t)", v0, v2, c, v1, result); + template compile(expr_gen, "(t*t)/(t*t)", v0, v2, c, v1, result); exprtk_debug(("(v0 / c) / (v1 / v2) --> (vovocov) (v0 * v2) / (c * v1)\n")); @@ -31207,7 +32653,12 @@ namespace exprtk if (synthesis_result) return result; - else if (!expr_gen.valid_operator(o0,f0)) + + binary_functor_t f0 = reinterpret_cast(0); + binary_functor_t f1 = reinterpret_cast(0); + binary_functor_t f2 = reinterpret_cast(0); + + if (!expr_gen.valid_operator(o0,f0)) return error_node(); else if (!expr_gen.valid_operator(o1,f1)) return error_node(); @@ -31254,10 +32705,6 @@ namespace exprtk const details::operator_type o1 = operation; const details::operator_type o2 = vov->operation(); - binary_functor_t f0 = reinterpret_cast(0); - binary_functor_t f1 = reinterpret_cast(0); - binary_functor_t f2 = reinterpret_cast(0); - details::free_node(*(expr_gen.node_allocator_),branch[0]); details::free_node(*(expr_gen.node_allocator_),branch[1]); @@ -31270,7 +32717,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf4ext_expression:: - template compile(expr_gen, "(t*t)/(t*t)", c, v1, v0, v2, result); + template compile(expr_gen, "(t*t)/(t*t)", c, v1, v0, v2, result); exprtk_debug(("(c / v0) * (v1 / v2) --> (covovov) (c * v1) / (v0 * v2)\n")); @@ -31281,7 +32728,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf4ext_expression:: - template compile(expr_gen, "(t*t)/(t*t)", c, v2, v0, v1, result); + template compile(expr_gen, "(t*t)/(t*t)", c, v2, v0, v1, result); exprtk_debug(("(c / v0) / (v1 / v2) --> (covovov) (c * v2) / (v0 * v1)\n")); @@ -31295,7 +32742,12 @@ namespace exprtk if (synthesis_result) return result; - else if (!expr_gen.valid_operator(o0,f0)) + + binary_functor_t f0 = reinterpret_cast(0); + binary_functor_t f1 = reinterpret_cast(0); + binary_functor_t f2 = reinterpret_cast(0); + + if (!expr_gen.valid_operator(o0,f0)) return error_node(); else if (!expr_gen.valid_operator(o1,f1)) return error_node(); @@ -31342,10 +32794,6 @@ namespace exprtk const details::operator_type o1 = operation; const details::operator_type o2 = cov1->operation(); - binary_functor_t f0 = reinterpret_cast(0); - binary_functor_t f1 = reinterpret_cast(0); - binary_functor_t f2 = reinterpret_cast(0); - details::free_node(*(expr_gen.node_allocator_),branch[0]); details::free_node(*(expr_gen.node_allocator_),branch[1]); @@ -31358,7 +32806,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t+t)+t", (c0 + c1), v0, v1, result); + template compile(expr_gen, "(t+t)+t", (c0 + c1), v0, v1, result); exprtk_debug(("(c0 + v0) + (c1 + v1) --> (covov) (c0 + c1) + v0 + v1\n")); @@ -31369,7 +32817,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t+t)-t", (c0 - c1), v0, v1, result); + template compile(expr_gen, "(t+t)-t", (c0 - c1), v0, v1, result); exprtk_debug(("(c0 + v0) - (c1 + v1) --> (covov) (c0 - c1) + v0 - v1\n")); @@ -31380,7 +32828,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t-t)+t", (c0 - c1), v0, v1, result); + template compile(expr_gen, "(t-t)+t", (c0 - c1), v0, v1, result); exprtk_debug(("(c0 - v0) - (c1 - v1) --> (covov) (c0 - c1) - v0 + v1\n")); @@ -31391,7 +32839,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t*t)*t", (c0 * c1), v0, v1, result); + template compile(expr_gen, "(t*t)*t", (c0 * c1), v0, v1, result); exprtk_debug(("(c0 * v0) * (c1 * v1) --> (covov) (c0 * c1) * v0 * v1\n")); @@ -31402,7 +32850,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t*t)/t", (c0 / c1), v0, v1, result); + template compile(expr_gen, "(t*t)/t", (c0 / c1), v0, v1, result); exprtk_debug(("(c0 * v0) / (c1 * v1) --> (covov) (c0 / c1) * (v0 / v1)\n")); @@ -31413,7 +32861,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "t/(t*t)", (c0 * c1), v0, v1, result); + template compile(expr_gen, "t/(t*t)", (c0 * c1), v0, v1, result); exprtk_debug(("(c0 / v0) * (c1 / v1) --> (covov) (c0 * c1) / (v0 * v1)\n")); @@ -31424,7 +32872,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t*t)/t", (c0 / c1), v1, v0, result); + template compile(expr_gen, "(t*t)/t", (c0 / c1), v1, v0, result); exprtk_debug(("(c0 / v0) / (c1 / v1) --> (covov) ((c0 / c1) * v1) / v0\n")); @@ -31435,7 +32883,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "t*(t*t)", (c0 / c1), v0, v1, result); + template compile(expr_gen, "t*(t*t)", (c0 / c1), v0, v1, result); exprtk_debug(("(c0 * v0) / (c1 / v1) --> (covov) (c0 / c1) * (v0 * v1)\n")); @@ -31446,7 +32894,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "t/(t*t)", (c0 / c1), v0, v1, result); + template compile(expr_gen, "t/(t*t)", (c0 / c1), v0, v1, result); exprtk_debug(("(c0 / v0) / (c1 * v1) --> (covov) (c0 / c1) / (v0 * v1)\n")); @@ -31488,7 +32936,12 @@ namespace exprtk if (synthesis_result) return result; - else if (!expr_gen.valid_operator(o0,f0)) + + binary_functor_t f0 = reinterpret_cast(0); + binary_functor_t f1 = reinterpret_cast(0); + binary_functor_t f2 = reinterpret_cast(0); + + if (!expr_gen.valid_operator(o0,f0)) return error_node(); else if (!expr_gen.valid_operator(o1,f1)) return error_node(); @@ -31535,10 +32988,6 @@ namespace exprtk const details::operator_type o1 = operation; const details::operator_type o2 = voc1->operation(); - binary_functor_t f0 = reinterpret_cast(0); - binary_functor_t f1 = reinterpret_cast(0); - binary_functor_t f2 = reinterpret_cast(0); - details::free_node(*(expr_gen.node_allocator_),branch[0]); details::free_node(*(expr_gen.node_allocator_),branch[1]); @@ -31551,7 +33000,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t+t)+t", (c0 + c1), v0, v1, result); + template compile(expr_gen, "(t+t)+t", (c0 + c1), v0, v1, result); exprtk_debug(("(v0 + c0) + (v1 + c1) --> (covov) (c0 + c1) + v0 + v1\n")); @@ -31562,7 +33011,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t+t)-t", (c0 - c1), v0, v1, result); + template compile(expr_gen, "(t+t)-t", (c0 - c1), v0, v1, result); exprtk_debug(("(v0 + c0) - (v1 + c1) --> (covov) (c0 - c1) + v0 - v1\n")); @@ -31573,7 +33022,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t+t)-t", (c1 - c0), v0, v1, result); + template compile(expr_gen, "(t+t)-t", (c1 - c0), v0, v1, result); exprtk_debug(("(v0 - c0) - (v1 - c1) --> (covov) (c1 - c0) + v0 - v1\n")); @@ -31584,7 +33033,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t*t)*t", (c0 * c1), v0, v1, result); + template compile(expr_gen, "(t*t)*t", (c0 * c1), v0, v1, result); exprtk_debug(("(v0 * c0) * (v1 * c1) --> (covov) (c0 * c1) * v0 * v1\n")); @@ -31595,7 +33044,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t*t)/t", (c0 / c1), v0, v1, result); + template compile(expr_gen, "(t*t)/t", (c0 / c1), v0, v1, result); exprtk_debug(("(v0 * c0) / (v1 * c1) --> (covov) (c0 / c1) * (v0 / v1)\n")); @@ -31606,7 +33055,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t*t)*t", Type(1) / (c0 * c1), v0, v1, result); + template compile(expr_gen, "(t*t)*t", Type(1) / (c0 * c1), v0, v1, result); exprtk_debug(("(v0 / c0) * (v1 / c1) --> (covov) (1 / (c0 * c1)) * v0 * v1\n")); @@ -31617,7 +33066,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t*t)/t", (c1 / c0), v0, v1, result); + template compile(expr_gen, "(t*t)/t", (c1 / c0), v0, v1, result); exprtk_debug(("(v0 / c0) / (v1 / c1) --> (covov) ((c1 / c0) * v0) / v1\n")); @@ -31628,7 +33077,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "t*(t/t)", (c0 * c1), v0, v1, result); + template compile(expr_gen, "t*(t/t)", (c0 * c1), v0, v1, result); exprtk_debug(("(v0 * c0) / (v1 / c1) --> (covov) (c0 * c1) * (v0 / v1)\n")); @@ -31639,7 +33088,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "t*(t/t)", Type(1) / (c0 * c1), v0, v1, result); + template compile(expr_gen, "t*(t/t)", Type(1) / (c0 * c1), v0, v1, result); exprtk_debug(("(v0 / c0) / (v1 * c1) --> (covov) (1 / (c0 * c1)) * v0 / v1\n")); @@ -31650,7 +33099,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf4ext_expression:: - template compile(expr_gen, "(t*t)*(t+t)", v0, T(1) / c0, v1, c1, result); + template compile(expr_gen, "(t*t)*(t+t)", v0, T(1) / c0, v1, c1, result); exprtk_debug(("(v0 / c0) * (v1 + c1) --> (vocovoc) (v0 * (1 / c0)) * (v1 + c1)\n")); @@ -31661,7 +33110,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf4ext_expression:: - template compile(expr_gen, "(t*t)*(t-t)", v0, T(1) / c0, v1, c1, result); + template compile(expr_gen, "(t*t)*(t-t)", v0, T(1) / c0, v1, c1, result); exprtk_debug(("(v0 / c0) * (v1 - c1) --> (vocovoc) (v0 * (1 / c0)) * (v1 - c1)\n")); @@ -31689,7 +33138,7 @@ namespace exprtk const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, specfunc, c0, v0, v1, result); + template compile(expr_gen, specfunc, c0, v0, v1, result); exprtk_debug(("(v0 * c) +/- (v1 * c) --> (covov) c * (v0 +/- v1)\n")); @@ -31717,7 +33166,7 @@ namespace exprtk const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, specfunc, v0, v1, c0, result); + template compile(expr_gen, specfunc, v0, v1, c0, result); exprtk_debug(("(v0 / c) +/- (v1 / c) --> (vovoc) (v0 +/- v1) / c\n")); @@ -31731,7 +33180,12 @@ namespace exprtk if (synthesis_result) return result; - else if (!expr_gen.valid_operator(o0,f0)) + + binary_functor_t f0 = reinterpret_cast(0); + binary_functor_t f1 = reinterpret_cast(0); + binary_functor_t f2 = reinterpret_cast(0); + + if (!expr_gen.valid_operator(o0,f0)) return error_node(); else if (!expr_gen.valid_operator(o1,f1)) return error_node(); @@ -31778,10 +33232,6 @@ namespace exprtk const details::operator_type o1 = operation; const details::operator_type o2 = voc->operation(); - binary_functor_t f0 = reinterpret_cast(0); - binary_functor_t f1 = reinterpret_cast(0); - binary_functor_t f2 = reinterpret_cast(0); - details::free_node(*(expr_gen.node_allocator_),branch[0]); details::free_node(*(expr_gen.node_allocator_),branch[1]); @@ -31794,7 +33244,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t+t)+t", (c0 + c1), v0, v1, result); + template compile(expr_gen, "(t+t)+t", (c0 + c1), v0, v1, result); exprtk_debug(("(c0 + v0) + (v1 + c1) --> (covov) (c0 + c1) + v0 + v1\n")); @@ -31805,7 +33255,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t+t)-t", (c0 - c1), v0, v1, result); + template compile(expr_gen, "(t+t)-t", (c0 - c1), v0, v1, result); exprtk_debug(("(c0 + v0) - (v1 + c1) --> (covov) (c0 - c1) + v0 - v1\n")); @@ -31816,7 +33266,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "t-(t+t)", (c0 + c1), v0, v1, result); + template compile(expr_gen, "t-(t+t)", (c0 + c1), v0, v1, result); exprtk_debug(("(c0 - v0) - (v1 - c1) --> (covov) (c0 + c1) - v0 - v1\n")); @@ -31827,7 +33277,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t*t)*t", (c0 * c1), v0, v1, result); + template compile(expr_gen, "(t*t)*t", (c0 * c1), v0, v1, result); exprtk_debug(("(c0 * v0) * (v1 * c1) --> (covov) (c0 * c1) * v0 * v1\n")); @@ -31838,7 +33288,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t*t)/t", (c0 / c1), v0, v1, result); + template compile(expr_gen, "(t*t)/t", (c0 / c1), v0, v1, result); exprtk_debug(("(c0 * v0) / (v1 * c1) --> (covov) (c0 / c1) * (v0 / v1)\n")); @@ -31849,7 +33299,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "t*(t/t)", (c0 / c1), v1, v0, result); + template compile(expr_gen, "t*(t/t)", (c0 / c1), v1, v0, result); exprtk_debug(("(c0 / v0) * (v1 / c1) --> (covov) (c0 / c1) * (v1 / v0)\n")); @@ -31860,7 +33310,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "t/(t*t)", (c0 * c1), v0, v1, result); + template compile(expr_gen, "t/(t*t)", (c0 * c1), v0, v1, result); exprtk_debug(("(c0 / v0) / (v1 / c1) --> (covov) (c0 * c1) / (v0 * v1)\n")); @@ -31871,7 +33321,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t*t)/t", (c0 * c1), v0, v1, result); + template compile(expr_gen, "(t*t)/t", (c0 * c1), v0, v1, result); exprtk_debug(("(c0 * v0) / (v1 / c1) --> (covov) (c0 * c1) * (v0 / v1)\n")); @@ -31882,7 +33332,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "t/(t*t)", (c0 / c1), v0, v1, result); + template compile(expr_gen, "t/(t*t)", (c0 / c1), v0, v1, result); exprtk_debug(("(c0 / v0) / (v1 * c1) --> (covov) (c0 / c1) / (v0 * v1)\n")); @@ -31910,7 +33360,7 @@ namespace exprtk const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen,specfunc, c0, v0, v1, result); + template compile(expr_gen,specfunc, c0, v0, v1, result); exprtk_debug(("(c * v0) +/- (v1 * c) --> (covov) c * (v0 +/- v1)\n")); @@ -31924,7 +33374,12 @@ namespace exprtk if (synthesis_result) return result; - else if (!expr_gen.valid_operator(o0,f0)) + + binary_functor_t f0 = reinterpret_cast(0); + binary_functor_t f1 = reinterpret_cast(0); + binary_functor_t f2 = reinterpret_cast(0); + + if (!expr_gen.valid_operator(o0,f0)) return error_node(); else if (!expr_gen.valid_operator(o1,f1)) return error_node(); @@ -31971,10 +33426,6 @@ namespace exprtk const details::operator_type o1 = operation; const details::operator_type o2 = cov->operation(); - binary_functor_t f0 = reinterpret_cast(0); - binary_functor_t f1 = reinterpret_cast(0); - binary_functor_t f2 = reinterpret_cast(0); - details::free_node(*(expr_gen.node_allocator_),branch[0]); details::free_node(*(expr_gen.node_allocator_),branch[1]); @@ -31987,7 +33438,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t+t)+t", (c0 + c1), v0, v1, result); + template compile(expr_gen, "(t+t)+t", (c0 + c1), v0, v1, result); exprtk_debug(("(v0 + c0) + (c1 + v1) --> (covov) (c0 + c1) + v0 + v1\n")); @@ -31998,7 +33449,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t+t)-t", (c0 - c1), v0, v1, result); + template compile(expr_gen, "(t+t)-t", (c0 - c1), v0, v1, result); exprtk_debug(("(v0 + c0) - (c1 + v1) --> (covov) (c0 - c1) + v0 - v1\n")); @@ -32009,7 +33460,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t+t)-t", v0, v1, (c1 + c0), result); + template compile(expr_gen, "(t+t)-t", v0, v1, (c1 + c0), result); exprtk_debug(("(v0 - c0) - (c1 - v1) --> (vovoc) v0 + v1 - (c1 + c0)\n")); @@ -32020,7 +33471,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t*t)*t", (c0 * c1), v0, v1, result); + template compile(expr_gen, "(t*t)*t", (c0 * c1), v0, v1, result); exprtk_debug(("(v0 * c0) * (c1 * v1) --> (covov) (c0 * c1) * v0 * v1\n")); @@ -32031,7 +33482,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t*t)/t", (c0 / c1), v0, v1, result); + template compile(expr_gen, "(t*t)/t", (c0 / c1), v0, v1, result); exprtk_debug(("(v0 * c0) / (c1 * v1) --> (covov) (c0 / c1) * (v0 * v1)\n")); @@ -32042,7 +33493,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t*t)/t", (c1 / c0), v0, v1, result); + template compile(expr_gen, "(t*t)/t", (c1 / c0), v0, v1, result); exprtk_debug(("(v0 / c0) * (c1 / v1) --> (covov) (c1 / c0) * (v0 / v1)\n")); @@ -32053,7 +33504,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t*t)*t", (c0 / c1), v0, v1, result); + template compile(expr_gen, "(t*t)*t", (c0 / c1), v0, v1, result); exprtk_debug(("(v0 * c0) / (c1 / v1) --> (covov) (c0 / c1) * (v0 * v1)\n")); @@ -32064,7 +33515,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t*t)/t", Type(1) / (c0 * c1), v0, v1, result); + template compile(expr_gen, "(t*t)/t", Type(1) / (c0 * c1), v0, v1, result); exprtk_debug(("(v0 / c0) / (c1 * v1) --> (covov) (1 / (c0 * c1)) * (v0 / v1)\n")); @@ -32075,7 +33526,7 @@ namespace exprtk { const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, "(t*t)*t", v0, v1, Type(1) / (c0 * c1), result); + template compile(expr_gen, "(t*t)*t", v0, v1, Type(1) / (c0 * c1), result); exprtk_debug(("(v0 / c0) / (c1 / v1) --> (vovoc) (v0 * v1) * (1 / (c0 * c1))\n")); @@ -32102,7 +33553,7 @@ namespace exprtk const bool synthesis_result = synthesize_sf3ext_expression:: - template compile(expr_gen, specfunc, c0, v0, v1, result); + template compile(expr_gen, specfunc, c0, v0, v1, result); exprtk_debug(("(v0 * c) +/- (c * v1) --> (covov) c * (v0 +/- v1)\n")); @@ -32116,7 +33567,12 @@ namespace exprtk if (synthesis_result) return result; - else if (!expr_gen.valid_operator(o0,f0)) + + binary_functor_t f0 = reinterpret_cast(0); + binary_functor_t f1 = reinterpret_cast(0); + binary_functor_t f2 = reinterpret_cast(0); + + if (!expr_gen.valid_operator(o0,f0)) return error_node(); else if (!expr_gen.valid_operator(o1,f1)) return error_node(); @@ -32172,14 +33628,18 @@ namespace exprtk expression_node_ptr result = error_node(); - if (synthesize_sf4ext_expression::template compile(expr_gen,id(expr_gen,o0,o1,o2),v0,v1,v2,v3,result)) + const bool synthesis_result = + synthesize_sf4ext_expression::template compile + (expr_gen,id(expr_gen, o0, o1, o2), v0, v1, v2, v3, result); + + if (synthesis_result) return result; else if (!expr_gen.valid_operator(o0,f0)) return error_node(); exprtk_debug(("v0 o0 (v1 o1 (v2 o2 v3))\n")); - return node_type::allocate(*(expr_gen.node_allocator_),v0,v1,v2,v3,f0,f1,f2); + return node_type::allocate(*(expr_gen.node_allocator_), v0, v1, v2, v3, f0, f1, f2); } static inline std::string id(expression_generator& expr_gen, @@ -34296,16 +35756,16 @@ namespace exprtk #ifndef exprtk_disable_string_capabilities - #define string_opr_switch_statements \ - case_stmt(details:: e_lt ,details:: lt_op) \ - case_stmt(details:: e_lte ,details:: lte_op) \ - case_stmt(details:: e_gt ,details:: gt_op) \ - case_stmt(details:: e_gte ,details:: gte_op) \ - case_stmt(details:: e_eq ,details:: eq_op) \ - case_stmt(details:: e_ne ,details:: ne_op) \ - case_stmt(details::e_in ,details:: in_op) \ - case_stmt(details::e_like ,details:: like_op) \ - case_stmt(details::e_ilike,details::ilike_op) \ + #define string_opr_switch_statements \ + case_stmt(details::e_lt , details::lt_op ) \ + case_stmt(details::e_lte , details::lte_op ) \ + case_stmt(details::e_gt , details::gt_op ) \ + case_stmt(details::e_gte , details::gte_op ) \ + case_stmt(details::e_eq , details::eq_op ) \ + case_stmt(details::e_ne , details::ne_op ) \ + case_stmt(details::e_in , details::in_op ) \ + case_stmt(details::e_like , details::like_op ) \ + case_stmt(details::e_ilike , details::ilike_op) \ template inline expression_node_ptr synthesize_str_xrox_expression_impl(const details::operator_type& opr, @@ -34452,7 +35912,7 @@ namespace exprtk inline expression_node_ptr synthesize_csos_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) { std::string s0 = static_cast*>(branch[0])->str(); - std::string& s1 = static_cast< details::stringvar_node*>(branch[1])->ref(); + std::string& s1 = static_cast* >(branch[1])->ref(); details::free_node(*node_allocator_,branch[0]); @@ -34461,9 +35921,9 @@ namespace exprtk inline expression_node_ptr synthesize_csosr_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) { - std::string s0 = static_cast*>(branch[0])->str (); - std::string& s1 = static_cast*> (branch[1])->ref (); - range_t rp1 = static_cast*> (branch[1])->range(); + std::string s0 = static_cast*>(branch[0])->str (); + std::string& s1 = static_cast* >(branch[1])->ref (); + range_t rp1 = static_cast* >(branch[1])->range(); static_cast*>(branch[1])->range_ref().clear(); @@ -34565,8 +36025,8 @@ namespace exprtk { const std::string s0 = static_cast*>(branch[0])->str (); std::string& s1 = static_cast*> (branch[1])->ref (); - range_t rp0 = static_cast*>(branch[0])->range(); - range_t rp1 = static_cast*> (branch[1])->range(); + const range_t rp0 = static_cast*>(branch[0])->range(); + const range_t rp1 = static_cast*> (branch[1])->range(); static_cast*>(branch[0])->range_ref().clear(); static_cast*> (branch[1])->range_ref().clear(); @@ -34579,9 +36039,9 @@ namespace exprtk inline expression_node_ptr synthesize_csrocs_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) { - std::string s0 = static_cast*>(branch[0])->str (); + const std::string s0 = static_cast*>(branch[0])->str (); const std::string s1 = static_cast*> (branch[1])->str (); - range_t rp0 = static_cast*>(branch[0])->range(); + const range_t rp0 = static_cast*>(branch[0])->range(); static_cast*>(branch[0])->range_ref().clear(); @@ -34592,10 +36052,10 @@ namespace exprtk inline expression_node_ptr synthesize_csrocsr_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) { - std::string s0 = static_cast*>(branch[0])->str (); - std::string s1 = static_cast*>(branch[1])->str (); - range_t rp0 = static_cast*>(branch[0])->range(); - range_t rp1 = static_cast*>(branch[1])->range(); + const std::string s0 = static_cast*>(branch[0])->str (); + const std::string s1 = static_cast*>(branch[1])->str (); + const range_t rp0 = static_cast*>(branch[0])->range(); + const range_t rp1 = static_cast*>(branch[1])->range(); static_cast*>(branch[0])->range_ref().clear(); static_cast*>(branch[1])->range_ref().clear(); @@ -34756,7 +36216,7 @@ namespace exprtk ) { std::string s0 = static_cast*>(branch[0])->str(); - std::string& s1 = static_cast< details::stringvar_node*>(branch[1])->ref(); + std::string& s1 = static_cast* >(branch[1])->ref(); std::string s2 = static_cast*>(branch[2])->str(); typedef typename details::sosos_node > inrange_t; @@ -34805,8 +36265,8 @@ namespace exprtk ) { std::string s0 = static_cast*>(branch[0])->str(); - std::string& s1 = static_cast< details::stringvar_node*>(branch[1])->ref(); - std::string& s2 = static_cast< details::stringvar_node*>(branch[2])->ref(); + std::string& s1 = static_cast* >(branch[1])->ref(); + std::string& s2 = static_cast* >(branch[2])->ref(); typedef typename details::sosos_node > inrange_t; @@ -34902,21 +36362,22 @@ namespace exprtk { return branch[0]; } - else if ( - (details::e_lt == operation) || (details::e_lte == operation) || - (details::e_gt == operation) || (details::e_gte == operation) || - (details::e_and == operation) || (details::e_nand == operation) || - (details::e_or == operation) || (details::e_nor == operation) || - (details::e_xor == operation) || (details::e_xnor == operation) || - (details::e_in == operation) || (details::e_like == operation) || - (details::e_ilike == operation) - ) + + details::free_node(*node_allocator_, branch[0]); + + if ( + (details::e_lt == operation) || (details::e_lte == operation) || + (details::e_gt == operation) || (details::e_gte == operation) || + (details::e_and == operation) || (details::e_nand == operation) || + (details::e_or == operation) || (details::e_nor == operation) || + (details::e_xor == operation) || (details::e_xnor == operation) || + (details::e_in == operation) || (details::e_like == operation) || + (details::e_ilike == operation) + ) { return node_allocator_->allocate_c(T(0)); } - details::free_node(*node_allocator_,branch[0]); - return node_allocator_->allocate >(); } @@ -34946,7 +36407,7 @@ namespace exprtk if (is_constant_foldable(branch)) { - Type v = expression_point->value(); + const Type v = expression_point->value(); details::free_node(*node_allocator_,expression_point); return node_allocator_->allocate(v); @@ -35099,45 +36560,45 @@ namespace exprtk #define register_unary_op(Op,UnaryFunctor) \ m.insert(std::make_pair(Op,UnaryFunctor::process)); \ - register_unary_op(details:: e_abs, details:: abs_op) - register_unary_op(details:: e_acos, details:: acos_op) - register_unary_op(details::e_acosh, details::acosh_op) - register_unary_op(details:: e_asin, details:: asin_op) - register_unary_op(details::e_asinh, details::asinh_op) - register_unary_op(details::e_atanh, details::atanh_op) - register_unary_op(details:: e_ceil, details:: ceil_op) - register_unary_op(details:: e_cos, details:: cos_op) - register_unary_op(details:: e_cosh, details:: cosh_op) - register_unary_op(details:: e_exp, details:: exp_op) - register_unary_op(details::e_expm1, details::expm1_op) - register_unary_op(details::e_floor, details::floor_op) - register_unary_op(details:: e_log, details:: log_op) - register_unary_op(details::e_log10, details::log10_op) - register_unary_op(details:: e_log2, details:: log2_op) - register_unary_op(details::e_log1p, details::log1p_op) - register_unary_op(details:: e_neg, details:: neg_op) - register_unary_op(details:: e_pos, details:: pos_op) - register_unary_op(details::e_round, details::round_op) - register_unary_op(details:: e_sin, details:: sin_op) - register_unary_op(details:: e_sinc, details:: sinc_op) - register_unary_op(details:: e_sinh, details:: sinh_op) - register_unary_op(details:: e_sqrt, details:: sqrt_op) - register_unary_op(details:: e_tan, details:: tan_op) - register_unary_op(details:: e_tanh, details:: tanh_op) - register_unary_op(details:: e_cot, details:: cot_op) - register_unary_op(details:: e_sec, details:: sec_op) - register_unary_op(details:: e_csc, details:: csc_op) - register_unary_op(details:: e_r2d, details:: r2d_op) - register_unary_op(details:: e_d2r, details:: d2r_op) - register_unary_op(details:: e_d2g, details:: d2g_op) - register_unary_op(details:: e_g2d, details:: g2d_op) - register_unary_op(details:: e_notl, details:: notl_op) - register_unary_op(details:: e_sgn, details:: sgn_op) - register_unary_op(details:: e_erf, details:: erf_op) - register_unary_op(details:: e_erfc, details:: erfc_op) - register_unary_op(details:: e_ncdf, details:: ncdf_op) - register_unary_op(details:: e_frac, details:: frac_op) - register_unary_op(details::e_trunc, details::trunc_op) + register_unary_op(details::e_abs , details::abs_op ) + register_unary_op(details::e_acos , details::acos_op ) + register_unary_op(details::e_acosh , details::acosh_op) + register_unary_op(details::e_asin , details::asin_op ) + register_unary_op(details::e_asinh , details::asinh_op) + register_unary_op(details::e_atanh , details::atanh_op) + register_unary_op(details::e_ceil , details::ceil_op ) + register_unary_op(details::e_cos , details::cos_op ) + register_unary_op(details::e_cosh , details::cosh_op ) + register_unary_op(details::e_exp , details::exp_op ) + register_unary_op(details::e_expm1 , details::expm1_op) + register_unary_op(details::e_floor , details::floor_op) + register_unary_op(details::e_log , details::log_op ) + register_unary_op(details::e_log10 , details::log10_op) + register_unary_op(details::e_log2 , details::log2_op ) + register_unary_op(details::e_log1p , details::log1p_op) + register_unary_op(details::e_neg , details::neg_op ) + register_unary_op(details::e_pos , details::pos_op ) + register_unary_op(details::e_round , details::round_op) + register_unary_op(details::e_sin , details::sin_op ) + register_unary_op(details::e_sinc , details::sinc_op ) + register_unary_op(details::e_sinh , details::sinh_op ) + register_unary_op(details::e_sqrt , details::sqrt_op ) + register_unary_op(details::e_tan , details::tan_op ) + register_unary_op(details::e_tanh , details::tanh_op ) + register_unary_op(details::e_cot , details::cot_op ) + register_unary_op(details::e_sec , details::sec_op ) + register_unary_op(details::e_csc , details::csc_op ) + register_unary_op(details::e_r2d , details::r2d_op ) + register_unary_op(details::e_d2r , details::d2r_op ) + register_unary_op(details::e_d2g , details::d2g_op ) + register_unary_op(details::e_g2d , details::g2d_op ) + register_unary_op(details::e_notl , details::notl_op ) + register_unary_op(details::e_sgn , details::sgn_op ) + register_unary_op(details::e_erf , details::erf_op ) + register_unary_op(details::e_erfc , details::erfc_op ) + register_unary_op(details::e_ncdf , details::ncdf_op ) + register_unary_op(details::e_frac , details::frac_op ) + register_unary_op(details::e_trunc , details::trunc_op) #undef register_unary_op } @@ -35148,24 +36609,24 @@ namespace exprtk #define register_binary_op(Op,BinaryFunctor) \ m.insert(value_type(Op,BinaryFunctor::process)); \ - register_binary_op(details:: e_add, details:: add_op) - register_binary_op(details:: e_sub, details:: sub_op) - register_binary_op(details:: e_mul, details:: mul_op) - register_binary_op(details:: e_div, details:: div_op) - register_binary_op(details:: e_mod, details:: mod_op) - register_binary_op(details:: e_pow, details:: pow_op) - register_binary_op(details:: e_lt, details:: lt_op) - register_binary_op(details:: e_lte, details:: lte_op) - register_binary_op(details:: e_gt, details:: gt_op) - register_binary_op(details:: e_gte, details:: gte_op) - register_binary_op(details:: e_eq, details:: eq_op) - register_binary_op(details:: e_ne, details:: ne_op) - register_binary_op(details:: e_and, details:: and_op) - register_binary_op(details::e_nand, details::nand_op) - register_binary_op(details:: e_or, details:: or_op) - register_binary_op(details:: e_nor, details:: nor_op) - register_binary_op(details:: e_xor, details:: xor_op) - register_binary_op(details::e_xnor, details::xnor_op) + register_binary_op(details::e_add , details::add_op ) + register_binary_op(details::e_sub , details::sub_op ) + register_binary_op(details::e_mul , details::mul_op ) + register_binary_op(details::e_div , details::div_op ) + register_binary_op(details::e_mod , details::mod_op ) + register_binary_op(details::e_pow , details::pow_op ) + register_binary_op(details::e_lt , details::lt_op ) + register_binary_op(details::e_lte , details::lte_op ) + register_binary_op(details::e_gt , details::gt_op ) + register_binary_op(details::e_gte , details::gte_op ) + register_binary_op(details::e_eq , details::eq_op ) + register_binary_op(details::e_ne , details::ne_op ) + register_binary_op(details::e_and , details::and_op ) + register_binary_op(details::e_nand , details::nand_op) + register_binary_op(details::e_or , details::or_op ) + register_binary_op(details::e_nor , details::nor_op ) + register_binary_op(details::e_xor , details::xor_op ) + register_binary_op(details::e_xnor , details::xnor_op) #undef register_binary_op } @@ -35176,24 +36637,24 @@ namespace exprtk #define register_binary_op(Op,BinaryFunctor) \ m.insert(value_type(BinaryFunctor::process,Op)); \ - register_binary_op(details:: e_add, details:: add_op) - register_binary_op(details:: e_sub, details:: sub_op) - register_binary_op(details:: e_mul, details:: mul_op) - register_binary_op(details:: e_div, details:: div_op) - register_binary_op(details:: e_mod, details:: mod_op) - register_binary_op(details:: e_pow, details:: pow_op) - register_binary_op(details:: e_lt, details:: lt_op) - register_binary_op(details:: e_lte, details:: lte_op) - register_binary_op(details:: e_gt, details:: gt_op) - register_binary_op(details:: e_gte, details:: gte_op) - register_binary_op(details:: e_eq, details:: eq_op) - register_binary_op(details:: e_ne, details:: ne_op) - register_binary_op(details:: e_and, details:: and_op) - register_binary_op(details::e_nand, details::nand_op) - register_binary_op(details:: e_or, details:: or_op) - register_binary_op(details:: e_nor, details:: nor_op) - register_binary_op(details:: e_xor, details:: xor_op) - register_binary_op(details::e_xnor, details::xnor_op) + register_binary_op(details::e_add , details::add_op ) + register_binary_op(details::e_sub , details::sub_op ) + register_binary_op(details::e_mul , details::mul_op ) + register_binary_op(details::e_div , details::div_op ) + register_binary_op(details::e_mod , details::mod_op ) + register_binary_op(details::e_pow , details::pow_op ) + register_binary_op(details::e_lt , details::lt_op ) + register_binary_op(details::e_lte , details::lte_op ) + register_binary_op(details::e_gt , details::gt_op ) + register_binary_op(details::e_gte , details::gte_op ) + register_binary_op(details::e_eq , details::eq_op ) + register_binary_op(details::e_ne , details::ne_op ) + register_binary_op(details::e_and , details::and_op ) + register_binary_op(details::e_nand , details::nand_op) + register_binary_op(details::e_or , details::or_op ) + register_binary_op(details::e_nor , details::nor_op ) + register_binary_op(details::e_xor , details::xor_op ) + register_binary_op(details::e_xnor , details::xnor_op) #undef register_binary_op } @@ -35321,6 +36782,8 @@ namespace exprtk lexer::helper::sequence_validator sequence_validator_; lexer::helper::sequence_validator_3tokens sequence_validator_3tkns_; + loop_runtime_check_ptr loop_runtime_check_; + template friend void details::disable_type_checking(ParserType& p); }; @@ -35565,8 +37028,8 @@ namespace exprtk if (var) { T& x = var->ref(); - T x_original = x; - T result = integrate(e, x, r0, r1, number_of_intervals); + const T x_original = x; + const T result = integrate(e, x, r0, r1, number_of_intervals); x = x_original; return result; @@ -35585,9 +37048,9 @@ namespace exprtk x = x_init + _2h; const T y0 = e.value(); - x = x_init + h; + x = x_init + h; const T y1 = e.value(); - x = x_init - h; + x = x_init - h; const T y2 = e.value(); x = x_init - _2h; const T y3 = e.value(); @@ -35607,9 +37070,9 @@ namespace exprtk const T y = e.value(); x = x_init + _2h; const T y0 = e.value(); - x = x_init + h; + x = x_init + h; const T y1 = e.value(); - x = x_init - h; + x = x_init - h; const T y2 = e.value(); x = x_init - _2h; const T y3 = e.value(); @@ -35628,9 +37091,9 @@ namespace exprtk x = x_init + _2h; const T y0 = e.value(); - x = x_init + h; + x = x_init + h; const T y1 = e.value(); - x = x_init - h; + x = x_init - h; const T y2 = e.value(); x = x_init - _2h; const T y3 = e.value(); @@ -35656,8 +37119,8 @@ namespace exprtk if (var) { T& x = var->ref(); - T x_original = x; - T result = derivative(e, x, h); + const T x_original = x; + const T result = derivative(e, x, h); x = x_original; return result; @@ -36004,62 +37467,62 @@ namespace exprtk inline virtual T operator() (const T& x, const T& c1, const T& c0) { - poly_rtrn(1) poly_impl::evaluate(x,c1,c0); + poly_rtrn(1) (poly_impl::evaluate(x, c1, c0)); } inline virtual T operator() (const T& x, const T& c2, const T& c1, const T& c0) { - poly_rtrn(2) poly_impl::evaluate(x,c2,c1,c0); + poly_rtrn(2) (poly_impl::evaluate(x, c2, c1, c0)); } inline virtual T operator() (const T& x, const T& c3, const T& c2, const T& c1, const T& c0) { - poly_rtrn(3) poly_impl::evaluate(x,c3,c2,c1,c0); + poly_rtrn(3) (poly_impl::evaluate(x, c3, c2, c1, c0)); } inline virtual T operator() (const T& x, const T& c4, const T& c3, const T& c2, const T& c1, const T& c0) { - poly_rtrn(4) poly_impl::evaluate(x,c4,c3,c2,c1,c0); + poly_rtrn(4) (poly_impl::evaluate(x, c4, c3, c2, c1, c0)); } inline virtual T operator() (const T& x, const T& c5, const T& c4, const T& c3, const T& c2, const T& c1, const T& c0) { - poly_rtrn(5) poly_impl::evaluate(x,c5,c4,c3,c2,c1,c0); + poly_rtrn(5) (poly_impl::evaluate(x, c5, c4, c3, c2, c1, c0)); } inline virtual T operator() (const T& x, const T& c6, const T& c5, const T& c4, const T& c3, const T& c2, const T& c1, const T& c0) { - poly_rtrn(6) poly_impl::evaluate(x,c6,c5,c4,c3,c2,c1,c0); + poly_rtrn(6) (poly_impl::evaluate(x, c6, c5, c4, c3, c2, c1, c0)); } inline virtual T operator() (const T& x, const T& c7, const T& c6, const T& c5, const T& c4, const T& c3, const T& c2, const T& c1, const T& c0) { - poly_rtrn(7) poly_impl::evaluate(x,c7,c6,c5,c4,c3,c2,c1,c0); + poly_rtrn(7) (poly_impl::evaluate(x, c7, c6, c5, c4, c3, c2, c1, c0)); } inline virtual T operator() (const T& x, const T& c8, const T& c7, const T& c6, const T& c5, const T& c4, const T& c3, const T& c2, const T& c1, const T& c0) { - poly_rtrn(8) poly_impl::evaluate(x,c8,c7,c6,c5,c4,c3,c2,c1,c0); + poly_rtrn(8) (poly_impl::evaluate(x, c8, c7, c6, c5, c4, c3, c2, c1, c0)); } inline virtual T operator() (const T& x, const T& c9, const T& c8, const T& c7, const T& c6, const T& c5, const T& c4, const T& c3, const T& c2, const T& c1, const T& c0) { - poly_rtrn(9) poly_impl::evaluate(x,c9,c8,c7,c6,c5,c4,c3,c2,c1,c0); + poly_rtrn(9) (poly_impl::evaluate(x, c9, c8, c7, c6, c5, c4, c3, c2, c1, c0)); } inline virtual T operator() (const T& x, const T& c10, const T& c9, const T& c8, const T& c7, const T& c6, const T& c5, const T& c4, const T& c3, const T& c2, const T& c1, const T& c0) { - poly_rtrn(10) poly_impl::evaluate(x,c10,c9,c8,c7,c6,c5,c4,c3,c2,c1,c0); + poly_rtrn(10) (poly_impl::evaluate(x, c10, c9, c8, c7, c6, c5, c4, c3, c2, c1, c0)); } inline virtual T operator() (const T& x, const T& c11, const T& c10, const T& c9, const T& c8, const T& c7, const T& c6, const T& c5, const T& c4, const T& c3, const T& c2, const T& c1, const T& c0) { - poly_rtrn(11) poly_impl::evaluate(x,c11,c10,c9,c8,c7,c6,c5,c4,c3,c2,c1,c0); + poly_rtrn(11) (poly_impl::evaluate(x, c11, c10, c9, c8, c7, c6, c5, c4, c3, c2, c1, c0)); } inline virtual T operator() (const T& x, const T& c12, const T& c11, const T& c10, const T& c9, const T& c8, const T& c7, const T& c6, const T& c5, const T& c4, const T& c3, const T& c2, const T& c1, const T& c0) { - poly_rtrn(12) poly_impl::evaluate(x,c12,c11,c10,c9,c8,c7,c6,c5,c4,c3,c2,c1,c0); + poly_rtrn(12) (poly_impl::evaluate(x, c12, c11, c10, c9, c8, c7, c6, c5, c4, c3, c2, c1, c0)); } #undef poly_rtrn @@ -36101,15 +37564,15 @@ namespace exprtk function(const std::string& name, const std::string& expression) - : name_(name), - expression_(expression) + : name_(name) + , expression_(expression) {} function(const std::string& name, const std::string& expression, const std::string& v0) - : name_(name), - expression_(expression) + : name_(name) + , expression_(expression) { v_.push_back(v0); } @@ -36117,8 +37580,8 @@ namespace exprtk function(const std::string& name, const std::string& expression, const std::string& v0, const std::string& v1) - : name_(name), - expression_(expression) + : name_(name) + , expression_(expression) { v_.push_back(v0); v_.push_back(v1); } @@ -36127,8 +37590,8 @@ namespace exprtk const std::string& expression, const std::string& v0, const std::string& v1, const std::string& v2) - : name_(name), - expression_(expression) + : name_(name) + , expression_(expression) { v_.push_back(v0); v_.push_back(v1); v_.push_back(v2); @@ -36138,8 +37601,8 @@ namespace exprtk const std::string& expression, const std::string& v0, const std::string& v1, const std::string& v2, const std::string& v3) - : name_(name), - expression_(expression) + : name_(name) + , expression_(expression) { v_.push_back(v0); v_.push_back(v1); v_.push_back(v2); v_.push_back(v3); @@ -36150,8 +37613,8 @@ namespace exprtk const std::string& v0, const std::string& v1, const std::string& v2, const std::string& v3, const std::string& v4) - : name_(name), - expression_(expression) + : name_(name) + , expression_(expression) { v_.push_back(v0); v_.push_back(v1); v_.push_back(v2); v_.push_back(v3); @@ -36195,9 +37658,9 @@ namespace exprtk using exprtk::ifunction::operator(); base_func(const std::size_t& pc = 0) - : exprtk::ifunction(pc), - local_var_stack_size(0), - stack_depth(0) + : exprtk::ifunction(pc) + , local_var_stack_size(0) + , stack_depth(0) { v.resize(pc); } @@ -36247,7 +37710,7 @@ namespace exprtk typedef typename expression_t::control_block::local_data_list_t ldl_t; - ldl_t ldl = expr.local_data_list(); + const ldl_t ldl = expr.local_data_list(); std::vector index_list; @@ -36416,8 +37879,16 @@ namespace exprtk template struct scoped_bft { - scoped_bft(BaseFuncType& bft) : bft_(bft) { bft_.pre (); } - ~scoped_bft() { bft_.post(); } + explicit scoped_bft(BaseFuncType& bft) + : bft_(bft) + { + bft_.pre (); + } + + ~scoped_bft() + { + bft_.post(); + } BaseFuncType& bft_; @@ -36517,7 +37988,7 @@ namespace exprtk typedef typename results_context_t::type_store_t type_t; typedef typename type_t::scalar_view scalar_t; - T result = e.value(); + const T result = e.value(); if (e.return_invoked()) { @@ -36569,7 +38040,7 @@ namespace exprtk remove(name, var_list.size()); } - if (compile_expression(name,expression,var_list)) + if (compile_expression(name, expression, var_list)) { const std::size_t n = var_list.size(); @@ -36590,15 +38061,15 @@ namespace exprtk function_compositor() : parser_(settings_t::compile_all_opts + - settings_t::e_disable_zero_return), - fp_map_(7) + settings_t::e_disable_zero_return) + , fp_map_(7) {} function_compositor(const symbol_table_t& st) - : symbol_table_(st), - parser_(settings_t::compile_all_opts + - settings_t::e_disable_zero_return), - fp_map_(7) + : symbol_table_(st) + , parser_(settings_t::compile_all_opts + + settings_t::e_disable_zero_return) + , fp_map_(7) {} ~function_compositor() @@ -36611,6 +38082,11 @@ namespace exprtk return symbol_table_; } + inline const symbol_table_t& symbol_table() const + { + return symbol_table_; + } + inline void add_auxiliary_symtab(symbol_table_t& symtab) { auxiliary_symtab_list_.push_back(&symtab); @@ -36826,89 +38302,90 @@ namespace exprtk template inline bool pgo_primer() { - static const std::string expression_list[] - = { - "(y + x)", - "2 * (y + x)", - "(2 * y + 2 * x)", - "(y + x / y) * (x - y / x)", - "x / ((x + y) * (x - y)) / y", - "1 - ((x * y) + (y / x)) - 3", - "sin(2 * x) + cos(pi / y)", - "1 - sin(2 * x) + cos(pi / y)", - "sqrt(1 - sin(2 * x) + cos(pi / y) / 3)", - "(x^2 / sin(2 * pi / y)) -x / 2", - "x + (cos(y - sin(2 / x * pi)) - sin(x - cos(2 * y / pi))) - y", - "clamp(-1.0, sin(2 * pi * x) + cos(y / 2 * pi), +1.0)", - "iclamp(-1.0, sin(2 * pi * x) + cos(y / 2 * pi), +1.0)", - "max(3.33, min(sqrt(1 - sin(2 * x) + cos(pi / y) / 3), 1.11))", - "if(avg(x,y) <= x + y, x - y, x * y) + 2 * pi / x", - "1.1x^1 + 2.2y^2 - 3.3x^3 + 4.4y^4 - 5.5x^5 + 6.6y^6 - 7.7x^27 + 8.8y^55", - "(yy + xx)", - "2 * (yy + xx)", - "(2 * yy + 2 * xx)", - "(yy + xx / yy) * (xx - yy / xx)", - "xx / ((xx + yy) * (xx - yy)) / yy", - "1 - ((xx * yy) + (yy / xx)) - 3", - "sin(2 * xx) + cos(pi / yy)", - "1 - sin(2 * xx) + cos(pi / yy)", - "sqrt(1 - sin(2 * xx) + cos(pi / yy) / 3)", - "(xx^2 / sin(2 * pi / yy)) -xx / 2", - "xx + (cos(yy - sin(2 / xx * pi)) - sin(xx - cos(2 * yy / pi))) - yy", - "clamp(-1.0, sin(2 * pi * xx) + cos(yy / 2 * pi), +1.0)", - "max(3.33, min(sqrt(1 - sin(2 * xx) + cos(pi / yy) / 3), 1.11))", - "if(avg(xx,yy) <= xx + yy, xx - yy, xx * yy) + 2 * pi / xx", - "1.1xx^1 + 2.2yy^2 - 3.3xx^3 + 4.4yy^4 - 5.5xx^5 + 6.6yy^6 - 7.7xx^27 + 8.8yy^55", - "(1.1*(2.2*(3.3*(4.4*(5.5*(6.6*(7.7*(8.8*(9.9+x)))))))))", - "(((((((((x+9.9)*8.8)*7.7)*6.6)*5.5)*4.4)*3.3)*2.2)*1.1)", - "(x + y) * z", "x + (y * z)", "(x + y) * 7", "x + (y * 7)", - "(x + 7) * y", "x + (7 * y)", "(7 + x) * y", "7 + (x * y)", - "(2 + x) * 3", "2 + (x * 3)", "(2 + 3) * x", "2 + (3 * x)", - "(x + 2) * 3", "x + (2 * 3)", - "(x + y) * (z / w)", "(x + y) * (z / 7)", "(x + y) * (7 / z)", "(x + 7) * (y / z)", - "(7 + x) * (y / z)", "(2 + x) * (y / z)", "(x + 2) * (y / 3)", "(2 + x) * (y / 3)", - "(x + 2) * (3 / y)", "x + (y * (z / w))", "x + (y * (z / 7))", "x + (y * (7 / z))", - "x + (7 * (y / z))", "7 + (x * (y / z))", "2 + (x * (3 / y))", "x + (2 * (y / 4))", - "2 + (x * (y / 3))", "x + (2 * (3 / y))", - "x + ((y * z) / w)", "x + ((y * z) / 7)", "x + ((y * 7) / z)", "x + ((7 * y) / z)", - "7 + ((y * z) / w)", "2 + ((x * 3) / y)", "x + ((2 * y) / 3)", "2 + ((x * y) / 3)", - "x + ((2 * 3) / y)", "(((x + y) * z) / w)", - "(((x + y) * z) / 7)", "(((x + y) * 7) / z)", "(((x + 7) * y) / z)", "(((7 + x) * y) / z)", - "(((2 + x) * 3) / y)", "(((x + 2) * y) / 3)", "(((2 + x) * y) / 3)", "(((x + 2) * 3) / y)", - "((x + (y * z)) / w)", "((x + (y * z)) / 7)", "((x + (y * 7)) / y)", "((x + (7 * y)) / z)", - "((7 + (x * y)) / z)", "((2 + (x * 3)) / y)", "((x + (2 * y)) / 3)", "((2 + (x * y)) / 3)", - "((x + (2 * 3)) / y)", - "(xx + yy) * zz", "xx + (yy * zz)", - "(xx + yy) * 7", "xx + (yy * 7)", - "(xx + 7) * yy", "xx + (7 * yy)", - "(7 + xx) * yy", "7 + (xx * yy)", - "(2 + x) * 3", "2 + (x * 3)", - "(2 + 3) * x", "2 + (3 * x)", - "(x + 2) * 3", "x + (2 * 3)", - "(xx + yy) * (zz / ww)", "(xx + yy) * (zz / 7)", - "(xx + yy) * (7 / zz)", "(xx + 7) * (yy / zz)", - "(7 + xx) * (yy / zz)", "(2 + xx) * (yy / zz)", - "(xx + 2) * (yy / 3)", "(2 + xx) * (yy / 3)", - "(xx + 2) * (3 / yy)", "xx + (yy * (zz / ww))", - "xx + (yy * (zz / 7))", "xx + (yy * (7 / zz))", - "xx + (7 * (yy / zz))", "7 + (xx * (yy / zz))", - "2 + (xx * (3 / yy))", "xx + (2 * (yy / 4))", - "2 + (xx * (yy / 3))", "xx + (2 * (3 / yy))", - "xx + ((yy * zz) / ww)", "xx + ((yy * zz) / 7)", - "xx + ((yy * 7) / zz)", "xx + ((7 * yy) / zz)", - "7 + ((yy * zz) / ww)", "2 + ((xx * 3) / yy)", - "xx + ((2 * yy) / 3)", "2 + ((xx * yy) / 3)", - "xx + ((2 * 3) / yy)", "(((xx + yy) * zz) / ww)", - "(((xx + yy) * zz) / 7)", "(((xx + yy) * 7) / zz)", - "(((xx + 7) * yy) / zz)", "(((7 + xx) * yy) / zz)", - "(((2 + xx) * 3) / yy)", "(((xx + 2) * yy) / 3)", - "(((2 + xx) * yy) / 3)", "(((xx + 2) * 3) / yy)", - "((xx + (yy * zz)) / ww)", "((xx + (yy * zz)) / 7)", - "((xx + (yy * 7)) / yy)", "((xx + (7 * yy)) / zz)", - "((7 + (xx * yy)) / zz)", "((2 + (xx * 3)) / yy)", - "((xx + (2 * yy)) / 3)", "((2 + (xx * yy)) / 3)", - "((xx + (2 * 3)) / yy)" - }; + static const std::string expression_list[] = + { + "(y + x)", + "2 * (y + x)", + "(2 * y + 2 * x)", + "(y + x / y) * (x - y / x)", + "x / ((x + y) * (x - y)) / y", + "1 - ((x * y) + (y / x)) - 3", + "sin(2 * x) + cos(pi / y)", + "1 - sin(2 * x) + cos(pi / y)", + "sqrt(1 - sin(2 * x) + cos(pi / y) / 3)", + "(x^2 / sin(2 * pi / y)) -x / 2", + "x + (cos(y - sin(2 / x * pi)) - sin(x - cos(2 * y / pi))) - y", + "clamp(-1.0, sin(2 * pi * x) + cos(y / 2 * pi), +1.0)", + "iclamp(-1.0, sin(2 * pi * x) + cos(y / 2 * pi), +1.0)", + "max(3.33, min(sqrt(1 - sin(2 * x) + cos(pi / y) / 3), 1.11))", + "if(avg(x,y) <= x + y, x - y, x * y) + 2 * pi / x", + "1.1x^1 + 2.2y^2 - 3.3x^3 + 4.4y^4 - 5.5x^5 + 6.6y^6 - 7.7x^27 + 8.8y^55", + "(yy + xx)", + "2 * (yy + xx)", + "(2 * yy + 2 * xx)", + "(yy + xx / yy) * (xx - yy / xx)", + "xx / ((xx + yy) * (xx - yy)) / yy", + "1 - ((xx * yy) + (yy / xx)) - 3", + "sin(2 * xx) + cos(pi / yy)", + "1 - sin(2 * xx) + cos(pi / yy)", + "sqrt(1 - sin(2 * xx) + cos(pi / yy) / 3)", + "(xx^2 / sin(2 * pi / yy)) -xx / 2", + "xx + (cos(yy - sin(2 / xx * pi)) - sin(xx - cos(2 * yy / pi))) - yy", + "clamp(-1.0, sin(2 * pi * xx) + cos(yy / 2 * pi), +1.0)", + "max(3.33, min(sqrt(1 - sin(2 * xx) + cos(pi / yy) / 3), 1.11))", + "if(avg(xx,yy) <= xx + yy, xx - yy, xx * yy) + 2 * pi / xx", + "1.1xx^1 + 2.2yy^2 - 3.3xx^3 + 4.4yy^4 - 5.5xx^5 + 6.6yy^6 - 7.7xx^27 + 8.8yy^55", + "(1.1*(2.2*(3.3*(4.4*(5.5*(6.6*(7.7*(8.8*(9.9+x)))))))))", + "(((((((((x+9.9)*8.8)*7.7)*6.6)*5.5)*4.4)*3.3)*2.2)*1.1)", + "(x + y) * z", "x + (y * z)", "(x + y) * 7", "x + (y * 7)", + "(x + 7) * y", "x + (7 * y)", "(7 + x) * y", "7 + (x * y)", + "(2 + x) * 3", "2 + (x * 3)", "(2 + 3) * x", "2 + (3 * x)", + "(x + 2) * 3", "x + (2 * 3)", + "(x + y) * (z / w)", "(x + y) * (z / 7)", "(x + y) * (7 / z)", "(x + 7) * (y / z)", + "(7 + x) * (y / z)", "(2 + x) * (y / z)", "(x + 2) * (y / 3)", "(2 + x) * (y / 3)", + "(x + 2) * (3 / y)", "x + (y * (z / w))", "x + (y * (z / 7))", "x + (y * (7 / z))", + "x + (7 * (y / z))", "7 + (x * (y / z))", "2 + (x * (3 / y))", "x + (2 * (y / 4))", + "2 + (x * (y / 3))", "x + (2 * (3 / y))", + "x + ((y * z) / w)", "x + ((y * z) / 7)", "x + ((y * 7) / z)", "x + ((7 * y) / z)", + "7 + ((y * z) / w)", "2 + ((x * 3) / y)", "x + ((2 * y) / 3)", "2 + ((x * y) / 3)", + "x + ((2 * 3) / y)", "(((x + y) * z) / w)", + "(((x + y) * z) / 7)", "(((x + y) * 7) / z)", "(((x + 7) * y) / z)", "(((7 + x) * y) / z)", + "(((2 + x) * 3) / y)", "(((x + 2) * y) / 3)", "(((2 + x) * y) / 3)", "(((x + 2) * 3) / y)", + "((x + (y * z)) / w)", "((x + (y * z)) / 7)", "((x + (y * 7)) / y)", "((x + (7 * y)) / z)", + "((7 + (x * y)) / z)", "((2 + (x * 3)) / y)", "((x + (2 * y)) / 3)", "((2 + (x * y)) / 3)", + "((x + (2 * 3)) / y)", + "(xx + yy) * zz", "xx + (yy * zz)", + "(xx + yy) * 7", "xx + (yy * 7)", + "(xx + 7) * yy", "xx + (7 * yy)", + "(7 + xx) * yy", "7 + (xx * yy)", + "(2 + x) * 3", "2 + (x * 3)", + "(2 + 3) * x", "2 + (3 * x)", + "(x + 2) * 3", "x + (2 * 3)", + "(xx + yy) * (zz / ww)", "(xx + yy) * (zz / 7)", + "(xx + yy) * (7 / zz)", "(xx + 7) * (yy / zz)", + "(7 + xx) * (yy / zz)", "(2 + xx) * (yy / zz)", + "(xx + 2) * (yy / 3)", "(2 + xx) * (yy / 3)", + "(xx + 2) * (3 / yy)", "xx + (yy * (zz / ww))", + "xx + (yy * (zz / 7))", "xx + (yy * (7 / zz))", + "xx + (7 * (yy / zz))", "7 + (xx * (yy / zz))", + "2 + (xx * (3 / yy))", "xx + (2 * (yy / 4))", + "2 + (xx * (yy / 3))", "xx + (2 * (3 / yy))", + "xx + ((yy * zz) / ww)", "xx + ((yy * zz) / 7)", + "xx + ((yy * 7) / zz)", "xx + ((7 * yy) / zz)", + "7 + ((yy * zz) / ww)", "2 + ((xx * 3) / yy)", + "xx + ((2 * yy) / 3)", "2 + ((xx * yy) / 3)", + "xx + ((2 * 3) / yy)", "(((xx + yy) * zz) / ww)", + "(((xx + yy) * zz) / 7)", "(((xx + yy) * 7) / zz)", + "(((xx + 7) * yy) / zz)", "(((7 + xx) * yy) / zz)", + "(((2 + xx) * 3) / yy)", "(((xx + 2) * yy) / 3)", + "(((2 + xx) * yy) / 3)", "(((xx + 2) * 3) / yy)", + "((xx + (yy * zz)) / ww)", "((xx + (yy * zz)) / 7)", + "((xx + (yy * 7)) / yy)", "((xx + (7 * yy)) / zz)", + "((7 + (xx * yy)) / zz)", "((2 + (xx * 3)) / yy)", + "((xx + (2 * yy)) / 3)", "((2 + (xx * yy)) / 3)", + "((xx + (2 * 3)) / yy)" + }; + static const std::size_t expression_list_size = sizeof(expression_list) / sizeof(std::string); T x = T(0); @@ -36990,7 +38467,7 @@ namespace exprtk { const T v = T(123.456 + i); - if (details::is_true(details::numeric::nequal(details::numeric::fast_exp::result(v),details::numeric::pow(v,T( 1))))) + if (details::is_true(details::numeric::nequal(details::numeric::fast_exp::result(v),details::numeric::pow(v,T(1))))) return false; #define else_stmt(N) \ @@ -37071,6 +38548,7 @@ namespace exprtk { start_time_.tv_sec = 0; start_time_.tv_usec = 0; + stop_time_.tv_sec = 0; stop_time_.tv_usec = 0; } @@ -37093,14 +38571,14 @@ namespace exprtk { if (stop_time_.tv_sec >= start_time_.tv_sec) { - return 1000000LLU * static_cast(stop_time_.tv_sec - start_time_.tv_sec ) + - static_cast(stop_time_.tv_usec - start_time_.tv_usec) ; + return 1000000LLU * static_cast(stop_time_.tv_sec - start_time_.tv_sec ) + + static_cast(stop_time_.tv_usec - start_time_.tv_usec) ; } else - return std::numeric_limits::max(); + return std::numeric_limits::max(); } else - return std::numeric_limits::max(); + return std::numeric_limits::max(); } inline double time() const @@ -37129,6 +38607,17 @@ namespace exprtk #endif }; + template + struct type_defs + { + typedef symbol_table symbol_table_t; + typedef expression expression_t; + typedef parser parser_t; + typedef parser_error::type error_t; + typedef function_compositor compositor_t; + typedef typename compositor_t::function function_t; + }; + } // namespace exprtk #ifndef exprtk_disable_rtl_io @@ -37262,7 +38751,7 @@ namespace exprtk return false; \ } \ - exprtk_register_function("print" , p) + exprtk_register_function("print" , p ) exprtk_register_function("println", pl) #undef exprtk_register_function @@ -37292,9 +38781,9 @@ namespace exprtk struct file_descriptor { file_descriptor(const std::string& fname, const std::string& access) - : stream_ptr(0), - mode(get_file_mode(access)), - file_name(fname) + : stream_ptr(0) + , mode(get_file_mode(access)) + , file_name(fname) {} void* stream_ptr; @@ -37596,32 +39085,32 @@ namespace exprtk { details::file_descriptor* fd = details::make_handle(scalar_t(parameters[0])()); - std::size_t amount = 0; - switch (ps_index) { case 0 : { const string_t buffer(parameters[1]); - amount = buffer.size(); + const std::size_t amount = buffer.size(); return T(fd->write(buffer, amount) ? 1 : 0); } case 1 : { const string_t buffer(parameters[1]); - amount = std::min(buffer.size(), + const std::size_t amount = + std::min(buffer.size(), static_cast(scalar_t(parameters[2])())); return T(fd->write(buffer, amount) ? 1 : 0); } case 2 : { const vector_t vec(parameters[1]); - amount = vec.size(); + const std::size_t amount = vec.size(); return T(fd->write(vec, amount) ? 1 : 0); } case 3 : { const vector_t vec(parameters[1]); - amount = std::min(vec.size(), + const std::size_t amount = + std::min(vec.size(), static_cast(scalar_t(parameters[2])())); return T(fd->write(vec, amount) ? 1 : 0); } @@ -37653,32 +39142,32 @@ namespace exprtk { details::file_descriptor* fd = details::make_handle(scalar_t(parameters[0])()); - std::size_t amount = 0; - switch (ps_index) { case 0 : { string_t buffer(parameters[1]); - amount = buffer.size(); + const std::size_t amount = buffer.size(); return T(fd->read(buffer,amount) ? 1 : 0); } case 1 : { string_t buffer(parameters[1]); - amount = std::min(buffer.size(), + const std::size_t amount = + std::min(buffer.size(), static_cast(scalar_t(parameters[2])())); return T(fd->read(buffer,amount) ? 1 : 0); } case 2 : { vector_t vec(parameters[1]); - amount = vec.size(); + const std::size_t amount = vec.size(); return T(fd->read(vec,amount) ? 1 : 0); } case 3 : { vector_t vec(parameters[1]); - amount = std::min(vec.size(), + const std::size_t amount = + std::min(vec.size(), static_cast(scalar_t(parameters[2])())); return T(fd->read(vec,amount) ? 1 : 0); } @@ -37751,12 +39240,12 @@ namespace exprtk return false; \ } \ - exprtk_register_function("open" ,o) - exprtk_register_function("close" ,c) - exprtk_register_function("write" ,w) - exprtk_register_function("read" ,r) - exprtk_register_function("getline",g) - exprtk_register_function("eof" ,e) + exprtk_register_function("open" , o) + exprtk_register_function("close" , c) + exprtk_register_function("write" , w) + exprtk_register_function("read" , r) + exprtk_register_function("getline" , g) + exprtk_register_function("eof" , e) #undef exprtk_register_function return true; @@ -38107,7 +39596,10 @@ namespace exprtk const std::size_t n = std::min(xr1 - xr0 + 1, yr1 - yr0 + 1); - std::copy(x.begin() + xr0, x.begin() + xr0 + n, y.begin() + yr0); + std::copy( + x.begin() + xr0, + x.begin() + xr0 + n, + y.begin() + yr0); return T(n); } @@ -38152,10 +39644,13 @@ namespace exprtk ) return T(0); - std::size_t dist = r1 - r0 + 1; - std::size_t shift = n % dist; + const std::size_t dist = r1 - r0 + 1; + const std::size_t shift = n % dist; - std::rotate(vec.begin() + r0, vec.begin() + r0 + shift, vec.begin() + r1 + 1); + std::rotate( + vec.begin() + r0, + vec.begin() + r0 + shift, + vec.begin() + r1 + 1); return T(1); } @@ -38203,7 +39698,10 @@ namespace exprtk std::size_t dist = r1 - r0 + 1; std::size_t shift = (dist - (n % dist)) % dist; - std::rotate(vec.begin() + r0, vec.begin() + r0 + shift, vec.begin() + r1 + 1); + std::rotate( + vec.begin() + r0, + vec.begin() + r0 + shift, + vec.begin() + r1 + 1); return T(1); } @@ -38248,12 +39746,15 @@ namespace exprtk ) return T(0); - std::size_t dist = r1 - r0 + 1; + const std::size_t dist = r1 - r0 + 1; if (n > dist) return T(0); - std::rotate(vec.begin() + r0, vec.begin() + r0 + n, vec.begin() + r1 + 1); + std::rotate( + vec.begin() + r0, + vec.begin() + r0 + n, + vec.begin() + r1 + 1); for (std::size_t i = r1 - n + 1; i <= r1; ++i) { @@ -38303,14 +39804,17 @@ namespace exprtk ) return T(0); - std::size_t dist = r1 - r0 + 1; + const std::size_t dist = r1 - r0 + 1; if (n > dist) return T(0); - std::size_t shift = (dist - (n % dist)) % dist; + const std::size_t shift = (dist - (n % dist)) % dist; - std::rotate(vec.begin() + r0, vec.begin() + r0 + shift, vec.begin() + r1 + 1); + std::rotate( + vec.begin() + r0, + vec.begin() + r0 + shift, + vec.begin() + r1 + 1); for (std::size_t i = r0; i < r0 + n; ++i) { @@ -38370,9 +39874,15 @@ namespace exprtk } if (ascending) - std::sort(vec.begin() + r0, vec.begin() + r1 + 1, std::less ()); + std::sort( + vec.begin() + r0, + vec.begin() + r1 + 1, + std::less()); else - std::sort(vec.begin() + r0, vec.begin() + r1 + 1, std::greater()); + std::sort( + vec.begin() + r0, + vec.begin() + r1 + 1, + std::greater()); return T(1); } @@ -38414,7 +39924,10 @@ namespace exprtk if ((1 == ps_index) && !helper::load_vector_range::process(parameters, r0, r1, 2, 3, 0)) return std::numeric_limits::quiet_NaN(); - std::nth_element(vec.begin() + r0, vec.begin() + r0 + n , vec.begin() + r1 + 1); + std::nth_element( + vec.begin() + r0, + vec.begin() + r0 + n , + vec.begin() + r1 + 1); return T(1); } @@ -38888,29 +40401,29 @@ namespace exprtk return false; \ } \ - exprtk_register_function("all_true" ,at) - exprtk_register_function("all_false" ,af) - exprtk_register_function("any_true" ,nt) - exprtk_register_function("any_false" ,nf) - exprtk_register_function("count" , c) - exprtk_register_function("copy" ,cp) - exprtk_register_function("rotate_left" ,rl) - exprtk_register_function("rol" ,rl) - exprtk_register_function("rotate_right" ,rr) - exprtk_register_function("ror" ,rr) - exprtk_register_function("shftl" ,sl) - exprtk_register_function("shftr" ,sr) - exprtk_register_function("sort" ,st) - exprtk_register_function("nth_element" ,ne) - exprtk_register_function("iota" ,ia) - exprtk_register_function("sumk" ,sk) - exprtk_register_function("axpy" ,b1_axpy) - exprtk_register_function("axpby" ,b1_axpby) - exprtk_register_function("axpyz" ,b1_axpyz) - exprtk_register_function("axpbyz",b1_axpbyz) - exprtk_register_function("axpbz" ,b1_axpbz) - exprtk_register_function("dot" ,dt) - exprtk_register_function("dotk" ,dtk) + exprtk_register_function("all_true" , at ) + exprtk_register_function("all_false" , af ) + exprtk_register_function("any_true" , nt ) + exprtk_register_function("any_false" , nf ) + exprtk_register_function("count" , c ) + exprtk_register_function("copy" , cp ) + exprtk_register_function("rotate_left" , rl ) + exprtk_register_function("rol" , rl ) + exprtk_register_function("rotate_right" , rr ) + exprtk_register_function("ror" , rr ) + exprtk_register_function("shftl" , sl ) + exprtk_register_function("shftr" , sr ) + exprtk_register_function("sort" , st ) + exprtk_register_function("nth_element" , ne ) + exprtk_register_function("iota" , ia ) + exprtk_register_function("sumk" , sk ) + exprtk_register_function("axpy" , b1_axpy ) + exprtk_register_function("axpby" , b1_axpby ) + exprtk_register_function("axpyz" , b1_axpyz ) + exprtk_register_function("axpbyz" , b1_axpbyz) + exprtk_register_function("axpbz" , b1_axpbz ) + exprtk_register_function("dot" , dt ) + exprtk_register_function("dotk" , dtk ) #undef exprtk_register_function return true; @@ -38927,9 +40440,11 @@ namespace exprtk namespace information { static const char* library = "Mathematical Expression Toolkit"; - static const char* version = "2.7182818284590452353602874713526624977572470936999595749" - "669676277240766303535475945713821785251664274274663919320"; - static const char* date = "20200101"; + static const char* version = "2.718281828459045235360287471352" + "66249775724709369995957496696762" + "77240766303535475945713821785251" + "66427427466391932003059921817413"; + static const char* date = "20210101"; static inline std::string data() { @@ -38957,6 +40472,14 @@ namespace exprtk #undef exprtk_disable_fallthrough_end #endif + #ifdef exprtk_override + #undef exprtk_override + #endif + + #ifdef exprtk_final + #undef exprtk_final + #endif + } // namespace exprtk #endif diff --git a/exprtk/exprtk_benchmark.cpp b/exprtk/exprtk_benchmark.cpp index 8e9c5fa..1e94f5f 100644 --- a/exprtk/exprtk_benchmark.cpp +++ b/exprtk/exprtk_benchmark.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * ExprTk vs Native Benchmarks * - * Author: Arash Partow (1999-2020) * + * Author: Arash Partow (1999-2021) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * @@ -150,7 +150,7 @@ template bool run_parse_benchmark(exprtk::symbol_table& symbol_table) { static const std::size_t rounds = 100000; - exprtk::parser parser; + exprtk::parser parser; exprtk::expression expression; expression.register_symbol_table(symbol_table); @@ -431,8 +431,8 @@ void perform_file_based_benchmark(const std::string& file_name, const std::size_ } typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; std::deque expression_list; diff --git a/exprtk/exprtk_simple_example_01.cpp b/exprtk/exprtk_simple_example_01.cpp index 80eafe1..f1fb113 100644 --- a/exprtk/exprtk_simple_example_01.cpp +++ b/exprtk/exprtk_simple_example_01.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 1 * - * Author: Arash Partow (1999-2020) * + * Author: Arash Partow (1999-2021) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * @@ -26,8 +26,8 @@ template void trig_function() { typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; const std::string expression_string = "clamp(-1.0,sin(2 * pi * x) + cos(x / 2 * pi),+1.0)"; diff --git a/exprtk/exprtk_simple_example_02.cpp b/exprtk/exprtk_simple_example_02.cpp index 56b9c9b..ef7f70c 100644 --- a/exprtk/exprtk_simple_example_02.cpp +++ b/exprtk/exprtk_simple_example_02.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 2 * - * Author: Arash Partow (1999-2020) * + * Author: Arash Partow (1999-2021) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * @@ -26,8 +26,8 @@ template void square_wave() { typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; const std::string expr_string = "a*(4/pi)*" diff --git a/exprtk/exprtk_simple_example_03.cpp b/exprtk/exprtk_simple_example_03.cpp index 8e5a164..0de505e 100644 --- a/exprtk/exprtk_simple_example_03.cpp +++ b/exprtk/exprtk_simple_example_03.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 3 * - * Author: Arash Partow (1999-2020) * + * Author: Arash Partow (1999-2021) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * @@ -26,8 +26,8 @@ template void polynomial() { typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; const std::string expression_string = "25x^5 - 35x^4 - 15x^3 + 40x^2 - 15x + 1"; diff --git a/exprtk/exprtk_simple_example_04.cpp b/exprtk/exprtk_simple_example_04.cpp index aca7014..0b25ec5 100644 --- a/exprtk/exprtk_simple_example_04.cpp +++ b/exprtk/exprtk_simple_example_04.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 4 * - * Author: Arash Partow (1999-2020) * + * Author: Arash Partow (1999-2021) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * @@ -25,11 +25,11 @@ template void fibonacci() { - typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; - typedef exprtk::function_compositor compositor_t; - typedef typename compositor_t::function function_t; + typedef exprtk::symbol_table symbol_table_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; + typedef exprtk::function_compositor compositor_t; + typedef typename compositor_t::function function_t; compositor_t compositor; diff --git a/exprtk/exprtk_simple_example_05.cpp b/exprtk/exprtk_simple_example_05.cpp index 50d7987..4450fb2 100644 --- a/exprtk/exprtk_simple_example_05.cpp +++ b/exprtk/exprtk_simple_example_05.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 5 * - * Author: Arash Partow (1999-2020) * + * Author: Arash Partow (1999-2021) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * @@ -47,8 +47,8 @@ template void custom_function() { typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; const std::string expression_string = "myfunc(sin(x / pi), otherfunc(3 * y, x / 2, x * y))"; diff --git a/exprtk/exprtk_simple_example_06.cpp b/exprtk/exprtk_simple_example_06.cpp index 0af6f8b..2475905 100644 --- a/exprtk/exprtk_simple_example_06.cpp +++ b/exprtk/exprtk_simple_example_06.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 6 * - * Author: Arash Partow (1999-2020) * + * Author: Arash Partow (1999-2021) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * @@ -26,8 +26,8 @@ template void vector_function() { typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; const std::string expression_string = " for (var i := 0; i < min(x[],y[],z[]); i += 1) " diff --git a/exprtk/exprtk_simple_example_07.cpp b/exprtk/exprtk_simple_example_07.cpp index bdf3c3b..ac7d7e2 100644 --- a/exprtk/exprtk_simple_example_07.cpp +++ b/exprtk/exprtk_simple_example_07.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 7 * - * Author: Arash Partow (1999-2020) * + * Author: Arash Partow (1999-2021) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * @@ -26,8 +26,8 @@ template void logic() { typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; const std::string expression_string = "not(A and B) or C"; diff --git a/exprtk/exprtk_simple_example_08.cpp b/exprtk/exprtk_simple_example_08.cpp index 4565098..f2b76c7 100644 --- a/exprtk/exprtk_simple_example_08.cpp +++ b/exprtk/exprtk_simple_example_08.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 8 * - * Author: Arash Partow (1999-2020) * + * Author: Arash Partow (1999-2021) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * @@ -25,12 +25,12 @@ template void composite() { - typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; - typedef exprtk::parser_error::type err_t; - typedef exprtk::function_compositor compositor_t; - typedef typename compositor_t::function function_t; + typedef exprtk::symbol_table symbol_table_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; + typedef exprtk::parser_error::type error_t; + typedef exprtk::function_compositor compositor_t; + typedef typename compositor_t::function function_t; compositor_t compositor; @@ -65,7 +65,7 @@ void composite() for (std::size_t i = 0; i < parser.error_count(); ++i) { - const err_t error = parser.get_error(i); + const error_t error = parser.get_error(i); printf("Error: %02d Position: %02d Type: [%14s] Msg: %s\tExpression: %s\n", static_cast(i), diff --git a/exprtk/exprtk_simple_example_09.cpp b/exprtk/exprtk_simple_example_09.cpp index b11f193..3a3892c 100644 --- a/exprtk/exprtk_simple_example_09.cpp +++ b/exprtk/exprtk_simple_example_09.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 9 * - * Author: Arash Partow (1999-2020) * + * Author: Arash Partow (1999-2021) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * @@ -25,11 +25,11 @@ template void primes() { - typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; - typedef exprtk::function_compositor compositor_t; - typedef typename compositor_t::function function_t; + typedef exprtk::symbol_table symbol_table_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; + typedef exprtk::function_compositor compositor_t; + typedef typename compositor_t::function function_t; T x = T(0); diff --git a/exprtk/exprtk_simple_example_10.cpp b/exprtk/exprtk_simple_example_10.cpp index 13728da..7b11d7b 100644 --- a/exprtk/exprtk_simple_example_10.cpp +++ b/exprtk/exprtk_simple_example_10.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 10 * - * Author: Arash Partow (1999-2020) * + * Author: Arash Partow (1999-2021) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * @@ -26,11 +26,11 @@ template void newton_sqrt() { - typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; - typedef exprtk::function_compositor compositor_t; - typedef typename compositor_t::function function_t; + typedef exprtk::symbol_table symbol_table_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; + typedef exprtk::function_compositor compositor_t; + typedef typename compositor_t::function function_t; T x = T(0); diff --git a/exprtk/exprtk_simple_example_11.cpp b/exprtk/exprtk_simple_example_11.cpp index 454c8f0..e2ccf35 100644 --- a/exprtk/exprtk_simple_example_11.cpp +++ b/exprtk/exprtk_simple_example_11.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 11 * - * Author: Arash Partow (1999-2020) * + * Author: Arash Partow (1999-2021) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * @@ -26,8 +26,8 @@ template void square_wave2() { typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; const std::string wave_program = " var r := 0; " diff --git a/exprtk/exprtk_simple_example_12.cpp b/exprtk/exprtk_simple_example_12.cpp index ce398bd..d1adb77 100644 --- a/exprtk/exprtk_simple_example_12.cpp +++ b/exprtk/exprtk_simple_example_12.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 12 * - * Author: Arash Partow (1999-2020) * + * Author: Arash Partow (1999-2021) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * @@ -26,8 +26,8 @@ template void bubble_sort() { typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; const std::string bubblesort_program = " var upper_bound := v[]; " diff --git a/exprtk/exprtk_simple_example_13.cpp b/exprtk/exprtk_simple_example_13.cpp index 839e749..2e8cb32 100644 --- a/exprtk/exprtk_simple_example_13.cpp +++ b/exprtk/exprtk_simple_example_13.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 13 * - * Author: Arash Partow (1999-2020) * + * Author: Arash Partow (1999-2021) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * @@ -89,7 +89,7 @@ void savitzky_golay_filter() for (std::size_t i = 0; i < v_out.size(); ++i) { - printf("%10.6f\t%10.6f\n",v_in[i],v_out[i]); + printf("%10.6f\t%10.6f\n", v_in[i], v_out[i]); } } diff --git a/exprtk/exprtk_simple_example_14.cpp b/exprtk/exprtk_simple_example_14.cpp index bc508a2..5ff9d79 100644 --- a/exprtk/exprtk_simple_example_14.cpp +++ b/exprtk/exprtk_simple_example_14.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 14 * - * Author: Arash Partow (1999-2020) * + * Author: Arash Partow (1999-2021) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * @@ -26,7 +26,7 @@ template void stddev_example() { typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::parser parser_t; const std::string stddev_program = " var x[25] := { " diff --git a/exprtk/exprtk_simple_example_15.cpp b/exprtk/exprtk_simple_example_15.cpp index f7364fd..852a643 100644 --- a/exprtk/exprtk_simple_example_15.cpp +++ b/exprtk/exprtk_simple_example_15.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 15 * - * Author: Arash Partow (1999-2020) * + * Author: Arash Partow (1999-2021) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * @@ -26,8 +26,8 @@ template void black_scholes_merton_model() { typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; const std::string bsm_model_program = " var d1 := (log(s / x) + (r + v^2 / 2) * t) / (v * sqrt(t)); " @@ -67,7 +67,7 @@ void black_scholes_merton_model() { callput_flag = "call"; - T bsm = expression.value(); + const T bsm = expression.value(); printf("BSM(%s,%5.3f,%5.3f,%5.3f,%5.3f,%5.3f) = %10.6f\n", callput_flag.c_str(), @@ -78,7 +78,7 @@ void black_scholes_merton_model() { callput_flag = "put"; - T bsm = expression.value(); + const T bsm = expression.value(); printf("BSM(%s,%5.3f,%5.3f,%5.3f,%5.3f,%5.3f) = %10.6f\n", callput_flag.c_str(), diff --git a/exprtk/exprtk_simple_example_16.cpp b/exprtk/exprtk_simple_example_16.cpp index cd76f84..06ee39c 100644 --- a/exprtk/exprtk_simple_example_16.cpp +++ b/exprtk/exprtk_simple_example_16.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 16 * - * Author: Arash Partow (1999-2020) * + * Author: Arash Partow (1999-2021) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * @@ -27,8 +27,8 @@ template void linear_least_squares() { typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; const std::string linear_least_squares_program = " if (x[] == y[]) " @@ -55,11 +55,11 @@ void linear_least_squares() T rmse = T(0); symbol_table_t symbol_table; - symbol_table.add_variable("alpha",alpha); - symbol_table.add_variable("beta" ,beta ); - symbol_table.add_variable("rmse" ,rmse ); - symbol_table.add_vector ("x" ,x ); - symbol_table.add_vector ("y" ,y ); + symbol_table.add_variable("alpha", alpha); + symbol_table.add_variable("beta" , beta ); + symbol_table.add_variable("rmse" , rmse ); + symbol_table.add_vector ("x" , x ); + symbol_table.add_vector ("y" , y ); expression_t expression; expression.register_symbol_table(symbol_table); @@ -69,10 +69,10 @@ void linear_least_squares() expression.value(); - printf("alpha: %15.12f\n",alpha); - printf("beta: %15.12f\n",beta ); - printf("rmse: %15.12f\n",rmse ); - printf("y = %15.12fx + %15.12f\n",beta,alpha); + printf("alpha: %15.12f\n", alpha); + printf("beta: %15.12f\n", beta ); + printf("rmse: %15.12f\n", rmse ); + printf("y = %15.12fx + %15.12f\n", beta, alpha); } int main() diff --git a/exprtk/exprtk_simple_example_17.cpp b/exprtk/exprtk_simple_example_17.cpp index 50263aa..d141204 100644 --- a/exprtk/exprtk_simple_example_17.cpp +++ b/exprtk/exprtk_simple_example_17.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 17 * - * Author: Arash Partow (1999-2020) * + * Author: Arash Partow (1999-2021) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * @@ -44,8 +44,8 @@ template void monte_carlo_pi() { typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; const std::string monte_carlo_pi_program = " var experiments[5 * 10^7] := [(rnd_01^2 + rnd_01^2) <= 1]; " diff --git a/exprtk/exprtk_simple_example_18.cpp b/exprtk/exprtk_simple_example_18.cpp index 4fabc72..84f4575 100644 --- a/exprtk/exprtk_simple_example_18.cpp +++ b/exprtk/exprtk_simple_example_18.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 18 * - * Author: Arash Partow (1999-2020) * + * Author: Arash Partow (1999-2021) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * @@ -26,8 +26,8 @@ template void file_io() { typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; const std::string fileio_program = " var file_name := 'file.txt'; " diff --git a/exprtk/exprtk_simple_example_19.cpp b/exprtk/exprtk_simple_example_19.cpp index 7720155..753022f 100644 --- a/exprtk/exprtk_simple_example_19.cpp +++ b/exprtk/exprtk_simple_example_19.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Simple Example 19 * - * Author: Arash Partow (1999-2020) * + * Author: Arash Partow (1999-2021) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * @@ -55,7 +55,7 @@ class randu : public exprtk::igeneric_function if ( (1 == ps_index) && !exprtk::rtl::vecops::helper:: - load_vector_range::process(parameters,r0,r1,1,2,0) + load_vector_range::process(parameters, r0, r1, 1, 2, 0) ) return T(0); @@ -81,8 +81,8 @@ template void vector_randu() { typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; const std::string vecrandu_program = " var noise[6] := [0]; " @@ -109,9 +109,9 @@ void vector_randu() randu randu; symbol_table_t symbol_table; - symbol_table.add_vector ("signal" , signal); - symbol_table.add_function("println",println); - symbol_table.add_function("randu" , randu); + symbol_table.add_vector ("signal" , signal ); + symbol_table.add_function("println", println); + symbol_table.add_function("randu" , randu ); expression_t expression; expression.register_symbol_table(symbol_table); diff --git a/exprtk/exprtk_test.cpp b/exprtk/exprtk_test.cpp index 91e7593..9e62b10 100644 --- a/exprtk/exprtk_test.cpp +++ b/exprtk/exprtk_test.cpp @@ -3,7 +3,7 @@ * C++ Mathematical Expression Toolkit Library * * * * Examples and Unit-Tests * - * Author: Arash Partow (1999-2020) * + * Author: Arash Partow (1999-2021) * * URL: http://www.partow.net/programming/exprtk/index.html * * * * Copyright notice: * @@ -358,6 +358,42 @@ static const test_t global_test_list[] = test_t("( 7 - 2 )",+5.0), test_t("( 8 - 1 )",+7.0), test_t("( 9 - 0 )",+9.0), + test_t("1 - -1" , 2.0), + test_t("1 --1" , 2.0), + test_t("1-- 1" , 2.0), + test_t("1--1" , 2.0), + test_t("1 -- -1", 0.0), + test_t("1 + -1" , 0.0), + test_t("1 +-1" , 0.0), + test_t("1+- 1" , 0.0), + test_t("1+-1" , 0.0), + test_t("1 +- -1", 2.0), + test_t("1 + +1" , 2.0), + test_t("1 ++1" , 2.0), + test_t("1 - -1 + 1" , 3.0), + test_t("1 --1 + 1" , 3.0), + test_t("1-- 1 + 1" , 3.0), + test_t("1--1 + 1" , 3.0), + test_t("1 -- -1 + 1", 1.0), + test_t("1 + -1 + 1" , 1.0), + test_t("1 +-1 + 1" , 1.0), + test_t("1+- 1 + 1" , 1.0), + test_t("1+-1 + 1" , 1.0), + test_t("1 +- -1 + 1", 3.0), + test_t("1 + +1 + 1" , 3.0), + test_t("1 ++1 + 1" , 3.0), + test_t("1 - -1 - 1" , 1.0), + test_t("1 --1 - 1" , 1.0), + test_t("1-- 1 - 1" , 1.0), + test_t("1--1 - 1" , 1.0), + test_t("1 -- -1 - 1", -1.0), + test_t("1 + -1 - 1" , -1.0), + test_t("1 +-1 - 1" , -1.0), + test_t("1+- 1 - 1" , -1.0), + test_t("1+-1 - 1" , -1.0), + test_t("1 +- -1 - 1", 1.0), + test_t("1 + +1 - 1" , 1.0), + test_t("1 ++1 - 1" , 1.0), test_t("-(1+2)",-3.0), test_t("+(1+2)",+3.0), test_t("+(1-2)",-1.0), @@ -1162,14 +1198,14 @@ inline bool test_expression(const std::string& expression_string, const T& expec return false; } - T result = expression.value(); + const T result = expression.value(); if (not_equal(result,expected_result)) { printf("test_expression() - Computation Error: Expression: [%s]\tExpected: %19.15f\tResult: %19.15f\n", expression_string.c_str(), - (double)expected_result, - (double)result); + static_cast(expected_result), + static_cast(result)); return false; } @@ -1177,6 +1213,43 @@ inline bool test_expression(const std::string& expression_string, const T& expec return true; } +template +struct edge_cases {}; + +template <> +struct edge_cases +{ + static inline std::vector test_cases() + { + std::vector cases; + cases.push_back(test_t(" 1.175494350822287508e-38", 1.175494350822287508e-38)); + cases.push_back(test_t(" 3.402823466385288598e+38", 3.402823466385288598e+38)); + cases.push_back(test_t("+1.175494350822287508e-38", +1.175494350822287508e-38)); + cases.push_back(test_t("+3.402823466385288598e+38", +3.402823466385288598e+38)); + cases.push_back(test_t("-1.175494350822287508e-38", -1.175494350822287508e-38)); + cases.push_back(test_t("-3.402823466385288598e+38", -3.402823466385288598e+38)); + + return cases; + } +}; + +template <> +struct edge_cases +{ + static inline std::vector test_cases() + { + std::vector cases; + cases.push_back(test_t(" 2.2250738585072013831e-308", 2.2250738585072013831e-308)); + cases.push_back(test_t(" 1.7976931348623157081e+308", 1.7976931348623157081e+308)); + cases.push_back(test_t("+2.2250738585072013831e-308", +2.2250738585072013831e-308)); + cases.push_back(test_t("+1.7976931348623157081e+308", +1.7976931348623157081e+308)); + cases.push_back(test_t("-2.2250738585072013831e-308", -2.2250738585072013831e-308)); + cases.push_back(test_t("-1.7976931348623157081e+308", -1.7976931348623157081e+308)); + + return cases; + } +}; + template inline bool run_test00() { @@ -1198,6 +1271,25 @@ inline bool run_test00() } } + { + const std::vector tests = edge_cases::test_cases(); + + bool result = true; + + for (std::size_t i = 0; i < tests.size(); ++i) + { + if (!test_expression(tests[i].first,T(tests[i].second))) + { + result = false; + } + } + + if (!result) + { + return false; + } + } + return true; } @@ -1256,34 +1348,106 @@ inline bool run_test01() test_xy("2 * (x + y) - 1" ,T(2.2),T(3.3),T(10.0 )), test_xy("y + (x + 1)" ,T(2.2),T(3.3),T(6.5 )), test_xy("(x + 1) + y" ,T(2.2),T(3.3),T(6.5 )), - test_xy("2 * x" ,T(2.2),T(0.0),T(4.4)), - test_xy("x * 2" ,T(2.2),T(0.0),T(4.4)), - test_xy("1.1 + x",T(2.2),T(0.0),T(3.3)), - test_xy("x + 1.1",T(2.2),T(0.0),T(3.3)), - test_xy("x * 1 == x" ,T(2.0),T(3.0),T(1.0)), - test_xy("1 * x == x" ,T(2.0),T(3.0),T(1.0)), - test_xy("y * 1 == y" ,T(2.0),T(3.0),T(1.0)), - test_xy("1 * y == y" ,T(2.0),T(3.0),T(1.0)), - test_xy("x * 0 == 0" ,T(2.0),T(3.0),T(1.0)), - test_xy("0 * x == 0" ,T(2.0),T(3.0),T(1.0)), - test_xy("y * 0 == 0" ,T(2.0),T(3.0),T(1.0)), - test_xy("0 * y == 0" ,T(2.0),T(3.0),T(1.0)), - test_xy("x + 1 == 1 + x",T(2.0),T(3.0),T(1.0)), - test_xy("y + 1 == 1 + y",T(2.0),T(3.0),T(1.0)), - test_xy("x + y == y + x",T(2.0),T(3.0),T(1.0)), - test_xy("x * y == y * x",T(2.0),T(3.0),T(1.0)), - test_xy("x < y" ,T(2.0),T(3.0),T(1.0)), - test_xy("y > x" ,T(2.0),T(3.0),T(1.0)), - test_xy("x <= y" ,T(2.0),T(3.0),T(1.0)), - test_xy("y >= x" ,T(2.0),T(3.0),T(1.0)), - test_xy("x + y > y" ,T(2.0),T(3.0),T(1.0)), - test_xy("x + y > x" ,T(2.0),T(3.0),T(1.0)), - test_xy("x * y > y" ,T(2.0),T(3.0),T(1.0)), - test_xy("x * y > x" ,T(2.0),T(3.0),T(1.0)), - test_xy("(x + y) > y" ,T(2.0),T(3.0),T(1.0)), - test_xy("(x + y) > x" ,T(2.0),T(3.0),T(1.0)), - test_xy("(x * y) > y" ,T(2.0),T(3.0),T(1.0)), - test_xy("(x * y) > x" ,T(2.0),T(3.0),T(1.0)), + test_xy("2 * x" ,T(2.2),T(0.0),T(4.4)), + test_xy("x * 2" ,T(2.2),T(0.0),T(4.4)), + test_xy("1.1 + x" ,T(2.2),T(0.0),T(3.3)), + test_xy("x + 1.1" ,T(2.2),T(0.0),T(3.3)), + test_xy("x - -1 " ,T(1.0),T(0.0),T(2)), + test_xy("x --1 " ,T(1.0),T(0.0),T(2)), + test_xy("x-- 1 " ,T(1.0),T(0.0),T(2)), + test_xy("x--1 " ,T(1.0),T(0.0),T(2)), + test_xy("x -- -1" ,T(1.0),T(0.0),T(0)), + test_xy("x + -1 " ,T(1.0),T(0.0),T(0)), + test_xy("x +-1 " ,T(1.0),T(0.0),T(0)), + test_xy("x+- 1 " ,T(1.0),T(0.0),T(0)), + test_xy("x+-1 " ,T(1.0),T(0.0),T(0)), + test_xy("x +- -1" ,T(1.0),T(0.0),T(2)), + test_xy("x + +1 " ,T(1.0),T(0.0),T(2)), + test_xy("x ++1 " ,T(1.0),T(0.0),T(2)), + test_xy("1 - -x " ,T(1.0),T(0.0),T(2)), + test_xy("1 --x " ,T(1.0),T(0.0),T(2)), + test_xy("1-- x " ,T(1.0),T(0.0),T(2)), + test_xy("1--x " ,T(1.0),T(0.0),T(2)), + test_xy("1 -- -x" ,T(1.0),T(0.0),T(0)), + test_xy("1 + -x " ,T(1.0),T(0.0),T(0)), + test_xy("1 +-x " ,T(1.0),T(0.0),T(0)), + test_xy("1+- x " ,T(1.0),T(0.0),T(0)), + test_xy("1+-x " ,T(1.0),T(0.0),T(0)), + test_xy("1 +- -x" ,T(1.0),T(0.0),T(2)), + test_xy("1 + +x " ,T(1.0),T(0.0),T(2)), + test_xy("1 ++x " ,T(1.0),T(0.0),T(2)), + test_xy("(x - -1 + 1)" ,T(1.0),T(0.0),T(3)), + test_xy("(x --1 + 1)" ,T(1.0),T(0.0),T(3)), + test_xy("(x-- 1 + 1)" ,T(1.0),T(0.0),T(3)), + test_xy("(x--1 + 1)" ,T(1.0),T(0.0),T(3)), + test_xy("(x -- -1 + 1)" ,T(1.0),T(0.0),T(1)), + test_xy("(x + -1 + 1)" ,T(1.0),T(0.0),T(1)), + test_xy("(x +-1 + 1)" ,T(1.0),T(0.0),T(1)), + test_xy("(x+- 1 + 1)" ,T(1.0),T(0.0),T(1)), + test_xy("(x+-1 + 1)" ,T(1.0),T(0.0),T(1)), + test_xy("(x +- -1 + 1)" ,T(1.0),T(0.0),T(3)), + test_xy("(x + +1 + 1)" ,T(1.0),T(0.0),T(3)), + test_xy("(x ++1 + 1)" ,T(1.0),T(0.0),T(3)), + test_xy("(1 - -x + 1)" ,T(1.0),T(0.0),T(3)), + test_xy("(1 --x + 1)" ,T(1.0),T(0.0),T(3)), + test_xy("(1-- x + 1)" ,T(1.0),T(0.0),T(3)), + test_xy("(1--x + 1)" ,T(1.0),T(0.0),T(3)), + test_xy("(1 -- -x + 1)" ,T(1.0),T(0.0),T(1)), + test_xy("(1 + -x + 1)" ,T(1.0),T(0.0),T(1)), + test_xy("(1 +-x + 1)" ,T(1.0),T(0.0),T(1)), + test_xy("(1+- x + 1)" ,T(1.0),T(0.0),T(1)), + test_xy("(1+-x + 1)" ,T(1.0),T(0.0),T(1)), + test_xy("(1 +- -x + 1)" ,T(1.0),T(0.0),T(3)), + test_xy("(1 + +x + 1)" ,T(1.0),T(0.0),T(3)), + test_xy("(1 ++x + 1)" ,T(1.0),T(0.0),T(3)), + test_xy("(x - -1 - 1)" ,T(1.0),T(0.0),T(1)), + test_xy("(x --1 - 1)" ,T(1.0),T(0.0),T(1)), + test_xy("(x-- 1 - 1)" ,T(1.0),T(0.0),T(1)), + test_xy("(x--1 - 1)" ,T(1.0),T(0.0),T(1)), + test_xy("(x -- -1 - 1)" ,T(1.0),T(0.0),T(-1)), + test_xy("(x + -1 - 1)" ,T(1.0),T(0.0),T(-1)), + test_xy("(x +-1 - 1)" ,T(1.0),T(0.0),T(-1)), + test_xy("(x+- 1 - 1)" ,T(1.0),T(0.0),T(-1)), + test_xy("(x+-1 - 1)" ,T(1.0),T(0.0),T(-1)), + test_xy("(x +- -1 - 1)" ,T(1.0),T(0.0),T(1)), + test_xy("(x + +1 - 1)" ,T(1.0),T(0.0),T(1)), + test_xy("(x ++1 - 1)" ,T(1.0),T(0.0),T(1)), + test_xy("(1 - -x - 1)" ,T(1.0),T(0.0),T(1)), + test_xy("(1 --x - 1)" ,T(1.0),T(0.0),T(1)), + test_xy("(1-- x - 1)" ,T(1.0),T(0.0),T(1)), + test_xy("(1--x - 1)" ,T(1.0),T(0.0),T(1)), + test_xy("(1 -- -x - 1)" ,T(1.0),T(0.0),T(-1)), + test_xy("(1 + -x - 1)" ,T(1.0),T(0.0),T(-1)), + test_xy("(1 +-x - 1)" ,T(1.0),T(0.0),T(-1)), + test_xy("(1+- x - 1)" ,T(1.0),T(0.0),T(-1)), + test_xy("(1+-x - 1)" ,T(1.0),T(0.0),T(-1)), + test_xy("(1 +- -x - 1)" ,T(1.0),T(0.0),T(1)), + test_xy("(1 + +x - 1)" ,T(1.0),T(0.0),T(1)), + test_xy("(1 ++x - 1)" ,T(1.0),T(0.0),T(1)), + test_xy("x * 1 == x" ,T(2.0),T(3.0),T(1.0)), + test_xy("1 * x == x" ,T(2.0),T(3.0),T(1.0)), + test_xy("y * 1 == y" ,T(2.0),T(3.0),T(1.0)), + test_xy("1 * y == y" ,T(2.0),T(3.0),T(1.0)), + test_xy("x * 0 == 0" ,T(2.0),T(3.0),T(1.0)), + test_xy("0 * x == 0" ,T(2.0),T(3.0),T(1.0)), + test_xy("y * 0 == 0" ,T(2.0),T(3.0),T(1.0)), + test_xy("0 * y == 0" ,T(2.0),T(3.0),T(1.0)), + test_xy("x + 1 == 1 + x" ,T(2.0),T(3.0),T(1.0)), + test_xy("y + 1 == 1 + y" ,T(2.0),T(3.0),T(1.0)), + test_xy("x + y == y + x" ,T(2.0),T(3.0),T(1.0)), + test_xy("x * y == y * x" ,T(2.0),T(3.0),T(1.0)), + test_xy("x < y" ,T(2.0),T(3.0),T(1.0)), + test_xy("y > x" ,T(2.0),T(3.0),T(1.0)), + test_xy("x <= y" ,T(2.0),T(3.0),T(1.0)), + test_xy("y >= x" ,T(2.0),T(3.0),T(1.0)), + test_xy("x + y > y" ,T(2.0),T(3.0),T(1.0)), + test_xy("x + y > x" ,T(2.0),T(3.0),T(1.0)), + test_xy("x * y > y" ,T(2.0),T(3.0),T(1.0)), + test_xy("x * y > x" ,T(2.0),T(3.0),T(1.0)), + test_xy("(x + y) > y" ,T(2.0),T(3.0),T(1.0)), + test_xy("(x + y) > x" ,T(2.0),T(3.0),T(1.0)), + test_xy("(x * y) > y" ,T(2.0),T(3.0),T(1.0)), + test_xy("(x * y) > x" ,T(2.0),T(3.0),T(1.0)), test_xy("(2x + 3y) == (2*x + 3*y)" ,T(2.0),T(3.0),T(1.0)), test_xy("2(x + y) == (2*x + 2*y)" ,T(2.0),T(3.0),T(1.0)), test_xy(" (x + y)3 == (3*x + 3*y)" ,T(2.0),T(3.0),T(1.0)), @@ -1646,14 +1810,14 @@ inline bool run_test01() } } - T result = expression.value(); + const T result = expression.value(); if (not_equal(result,test.result)) { printf("run_test01() - Computation Error: Expression: [%s]\tExpected: %19.15f\tResult: %19.15f\n", test.expr.c_str(), - (double)test.result, - (double)result); + static_cast(test.result), + static_cast(result)); loop_result = false; } @@ -1758,14 +1922,14 @@ inline bool run_test01() } } - T result = expression.value(); + const T result = expression.value(); if (not_equal(result,test.result)) { printf("run_test01() - Computation Error: Expression: [%s]\tExpected: %19.15f\tResult: %19.15f\n", test.expr.c_str(), - (double)test.result, - (double)result); + static_cast(test.result), + static_cast(result)); loop_result = false; } @@ -1841,14 +2005,14 @@ inline bool run_test01() } } - T result = expression.value(); + const T result = expression.value(); if (not_equal(result,T(1))) { printf("run_test01() - Computation Error: Expression: [%s]\tExpected: %19.15f\tResult: %19.15f\n", expr_list[i].c_str(), - (double)1.0, - (double)result); + static_cast(1.0), + static_cast(result)); loop_result = false; } @@ -1901,14 +2065,14 @@ inline bool run_test01() } } - T result = expression.value(); + const T result = expression.value(); if (not_equal(result,T(1))) { printf("run_test01() - Computation Error: Expression: [%s]\tExpected: %19.15f\tResult: %19.15f\n", expr_list[i].c_str(), - (double)1.0, - (double)result); + static_cast(1.0), + static_cast(result)); loop_result = false; } } @@ -2422,6 +2586,17 @@ inline bool run_test02() test_ab("var i := 0; a[0:i+3] <=> b[:]; (a == '0123X') and (b == 'XXXX4567890')", "XXXXX","01234567890",T(1.0)), test_ab("var i := 0; a[0:i+4] <=> b[:]; (a == '01234') and (b == 'XXXXX567890')", "XXXXX","01234567890",T(1.0)), + test_ab("var y:= 2; '01234567890'[y:] == a ", "234567890","" ,T(1.0)), + test_ab("var y:= 2; '01234567890'[y:][y:] == a ", "4567890" ,"" ,T(1.0)), + test_ab("var y:= 2; '01234567890'[y:][y:][y:] == a ", "67890" ,"" ,T(1.0)), + test_ab("var y:= 2; '01234567890'[y:][y:][y:][y:] == a ", "890" ,"" ,T(1.0)), + test_ab("var y:= 2; '01234567890'[y:][y:][y:][y:][y:] == a", "0" ,"" ,T(1.0)), + test_ab("var y:= 2; '0123456789'[y:] == a ", "23456789" ,"" ,T(1.0)), + test_ab("var y:= 2; '0123456789'[y:][y:] == a ", "456789" ,"" ,T(1.0)), + test_ab("var y:= 2; '0123456789'[y:][y:][y:] == a ", "6789" ,"" ,T(1.0)), + test_ab("var y:= 2; '0123456789'[y:][y:][y:][y:] == a ", "89" ,"" ,T(1.0)), + test_ab("var y:= 2; '0123456789'[y:][y:][y:][y:][y:] == a ", "" ,"" ,T(1.0)), + test_ab("var x := 'XXXXX'; var y := '01234567890'; x[0:0] := y[:]; x == '0XXXX'", "","",T(1.0)), test_ab("var x := 'XXXXX'; var y := '01234567890'; x[0:1] := y[:]; x == '01XXX'", "","",T(1.0)), test_ab("var x := 'XXXXX'; var y := '01234567890'; x[0:2] := y[:]; x == '012XX'", "","",T(1.0)), @@ -2598,8 +2773,8 @@ inline bool run_test02() printf("run_test02() - Computation Error: Expression: [%s]\tExpected: %19.15f\tResult: %19.15f\t" "a='%s'\tb='%s'\tc='%s'\n", test.expr.c_str(), - (double)test.result, - (double)expr_result, + static_cast(test.result), + static_cast(expr_result), str_a.c_str(), str_b.c_str(), str_c.c_str()); @@ -2676,8 +2851,8 @@ template inline bool run_test03() { typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; std::string expression_string = "A+A0+aA+Aa0+b+B1+Bb+bB1+A+A0+AA+AA0+B+B1+BB+BB1+a+a0+aa+aa0+b+b1+bb+bb1+" "c+C2+Cc+Cc2+D+D3+dD+dD3+C+C2+CC+CC2+D+D3+DD+DD3+c+c2+cc+cc2+d+d3+dd+dd3+" @@ -3013,10 +3188,10 @@ inline bool run_test04() { printf("run_test04() - Computation Error: Expression: [%s]\tExpected: %19.15f\tResult: %19.15f x:%19.15f\ty:%19.15f\n", expression_string.c_str(), - (double)result1, - (double)result2, - (double)x, - (double)y); + static_cast(result1), + static_cast(result2), + static_cast(x), + static_cast(y)); return false; } @@ -3083,10 +3258,10 @@ inline bool run_test05() { printf("run_test05() - Computation Error: Expression: [%s]\tExpected: %19.15f\tResult: %19.15f x:%19.15f\ty:%19.15f\tIndex:%d\n", expression_string.c_str(), - (double)real_result, - (double)result, - (double)x, - (double)y, + static_cast(real_result), + static_cast(result), + static_cast(x), + static_cast(y), static_cast(i)); return false; @@ -3140,8 +3315,8 @@ inline bool run_test06() if (not_equal(total_area1,T(pi) / T(2),T(0.000001))) { printf("run_test06() - Integration Error: Expected: %19.15f\tResult: %19.15f\n", - (double)(pi / T(2)), - (double)total_area1); + static_cast(pi / T(2)), + static_cast(total_area1)); return false; } @@ -3192,9 +3367,9 @@ inline bool run_test07() if (not_equal(deriv1_result1,deriv1_real_result,T(0.00001))) { printf("run_test07() - 1st Derivative Error: x: %19.15f\tExpected: %19.15f\tResult: %19.15f\n", - (double)x, - (double)deriv1_real_result, - (double)deriv1_result1); + static_cast(x), + static_cast(deriv1_real_result), + static_cast(deriv1_result1)); return false; } @@ -3214,9 +3389,9 @@ inline bool run_test07() if (not_equal(deriv2_result1,deriv2_real_result,T(0.01))) { printf("run_test07() - 2nd Derivative Error: x: %19.15f\tExpected: %19.15f\tResult: %19.15f\n", - (double)x, - (double)deriv2_real_result, - (double)deriv2_result1); + static_cast(x), + static_cast(deriv2_real_result), + static_cast(deriv2_result1)); return false; } @@ -3236,9 +3411,9 @@ inline bool run_test07() if (not_equal(deriv3_result1,deriv3_real_result,T(0.01))) { printf("run_test07() - 3rd Derivative Error: x: %19.15f\tExpected: %19.15f\tResult: %19.15f\n", - (double)x, - (double)deriv3_real_result, - (double)deriv3_result1); + static_cast(x), + static_cast(deriv3_real_result), + static_cast(deriv3_result1)); return false; } @@ -3526,9 +3701,9 @@ inline bool run_test09() const T pi = T(3.141592653589793238462643383279502); - T result = expression.value(); + const T result = expression.value(); - T expected = T(4) * + const T expected = T(4) * ( mf(sin(x*pi),y / T(2)) + mf(sin(x*pi),y / T(2)) + @@ -3545,8 +3720,8 @@ inline bool run_test09() if (not_equal(result,expected,T(0.0000001))) { printf("run_test09() - Error Expected: %19.15f\tResult: %19.15f\n", - (double)expected, - (double)result); + static_cast(expected), + static_cast(result)); return false; } @@ -4311,6 +4486,78 @@ inline bool run_test10() { "var x; 1", "var x := 1; x", + "var x:= 1; x - -1 == 2", + "var x:= 1; x --1 == 2", + "var x:= 1; x-- 1 == 2", + "var x:= 1; x--1 == 2", + "var x:= 1; x -- -1== 0", + "var x:= 1; x + -1 == 0", + "var x:= 1; x +-1 == 0", + "var x:= 1; x+- 1 == 0", + "var x:= 1; x+-1 == 0", + "var x:= 1; x +- -1== 2", + "var x:= 1; x + +1 == 2", + "var x:= 1; x ++1 == 2", + "var x:= 1; 1 - -x == 2", + "var x:= 1; 1 --x == 2", + "var x:= 1; 1-- x == 2", + "var x:= 1; 1--x == 2", + "var x:= 1; 1 -- -x== 0", + "var x:= 1; 1 + -x == 0", + "var x:= 1; 1 +-x == 0", + "var x:= 1; 1+- x == 0", + "var x:= 1; 1+-x == 0", + "var x:= 1; 1 +- -x== 2", + "var x:= 1; 1 + +x == 2", + "var x:= 1; 1 ++x == 2", + "var x:= 1; (x - -1 + 1) == 3", + "var x:= 1; (x --1 + 1) == 3", + "var x:= 1; (x-- 1 + 1) == 3", + "var x:= 1; (x--1 + 1) == 3", + "var x:= 1; (x -- -1 + 1) == 1", + "var x:= 1; (x + -1 + 1) == 1", + "var x:= 1; (x +-1 + 1) == 1", + "var x:= 1; (x+- 1 + 1) == 1", + "var x:= 1; (x+-1 + 1) == 1", + "var x:= 1; (x +- -1 + 1) == 3", + "var x:= 1; (x + +1 + 1) == 3", + "var x:= 1; (x ++1 + 1) == 3", + "var x:= 1; (1 - -x + 1) == 3", + "var x:= 1; (1 --x + 1) == 3", + "var x:= 1; (1-- x + 1) == 3", + "var x:= 1; (1--x + 1) == 3", + "var x:= 1; (1 -- -x + 1) == 1", + "var x:= 1; (1 + -x + 1) == 1", + "var x:= 1; (1 +-x + 1) == 1", + "var x:= 1; (1+- x + 1) == 1", + "var x:= 1; (1+-x + 1) == 1", + "var x:= 1; (1 +- -x + 1) == 3", + "var x:= 1; (1 + +x + 1) == 3", + "var x:= 1; (1 ++x + 1) == 3", + "var x:= 1; (x - -1 - 1) == 1", + "var x:= 1; (x --1 - 1) == 1", + "var x:= 1; (x-- 1 - 1) == 1", + "var x:= 1; (x--1 - 1) == 1", + "var x:= 1; (x -- -1 - 1) == -1", + "var x:= 1; (x + -1 - 1) == -1", + "var x:= 1; (x +-1 - 1) == -1", + "var x:= 1; (x+- 1 - 1) == -1", + "var x:= 1; (x+-1 - 1) == -1", + "var x:= 1; (x +- -1 - 1) == 1", + "var x:= 1; (x + +1 - 1) == 1", + "var x:= 1; (x ++1 - 1) == 1", + "var x:= 1; (1 - -x - 1) == 1", + "var x:= 1; (1 --x - 1) == 1", + "var x:= 1; (1-- x - 1) == 1", + "var x:= 1; (1--x - 1) == 1", + "var x:= 1; (1 -- -x - 1) == -1", + "var x:= 1; (1 + -x - 1) == -1", + "var x:= 1; (1 +-x - 1) == -1", + "var x:= 1; (1+- x - 1) == -1", + "var x:= 1; (1+-x - 1) == -1", + "var x:= 1; (1 +- -x - 1) == 1", + "var x:= 1; (1 + +x - 1) == 1", + "var x:= 1; (1 ++x - 1) == 1", "var x := 1; var y := 2; 1", "var x := 1; var y := 2; x", "var x:=6; var y:=4; x + -3 == 3", @@ -4623,7 +4870,43 @@ inline bool run_test10() "var s := 'abc'; ~{1 + 2; 'abc' + s; s} == s ", "var s := 'abc'; ~{1 + 2; var x := 'ab'; x + 'c'} == s ", - "var x[10^6] := null; var y[10^7] := null; 0 * (min(x) + min(y)) + x[] + y[] == 10^7 + 10^6" + "var x[10^6] := null; var y[10^7] := null; 0 * (min(x) + min(y)) + x[] + y[] == 10^7 + 10^6", + + "var v0[3] := {1,2,3}; var v1[3] := {7,8,9}; if (1 < 2, v0, v1) == v0", + "var v0[3] := {1,2,3}; var v1[3] := {7,8,9}; if (1 > 2, v0, v1) == v1", + "var v0[3] := {1,2,3}; var v1[3] := {7,8,9}; if (1 < 2, v0 - v1, v1 - v0) == (v0 - v1)", + "var v0[3] := {1,2,3}; var v1[3] := {7,8,9}; if (1 > 2, v0 - v1, v1 - v0) == (v1 - v0)", + "var v0[3] := {1,2,3}; var v1[3] := {7,8,9}; var x := 1; var y := 2; if (x < y, v0, v1) == v0", + "var v0[3] := {1,2,3}; var v1[3] := {7,8,9}; var x := 1; var y := 2; if (x > y, v0, v1) == v1", + "var v0[3] := {1,2,3}; var v1[3] := {7,8,9}; var x := 1; var y := 2; if (x < y, v0 - v1, v1 - v0) == (v0 - v1)", + "var v0[3] := {1,2,3}; var v1[3] := {7,8,9}; var x := 1; var y := 2; if (x > y, v0 - v1, v1 - v0) == (v1 - v0)", + + "var v0[3] := {1,2,3}; var v1[4] := {6,7,8,9}; if (1 < 2, v0, v1) == v0", + "var v0[3] := {1,2,3}; var v1[4] := {6,7,8,9}; if (1 > 2, v0, v1) == v1", + "var v0[3] := {1,2,3}; var v1[4] := {6,7,8,9}; if (1 < 2, v0 - v1, v1 - v0) == (v0 - v1)", + "var v0[3] := {1,2,3}; var v1[4] := {6,7,8,9}; if (1 > 2, v0 - v1, v1 - v0) == (v1 - v0)", + "var v0[3] := {1,2,3}; var v1[4] := {6,7,8,9}; var x := 1; var y := 2; if (x < y, v0, v1) == v0", + "var v0[3] := {1,2,3}; var v1[4] := {6,7,8,9}; var x := 1; var y := 2; if (x > y, v0, v1) == v1", + "var v0[3] := {1,2,3}; var v1[4] := {6,7,8,9}; var x := 1; var y := 2; if (x < y, v0 - v1, v1 - v0) == (v0 - v1)", + "var v0[3] := {1,2,3}; var v1[4] := {6,7,8,9}; var x := 1; var y := 2; if (x > y, v0 - v1, v1 - v0) == (v1 - v0)", + + "var v0[3] := {1,2,3}; var v1[3] := {7,8,9}; (if (1 < 2) v0; else v1;) == v0", + "var v0[3] := {1,2,3}; var v1[3] := {7,8,9}; (if (1 > 2) v0; else v1;) == v1", + "var v0[3] := {1,2,3}; var v1[3] := {7,8,9}; (if (1 < 2) v0 - v1; else v1 - v0;) == (v0 - v1)", + "var v0[3] := {1,2,3}; var v1[3] := {7,8,9}; (if (1 > 2) v0 - v1; else v1 - v0;) == (v1 - v0)", + "var v0[3] := {1,2,3}; var v1[3] := {7,8,9}; var x := 1; var y := 2; (if (x < y) v0; else v1;) == v0", + "var v0[3] := {1,2,3}; var v1[3] := {7,8,9}; var x := 1; var y := 2; (if (x > y) v0; else v1;) == v1", + "var v0[3] := {1,2,3}; var v1[3] := {7,8,9}; var x := 1; var y := 2; (if (x < y) v0 - v1; else v1 - v0;) == (v0 - v1)", + "var v0[3] := {1,2,3}; var v1[3] := {7,8,9}; var x := 1; var y := 2; (if (x > y) v0 - v1; else v1 - v0;) == (v1 - v0)", + + "var v0[3] := {1,2,3}; var v1[4] := {6,7,8,9}; (if (1 < 2) v0; else v1;) == v0", + "var v0[3] := {1,2,3}; var v1[4] := {6,7,8,9}; (if (1 > 2) v0; else v1;) == v1", + "var v0[3] := {1,2,3}; var v1[4] := {6,7,8,9}; (if (1 < 2) v0 - v1; else v1 - v0;) == (v0 - v1)", + "var v0[3] := {1,2,3}; var v1[4] := {6,7,8,9}; (if (1 > 2) v0 - v1; else v1 - v0;) == (v1 - v0)", + "var v0[3] := {1,2,3}; var v1[4] := {6,7,8,9}; var x := 1; var y := 2; (if (x < y) v0; else v1;) == v0", + "var v0[3] := {1,2,3}; var v1[4] := {6,7,8,9}; var x := 1; var y := 2; (if (x > y) v0; else v1;) == v1", + "var v0[3] := {1,2,3}; var v1[4] := {6,7,8,9}; var x := 1; var y := 2; (if (x < y) v0 - v1; else v1 - v0;) == (v0 - v1)", + "var v0[3] := {1,2,3}; var v1[4] := {6,7,8,9}; var x := 1; var y := 2; (if (x > y) v0 - v1; else v1 - v0;) == (v1 - v0)", }; const std::size_t expression_list_size = sizeof(expression_list) / sizeof(std::string); @@ -4662,7 +4945,7 @@ inline bool run_test10() } } - T result = expression.value(); + const T result = expression.value(); if (T(1) != result) { @@ -4699,7 +4982,7 @@ inline bool run_test10() continue; } - T result = expression.value(); + const T result = expression.value(); if (T(1) != result) { @@ -4927,8 +5210,8 @@ template inline bool run_test13() { typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; static const std::string expression_string[] = { @@ -5287,8 +5570,8 @@ inline bool run_test15() if (not_equal(base_result,result)) { printf("run_test15() - Error in evaluation! (1) Base: %20.10f\tResult: %20.10f\tExpression: %s\n", - (double)base_result, - (double)result, + static_cast(base_result), + static_cast(result), expr_str_list[i].c_str()); failure = true; @@ -5917,6 +6200,96 @@ struct overload_func : exprtk::igeneric_function template inline bool run_test18() { + { + exprtk::symbol_table symbol_table; + symbol_table.remove_variable("x",true); + symbol_table.remove_variable("x",false); + symbol_table.remove_stringvar("x"); + symbol_table.remove_function("x"); + symbol_table.remove_vararg_function("x"); + symbol_table.remove_vector("x"); + } + + { + exprtk::symbol_table symbol_table; + + { + T x; + const bool result1 = symbol_table.add_variable("x", x); + const bool result2 = symbol_table.remove_variable("x"); + const bool result3 = symbol_table.remove_variable("x"); + + if (!result1 || !result2 || result3) + { + printf("run_test18() - Failed sym_tab add/remove [1]\n"); + } + } + + { + std::string x; + const bool result1 = symbol_table.add_stringvar("x", x); + const bool result2 = symbol_table.remove_stringvar("x"); + const bool result3 = symbol_table.remove_stringvar("x"); + + if (!result1 || !result2 || result3) + { + printf("run_test18() - Failed sym_tab add/remove [2]\n"); + } + } + + { + std::vector x(10,T(0)); + const bool result1 = symbol_table.add_vector("x", x); + const bool result2 = symbol_table.remove_vector("x"); + const bool result3 = symbol_table.remove_vector("x"); + + if (!result1 || !result2 || result3) + { + printf("run_test18() - Failed sym_tab add/remove [3]\n"); + } + } + + { + myfunc x; + const bool result1 = symbol_table.add_function("x", x); + const bool result2 = symbol_table.remove_function("x"); + const bool result3 = symbol_table.remove_function("x"); + + if (!result1 || !result2 || result3) + { + printf("run_test18() - Failed sym_tab add/remove [4]\n"); + } + } + + { + va_func x; + const bool result1 = symbol_table.add_function("x", x); + const bool result2 = symbol_table.remove_vararg_function("x"); + const bool result3 = symbol_table.remove_vararg_function("x"); + + if (!result1 || !result2 || result3) + { + printf("run_test18() - Failed sym_tab add/remove [5]\n"); + } + } + + { + symbol_table.add_function("foo1",foo1); + symbol_table.add_function("foo2",foo2); + symbol_table.add_function("foo3",foo3); + symbol_table.add_function("foo4",foo4); + symbol_table.add_function("foo5",foo5); + symbol_table.add_function("foo6",foo6); + + symbol_table.remove_function("foo1"); + symbol_table.remove_function("foo2"); + symbol_table.remove_function("foo3"); + symbol_table.remove_function("foo4"); + symbol_table.remove_function("foo5"); + symbol_table.remove_function("foo6"); + } + } + { typedef exprtk::expression expression_t; @@ -6001,8 +6374,8 @@ inline bool run_test18() { typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; T x = T(33); T y = T(77); @@ -6100,8 +6473,8 @@ inline bool run_test18() { typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; T x = T(33); T y = T(77); @@ -6278,8 +6651,8 @@ inline bool run_test18() for (std::size_t i = 0; i < expression_list_size; ++i) { typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; T x = T(33); T y = T(77); @@ -6395,8 +6768,8 @@ inline bool run_test18() std::string s4 = "XXXXXXXXXXXXXXX"; typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; symbol_table_t symbol_table; @@ -6448,7 +6821,7 @@ inline bool run_test18() return false; } - T result = expression.value(); + const T result = expression.value(); if (result != T(1)) { @@ -6508,8 +6881,8 @@ inline bool run_test18() bool failure = false; typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; symbol_table_t symbol_table; @@ -6579,8 +6952,8 @@ inline bool run_test18() bool failure = false; typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; std::vector v0; std::vector v1; @@ -6666,8 +7039,8 @@ inline bool run_test18() bool failure = false; typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; std::vector v0; std::vector s; @@ -6729,8 +7102,8 @@ inline bool run_test18() bool failure = false; typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; std::vector v0; std::vector s; @@ -6792,8 +7165,8 @@ inline bool run_test18() bool failure = false; typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; std::vector v0; std::vector s; @@ -6853,8 +7226,8 @@ inline bool run_test18() { typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; T v0[] = { T(0), T(1), T(2), T(3), T(4) }; T v1[] = { T(5), T(6), T(7), T(8), T(9) }; @@ -6917,8 +7290,8 @@ inline bool run_test18() bool failure = false; typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; exprtk::rtl::vecops::package vecops_pkg; @@ -7041,7 +7414,7 @@ inline bool run_test18() continue; } - T result = expression.value(); + const T result = expression.value(); if (result != T(1)) { @@ -7351,11 +7724,11 @@ inline bool run_test18() template inline bool run_test19() { - typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; - typedef exprtk::function_compositor compositor_t; - typedef typename compositor_t::function function_t; + typedef exprtk::symbol_table symbol_table_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; + typedef exprtk::function_compositor compositor_t; + typedef typename compositor_t::function function_t; { T x = T(123.123); @@ -7564,7 +7937,7 @@ inline bool run_test19() continue; } - T result = expression.value(); + const T result = expression.value(); if (result_list[i] != result) { @@ -8061,15 +8434,15 @@ inline bool run_test19() { x = static_cast(i); - T result = expression.value(); + const T result = expression.value(); if (not_equal(result,std::sqrt(x),T(0.0000001))) { printf("run_test19() - Computation Error " "Expression: [%s]\tExpected: %12.8f\tResult: %12.8f\n", expression_str.c_str(), - (double)std::sqrt(x), - (double)result); + static_cast(std::sqrt(x)), + static_cast(result)); failure = true; } @@ -8191,7 +8564,7 @@ inline bool run_test19() sum += x; - T result = expression.value(); + const T result = expression.value(); if (result != sum) { @@ -8684,8 +9057,8 @@ template inline bool run_test21() { typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; T x = T(1.1); T y = T(2.2); diff --git a/exprtk/readme.txt b/exprtk/readme.txt index 4f4911f..6c19f34 100644 --- a/exprtk/readme.txt +++ b/exprtk/readme.txt @@ -59,7 +59,7 @@ arithmetic operations, functions and processes: (05) Functions: abs, avg, ceil, clamp, equal, erf, erfc, exp, expm1, floor, frac, log, log10, log1p, log2, - logn, max, min, mul, ncdf, nequal, root, + logn, max, min, mul, ncdf, not_equal, root, round, roundn, sgn, sqrt, sum, swap, trunc (06) Trigonometry: acos, acosh, asin, asinh, atan, atanh, atan2, @@ -124,7 +124,7 @@ The most recent version of the C++ Mathematical Expression Toolkit Library including all updates and tests can be found at the following locations: - (a) Download: http://www.partow.net/programming/exprtk/index.html + (a) Download: https://www.partow.net/programming/exprtk/index.html (b) Repository: https://github.com/ArashPartow/exprtk https://github.com/ArashPartow/exprtk-extras @@ -321,7 +321,7 @@ of C++ compilers: +----------+---------------------------------------------------------+ | ncdf | Normal cumulative distribution function. (eg: ncdf(x)) | +----------+---------------------------------------------------------+ -| nequal | Not-equal test between x and y using normalised epsilon | +| not_equal| Not-equal test between x and y using normalised epsilon | +----------+---------------------------------------------------------+ | pow | x to the power of y. (eg: pow(x,y) == x ^ y) | +----------+---------------------------------------------------------+ @@ -428,8 +428,8 @@ of C++ compilers: | [r0:r1] | The closed interval [r0,r1] of the specified string. | | | eg: Given a string x with a value of 'abcdefgh' then: | | | 1. x[1:4] == 'bcde' | -| | 2. x[ :5] == x[:5] == 'abcdef' | -| | 3. x[3: ] == x[3:] =='cdefgh' | +| | 2. x[ :5] == x[:10 / 2] == 'abcdef' | +| | 3. x[2 + 1: ] == x[3:] =='defgh' | | | 4. x[ : ] == x[:] == 'abcdefgh' | | | 5. x[4/2:3+2] == x[2:5] == 'cdef' | | | | @@ -767,8 +767,8 @@ normally would in a program, and when the expression is evaluated the current values assigned to the variables will be used. typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; symbol_table_t symbol_table; expression_t expression; @@ -811,8 +811,8 @@ expansive discussion please review section [17 - Hierarchies Of Symbol Tables] typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; symbol_table_t symbol_table0; symbol_table_t symbol_table1; @@ -920,7 +920,7 @@ The above denoted AST will be evaluated in the following order: Generally an expression in ExprTk can be thought of as a free function similar to those found in imperative languages. This form of pseudo function will have a name, it may have a set of one or more inputs and -will return at least one value as its result. Futhermore the function +will return at least one value as its result. Furthermore the function when invoked, may cause a side-effect that changes the state of the host program. @@ -1023,7 +1023,7 @@ copied, it will then result in two or more identical expressions utilizing the exact same references for variables. This obviously is not the default assumed scenario and will give rise to non-obvious behaviours when using the expressions in various contexts such as -muli-threading et al. +multi-threading et al. The prescribed method for cloning an expression is to compile it from its string form. Doing so will allow the 'user' to properly consider @@ -1315,7 +1315,7 @@ in a statement will cause it to have a side-effect: (b) Invoking a user-defined function that has side-effects The following are examples of expressions where the side-effect status -of the statements (or sub-exressions) within the expressions have been +of the statements (sub-expressions) within the expressions have been noted: +-+----------------------+------------------------------+ @@ -1342,7 +1342,7 @@ noted: Note: In example 6 from the above set, it is assumed the user defined -function foo has been registered as having a side_effect. By default +function foo has been registered as having a side-effect. By default all user defined functions are assumed to have side-effects, unless they are configured in their constructors to not have side-effects using the 'disable_has_side_effects' free function. For more @@ -2351,11 +2351,11 @@ expression, an instance of each function needs to be registered with a symbol_table that has been associated with the expression instance. The following demonstrates how all the pieces are put together: - typedef exprtk::symbol_table symbol_table_t; + typedef exprtk::symbol_table symbol_table_t; typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::parser parser_t; typedef exprtk::function_compositor compositor_t; - typedef typename compositor_t::function function_t; + typedef typename compositor_t::function function_t; foo f; boo b; @@ -2747,7 +2747,7 @@ expression that makes use of various elements of each symbol table is then compiled and later on evaluated: typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; + typedef exprtk::expression expression_t; // Setup global constants symbol table symbol_table_t glbl_const_symbol_table; @@ -3511,8 +3511,8 @@ expression will return normally. " return [x, y, x + y, x - y, 'return-call 3'] "; typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; symbol_table_t symbol_table; expression_t expression; @@ -3574,8 +3574,8 @@ itself to have the result variables be assigned the appropriate values. typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; std::string expression_string = " var x := 123.456; " @@ -3843,7 +3843,7 @@ follows: } } else - printf("An error occured."); + printf("An error occurred."); (b) collect_functions @@ -3867,7 +3867,7 @@ follows: } } else - printf("An error occured."); + printf("An error occurred."); Note: When either the 'collect_variables' or 'collect_functions' free @@ -3879,10 +3879,10 @@ true. Note: The default interface provided for both the collect_variables and collect_functions free_functions, assumes that expressions will -only be utilising the ExprTk reserved funnctions (eg: abs, cos, min +only be utilising the ExprTk reserved functions (eg: abs, cos, min etc). When user defined functions are to be used in an expression, a symbol_table instance containing said functions can be passed to -either routine, and will be incorparated during the compilation and +either routine, and will be incorporated during the compilation and Dependent Entity Collection processes. In the following example, a user defined free function named 'foo' is registered with a symbol_table. Finally the symbol_table instance and associated @@ -3912,7 +3912,7 @@ expression string are passed to the exprtk::collect_functions routine. } } else - printf("An error occured."); + printf("An error occurred."); (c) compute @@ -4295,9 +4295,11 @@ into account when using ExprTk: function names are case-insensitive. (07) Variable, vector, string variable and function names must begin - with a letter (A-Z or a-z), then can be comprised of any - combination of letters, digits, underscores and dots. (eg: x, - var1 or power_func99, person.age, item.size.0) + with a letter (A-Z or a-z), then can be comprised of any + combination of letters, digits, underscores and dots, ending in + either a letter (A-Z or a-z), digit or underscore. (eg: x, y2, + var1, power_func99, person.age, item.size.0). The associated + regex pattern is: [a-zA-Z]([a-zA-Z0-9_.]*|[a-zA-Z0-9_]) (08) Expression lengths and sub-expression lists are limited only by storage capacity. @@ -4308,7 +4310,7 @@ into account when using ExprTk: of that symbol-table, otherwise the result will be undefined behavior. - (10) Equal and Nequal are normalised-epsilon equality routines, + (10) Equal and not_equal are normalised-epsilon equality routines, which use epsilons of 0.0000000001 and 0.000001 for double and float types respectively. @@ -4515,9 +4517,9 @@ struct myfunc : public exprtk::ifunction int main() { typedef exprtk::symbol_table symbol_table_t; - typedef exprtk::expression expression_t; - typedef exprtk::parser parser_t; - typedef exprtk::parser_error::type error_t; + typedef exprtk::expression expression_t; + typedef exprtk::parser parser_t; + typedef exprtk::parser_error::type error_t; std::string expression_str = "z := 2 myfunc([4 + sin(x / pi)^3],y ^ 2)"; diff --git a/math-parser-benchmark-project/math-parser-benchmark-project_msvc2015.vcxproj b/math-parser-benchmark-project/math-parser-benchmark-project_msvc2015.vcxproj index 7691828..feb5b56 100644 --- a/math-parser-benchmark-project/math-parser-benchmark-project_msvc2015.vcxproj +++ b/math-parser-benchmark-project/math-parser-benchmark-project_msvc2015.vcxproj @@ -1,406 +1,406 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {48C67E95-2BEA-48EB-8C6A-C30C4ACACADA} - Win32Proj - mathparserbenchmarkproject - - - - Application - true - NotSet - Static - v140 - - - Application - false - true - NotSet - Static - v140 - - - - - - - - - - - - - true - ParserBenchmark - - - false - ParserBenchmark - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_USE_MATH_DEFINES;WIN32_LEAN_AND_MEAN;VC_EXTRALEAN;NOMINMAX;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_SECURE_SCL=0;MUPARSERLIB_EXPORTS;%(PreprocessorDefinitions) - /bigobj %(AdditionalOptions) - true - false - ..\;..\include;..\mpfr - - - Console - true - Advapi32.lib;OleAut32.lib;User32.lib;mpfr.lib;mpir.lib;%(AdditionalDependencies) - $(SolutionDir)$(Configuration)\ParserBenchmark.exe - ..\mpfr\lib;%(AdditionalLibraryDirectories) - - - copy /Y "$(SolutionDir)mpfr\dll\*.dll" "$(TargetDir)" - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_USE_MATH_DEFINES;WIN32_LEAN_AND_MEAN;VC_EXTRALEAN;NOMINMAX;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_SECURE_SCL=0;MUPARSERLIB_EXPORTS;%(PreprocessorDefinitions) - true - AnySuitable - Speed - Precise - ..\;..\include;..\mpfr;..\AsmJit - - - Console - true - true - true - Advapi32.lib;OleAut32.lib;User32.lib;mpfr.lib;mpir.lib;%(AdditionalDependencies) - $(SolutionDir)$(Configuration)\ParserBenchmark.exe - ..\mpfr\lib;%(AdditionalLibraryDirectories) - - - copy /Y "$(SolutionDir)mpfr\dll\*.dll" "$(TargetDir)" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + Debug + Win32 + + + Release + Win32 + + + + {48C67E95-2BEA-48EB-8C6A-C30C4ACACADA} + Win32Proj + mathparserbenchmarkproject + + + + Application + true + NotSet + Static + v140 + + + Application + false + true + NotSet + Static + v140 + + + + + + + + + + + + + true + ParserBenchmark + + + false + ParserBenchmark + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_USE_MATH_DEFINES;WIN32_LEAN_AND_MEAN;VC_EXTRALEAN;NOMINMAX;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_SECURE_SCL=0;MUPARSERLIB_EXPORTS;%(PreprocessorDefinitions) + /bigobj %(AdditionalOptions) + true + false + ..\;..\include;..\mpfr + + + Console + true + Advapi32.lib;OleAut32.lib;User32.lib;mpfr.lib;mpir.lib;%(AdditionalDependencies) + $(SolutionDir)$(Configuration)\ParserBenchmark.exe + ..\mpfr\lib;%(AdditionalLibraryDirectories) + + + copy /Y "$(SolutionDir)mpfr\dll\*.dll" "$(TargetDir)" + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_USE_MATH_DEFINES;WIN32_LEAN_AND_MEAN;VC_EXTRALEAN;NOMINMAX;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_SECURE_SCL=0;MUPARSERLIB_EXPORTS;%(PreprocessorDefinitions) + true + AnySuitable + Speed + Precise + ..\;..\include;..\mpfr;..\AsmJit + + + Console + true + true + true + Advapi32.lib;OleAut32.lib;User32.lib;mpfr.lib;mpir.lib;%(AdditionalDependencies) + $(SolutionDir)$(Configuration)\ParserBenchmark.exe + ..\mpfr\lib;%(AdditionalLibraryDirectories) + + + copy /Y "$(SolutionDir)mpfr\dll\*.dll" "$(TargetDir)" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/math-parser-benchmark-project/math-parser-benchmark-project_msvc2015.vcxproj.filters b/math-parser-benchmark-project/math-parser-benchmark-project_msvc2015.vcxproj.filters index 1510ba7..51e656c 100644 --- a/math-parser-benchmark-project/math-parser-benchmark-project_msvc2015.vcxproj.filters +++ b/math-parser-benchmark-project/math-parser-benchmark-project_msvc2015.vcxproj.filters @@ -1,902 +1,902 @@ - - - - - fparser - - - libcpuid - - - libcpuid - - - libcpuid - - - mathexpr - - - mtparser - - - mtparser - - - mtparser - - - mtparser - - - mtparser - - - mtparser - - - mtparser - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparser2 - - - muparser2 - - - muparser2 - - - muparser2 - - - muparser2 - - - muparser2 - - - libcpuid - - - libcpuid - - - libcpuid - - - - - - - - - - - - - - - - - - - libcpuid - - - lepton - - - lepton - - - lepton - - - lepton - - - lepton - - - lepton - - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - tinyexpr - - - - muparsersse - - - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - exprtk - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - libcpuid - - - libcpuid - - - libcpuid - - - libcpuid - - - libcpuid - - - mathexpr - - - mtparser - - - mtparser - - - mtparser - - - mtparser - - - mtparser - - - mtparser - - - mtparser - - - mtparser - - - mtparser - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparser2 - - - muparser2 - - - muparser2 - - - muparser2 - - - muparser2 - - - muparser2 - - - muparser2 - - - muparser2 - - - muparser2 - - - muparser2 - - - muparser2 - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - libcpuid - - - libcpuid - - - chaiscript - - - muparsersse - - - chaiscript - - - chaiscript - - - chaiscript - - - muparserx - - - muparserx - - - chaiscript - - - muparserx - - - mpfr - - - mpfr - - - mpfr - - - mpfr - - - mpfr - - - mpfr - - - mpfr - - - mpfr - - - exprtk - - - headers - - - headers - - - headers - - - headers - - - headers - - - headers - - - headers - - - headers - - - headers - - - headers - - - headers - - - headers - - - headers - - - headers - - - headers - - - libcpuid - - - lepton - - - lepton - - - lepton - - - lepton - - - lepton - - - lepton - - - lepton - - - lepton - - - lepton - - - lepton - - - lepton - - - headers - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - tinyexpr - - - headers - - - atmsp - - - libcpuid - - - libcpuid - - - libcpuid - - - libcpuid - - - - - fparser - - - chaiscript - - - - - {c28ab40d-41c8-467e-b5c2-92d07af2607e} - - - {9c5daf4d-6f56-4406-96a6-f2b8bf17e28e} - - - {e5240e10-86f9-4344-9abf-f7916671604a} - - - {58983fac-53f7-469f-9366-b88fd1056d4d} - - - {43d309e3-106f-4c92-998f-46007b9b7140} - - - {cce58da5-5a3c-467a-91be-14e814fc8310} - - - {42ba0b45-daf4-478f-b4a6-3e94d1d1680b} - - - {954d0675-ef4b-4ec2-a70c-eafd3cf51e3a} - - - {62022d91-0758-4c48-9ec1-357588124a4c} - - - {f7e6e6a7-b0d3-42e4-9929-52187ce2ce0d} - - - {208371d7-843d-4242-932e-e69219f74637} - - - {087dd1b5-eba9-49b9-9c03-ba91dcda4f46} - - - {7d03bb0e-8cbc-4f3f-8619-2050f99cd007} - - - {64c71230-dd29-4c16-99e9-34d50edaf410} - - - {b1b43109-aa45-419d-bf8d-437e1b5cbab8} - - + + + + + fparser + + + libcpuid + + + libcpuid + + + libcpuid + + + mathexpr + + + mtparser + + + mtparser + + + mtparser + + + mtparser + + + mtparser + + + mtparser + + + mtparser + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparser2 + + + muparser2 + + + muparser2 + + + muparser2 + + + muparser2 + + + muparser2 + + + libcpuid + + + libcpuid + + + libcpuid + + + + + + + + + + + + + + + + + + + libcpuid + + + lepton + + + lepton + + + lepton + + + lepton + + + lepton + + + lepton + + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + tinyexpr + + + + muparsersse + + + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + exprtk + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + libcpuid + + + libcpuid + + + libcpuid + + + libcpuid + + + libcpuid + + + mathexpr + + + mtparser + + + mtparser + + + mtparser + + + mtparser + + + mtparser + + + mtparser + + + mtparser + + + mtparser + + + mtparser + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparser2 + + + muparser2 + + + muparser2 + + + muparser2 + + + muparser2 + + + muparser2 + + + muparser2 + + + muparser2 + + + muparser2 + + + muparser2 + + + muparser2 + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + libcpuid + + + libcpuid + + + chaiscript + + + muparsersse + + + chaiscript + + + chaiscript + + + chaiscript + + + muparserx + + + muparserx + + + chaiscript + + + muparserx + + + mpfr + + + mpfr + + + mpfr + + + mpfr + + + mpfr + + + mpfr + + + mpfr + + + mpfr + + + exprtk + + + headers + + + headers + + + headers + + + headers + + + headers + + + headers + + + headers + + + headers + + + headers + + + headers + + + headers + + + headers + + + headers + + + headers + + + headers + + + libcpuid + + + lepton + + + lepton + + + lepton + + + lepton + + + lepton + + + lepton + + + lepton + + + lepton + + + lepton + + + lepton + + + lepton + + + headers + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + tinyexpr + + + headers + + + atmsp + + + libcpuid + + + libcpuid + + + libcpuid + + + libcpuid + + + + + fparser + + + chaiscript + + + + + {c28ab40d-41c8-467e-b5c2-92d07af2607e} + + + {9c5daf4d-6f56-4406-96a6-f2b8bf17e28e} + + + {e5240e10-86f9-4344-9abf-f7916671604a} + + + {58983fac-53f7-469f-9366-b88fd1056d4d} + + + {43d309e3-106f-4c92-998f-46007b9b7140} + + + {cce58da5-5a3c-467a-91be-14e814fc8310} + + + {42ba0b45-daf4-478f-b4a6-3e94d1d1680b} + + + {954d0675-ef4b-4ec2-a70c-eafd3cf51e3a} + + + {62022d91-0758-4c48-9ec1-357588124a4c} + + + {f7e6e6a7-b0d3-42e4-9929-52187ce2ce0d} + + + {208371d7-843d-4242-932e-e69219f74637} + + + {087dd1b5-eba9-49b9-9c03-ba91dcda4f46} + + + {7d03bb0e-8cbc-4f3f-8619-2050f99cd007} + + + {64c71230-dd29-4c16-99e9-34d50edaf410} + + + {b1b43109-aa45-419d-bf8d-437e1b5cbab8} + + \ No newline at end of file diff --git a/math-parser-benchmark-project/math-parser-benchmark-project_msvc2017.vcxproj b/math-parser-benchmark-project/math-parser-benchmark-project_msvc2017.vcxproj index b910fd3..4d6993c 100644 --- a/math-parser-benchmark-project/math-parser-benchmark-project_msvc2017.vcxproj +++ b/math-parser-benchmark-project/math-parser-benchmark-project_msvc2017.vcxproj @@ -1,425 +1,425 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {48C67E95-2BEA-48EB-8C6A-C30C4ACACADA} - Win32Proj - mathparserbenchmarkproject - 10.0.16299.0 - - - - Application - true - NotSet - Static - v141 - - - Application - false - true - NotSet - Static - v141 - - - - - - - - - - - - - true - ParserBenchmark - - - false - ParserBenchmark - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_USE_MATH_DEFINES;WIN32_LEAN_AND_MEAN;VC_EXTRALEAN;NOMINMAX;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_SECURE_SCL=0;MUPARSERLIB_EXPORTS;%(PreprocessorDefinitions) - /bigobj %(AdditionalOptions) - true - false - ..\;..\include;..\mpfr;..\metl; - - - Console - true - Advapi32.lib;OleAut32.lib;User32.lib;mpfr.lib;mpir.lib;%(AdditionalDependencies) - $(SolutionDir)$(Configuration)\ParserBenchmark.exe - ..\mpfr\lib;%(AdditionalLibraryDirectories) - - - copy /Y "$(SolutionDir)mpfr\dll\*.dll" "$(TargetDir)" - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_USE_MATH_DEFINES;WIN32_LEAN_AND_MEAN;VC_EXTRALEAN;NOMINMAX;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_SECURE_SCL=0;MUPARSERLIB_EXPORTS;%(PreprocessorDefinitions) - true - AnySuitable - Speed - Precise - ..\;..\include;..\mpfr;..\metl;..\AsmJit - - - Console - true - true - true - Advapi32.lib;OleAut32.lib;User32.lib;mpfr.lib;mpir.lib;%(AdditionalDependencies) - $(SolutionDir)$(Configuration)\ParserBenchmark.exe - ..\mpfr\lib;%(AdditionalLibraryDirectories) - - - copy /Y "$(SolutionDir)mpfr\dll\*.dll" "$(TargetDir)" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + Debug + Win32 + + + Release + Win32 + + + + {48C67E95-2BEA-48EB-8C6A-C30C4ACACADA} + Win32Proj + mathparserbenchmarkproject + 10.0.16299.0 + + + + Application + true + NotSet + Static + v141 + + + Application + false + true + NotSet + Static + v141 + + + + + + + + + + + + + true + ParserBenchmark + + + false + ParserBenchmark + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_USE_MATH_DEFINES;WIN32_LEAN_AND_MEAN;VC_EXTRALEAN;NOMINMAX;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_SECURE_SCL=0;MUPARSERLIB_EXPORTS;%(PreprocessorDefinitions) + /bigobj %(AdditionalOptions) + true + false + ..\;..\include;..\mpfr;..\metl; + + + Console + true + Advapi32.lib;OleAut32.lib;User32.lib;mpfr.lib;mpir.lib;%(AdditionalDependencies) + $(SolutionDir)$(Configuration)\ParserBenchmark.exe + ..\mpfr\lib;%(AdditionalLibraryDirectories) + + + copy /Y "$(SolutionDir)mpfr\dll\*.dll" "$(TargetDir)" + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_USE_MATH_DEFINES;WIN32_LEAN_AND_MEAN;VC_EXTRALEAN;NOMINMAX;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_SECURE_SCL=0;MUPARSERLIB_EXPORTS;%(PreprocessorDefinitions) + true + AnySuitable + Speed + Precise + ..\;..\include;..\mpfr;..\metl;..\AsmJit + + + Console + true + true + true + Advapi32.lib;OleAut32.lib;User32.lib;mpfr.lib;mpir.lib;%(AdditionalDependencies) + $(SolutionDir)$(Configuration)\ParserBenchmark.exe + ..\mpfr\lib;%(AdditionalLibraryDirectories) + + + copy /Y "$(SolutionDir)mpfr\dll\*.dll" "$(TargetDir)" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/math-parser-benchmark-project/math-parser-benchmark-project_msvc2017.vcxproj.filters b/math-parser-benchmark-project/math-parser-benchmark-project_msvc2017.vcxproj.filters index 1ff9aaf..cd62e2d 100644 --- a/math-parser-benchmark-project/math-parser-benchmark-project_msvc2017.vcxproj.filters +++ b/math-parser-benchmark-project/math-parser-benchmark-project_msvc2017.vcxproj.filters @@ -1,957 +1,957 @@ - - - - - fparser - - - libcpuid - - - libcpuid - - - libcpuid - - - mathexpr - - - mtparser - - - mtparser - - - mtparser - - - mtparser - - - mtparser - - - mtparser - - - mtparser - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparser2 - - - muparser2 - - - muparser2 - - - muparser2 - - - muparser2 - - - muparser2 - - - libcpuid - - - libcpuid - - - libcpuid - - - - - - - - - - - - - - - - - - - libcpuid - - - lepton - - - lepton - - - lepton - - - lepton - - - lepton - - - lepton - - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - tinyexpr - - - - muparsersse - - - - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - exprtk - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - libcpuid - - - libcpuid - - - libcpuid - - - libcpuid - - - libcpuid - - - mathexpr - - - mtparser - - - mtparser - - - mtparser - - - mtparser - - - mtparser - - - mtparser - - - mtparser - - - mtparser - - - mtparser - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparserx - - - muparser2 - - - muparser2 - - - muparser2 - - - muparser2 - - - muparser2 - - - muparser2 - - - muparser2 - - - muparser2 - - - muparser2 - - - muparser2 - - - muparser2 - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - chaiscript - - - libcpuid - - - libcpuid - - - chaiscript - - - muparsersse - - - chaiscript - - - chaiscript - - - chaiscript - - - muparserx - - - muparserx - - - chaiscript - - - muparserx - - - mpfr - - - mpfr - - - mpfr - - - mpfr - - - mpfr - - - mpfr - - - mpfr - - - mpfr - - - exprtk - - - headers - - - headers - - - headers - - - headers - - - headers - - - headers - - - headers - - - headers - - - headers - - - headers - - - headers - - - headers - - - headers - - - headers - - - headers - - - libcpuid - - - lepton - - - lepton - - - lepton - - - lepton - - - lepton - - - lepton - - - lepton - - - lepton - - - lepton - - - lepton - - - lepton - - - headers - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - muparsersse - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - asmjit - - - tinyexpr - - - headers - - - atmsp - - - libcpuid - - - libcpuid - - - libcpuid - - - libcpuid - - - metl - - - metl - - - metl - - - metl - - - metl - - - metl - - - metl - - - metl - - - metl - - - metl - - - metl - - - metl - - - metl - - - metl - - - metl - - - metl - - - headers - - - - - fparser - - - chaiscript - - - - - {c28ab40d-41c8-467e-b5c2-92d07af2607e} - - - {9c5daf4d-6f56-4406-96a6-f2b8bf17e28e} - - - {e5240e10-86f9-4344-9abf-f7916671604a} - - - {58983fac-53f7-469f-9366-b88fd1056d4d} - - - {43d309e3-106f-4c92-998f-46007b9b7140} - - - {cce58da5-5a3c-467a-91be-14e814fc8310} - - - {42ba0b45-daf4-478f-b4a6-3e94d1d1680b} - - - {954d0675-ef4b-4ec2-a70c-eafd3cf51e3a} - - - {62022d91-0758-4c48-9ec1-357588124a4c} - - - {f7e6e6a7-b0d3-42e4-9929-52187ce2ce0d} - - - {208371d7-843d-4242-932e-e69219f74637} - - - {087dd1b5-eba9-49b9-9c03-ba91dcda4f46} - - - {7d03bb0e-8cbc-4f3f-8619-2050f99cd007} - - - {64c71230-dd29-4c16-99e9-34d50edaf410} - - - {b1b43109-aa45-419d-bf8d-437e1b5cbab8} - - - {121d274d-9553-487e-9d0e-5d05f26a7453} - - + + + + + fparser + + + libcpuid + + + libcpuid + + + libcpuid + + + mathexpr + + + mtparser + + + mtparser + + + mtparser + + + mtparser + + + mtparser + + + mtparser + + + mtparser + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparser2 + + + muparser2 + + + muparser2 + + + muparser2 + + + muparser2 + + + muparser2 + + + libcpuid + + + libcpuid + + + libcpuid + + + + + + + + + + + + + + + + + + + libcpuid + + + lepton + + + lepton + + + lepton + + + lepton + + + lepton + + + lepton + + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + tinyexpr + + + + muparsersse + + + + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + exprtk + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + libcpuid + + + libcpuid + + + libcpuid + + + libcpuid + + + libcpuid + + + mathexpr + + + mtparser + + + mtparser + + + mtparser + + + mtparser + + + mtparser + + + mtparser + + + mtparser + + + mtparser + + + mtparser + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparserx + + + muparser2 + + + muparser2 + + + muparser2 + + + muparser2 + + + muparser2 + + + muparser2 + + + muparser2 + + + muparser2 + + + muparser2 + + + muparser2 + + + muparser2 + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + chaiscript + + + libcpuid + + + libcpuid + + + chaiscript + + + muparsersse + + + chaiscript + + + chaiscript + + + chaiscript + + + muparserx + + + muparserx + + + chaiscript + + + muparserx + + + mpfr + + + mpfr + + + mpfr + + + mpfr + + + mpfr + + + mpfr + + + mpfr + + + mpfr + + + exprtk + + + headers + + + headers + + + headers + + + headers + + + headers + + + headers + + + headers + + + headers + + + headers + + + headers + + + headers + + + headers + + + headers + + + headers + + + headers + + + libcpuid + + + lepton + + + lepton + + + lepton + + + lepton + + + lepton + + + lepton + + + lepton + + + lepton + + + lepton + + + lepton + + + lepton + + + headers + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + muparsersse + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + asmjit + + + tinyexpr + + + headers + + + atmsp + + + libcpuid + + + libcpuid + + + libcpuid + + + libcpuid + + + metl + + + metl + + + metl + + + metl + + + metl + + + metl + + + metl + + + metl + + + metl + + + metl + + + metl + + + metl + + + metl + + + metl + + + metl + + + metl + + + headers + + + + + fparser + + + chaiscript + + + + + {c28ab40d-41c8-467e-b5c2-92d07af2607e} + + + {9c5daf4d-6f56-4406-96a6-f2b8bf17e28e} + + + {e5240e10-86f9-4344-9abf-f7916671604a} + + + {58983fac-53f7-469f-9366-b88fd1056d4d} + + + {43d309e3-106f-4c92-998f-46007b9b7140} + + + {cce58da5-5a3c-467a-91be-14e814fc8310} + + + {42ba0b45-daf4-478f-b4a6-3e94d1d1680b} + + + {954d0675-ef4b-4ec2-a70c-eafd3cf51e3a} + + + {62022d91-0758-4c48-9ec1-357588124a4c} + + + {f7e6e6a7-b0d3-42e4-9929-52187ce2ce0d} + + + {208371d7-843d-4242-932e-e69219f74637} + + + {087dd1b5-eba9-49b9-9c03-ba91dcda4f46} + + + {7d03bb0e-8cbc-4f3f-8619-2050f99cd007} + + + {64c71230-dd29-4c16-99e9-34d50edaf410} + + + {b1b43109-aa45-419d-bf8d-437e1b5cbab8} + + + {121d274d-9553-487e-9d0e-5d05f26a7453} + + \ No newline at end of file diff --git a/math-parser-benchmark-project_msvc2015.sln b/math-parser-benchmark-project_msvc2015.sln index cb31548..bbc3cef 100644 --- a/math-parser-benchmark-project_msvc2015.sln +++ b/math-parser-benchmark-project_msvc2015.sln @@ -1,23 +1,23 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25123.0 -MinimumVisualStudioVersion = 10.0.40219.1 -# Visual Studio 2015 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "math-parser-benchmark-project", "math-parser-benchmark-project\math-parser-benchmark-project.vcxproj", "{48C67E95-2BEA-48EB-8C6A-C30C4ACACADA}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {48C67E95-2BEA-48EB-8C6A-C30C4ACACADA}.Debug|Win32.ActiveCfg = Debug|Win32 - {48C67E95-2BEA-48EB-8C6A-C30C4ACACADA}.Debug|Win32.Build.0 = Debug|Win32 - {48C67E95-2BEA-48EB-8C6A-C30C4ACACADA}.Release|Win32.ActiveCfg = Release|Win32 - {48C67E95-2BEA-48EB-8C6A-C30C4ACACADA}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +# Visual Studio 2015 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "math-parser-benchmark-project", "math-parser-benchmark-project\math-parser-benchmark-project.vcxproj", "{48C67E95-2BEA-48EB-8C6A-C30C4ACACADA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {48C67E95-2BEA-48EB-8C6A-C30C4ACACADA}.Debug|Win32.ActiveCfg = Debug|Win32 + {48C67E95-2BEA-48EB-8C6A-C30C4ACACADA}.Debug|Win32.Build.0 = Debug|Win32 + {48C67E95-2BEA-48EB-8C6A-C30C4ACACADA}.Release|Win32.ActiveCfg = Release|Win32 + {48C67E95-2BEA-48EB-8C6A-C30C4ACACADA}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/math-parser-benchmark-project_msvc2017.sln b/math-parser-benchmark-project_msvc2017.sln index 2937314..cd95f9f 100644 --- a/math-parser-benchmark-project_msvc2017.sln +++ b/math-parser-benchmark-project_msvc2017.sln @@ -1,23 +1,23 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27130.2027 -MinimumVisualStudioVersion = 10.0.40219.1 -# Visual Studio 2015 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "math-parser-benchmark-project", "math-parser-benchmark-project\math-parser-benchmark-project_msvc2017.vcxproj", "{48C67E95-2BEA-48EB-8C6A-C30C4ACACADA}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {48C67E95-2BEA-48EB-8C6A-C30C4ACACADA}.Debug|Win32.ActiveCfg = Debug|Win32 - {48C67E95-2BEA-48EB-8C6A-C30C4ACACADA}.Debug|Win32.Build.0 = Debug|Win32 - {48C67E95-2BEA-48EB-8C6A-C30C4ACACADA}.Release|Win32.ActiveCfg = Release|Win32 - {48C67E95-2BEA-48EB-8C6A-C30C4ACACADA}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27130.2027 +MinimumVisualStudioVersion = 10.0.40219.1 +# Visual Studio 2015 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "math-parser-benchmark-project", "math-parser-benchmark-project\math-parser-benchmark-project_msvc2017.vcxproj", "{48C67E95-2BEA-48EB-8C6A-C30C4ACACADA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {48C67E95-2BEA-48EB-8C6A-C30C4ACACADA}.Debug|Win32.ActiveCfg = Debug|Win32 + {48C67E95-2BEA-48EB-8C6A-C30C4ACACADA}.Debug|Win32.Build.0 = Debug|Win32 + {48C67E95-2BEA-48EB-8C6A-C30C4ACACADA}.Release|Win32.ActiveCfg = Release|Win32 + {48C67E95-2BEA-48EB-8C6A-C30C4ACACADA}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal