diff --git a/exprtk.hpp b/exprtk.hpp index 2da41d8..67752a2 100644 --- a/exprtk.hpp +++ b/exprtk.hpp @@ -64,6 +64,23 @@ namespace exprtk #define exprtk_debug(params) (void)0 #endif + #define exprtk_error_location \ + "exprtk.hpp:" + details::to_str(__LINE__) \ + + #if __GNUC__ >= 7 + + #define exprtk_disable_fallthrough_begin \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wimplicit-fallthrough\"") \ + + #define exprtk_disable_fallthrough_end \ + _Pragma ("GCC diagnostic pop") \ + + #else + #define exprtk_disable_fallthrough_begin (void)0; + #define exprtk_disable_fallthrough_end (void)0; + #endif + namespace details { typedef unsigned char uchar_t; @@ -144,8 +161,10 @@ namespace exprtk #ifndef exprtk_disable_caseinsensitivity inline void case_normalise(std::string& s) { - std::transform - (s.begin(), s.end(), s.begin(), static_cast(std::tolower)); + for (std::size_t i = 0; i < s.size(); ++i) + { + s[i] = static_cast(std::tolower(s[i])); + } } inline bool imatch(const char_t c1, const char_t c2) @@ -173,7 +192,7 @@ namespace exprtk struct ilesscompare { - inline bool operator()(const std::string& s1, const std::string& s2) const + inline bool operator() (const std::string& s1, const std::string& s2) const { const std::size_t length = std::min(s1.size(),s2.size()); @@ -208,7 +227,7 @@ namespace exprtk struct ilesscompare { - inline bool operator()(const std::string& s1, const std::string& s2) const + inline bool operator() (const std::string& s1, const std::string& s2) const { return s1 < s2; } @@ -264,6 +283,11 @@ namespace exprtk return result; } + inline std::string to_str(std::size_t i) + { + return to_str(static_cast(i)); + } + inline bool is_hex_digit(const std::string::value_type digit) { return (('0' <= digit) && (digit <= '9')) || @@ -473,7 +497,7 @@ namespace exprtk { for (std::size_t i = 0; i < reserved_words_size; ++i) { - if (imatch(symbol,reserved_words[i])) + if (imatch(symbol, reserved_words[i])) { return true; } @@ -486,7 +510,7 @@ namespace exprtk { for (std::size_t i = 0; i < reserved_symbols_size; ++i) { - if (imatch(symbol,reserved_symbols[i])) + if (imatch(symbol, reserved_symbols[i])) { return true; } @@ -499,7 +523,7 @@ namespace exprtk { for (std::size_t i = 0; i < base_function_list_size; ++i) { - if (imatch(function_name,base_function_list[i])) + if (imatch(function_name, base_function_list[i])) { return true; } @@ -512,7 +536,7 @@ namespace exprtk { for (std::size_t i = 0; i < cntrl_struct_list_size; ++i) { - if (imatch(cntrl_strct,cntrl_struct_list[i])) + if (imatch(cntrl_strct, cntrl_struct_list[i])) { return true; } @@ -525,7 +549,7 @@ namespace exprtk { for (std::size_t i = 0; i < logic_ops_list_size; ++i) { - if (imatch(lgc_opr,logic_ops_list[i])) + if (imatch(lgc_opr, logic_ops_list[i])) { return true; } @@ -729,23 +753,29 @@ namespace exprtk namespace details { - struct unknown_type_tag {}; - struct real_type_tag {}; - struct complex_type_tag {}; - struct int_type_tag {}; + struct unknown_type_tag { unknown_type_tag() {} }; + struct real_type_tag { real_type_tag () {} }; + struct complex_type_tag { complex_type_tag() {} }; + struct int_type_tag { int_type_tag () {} }; template - struct number_type { typedef unknown_type_tag type; }; + struct number_type + { + typedef unknown_type_tag type; + number_type() {} + }; - #define exprtk_register_real_type_tag(T) \ - template<> struct number_type { typedef real_type_tag type; }; \ + #define exprtk_register_real_type_tag(T) \ + template<> struct number_type \ + { typedef real_type_tag type; number_type() {} }; \ - #define exprtk_register_complex_type_tag(T) \ - template<> struct number_type > \ - { typedef complex_type_tag type; }; \ + #define exprtk_register_complex_type_tag(T) \ + template<> struct number_type > \ + { typedef complex_type_tag type; number_type() {} }; \ - #define exprtk_register_int_type_tag(T) \ - template<> struct number_type { typedef int_type_tag type; }; \ + #define exprtk_register_int_type_tag(T) \ + template<> struct number_type \ + { typedef int_type_tag type; number_type() {} }; \ exprtk_register_real_type_tag(double ) exprtk_register_real_type_tag(long double) @@ -965,7 +995,15 @@ namespace exprtk template inline T root_impl(const T v0, const T v1, real_type_tag) { - return std::pow(v0,T(1) / v1); + if (v1 < T(0)) + return std::numeric_limits::quiet_NaN(); + + const std::size_t n = static_cast(v1); + + if ((v0 < T(0)) && (0 == (n % 2))) + return std::numeric_limits::quiet_NaN(); + + return std::pow(v0, T(1) / n); } template @@ -1278,6 +1316,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 numeric::constant::pi; } + template inline T const_e_impl (real_type_tag) { return numeric::constant::e; } + 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); } template inline T log_impl(const T v, int_type_tag) { return std::log (v); } @@ -1332,161 +1373,161 @@ namespace exprtk template inline int to_int32(const T v) { - typename details::number_type::type num_type; + const typename details::number_type::type num_type; return to_int32_impl(v, num_type); } template inline long long int to_int64(const T v) { - typename details::number_type::type num_type; + const typename details::number_type::type num_type; return to_int64_impl(v, num_type); } template inline bool is_nan(const T v) { - typename details::number_type::type num_type; + const typename details::number_type::type num_type; return is_nan_impl(v, num_type); } template inline T min(const T v0, const T v1) { - typename details::number_type::type num_type; + const typename details::number_type::type num_type; return min_impl(v0, v1, num_type); } template inline T max(const T v0, const T v1) { - typename details::number_type::type num_type; + const typename details::number_type::type num_type; return max_impl(v0, v1, num_type); } template inline T equal(const T v0, const T v1) { - typename details::number_type::type num_type; + const typename details::number_type::type num_type; return equal_impl(v0, v1, num_type); } template inline T nequal(const T v0, const T v1) { - typename details::number_type::type num_type; + const typename details::number_type::type num_type; return nequal_impl(v0, v1, num_type); } template inline T modulus(const T v0, const T v1) { - typename details::number_type::type num_type; + const typename details::number_type::type num_type; return modulus_impl(v0, v1, num_type); } template inline T pow(const T v0, const T v1) { - typename details::number_type::type num_type; + const typename details::number_type::type num_type; return pow_impl(v0, v1, num_type); } template inline T logn(const T v0, const T v1) { - typename details::number_type::type num_type; + const typename details::number_type::type num_type; return logn_impl(v0, v1, num_type); } template inline T root(const T v0, const T v1) { - typename details::number_type::type num_type; + const typename details::number_type::type num_type; return root_impl(v0, v1, num_type); } template inline T roundn(const T v0, const T v1) { - typename details::number_type::type num_type; + const typename details::number_type::type num_type; return roundn_impl(v0, v1, num_type); } template inline T hypot(const T v0, const T v1) { - typename details::number_type::type num_type; + const typename details::number_type::type num_type; return hypot_impl(v0, v1, num_type); } template inline T atan2(const T v0, const T v1) { - typename details::number_type::type num_type; + const typename details::number_type::type num_type; return atan2_impl(v0, v1, num_type); } template inline T shr(const T v0, const T v1) { - typename details::number_type::type num_type; + const typename details::number_type::type num_type; return shr_impl(v0, v1, num_type); } template inline T shl(const T v0, const T v1) { - typename details::number_type::type num_type; + const typename details::number_type::type num_type; return shl_impl(v0, v1, num_type); } template inline T and_opr(const T v0, const T v1) { - typename details::number_type::type num_type; + const typename details::number_type::type num_type; return and_impl(v0, v1, num_type); } template inline T nand_opr(const T v0, const T v1) { - typename details::number_type::type num_type; + const typename details::number_type::type num_type; return nand_impl(v0, v1, num_type); } template inline T or_opr(const T v0, const T v1) { - typename details::number_type::type num_type; + const typename details::number_type::type num_type; return or_impl(v0, v1, num_type); } template inline T nor_opr(const T v0, const T v1) { - typename details::number_type::type num_type; + const typename details::number_type::type num_type; return nor_impl(v0, v1, num_type); } template inline T xor_opr(const T v0, const T v1) { - typename details::number_type::type num_type; + const typename details::number_type::type num_type; return xor_impl(v0, v1, num_type); } template inline T xnor_opr(const T v0, const T v1) { - typename details::number_type::type num_type; + const typename details::number_type::type num_type; return xnor_impl(v0, v1, num_type); } template inline bool is_integer(const T v) { - typename details::number_type::type num_type; + const typename details::number_type::type num_type; return is_integer_impl(v, num_type); } @@ -1526,13 +1567,13 @@ namespace exprtk template struct fast_exp { static inline T result(T v) { return v; } }; template struct fast_exp { static inline T result(T ) { return T(1); } }; - #define exprtk_define_unary_function(FunctionName) \ - template \ - inline T FunctionName (const T v) \ - { \ - typename details::number_type::type num_type; \ - return FunctionName##_impl(v,num_type); \ - } \ + #define exprtk_define_unary_function(FunctionName) \ + template \ + inline T FunctionName (const T v) \ + { \ + const typename details::number_type::type num_type; \ + return FunctionName##_impl(v,num_type); \ + } \ exprtk_define_unary_function(abs ) exprtk_define_unary_function(acos ) @@ -1663,6 +1704,7 @@ namespace exprtk if (length <= 4) { + exprtk_disable_fallthrough_begin switch (length) { #ifdef exprtk_use_lut @@ -1696,6 +1738,7 @@ namespace exprtk #undef exprtk_process_digit } + exprtk_disable_fallthrough_end } else return_result = false; @@ -1875,7 +1918,7 @@ namespace exprtk { int exp = 0; - if (!details::string_to_type_converter_impl_ref(++itr,end,exp)) + if (!details::string_to_type_converter_impl_ref(++itr, end, exp)) { if (end == itr) return false; @@ -1898,11 +1941,11 @@ namespace exprtk { if (('i' == (*itr)) || ('I' == (*itr))) { - return parse_inf(itr,end,t,negative); + return parse_inf(itr, end, t, negative); } else if (('n' == (*itr)) || ('N' == (*itr))) { - return parse_nan(itr,end,t); + return parse_nan(itr, end, t); } else return false; @@ -1914,11 +1957,11 @@ namespace exprtk { if (('i' == (*itr)) || ('I' == (*itr))) { - return parse_inf(itr,end,t,negative); + return parse_inf(itr, end, t, negative); } else if (('n' == (*itr)) || ('N' == (*itr))) { - return parse_nan(itr,end,t); + return parse_nan(itr, end, t); } else return false; @@ -1941,9 +1984,11 @@ namespace exprtk template inline bool string_to_real(const std::string& s, T& t) { + const typename numeric::details::number_type::type num_type; + const char_t* begin = s.data(); const char_t* end = s.data() + s.size(); - typename numeric::details::number_type::type num_type; + return string_to_real(begin, end, t, num_type); } @@ -2003,13 +2048,15 @@ namespace exprtk } template - inline token& set_operator(const token_type tt, const Iterator begin, const Iterator end, const Iterator base_begin = Iterator(0)) + inline token& set_operator(const token_type tt, + const Iterator begin, const Iterator end, + const Iterator base_begin = Iterator(0)) { type = tt; value.assign(begin,end); if (base_begin) position = static_cast(std::distance(base_begin,begin)); - return *this; + return (*this); } template @@ -2019,7 +2066,7 @@ namespace exprtk value.assign(begin,end); if (base_begin) position = static_cast(std::distance(base_begin,begin)); - return *this; + return (*this); } template @@ -2029,7 +2076,7 @@ namespace exprtk value.assign(begin,end); if (base_begin) position = static_cast(std::distance(base_begin,begin)); - return *this; + return (*this); } template @@ -2039,7 +2086,7 @@ namespace exprtk value.assign(begin,end); if (base_begin) position = static_cast(std::distance(base_begin,begin)); - return *this; + return (*this); } inline token& set_string(const std::string& s, const std::size_t p) @@ -2047,11 +2094,13 @@ namespace exprtk type = e_string; value = s; position = p; - return *this; + return (*this); } template - inline token& set_error(const token_type et, const Iterator begin, const Iterator end, const Iterator base_begin = Iterator(0)) + inline token& set_error(const token_type et, + const Iterator begin, const Iterator end, + const Iterator base_begin = Iterator(0)) { if ( (e_error == et) || @@ -2071,7 +2120,7 @@ namespace exprtk if (base_begin) position = static_cast(std::distance(base_begin,begin)); - return *this; + return (*this); } static inline std::string to_str(token_type t) @@ -2177,9 +2226,7 @@ namespace exprtk { scan_token(); - if (token_list_.empty()) - return true; - else if (token_list_.back().is_error()) + if (!token_list_.empty() && token_list_.back().is_error()) return false; } @@ -2292,6 +2339,23 @@ namespace exprtk return (s_end_ == itr); } + inline bool is_comment_start(const char_t* itr) + { + #ifndef exprtk_disable_comments + const char_t c0 = *(itr + 0); + const char_t c1 = *(itr + 1); + + if ('#' == c0) + return true; + else if (!is_end(itr + 1)) + { + if (('/' == c0) && ('/' == c1)) return true; + if (('/' == c0) && ('*' == c1)) return true; + } + #endif + return false; + } + inline void skip_whitespace() { while (!is_end(s_itr_) && details::is_whitespace(*s_itr_)) @@ -2321,47 +2385,72 @@ namespace exprtk return (0 != mode); } - static inline bool comment_end(const char_t c0, const char_t c1, const int mode) + static inline bool comment_end(const char_t c0, const char_t c1, int& mode) { - return ( - ((1 == mode) && ('\n' == c0)) || - ((2 == mode) && ( '*' == c0) && ('/' == c1)) - ); + if ( + ((1 == mode) && ('\n' == c0)) || + ((2 == mode) && ( '*' == c0) && ('/' == c1)) + ) + { + mode = 0; + return true; + } + else + return false; } }; int mode = 0; int increment = 0; - if (is_end(s_itr_) || is_end((s_itr_ + 1))) + if (is_end(s_itr_)) return; - else if (!test::comment_start(*s_itr_,*(s_itr_ + 1),mode,increment)) + else if (!test::comment_start(*s_itr_, *(s_itr_ + 1), mode, increment)) return; + const char_t* cmt_start = s_itr_; + s_itr_ += increment; - while (!is_end(s_itr_) && !test::comment_end(*s_itr_,*(s_itr_ + 1),mode)) + while (!is_end(s_itr_)) { - ++s_itr_; + if ((1 == mode) && test::comment_end(*s_itr_, 0, mode)) + { + ++s_itr_; + return; + } + + if ((2 == mode)) + { + if (!is_end((s_itr_ + 1)) && test::comment_end(*s_itr_, *(s_itr_ + 1), mode)) + { + s_itr_ += 2; + return; + } + } + + ++s_itr_; } - if (!is_end(s_itr_)) + if (2 == mode) { - s_itr_ += mode; - skip_whitespace(); - skip_comments(); + token_t t; + t.set_error(token::e_error, cmt_start, cmt_start + mode, base_itr_); + token_list_.push_back(t); } #endif } inline void scan_token() { - skip_whitespace(); - - skip_comments(); - - if (is_end(s_itr_)) + if (details::is_whitespace(*s_itr_)) { + skip_whitespace(); + return; + } + else if (is_comment_start(s_itr_)) + { + skip_comments(); return; } else if (details::is_operator_char(*s_itr_)) @@ -2457,11 +2546,11 @@ namespace exprtk } if ('<' == c0) - t.set_operator(token_t::e_lt ,s_itr_, s_itr_ + 1, base_itr_); + t.set_operator(token_t::e_lt , s_itr_, s_itr_ + 1, base_itr_); else if ('>' == c0) - t.set_operator(token_t::e_gt ,s_itr_, s_itr_ + 1, base_itr_); + t.set_operator(token_t::e_gt , s_itr_, s_itr_ + 1, base_itr_); else if (';' == c0) - t.set_operator(token_t::e_eof,s_itr_, s_itr_ + 1, base_itr_); + t.set_operator(token_t::e_eof, s_itr_, s_itr_ + 1, base_itr_); else if ('&' == c0) t.set_symbol(s_itr_, s_itr_ + 1, base_itr_); else if ('|' == c0) @@ -2816,7 +2905,7 @@ namespace exprtk const token& t0 = g.token_list_[i ]; const token& t1 = g.token_list_[i + 1]; - if (!operator()(t0,t1)) + if (!operator()(t0, t1)) { return i; } @@ -2829,7 +2918,7 @@ namespace exprtk const token& t1 = g.token_list_[i + 1]; const token& t2 = g.token_list_[i + 2]; - if (!operator()(t0,t1,t2)) + if (!operator()(t0, t1, t2)) { return i; } @@ -2843,7 +2932,7 @@ namespace exprtk const token& t2 = g.token_list_[i + 2]; const token& t3 = g.token_list_[i + 3]; - if (!operator()(t0,t1,t2,t3)) + if (!operator()(t0, t1, t2, t3)) { return i; } @@ -2856,22 +2945,22 @@ namespace exprtk return (g.token_list_.size() - stride_ + 1); } - virtual bool operator()(const token&) + virtual bool operator() (const token&) { return false; } - virtual bool operator()(const token&, const token&) + virtual bool operator() (const token&, const token&) { return false; } - virtual bool operator()(const token&, const token&, const token&) + virtual bool operator() (const token&, const token&, const token&) { return false; } - virtual bool operator()(const token&, const token&, const token&, const token&) + virtual bool operator() (const token&, const token&, const token&, const token&) { return false; } @@ -3007,7 +3096,7 @@ namespace exprtk } } - virtual bool join(const token&, const token&, token&) { return false; } + virtual bool join(const token&, const token&, token&) { return false; } virtual bool join(const token&, const token&, const token&, token&) { return false; } private: @@ -3280,7 +3369,7 @@ namespace exprtk return true; } - // '- -' --> '-' + // '- -' --> '+' else if ((t0.type == lexer::token::e_sub) && (t1.type == lexer::token::e_sub)) { /* @@ -3357,7 +3446,7 @@ namespace exprtk error_token_.clear(); } - bool operator()(const lexer::token& t) + bool operator() (const lexer::token& t) { if ( !t.value.empty() && @@ -3368,7 +3457,7 @@ namespace exprtk { details::char_t c = t.value[0]; - if (t.type == lexer::token::e_lbracket) stack_.push(std::make_pair(')',t.position)); + if (t.type == lexer::token::e_lbracket ) stack_.push(std::make_pair(')',t.position)); else if (t.type == lexer::token::e_lcrlbracket) stack_.push(std::make_pair('}',t.position)); else if (t.type == lexer::token::e_lsqrbracket) stack_.push(std::make_pair(']',t.position)); else if (exprtk::details::is_right_bracket(c)) @@ -3424,7 +3513,7 @@ namespace exprtk current_index_ = 0; } - bool operator()(const lexer::token& t) + bool operator() (const lexer::token& t) { if (token::e_number == t.type) { @@ -3475,7 +3564,7 @@ namespace exprtk bool remove(const std::string& target_symbol) { - replace_map_t::iterator itr = replace_map_.find(target_symbol); + const replace_map_t::iterator itr = replace_map_.find(target_symbol); if (replace_map_.end() == itr) return false; @@ -3489,7 +3578,7 @@ namespace exprtk const std::string& replace_symbol, const lexer::token::token_type token_type = lexer::token::e_symbol) { - replace_map_t::iterator itr = replace_map_.find(target_symbol); + const replace_map_t::iterator itr = replace_map_.find(target_symbol); if (replace_map_.end() != itr) { @@ -3515,7 +3604,7 @@ namespace exprtk if (replace_map_.empty()) return false; - replace_map_t::iterator itr = replace_map_.find(t.value); + const replace_map_t::iterator itr = replace_map_.find(t.value); if (replace_map_.end() != itr) { @@ -3550,7 +3639,6 @@ namespace exprtk add_invalid(lexer::token::e_string ,lexer::token::e_string ); add_invalid(lexer::token::e_number ,lexer::token::e_string ); add_invalid(lexer::token::e_string ,lexer::token::e_number ); - add_invalid(lexer::token::e_string ,lexer::token::e_ternary); add_invalid_set1(lexer::token::e_assign ); add_invalid_set1(lexer::token::e_shr ); add_invalid_set1(lexer::token::e_shl ); @@ -3576,7 +3664,7 @@ namespace exprtk return error_list_.empty(); } - bool operator()(const lexer::token& t0, const lexer::token& t1) + bool operator() (const lexer::token& t0, const lexer::token& t1) { set_t::value_type p = std::make_pair(t0.type,t1.type); @@ -3709,7 +3797,7 @@ namespace exprtk inline bool register_scanner(lexer::token_scanner* scanner) { if (token_scanner_list.end() != std::find(token_scanner_list.begin(), - token_scanner_list.end(), + token_scanner_list.end (), scanner)) { return false; @@ -3723,7 +3811,7 @@ namespace exprtk inline bool register_modifier(lexer::token_modifier* modifier) { if (token_modifier_list.end() != std::find(token_modifier_list.begin(), - token_modifier_list.end(), + token_modifier_list.end (), modifier)) { return false; @@ -3737,7 +3825,7 @@ namespace exprtk inline bool register_joiner(lexer::token_joiner* joiner) { if (token_joiner_list.end() != std::find(token_joiner_list.begin(), - token_joiner_list.end(), + token_joiner_list.end (), joiner)) { return false; @@ -3751,7 +3839,7 @@ namespace exprtk inline bool register_inserter(lexer::token_inserter* inserter) { if (token_inserter_list.end() != std::find(token_inserter_list.begin(), - token_inserter_list.end(), + token_inserter_list.end (), inserter)) { return false; @@ -4096,8 +4184,8 @@ namespace exprtk enum store_type { e_unknown, - e_scalar, - e_vector, + e_scalar , + e_vector , e_string }; @@ -4177,6 +4265,11 @@ namespace exprtk data_(reinterpret_cast(ts_.data)) {} + type_view(const type_store_t& ts) + : ts_(const_cast(ts)), + data_(reinterpret_cast(ts_.data)) + {} + inline std::size_t size() const { return ts_.size; @@ -4225,12 +4318,12 @@ namespace exprtk : v_(*reinterpret_cast(const_cast(ts).data)) {} - inline value_t& operator()() + inline value_t& operator() () { return v_; } - inline const value_t& operator()() const + inline const value_t& operator() () const { return v_; } @@ -4456,7 +4549,7 @@ namespace exprtk { details(const std::size_t& vsize, const unsigned int loop_batch_size = global_loop_batch_size) - : batch_size(loop_batch_size), + : batch_size(loop_batch_size ), remainder (vsize % batch_size), upper_bound(static_cast(vsize - (remainder ? loop_batch_size : 0))) {} @@ -4522,7 +4615,7 @@ namespace exprtk { dump_ptr("~control_block() data",data); delete[] data; - data = 0; + data = reinterpret_cast(0); } } @@ -4531,12 +4624,12 @@ namespace exprtk if (dsize) { if (0 == data_ptr) - return new control_block(dsize); + return (new control_block(dsize)); else - return new control_block(dsize, data_ptr, dstrct); + return (new control_block(dsize, data_ptr, dstrct)); } else - return new control_block; + return (new control_block); } static inline void destroy(control_block*& cntrl_blck) @@ -4617,7 +4710,7 @@ namespace exprtk } } - return *this; + return (*this); } inline data_t data() @@ -5173,10 +5266,17 @@ namespace exprtk return; node_allocator.free(node); - node = 0; + node = reinterpret_cast*>(0); } } + template + inline void destroy_node(expression_node*& node) + { + delete node; + node = reinterpret_cast*>(0); + } + template class vector_holder { @@ -5190,7 +5290,7 @@ namespace exprtk { public: - virtual ~vector_holder_base(){} + virtual ~vector_holder_base() {} inline value_ptr operator[](const std::size_t& index) const { @@ -5360,7 +5460,7 @@ namespace exprtk void set_ref(value_ptr* ref) { - return vector_holder_base_->set_ref(ref); + vector_holder_base_->set_ref(ref); } bool rebaseable() const @@ -5407,8 +5507,7 @@ namespace exprtk { if (branch_ && branch_deletable_) { - delete branch_; - branch_ = 0; + destroy_node(branch_); } } @@ -5472,7 +5571,7 @@ namespace exprtk private: literal_node(literal_node&) {} - literal_node& operator=(literal_node&) { return *this; } + literal_node& operator=(literal_node&) { return (*this); } const T value_; }; @@ -5602,8 +5701,7 @@ namespace exprtk { if (branch_ && branch_deletable_) { - delete branch_; - branch_ = 0; + destroy_node(branch_); } } @@ -5696,8 +5794,7 @@ namespace exprtk { if (branch[i].first && branch[i].second) { - delete branch[i].first; - branch[i].first = 0; + destroy_node(branch[i].first); } } } @@ -5711,8 +5808,7 @@ namespace exprtk { if (branch[i].first && branch[i].second) { - delete branch[i].first; - branch[i].first = 0; + destroy_node(branch[i].first); } } } @@ -5940,9 +6036,20 @@ namespace exprtk ~conditional_node() { - if (test_ && test_deletable_ ) delete test_; - if (consequent_ && consequent_deletable_ ) delete consequent_; - if (alternative_ && alternative_deletable_) delete alternative_; + if (test_ && test_deletable_) + { + destroy_node(test_); + } + + if (consequent_ && consequent_deletable_ ) + { + destroy_node(consequent_); + } + + if (alternative_ && alternative_deletable_) + { + destroy_node(alternative_); + } } inline T value() const @@ -5986,8 +6093,15 @@ namespace exprtk ~cons_conditional_node() { - if (test_ && test_deletable_ ) delete test_; - if (consequent_ && consequent_deletable_) delete consequent_; + if (test_ && test_deletable_) + { + destroy_node(test_); + } + + if (consequent_ && consequent_deletable_) + { + destroy_node(consequent_); + } } inline T value() const @@ -6043,7 +6157,7 @@ namespace exprtk { if (return_deletable_) { - delete return_; + destroy_node(return_); } } @@ -6104,12 +6218,12 @@ namespace exprtk { if (condition_ && condition_deletable_) { - delete condition_; + destroy_node(condition_); } if (loop_body_ && loop_body_deletable_) { - delete loop_body_; + destroy_node(loop_body_); } } @@ -6156,12 +6270,12 @@ namespace exprtk { if (condition_ && condition_deletable_) { - delete condition_; + destroy_node(condition_); } if (loop_body_ && loop_body_deletable_) { - delete loop_body_; + destroy_node(loop_body_); } } @@ -6203,9 +6317,9 @@ namespace exprtk expression_ptr incrementor, expression_ptr loop_body) : initialiser_(initialiser), - condition_ (condition), + condition_ (condition ), incrementor_(incrementor), - loop_body_ (loop_body), + loop_body_ (loop_body ), initialiser_deletable_(branch_deletable(initialiser_)), condition_deletable_ (branch_deletable(condition_ )), incrementor_deletable_(branch_deletable(incrementor_)), @@ -6216,22 +6330,22 @@ namespace exprtk { if (initialiser_ && initialiser_deletable_) { - delete initialiser_; + destroy_node(initialiser_); } if (condition_ && condition_deletable_) { - delete condition_; + destroy_node(condition_); } if (incrementor_ && incrementor_deletable_) { - delete incrementor_; + destroy_node(incrementor_); } if (loop_body_ && loop_body_deletable_) { - delete loop_body_; + destroy_node(loop_body_); } } @@ -6297,12 +6411,12 @@ namespace exprtk { if (condition_ && condition_deletable_) { - delete condition_; + destroy_node(condition_); } if (loop_body_ && loop_body_deletable_) { - delete loop_body_; + destroy_node(loop_body_); } } @@ -6358,12 +6472,12 @@ namespace exprtk { if (condition_ && condition_deletable_) { - delete condition_; + destroy_node(condition_); } if (loop_body_ && loop_body_deletable_) { - delete loop_body_; + destroy_node(loop_body_); } } @@ -6427,22 +6541,22 @@ namespace exprtk { if (initialiser_ && initialiser_deletable_) { - delete initialiser_; + destroy_node(initialiser_); } if (condition_ && condition_deletable_) { - delete condition_; + destroy_node(condition_); } if (incrementor_ && incrementor_deletable_) { - delete incrementor_; + destroy_node(incrementor_); } if (loop_body_ && loop_body_deletable_) { - delete loop_body_; + destroy_node(loop_body_); } } @@ -6548,8 +6662,7 @@ namespace exprtk { if (arg_list_[i] && delete_branch_[i]) { - delete arg_list_[i]; - arg_list_[i] = 0; + destroy_node(arg_list_[i]); } } } @@ -6646,8 +6759,7 @@ namespace exprtk { if (arg_list_[i] && delete_branch_[i]) { - delete arg_list_[i]; - arg_list_[i] = 0; + destroy_node(arg_list_[i]); } } } @@ -6783,8 +6895,7 @@ namespace exprtk !is_string_node (n0_e.second) ) { - delete n0_e.second; - n0_e.second = expression_node_ptr(0); + destroy_node(n0_e.second); } } @@ -6797,8 +6908,7 @@ namespace exprtk !is_string_node (n1_e.second) ) { - delete n1_e.second; - n1_e.second = expression_node_ptr(0); + destroy_node(n1_e.second); } } } @@ -6815,7 +6925,7 @@ namespace exprtk (!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; @@ -7016,7 +7126,7 @@ namespace exprtk { if (index_ && index_deletable_) { - delete index_; + destroy_node(index_); } } @@ -7077,7 +7187,7 @@ namespace exprtk { if (index_ && index_deletable_) { - delete index_; + destroy_node(index_); } } @@ -7188,7 +7298,7 @@ namespace exprtk { if (branch_deletable(initialiser_list_[i])) { - delete initialiser_list_[i]; + destroy_node(initialiser_list_[i]); } } } @@ -7277,7 +7387,7 @@ namespace exprtk typedef ivariable* ivariable_ptr; swap_generic_node(expression_ptr var0, expression_ptr var1) - : binary_node(details::e_swap,var0,var1), + : binary_node(details::e_swap, var0, var1), var0_(dynamic_cast(var0)), var1_(dynamic_cast(var1)) {} @@ -7311,7 +7421,7 @@ namespace exprtk swap_vecvec_node(expression_ptr branch0, expression_ptr branch1) - : binary_node(details::e_swap,branch0,branch1), + : binary_node(details::e_swap, branch0, branch1), vec0_node_ptr_(0), vec1_node_ptr_(0), vec_size_ (0), @@ -7696,8 +7806,7 @@ namespace exprtk if (branch_ && branch_deletable_) { - delete branch_; - branch_ = 0; + destroy_node(branch_); } } @@ -7793,7 +7902,7 @@ namespace exprtk string_concat_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr,branch0,branch1), + : binary_node(opr, branch0, branch1), initialised_(false), str0_base_ptr_ (0), str1_base_ptr_ (0), @@ -7930,7 +8039,7 @@ namespace exprtk typedef irange_t* irange_ptr; swap_string_node(expression_ptr branch0, expression_ptr branch1) - : binary_node(details::e_swap,branch0,branch1), + : binary_node(details::e_swap, branch0, branch1), initialised_(false), str0_node_ptr_(0), str1_node_ptr_(0) @@ -8012,7 +8121,7 @@ namespace exprtk swap_genstrings_node(expression_ptr branch0, expression_ptr branch1) - : binary_node(details::e_default,branch0,branch1), + : binary_node(details::e_default, branch0, branch1), str0_base_ptr_ (0), str1_base_ptr_ (0), str0_range_ptr_(0), @@ -8108,6 +8217,7 @@ namespace exprtk int i = 0; + exprtk_disable_fallthrough_begin switch (lud.remainder) { #define case_stmt(N) \ @@ -8124,6 +8234,7 @@ namespace exprtk case_stmt( 3) case_stmt( 2) case_stmt( 1) } + exprtk_disable_fallthrough_end #undef exprtk_loop #undef case_stmt @@ -8209,8 +8320,7 @@ namespace exprtk { if (branch_ && branch_deletable_) { - delete branch_; - branch_ = 0; + destroy_node(branch_); } } @@ -8269,7 +8379,7 @@ namespace exprtk assignment_string_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr,branch0,branch1), + : binary_node(opr, branch0, branch1), initialised_(false), str0_base_ptr_ (0), str1_base_ptr_ (0), @@ -8315,7 +8425,7 @@ namespace exprtk range_t& range = (*str1_range_ptr_); - if (range(r0,r1,str1_base_ptr_->size())) + if (range(r0, r1, str1_base_ptr_->size())) { AssignmentProcess::execute(str0_node_ptr_->ref(), str1_base_ptr_->base() + r0, @@ -8385,7 +8495,7 @@ namespace exprtk assignment_string_range_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr,branch0,branch1), + : binary_node(opr, branch0, branch1), initialised_(false), str0_base_ptr_ (0), str1_base_ptr_ (0), @@ -8446,8 +8556,8 @@ namespace exprtk 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()) + 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; @@ -8676,7 +8786,7 @@ namespace exprtk cons_conditional_str_node(expression_ptr test, expression_ptr consequent) - : binary_node(details::e_default,consequent,test), + : binary_node(details::e_default, consequent, test), initialised_(false), str0_base_ptr_ (0), str0_range_ptr_(0), @@ -8845,16 +8955,14 @@ namespace exprtk { if (final_node_ && final_deletable_) { - delete final_node_; - final_node_ = 0; + destroy_node(final_node_); } for (std::size_t i = 0; i < arg_list_.size(); ++i) { if (arg_list_[i] && delete_branch_[i]) { - delete arg_list_[i]; - arg_list_[i] = 0; + destroy_node(arg_list_[i]); } } } @@ -9145,7 +9253,7 @@ namespace exprtk expression_ptr branch0, expression_ptr branch1, expression_ptr branch2) - : trinary_node(opr,branch0,branch1,branch2) + : trinary_node(opr, branch0, branch1, branch2) {} inline T value() const @@ -9154,7 +9262,7 @@ namespace exprtk const T y = trinary_node::branch_[1].first->value(); const T z = trinary_node::branch_[2].first->value(); - return SpecialFunction::process(x,y,z); + return SpecialFunction::process(x, y, z); } }; @@ -9170,7 +9278,7 @@ namespace exprtk expression_ptr branch1, expression_ptr branch2, expression_ptr branch3) - : quaternary_node(opr,branch0,branch1,branch2,branch3) + : quaternary_node(opr, branch0, branch1, branch2, branch3) {} inline T value() const @@ -9180,7 +9288,7 @@ namespace exprtk const T z = quaternary_node::branch_[2].first->value(); const T w = quaternary_node::branch_[3].first->value(); - return SpecialFunction::process(x,y,z,w); + return SpecialFunction::process(x, y, z, w); } }; @@ -9199,7 +9307,7 @@ namespace exprtk inline T value() const { - return SpecialFunction::process(v0_,v1_,v2_); + return SpecialFunction::process(v0_, v1_, v2_); } inline typename expression_node::node_type type() const @@ -9233,7 +9341,7 @@ namespace exprtk inline T value() const { - return SpecialFunction::process(v0_,v1_,v2_,v3_); + return SpecialFunction::process(v0_, v1_, v2_, v3_); } inline typename expression_node::node_type type() const @@ -9263,7 +9371,7 @@ namespace exprtk template class Sequence> vararg_node(const Sequence& arg_list) { - arg_list_.resize(arg_list.size()); + arg_list_ .resize(arg_list.size()); delete_branch_.resize(arg_list.size()); for (std::size_t i = 0; i < arg_list.size(); ++i) @@ -9288,8 +9396,7 @@ namespace exprtk { if (arg_list_[i] && delete_branch_[i]) { - delete arg_list_[i]; - arg_list_[i] = 0; + destroy_node(arg_list_[i]); } } } @@ -9383,7 +9490,7 @@ namespace exprtk { if (v_ && v_deletable_) { - delete v_; + destroy_node(v_); } } @@ -9420,7 +9527,7 @@ namespace exprtk assignment_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr,branch0,branch1), + : binary_node(opr, branch0, branch1), var_node_ptr_(0) { if (is_variable_node(binary_node::branch_[0].first)) @@ -9458,7 +9565,7 @@ namespace exprtk assignment_vec_elem_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr,branch0,branch1), + : binary_node(opr, branch0, branch1), vec_node_ptr_(0) { if (is_vector_elem_node(binary_node::branch_[0].first)) @@ -9496,7 +9603,7 @@ namespace exprtk assignment_rebasevec_elem_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr,branch0,branch1), + : binary_node(opr, branch0, branch1), rbvec_node_ptr_(0) { if (is_rebasevector_elem_node(binary_node::branch_[0].first)) @@ -9534,7 +9641,7 @@ namespace exprtk assignment_rebasevec_celem_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr,branch0,branch1), + : binary_node(opr, branch0, branch1), rbvec_node_ptr_(0) { if (is_rebasevector_celem_node(binary_node::branch_[0].first)) @@ -9575,7 +9682,7 @@ namespace exprtk assignment_vec_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr,branch0,branch1), + : binary_node(opr, branch0, branch1), vec_node_ptr_(0) { if (is_vector_node(binary_node::branch_[0].first)) @@ -9615,6 +9722,7 @@ namespace exprtk vec += lud.batch_size; } + exprtk_disable_fallthrough_begin switch (lud.remainder) { #define case_stmt(N) \ @@ -9631,6 +9739,7 @@ namespace exprtk case_stmt( 3) case_stmt( 2) case_stmt( 1) } + exprtk_disable_fallthrough_end #undef exprtk_loop #undef case_stmt @@ -9690,7 +9799,7 @@ namespace exprtk assignment_vecvec_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr,branch0,branch1), + : binary_node(opr, branch0, branch1), vec0_node_ptr_(0), vec1_node_ptr_(0), initialised_(false), @@ -9763,6 +9872,7 @@ namespace exprtk vec1 += lud.batch_size; } + exprtk_disable_fallthrough_begin switch (lud.remainder) { #define case_stmt(N) \ @@ -9779,6 +9889,7 @@ namespace exprtk case_stmt( 3) case_stmt( 2) case_stmt( 1) } + exprtk_disable_fallthrough_end #undef exprtk_loop #undef case_stmt @@ -9838,7 +9949,7 @@ namespace exprtk assignment_op_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr,branch0,branch1), + : binary_node(opr, branch0, branch1), var_node_ptr_(0) { if (is_variable_node(binary_node::branch_[0].first)) @@ -9875,7 +9986,7 @@ namespace exprtk assignment_vec_elem_op_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr,branch0,branch1), + : binary_node(opr, branch0, branch1), vec_node_ptr_(0) { if (is_vector_elem_node(binary_node::branch_[0].first)) @@ -9912,7 +10023,7 @@ namespace exprtk assignment_rebasevec_elem_op_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr,branch0,branch1), + : binary_node(opr, branch0, branch1), rbvec_node_ptr_(0) { if (is_rebasevector_elem_node(binary_node::branch_[0].first)) @@ -9949,7 +10060,7 @@ namespace exprtk assignment_rebasevec_celem_op_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr,branch0,branch1), + : binary_node(opr, branch0, branch1), rbvec_node_ptr_(0) { if (is_rebasevector_celem_node(binary_node::branch_[0].first)) @@ -9989,7 +10100,7 @@ namespace exprtk assignment_vec_op_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr,branch0,branch1), + : binary_node(opr, branch0, branch1), vec_node_ptr_(0) { if (is_vector_node(binary_node::branch_[0].first)) @@ -10029,6 +10140,7 @@ namespace exprtk vec += lud.batch_size; } + exprtk_disable_fallthrough_begin switch (lud.remainder) { #define case_stmt(N) \ @@ -10045,6 +10157,8 @@ namespace exprtk case_stmt( 3) case_stmt( 2) case_stmt( 1) } + exprtk_disable_fallthrough_end + #undef exprtk_loop #undef case_stmt @@ -10109,7 +10223,7 @@ namespace exprtk assignment_vecvec_op_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr,branch0,branch1), + : binary_node(opr, branch0, branch1), vec0_node_ptr_(0), vec1_node_ptr_(0), initialised_(false) @@ -10176,6 +10290,7 @@ namespace exprtk int i = 0; + exprtk_disable_fallthrough_begin switch (lud.remainder) { #define case_stmt(N) \ @@ -10192,6 +10307,7 @@ namespace exprtk case_stmt( 3) case_stmt( 2) case_stmt( 1) } + exprtk_disable_fallthrough_end #undef exprtk_loop #undef case_stmt @@ -10259,7 +10375,7 @@ namespace exprtk vec_binop_vecvec_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr,branch0,branch1), + : binary_node(opr, branch0, branch1), vec0_node_ptr_(0), vec1_node_ptr_(0), temp_ (0), @@ -10361,6 +10477,7 @@ namespace exprtk int i = 0; + exprtk_disable_fallthrough_begin switch (lud.remainder) { #define case_stmt(N) \ @@ -10377,6 +10494,7 @@ namespace exprtk case_stmt( 3) case_stmt( 2) case_stmt( 1) } + exprtk_disable_fallthrough_end #undef exprtk_loop #undef case_stmt @@ -10441,7 +10559,7 @@ namespace exprtk vec_binop_vecval_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr,branch0,branch1), + : binary_node(opr, branch0, branch1), vec0_node_ptr_(0), temp_ (0), temp_vec_node_(0) @@ -10516,6 +10634,7 @@ namespace exprtk int i = 0; + exprtk_disable_fallthrough_begin switch (lud.remainder) { #define case_stmt(N) \ @@ -10532,6 +10651,7 @@ namespace exprtk case_stmt( 3) case_stmt( 2) case_stmt( 1) } + exprtk_disable_fallthrough_end #undef exprtk_loop #undef case_stmt @@ -10594,7 +10714,7 @@ namespace exprtk vec_binop_valvec_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr,branch0,branch1), + : binary_node(opr, branch0, branch1), vec1_node_ptr_(0), temp_ (0), temp_vec_node_(0) @@ -10669,6 +10789,7 @@ namespace exprtk int i = 0; + exprtk_disable_fallthrough_begin switch (lud.remainder) { #define case_stmt(N) \ @@ -10685,6 +10806,7 @@ namespace exprtk case_stmt( 3) case_stmt( 2) case_stmt( 1) } + exprtk_disable_fallthrough_end #undef exprtk_loop #undef case_stmt @@ -10745,7 +10867,7 @@ namespace exprtk typedef vec_data_store vds_t; unary_vector_node(const operator_type& opr, expression_ptr branch0) - : unary_node(opr,branch0), + : unary_node(opr, branch0), vec0_node_ptr_(0), temp_ (0), temp_vec_node_(0) @@ -10819,6 +10941,7 @@ namespace exprtk int i = 0; + exprtk_disable_fallthrough_begin switch (lud.remainder) { #define case_stmt(N) \ @@ -10835,6 +10958,7 @@ namespace exprtk case_stmt( 3) case_stmt( 2) case_stmt( 1) } + exprtk_disable_fallthrough_end #undef exprtk_loop #undef case_stmt @@ -10893,7 +11017,7 @@ namespace exprtk scand_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr,branch0,branch1) + : binary_node(opr, branch0, branch1) {} inline T value() const @@ -10917,7 +11041,7 @@ namespace exprtk scor_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr,branch0,branch1) + : binary_node(opr, branch0, branch1) {} inline T value() const @@ -11280,8 +11404,7 @@ namespace exprtk { if (arg_list_[i] && !details::is_variable_node(arg_list_[i])) { - delete arg_list_[i]; - arg_list_[i] = 0; + destroy_node(arg_list_[i]); } } } @@ -11707,7 +11830,7 @@ namespace exprtk typedef type_store generic_type; typedef typename generic_type::parameter_list parameter_list_t; - inline virtual T operator()(parameter_list_t) + inline virtual T operator() (parameter_list_t) { return std::numeric_limits::quiet_NaN(); } @@ -11767,9 +11890,9 @@ namespace exprtk typedef results_context results_context_t; return_envelope_node(expression_ptr body, results_context_t& rc) - : results_context_(&rc), + : results_context_(&rc ), return_invoked_ (false), - body_ (body), + body_ (body ), body_deletable_ (branch_deletable(body_)) {} @@ -11777,7 +11900,7 @@ namespace exprtk { if (body_ && body_deletable_) { - delete body_; + destroy_node(body_); } } @@ -12761,6 +12884,7 @@ namespace exprtk T result = T(0); int i = 0; + exprtk_disable_fallthrough_begin switch (vec_size) { #define case_stmt(N) \ @@ -12777,6 +12901,7 @@ namespace exprtk case_stmt( 4) case_stmt( 3) case_stmt( 2) case_stmt( 1) } + exprtk_disable_fallthrough_end #undef case_stmt @@ -12811,6 +12936,7 @@ namespace exprtk int i = 0; + exprtk_disable_fallthrough_begin switch (lud.remainder) { #define case_stmt(N) \ @@ -12827,6 +12953,7 @@ namespace exprtk case_stmt( 3) case_stmt( 2) case_stmt( 1) } + exprtk_disable_fallthrough_end #undef exprtk_loop #undef case_stmt @@ -12858,6 +12985,7 @@ namespace exprtk T result = T(1); int i = 0; + exprtk_disable_fallthrough_begin switch (vec_size) { #define case_stmt(N) \ @@ -12874,6 +13002,7 @@ namespace exprtk case_stmt( 4) case_stmt( 3) case_stmt( 2) case_stmt( 1) } + exprtk_disable_fallthrough_end #undef case_stmt @@ -12908,6 +13037,7 @@ namespace exprtk int i = 0; + exprtk_disable_fallthrough_begin switch (lud.remainder) { #define case_stmt(N) \ @@ -12924,6 +13054,7 @@ namespace exprtk case_stmt( 3) case_stmt( 2) case_stmt( 1) } + exprtk_disable_fallthrough_end #undef exprtk_loop #undef case_stmt @@ -13237,9 +13368,9 @@ namespace exprtk ufunc_t uf0, ufunc_t uf1, bfunc_t bf) : v0_(var0), v1_(var1), - u0_(uf0), - u1_(uf1), - f_ (bf) + u0_(uf0 ), + u1_(uf1 ), + f_ (bf ) {} inline T value() const @@ -13311,8 +13442,7 @@ namespace exprtk { if (branch_ && branch_deletable_) { - delete branch_; - branch_ = 0; + destroy_node(branch_); } } @@ -13648,13 +13778,15 @@ namespace exprtk T0 p0, T1 p1, bfunc_t p2) { - return allocator.template allocate_type(p0,p1,p2); + return allocator + .template allocate_type + (p0, p1, p2); } private: T0oT1(T0oT1&) {} - T0oT1& operator=(T0oT1&) { return *this; } + T0oT1& operator=(T0oT1&) { return (*this); } T0 t0_; T1 t1_; @@ -13734,13 +13866,15 @@ namespace exprtk template static inline expression_node* allocate(Allocator& allocator, T0 p0, T1 p1, T2 p2, bfunc_t p3, bfunc_t p4) { - return allocator.template allocate_type(p0,p1,p2,p3,p4); + return allocator + .template allocate_type + (p0, p1, p2, p3, p4); } private: T0oT1oT2(node_type&) {} - node_type& operator=(node_type&) { return *this; } + node_type& operator=(node_type&) { return (*this); } T0 t0_; T1 t1_; @@ -13776,7 +13910,7 @@ namespace exprtk inline T value() const { - return ProcessMode::process(t0_,t1_,t2_,t3_,f0_,f1_,f2_); + return ProcessMode::process(t0_, t1_, t2_, t3_, f0_, f1_, f2_); } inline T0 t0() const @@ -13829,13 +13963,15 @@ namespace exprtk T0 p0, T1 p1, T2 p2, T3 p3, bfunc_t p4, bfunc_t p5, bfunc_t p6) { - return allocator.template allocate_type(p0,p1,p2,p3,p4,p5,p6); + return allocator + .template allocate_type + (p0, p1, p2, p3, p4, p5, p6); } private: T0oT1oT2oT3(node_type&) {} - node_type& operator=(node_type&) { return *this; } + node_type& operator=(node_type&) { return (*this); } T0 t0_; T1 t1_; @@ -13876,7 +14012,7 @@ namespace exprtk inline T value() const { - return f_(t0_,t1_,t2_); + return f_(t0_, t1_, t2_); } inline T0 t0() const @@ -13912,13 +14048,15 @@ namespace exprtk template static inline expression_node* allocate(Allocator& allocator, T0 p0, T1 p1, T2 p2, tfunc_t p3) { - return allocator.template allocate_type(p0,p1,p2,p3); + return allocator + .template allocate_type + (p0, p1, p2, p3); } private: T0oT1oT2_sf3(node_type&) {} - node_type& operator=(node_type&) { return *this; } + node_type& operator=(node_type&) { return (*this); } T0 t0_; T1 t1_; @@ -13970,7 +14108,7 @@ namespace exprtk inline T value() const { - return SF3Operation::process(t0_,t1_,t2_); + return SF3Operation::process(t0_, t1_, t2_); } T0 t0() const @@ -14001,13 +14139,15 @@ namespace exprtk template static inline expression_node* allocate(Allocator& allocator, T0 p0, T1 p1, T2 p2) { - return allocator.template allocate_type(p0,p1,p2); + return allocator + .template allocate_type + (p0, p1, p2); } private: T0oT1oT2_sf3ext(node_type&) {} - node_type& operator=(node_type&) { return *this; } + node_type& operator=(node_type&) { return (*this); } T0 t0_; T1 t1_; @@ -14059,7 +14199,7 @@ namespace exprtk inline T value() const { - return f_(t0_,t1_,t2_,t3_); + return f_(t0_, t1_, t2_, t3_); } inline T0 t0() const @@ -14100,13 +14240,15 @@ namespace exprtk template static inline expression_node* allocate(Allocator& allocator, T0 p0, T1 p1, T2 p2, T3 p3, qfunc_t p4) { - return allocator.template allocate_type(p0,p1,p2,p3,p4); + return allocator + .template allocate_type + (p0, p1, p2, p3, p4); } private: T0oT1oT2oT3_sf4(node_type&) {} - node_type& operator=(node_type&) { return *this; } + node_type& operator=(node_type&) { return (*this); } T0 t0_; T1 t1_; @@ -14145,7 +14287,7 @@ namespace exprtk inline T value() const { - return SF4Operation::process(t0_,t1_,t2_,t3_); + return SF4Operation::process(t0_, t1_, t2_, t3_); } inline T0 t0() const @@ -14181,13 +14323,15 @@ namespace exprtk template static inline expression_node* allocate(Allocator& allocator, T0 p0, T1 p1, T2 p2, T3 p3) { - return allocator.template allocate_type(p0,p1,p2,p3); + return allocator + .template allocate_type + (p0, p1, p2, p3); } private: T0oT1oT2oT3_sf4ext(node_type&) {} - node_type& operator=(node_type&) { return *this; } + node_type& operator=(node_type&) { return (*this); } T0 t0_; T1 t1_; @@ -14667,8 +14811,8 @@ namespace exprtk // string-range op string node explicit str_xrox_node(SType0 p0, SType1 p1, RangePack rp0) - : s0_(p0), - s1_(p1), + : s0_ (p0 ), + s1_ (p1 ), rp0_(rp0) {} @@ -14874,7 +15018,7 @@ namespace exprtk str_sogens_node(const operator_type& opr, expression_ptr branch0, expression_ptr branch1) - : binary_node(opr,branch0,branch1), + : binary_node(opr, branch0, branch1), str0_base_ptr_ (0), str1_base_ptr_ (0), str0_range_ptr_(0), @@ -15342,7 +15486,7 @@ namespace exprtk template inline expression_node* allocate() const { - return new node_type(); + return (new node_type()); } template class Sequence> inline expression_node* allocate(const Sequence& seq) const { - return new node_type(seq); + return (new node_type(seq)); } template inline expression_node* allocate(T1& t1) const { - return new node_type(t1); + return (new node_type(t1)); } template inline expression_node* allocate_c(const T1& t1) const { - return new node_type(t1); + return (new node_type(t1)); } template inline expression_node* allocate(const T1& t1, const T2& t2) const { - return new node_type(t1,t2); + return (new node_type(t1,t2)); } template inline expression_node* allocate_cr(const T1& t1, T2& t2) const { - return new node_type(t1,t2); + return (new node_type(t1,t2)); } template inline expression_node* allocate_rc(T1& t1, const T2& t2) const { - return new node_type(t1,t2); + return (new node_type(t1,t2)); } template inline expression_node* allocate_rr(T1& t1, T2& t2) const { - return new node_type(t1,t2); + return (new node_type(t1,t2)); } template inline expression_node* allocate_tt(T1 t1, T2 t2) const { - return new node_type(t1,t2); + return (new node_type(t1,t2)); } template inline expression_node* allocate_ttt(T1 t1, T2 t2, T3 t3) const { - return new node_type(t1,t2,t3); + return (new node_type(t1,t2,t3)); } template inline expression_node* allocate_tttt(T1 t1, T2 t2, T3 t3, T4 t4) const { - return new node_type(t1,t2,t3,t4); + return (new node_type(t1,t2,t3,t4)); } template inline expression_node* allocate_rrr(T1& t1, T2& t2, T3& t3) const { - return new node_type(t1,t2,t3); + return (new node_type(t1,t2,t3)); } template inline expression_node* allocate_rrrr(T1& t1, T2& t2, T3& t3, T4& t4) const { - return new node_type(t1,t2,t3,t4); + return (new node_type(t1,t2,t3,t4)); } 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); + return (new node_type(t1,t2,t3,t4,t5)); } template * allocate(const T1& t1, const T2& t2, const T3& t3) const { - return new node_type(t1,t2,t3); + return (new node_type(t1,t2,t3)); } template * allocate(const T1& t1, const T2& t2, const T3& t3, const T4& t4) const { - return new node_type(t1,t2,t3,t4); + return (new node_type(t1,t2,t3,t4)); } template inline expression_node* allocate_type(T1 t1, T2 t2, T3 t3) const { - return new node_type(t1,t2,t3); + return (new node_type(t1,t2,t3)); } template * allocate_type(T1 t1, T2 t2, T3 t3, T4 t4) const { - return new node_type(t1,t2,t3,t4); + return (new node_type(t1,t2,t3,t4)); } template + inline expression_node* allocate_type(T1 t1, T2 t2, + T3 t3, T4 t4, + T5 t5, T6 t6) const + { + return (new node_type(t1,t2,t3,t4,t5,t6)); } template @@ -15736,77 +15891,77 @@ namespace exprtk return std::numeric_limits::quiet_NaN(); \ } \ - inline virtual T operator()() + inline virtual T operator() () empty_method_body - inline virtual T operator()(const T&) + inline virtual T operator() (const T&) empty_method_body - inline virtual T operator()(const T&,const T&) + inline virtual T operator() (const T&,const T&) empty_method_body - inline virtual T operator()(const T&, const T&, const T&) + inline virtual T operator() (const T&, const T&, const T&) empty_method_body - inline virtual T operator()(const T&, const T&, const T&, const T&) + inline virtual T operator() (const T&, const T&, const T&, const T&) empty_method_body - inline virtual T operator()(const T&, const T&, const T&, const T&, const T&) + inline virtual T operator() (const T&, const T&, const T&, const T&, const T&) empty_method_body - inline virtual T operator()(const T&, const T&, const T&, const T&, const T&, const T&) + inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&) empty_method_body - inline virtual T operator()(const T&, const T&, const T&, const T&, const T&, const T&, const T&) + inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&) empty_method_body - inline virtual T operator()(const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&) + inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&) empty_method_body - inline virtual T operator()(const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&) + 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 - inline virtual T operator()(const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&) + 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 - inline virtual T operator()(const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, + 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 - 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&) + 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 - 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&) + 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 - 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&) + 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 - 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&) + 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 - 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&) + 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 - 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&) + 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 - 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&) + 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 - 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&) + 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 - 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&) + 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 #undef empty_method_body @@ -15822,7 +15977,7 @@ namespace exprtk virtual ~ivararg_function() {} - inline virtual T operator()(const std::vector&) + inline virtual T operator() (const std::vector&) { exprtk_debug(("ivararg_function::operator() - Operator has not been overridden.\n")); return std::numeric_limits::quiet_NaN(); @@ -15859,19 +16014,19 @@ namespace exprtk } \ // f(i_0,i_1,....,i_N) --> Scalar - inline virtual T operator()(parameter_list_t) + inline virtual T operator() (parameter_list_t) igeneric_function_empty_body(1) // f(i_0,i_1,....,i_N) --> String - inline virtual T operator()(std::string&, parameter_list_t) + inline virtual T operator() (std::string&, parameter_list_t) igeneric_function_empty_body(2) // f(psi,i_0,i_1,....,i_N) --> Scalar - inline virtual T operator()(const std::size_t&, parameter_list_t) + inline virtual T operator() (const std::size_t&, parameter_list_t) igeneric_function_empty_body(3) // f(psi,i_0,i_1,....,i_N) --> String - inline virtual T operator()(const std::size_t&, std::string&, parameter_list_t) + inline virtual T operator() (const std::size_t&, std::string&, parameter_list_t) igeneric_function_empty_body(4) std::string parameter_sequence; @@ -15886,6 +16041,7 @@ namespace exprtk { public: + typedef T (*ff00_functor)(); typedef T (*ff01_functor)(T); typedef T (*ff02_functor)(T,T); typedef T (*ff03_functor)(T,T,T); @@ -15904,12 +16060,22 @@ namespace exprtk protected: + struct freefunc00 : public exprtk::ifunction + { + using exprtk::ifunction::operator(); + + freefunc00(ff00_functor ff) : exprtk::ifunction(0), f(ff) {} + inline T operator() () + { return f(); } + ff00_functor f; + }; + struct freefunc01 : public exprtk::ifunction { using exprtk::ifunction::operator(); freefunc01(ff01_functor ff) : exprtk::ifunction(1), f(ff) {} - inline T operator()(const T& v0) + inline T operator() (const T& v0) { return f(v0); } ff01_functor f; }; @@ -15919,7 +16085,7 @@ namespace exprtk using exprtk::ifunction::operator(); freefunc02(ff02_functor ff) : exprtk::ifunction(2), f(ff) {} - inline T operator()(const T& v0, const T& v1) + inline T operator() (const T& v0, const T& v1) { return f(v0, v1); } ff02_functor f; }; @@ -15929,7 +16095,7 @@ namespace exprtk using exprtk::ifunction::operator(); freefunc03(ff03_functor ff) : exprtk::ifunction(3), f(ff) {} - inline T operator()(const T& v0, const T& v1, const T& v2) + inline T operator() (const T& v0, const T& v1, const T& v2) { return f(v0, v1, v2); } ff03_functor f; }; @@ -15939,7 +16105,7 @@ namespace exprtk using exprtk::ifunction::operator(); freefunc04(ff04_functor ff) : exprtk::ifunction(4), f(ff) {} - inline T operator()(const T& v0, const T& v1, const T& v2, const T& v3) + inline T operator() (const T& v0, const T& v1, const T& v2, const T& v3) { return f(v0, v1, v2, v3); } ff04_functor f; }; @@ -15949,7 +16115,7 @@ namespace exprtk using exprtk::ifunction::operator(); freefunc05(ff05_functor ff) : exprtk::ifunction(5), f(ff) {} - inline T operator()(const T& v0, const T& v1, const T& v2, const T& v3, const T& v4) + inline T operator() (const T& v0, const T& v1, const T& v2, const T& v3, const T& v4) { return f(v0, v1, v2, v3, v4); } ff05_functor f; }; @@ -15959,7 +16125,7 @@ namespace exprtk using exprtk::ifunction::operator(); freefunc06(ff06_functor ff) : exprtk::ifunction(6), f(ff) {} - inline T operator()(const T& v0, const T& v1, const T& v2, const T& v3, const T& v4, const T& v5) + inline T operator() (const T& v0, const T& v1, const T& v2, const T& v3, const T& v4, const T& v5) { return f(v0, v1, v2, v3, v4, v5); } ff06_functor f; }; @@ -15969,8 +16135,8 @@ namespace exprtk using exprtk::ifunction::operator(); freefunc07(ff07_functor ff) : exprtk::ifunction(7), f(ff) {} - inline T operator()(const T& v0, const T& v1, const T& v2, const T& v3, const T& v4, - const T& v5, const T& v6) + inline T operator() (const T& v0, const T& v1, const T& v2, const T& v3, const T& v4, + const T& v5, const T& v6) { return f(v0, v1, v2, v3, v4, v5, v6); } ff07_functor f; }; @@ -15980,8 +16146,8 @@ namespace exprtk using exprtk::ifunction::operator(); freefunc08(ff08_functor ff) : exprtk::ifunction(8), f(ff) {} - inline T operator()(const T& v0, const T& v1, const T& v2, const T& v3, const T& v4, - const T& v5, const T& v6, const T& v7) + inline T operator() (const T& v0, const T& v1, const T& v2, const T& v3, const T& v4, + const T& v5, const T& v6, const T& v7) { return f(v0, v1, v2, v3, v4, v5, v6, v7); } ff08_functor f; }; @@ -15991,8 +16157,8 @@ namespace exprtk using exprtk::ifunction::operator(); freefunc09(ff09_functor ff) : exprtk::ifunction(9), f(ff) {} - inline T operator()(const T& v0, const T& v1, const T& v2, const T& v3, const T& v4, - const T& v5, const T& v6, const T& v7, const T& v8) + inline T operator() (const T& v0, const T& v1, const T& v2, const T& v3, const T& v4, + const T& v5, const T& v6, const T& v7, const T& v8) { return f(v0, v1, v2, v3, v4, v5, v6, v7, v8); } ff09_functor f; }; @@ -16002,8 +16168,8 @@ namespace exprtk using exprtk::ifunction::operator(); freefunc10(ff10_functor ff) : exprtk::ifunction(10), f(ff) {} - inline T operator()(const T& v0, const T& v1, const T& v2, const T& v3, const T& v4, - const T& v5, const T& v6, const T& v7, const T& v8, const T& v9) + inline T operator() (const T& v0, const T& v1, const T& v2, const T& v3, const T& v4, + const T& v5, const T& v6, const T& v7, const T& v8, const T& v9) { return f(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9); } ff10_functor f; }; @@ -16013,8 +16179,8 @@ namespace exprtk using exprtk::ifunction::operator(); freefunc11(ff11_functor ff) : exprtk::ifunction(11), f(ff) {} - inline T operator()(const T& v0, const T& v1, const T& v2, const T& v3, const T& v4, - const T& v5, const T& v6, const T& v7, const T& v8, const T& v9, const T& v10) + inline T operator() (const T& v0, const T& v1, const T& v2, const T& v3, const T& v4, + const T& v5, const T& v6, const T& v7, const T& v8, const T& v9, const T& v10) { return f(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10); } ff11_functor f; }; @@ -16024,9 +16190,9 @@ namespace exprtk using exprtk::ifunction::operator(); freefunc12(ff12_functor ff) : exprtk::ifunction(12), f(ff) {} - inline T operator()(const T& v00, const T& v01, const T& v02, const T& v03, const T& v04, - const T& v05, const T& v06, const T& v07, const T& v08, const T& v09, - const T& v10, const T& v11) + inline T operator() (const T& v00, const T& v01, const T& v02, const T& v03, const T& v04, + const T& v05, const T& v06, const T& v07, const T& v08, const T& v09, + const T& v10, const T& v11) { return f(v00, v01, v02, v03, v04, v05, v06, v07, v08, v09, v10, v11); } ff12_functor f; }; @@ -16036,9 +16202,9 @@ namespace exprtk using exprtk::ifunction::operator(); freefunc13(ff13_functor ff) : exprtk::ifunction(13), f(ff) {} - inline T operator()(const T& v00, const T& v01, const T& v02, const T& v03, const T& v04, - const T& v05, const T& v06, const T& v07, const T& v08, const T& v09, - const T& v10, const T& v11, const T& v12) + inline T operator() (const T& v00, const T& v01, const T& v02, const T& v03, const T& v04, + const T& v05, const T& v06, const T& v07, const T& v08, const T& v09, + const T& v10, const T& v11, const T& v12) { return f(v00, v01, v02, v03, v04, v05, v06, v07, v08, v09, v10, v11, v12); } ff13_functor f; }; @@ -16048,9 +16214,9 @@ namespace exprtk using exprtk::ifunction::operator(); freefunc14(ff14_functor ff) : exprtk::ifunction(14), f(ff) {} - inline T operator()(const T& v00, const T& v01, const T& v02, const T& v03, const T& v04, - const T& v05, const T& v06, const T& v07, const T& v08, const T& v09, - const T& v10, const T& v11, const T& v12, const T& v13) + inline T operator() (const T& v00, const T& v01, const T& v02, const T& v03, const T& v04, + const T& v05, const T& v06, const T& v07, const T& v08, const T& v09, + const T& v10, const T& v11, const T& v12, const T& v13) { return f(v00, v01, v02, v03, v04, v05, v06, v07, v08, v09, v10, v11, v12, v13); } ff14_functor f; }; @@ -16060,9 +16226,9 @@ namespace exprtk using exprtk::ifunction::operator(); freefunc15(ff15_functor ff) : exprtk::ifunction(15), f(ff) {} - inline T operator()(const T& v00, const T& v01, const T& v02, const T& v03, const T& v04, - const T& v05, const T& v06, const T& v07, const T& v08, const T& v09, - const T& v10, const T& v11, const T& v12, const T& v13, const T& v14) + inline T operator() (const T& v00, const T& v01, const T& v02, const T& v03, const T& v04, + const T& v05, const T& v06, const T& v07, const T& v08, const T& v09, + const T& v10, const T& v11, const T& v12, const T& v13, const T& v14) { return f(v00, v01, v02, v03, v04, v05, v06, v07, v08, v09, v10, v11, v12, v13, v14); } ff15_functor f; }; @@ -16133,7 +16299,7 @@ namespace exprtk return false; else { - tm_const_itr_t itr = map.find(symbol_name); + const tm_const_itr_t itr = map.find(symbol_name); if (map.end() == itr) return false; @@ -16156,7 +16322,7 @@ namespace exprtk } } - tm_itr_t itr = map.find(symbol_name); + const tm_itr_t itr = map.find(symbol_name); if (map.end() == itr) { @@ -16266,7 +16432,7 @@ namespace exprtk } }; - tm_itr_t itr = map.find(symbol_name); + const tm_itr_t itr = map.find(symbol_name); if (map.end() == itr) { @@ -16279,7 +16445,7 @@ namespace exprtk inline type_ptr get(const std::string& symbol_name) const { - tm_const_itr_t itr = map.find(symbol_name); + const tm_const_itr_t itr = map.find(symbol_name); if (map.end() == itr) return reinterpret_cast(0); @@ -16327,7 +16493,7 @@ namespace exprtk inline bool remove(const std::string& symbol_name, const bool delete_node = true) { - tm_itr_t itr = map.find(symbol_name); + const tm_itr_t itr = map.find(symbol_name); if (map.end() != itr) { @@ -16367,7 +16533,7 @@ namespace exprtk static RawType null_type = init_type::set(RawType()); - tm_const_itr_t itr = map.find(symbol_name); + const tm_const_itr_t itr = map.find(symbol_name); if (map.end() == itr) return null_type; @@ -16392,7 +16558,7 @@ namespace exprtk if (delete_node) { tm_itr_t itr = map.begin(); - tm_itr_t end = map.end(); + tm_itr_t end = map.end (); while (end != itr) { @@ -16416,7 +16582,7 @@ namespace exprtk if (!map.empty()) { tm_const_itr_t itr = map.begin(); - tm_const_itr_t end = map.end(); + tm_const_itr_t end = map.end (); while (end != itr) { @@ -16438,7 +16604,7 @@ namespace exprtk if (!map.empty()) { tm_const_itr_t itr = map.begin(); - tm_const_itr_t end = map.end(); + tm_const_itr_t end = map.end (); while (end != itr) { @@ -16510,6 +16676,17 @@ namespace exprtk return (reserved_symbol_table_.end() != reserved_symbol_table_.find(symbol)); } + static inline st_data* create() + { + return (new st_data); + } + + static inline void destroy(st_data*& sd) + { + delete sd; + sd = reinterpret_cast(0); + } + std::list local_symbol_list_; std::list local_stringvar_list_; std::set reserved_symbol_table_; @@ -16518,7 +16695,7 @@ namespace exprtk control_block() : ref_count(1), - data_(new st_data) + data_(st_data::create()) {} control_block(st_data* data) @@ -16530,14 +16707,13 @@ namespace exprtk { if (data_ && (0 == ref_count)) { - delete data_; - data_ = 0; + st_data::destroy(data_); } } static inline control_block* create() { - return new control_block; + return (new control_block); } template @@ -16593,7 +16769,7 @@ namespace exprtk control_block_->ref_count++; } - return *this; + return (*this); } inline bool operator==(const symbol_table& st) @@ -16922,11 +17098,11 @@ namespace exprtk inline bool add_function(const std::string& function_name, ff##NN##_functor function) \ { \ if (!valid()) \ - return false; \ - else if (!valid_symbol(function_name)) \ - return false; \ - else if (symbol_exists(function_name)) \ - return false; \ + { return false; } \ + if (!valid_symbol(function_name)) \ + { return false; } \ + if (symbol_exists(function_name)) \ + { return false; } \ \ exprtk::ifunction* ifunc = new freefunc##NN(function); \ \ @@ -16935,14 +17111,14 @@ namespace exprtk return add_function(function_name,(*local_data().free_function_list_.back())); \ } \ - exprtk_define_freefunction(01) exprtk_define_freefunction(02) - exprtk_define_freefunction(03) exprtk_define_freefunction(04) - exprtk_define_freefunction(05) exprtk_define_freefunction(06) - exprtk_define_freefunction(07) exprtk_define_freefunction(08) - exprtk_define_freefunction(09) exprtk_define_freefunction(10) - exprtk_define_freefunction(11) exprtk_define_freefunction(12) - exprtk_define_freefunction(13) exprtk_define_freefunction(14) - exprtk_define_freefunction(15) + exprtk_define_freefunction(00) exprtk_define_freefunction(01) + exprtk_define_freefunction(02) exprtk_define_freefunction(03) + exprtk_define_freefunction(04) exprtk_define_freefunction(05) + exprtk_define_freefunction(06) exprtk_define_freefunction(07) + exprtk_define_freefunction(08) exprtk_define_freefunction(09) + exprtk_define_freefunction(10) exprtk_define_freefunction(11) + exprtk_define_freefunction(12) exprtk_define_freefunction(13) + exprtk_define_freefunction(14) exprtk_define_freefunction(15) #undef exprtk_define_freefunction @@ -17009,6 +17185,8 @@ namespace exprtk return false; else if (symbol_exists(vector_name)) return false; + else if (0 == v_size) + return false; else return local_data().vector_store.add(vector_name,v,v_size); } @@ -17022,6 +17200,8 @@ namespace exprtk return false; else if (symbol_exists(vector_name)) return false; + else if (0 == v.size()) + return false; else return local_data().vector_store.add(vector_name,v); } @@ -17034,6 +17214,8 @@ namespace exprtk return false; else if (symbol_exists(vector_name)) return false; + else if (0 == v.size()) + return false; else return local_data().vector_store.add(vector_name,v); } @@ -17084,12 +17266,13 @@ namespace exprtk { return add_pi () && add_epsilon () && - add_infinity(); + add_infinity() ; } inline bool add_pi() { - static const T local_pi = T(details::numeric::constant::pi); + const typename details::numeric::details::number_type::type num_type; + static const T local_pi = details::numeric::details::const_pi_impl(num_type); return add_constant("pi",local_pi); } @@ -17471,8 +17654,7 @@ namespace exprtk { if (expr && details::branch_deletable(expr)) { - delete expr; - expr = reinterpret_cast(0); + destroy_node(expr); } if (!local_data_list.empty()) @@ -17547,7 +17729,7 @@ namespace exprtk } expression(const expression& e) - : control_block_(e.control_block_), + : control_block_ (e.control_block_ ), symbol_table_list_(e.symbol_table_list_) { control_block_->ref_count++; @@ -17595,7 +17777,7 @@ namespace exprtk { control_block::destroy(control_block_); - return *this; + return (*this); } ~expression() @@ -17608,7 +17790,7 @@ namespace exprtk return control_block_->expr->value(); } - inline T operator()() const + inline T operator() () const { return value(); } @@ -17835,27 +18017,35 @@ namespace exprtk lexer::token token; error_mode mode; std::string diagnostic; + std::string src_location; std::string error_line; std::size_t line_no; std::size_t column_no; }; - inline type make_error(error_mode mode, const std::string& diagnostic = "") + inline type make_error(error_mode mode, + const std::string& diagnostic = "", + const std::string& src_location = "") { type t; - t.mode = mode; - t.token.type = lexer::token::e_error; - t.diagnostic = diagnostic; + t.mode = mode; + t.token.type = lexer::token::e_error; + t.diagnostic = diagnostic; + t.src_location = src_location; exprtk_debug(("%s\n",diagnostic .c_str())); return t; } - inline type make_error(error_mode mode, const lexer::token& tk, const std::string& diagnostic = "") + inline type make_error(error_mode mode, + const lexer::token& tk, + const std::string& diagnostic = "", + const std::string& src_location = "") { type t; t.mode = mode; t.token = tk; t.diagnostic = diagnostic; + t.src_location = src_location; exprtk_debug(("%s\n",diagnostic .c_str())); return t; } @@ -18012,6 +18202,7 @@ namespace exprtk 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; @@ -18321,7 +18512,7 @@ namespace exprtk se.active && se.var_node && details::is_variable_node(se.var_node) - ) + ) { variable_node_ptr vn = reinterpret_cast(se.var_node); @@ -19163,43 +19354,43 @@ namespace exprtk settings_store& enable_all_base_functions() { disabled_func_set_.clear(); - return *this; + return (*this); } settings_store& enable_all_control_structures() { disabled_ctrl_set_.clear(); - return *this; + return (*this); } settings_store& enable_all_logic_ops() { disabled_logic_set_.clear(); - return *this; + return (*this); } settings_store& enable_all_arithmetic_ops() { disabled_arithmetic_set_.clear(); - return *this; + return (*this); } settings_store& enable_all_assignment_ops() { disabled_assignment_set_.clear(); - return *this; + return (*this); } settings_store& enable_all_inequality_ops() { disabled_inequality_set_.clear(); - return *this; + return (*this); } settings_store& enable_local_vardef() { disable_vardef_ = false; - return *this; + return (*this); } settings_store& disable_all_base_functions() @@ -19208,7 +19399,7 @@ namespace exprtk details::base_function_list + details::base_function_list_size, std::insert_iterator (disabled_func_set_, disabled_func_set_.begin())); - return *this; + return (*this); } settings_store& disable_all_control_structures() @@ -19217,7 +19408,7 @@ namespace exprtk details::cntrl_struct_list + details::cntrl_struct_list_size, std::insert_iterator (disabled_ctrl_set_, disabled_ctrl_set_.begin())); - return *this; + return (*this); } settings_store& disable_all_logic_ops() @@ -19226,7 +19417,7 @@ namespace exprtk details::logic_ops_list + details::logic_ops_list_size, std::insert_iterator (disabled_logic_set_, disabled_logic_set_.begin())); - return *this; + return (*this); } settings_store& disable_all_arithmetic_ops() @@ -19235,7 +19426,7 @@ namespace exprtk details::arithmetic_ops_list + details::arithmetic_ops_list_size, std::insert_iterator (disabled_arithmetic_set_, disabled_arithmetic_set_.begin())); - return *this; + return (*this); } settings_store& disable_all_assignment_ops() @@ -19244,7 +19435,7 @@ namespace exprtk details::assignment_ops_list + details::assignment_ops_list_size, std::insert_iterator (disabled_assignment_set_, disabled_assignment_set_.begin())); - return *this; + return (*this); } settings_store& disable_all_inequality_ops() @@ -19253,13 +19444,13 @@ namespace exprtk details::inequality_ops_list + details::inequality_ops_list_size, std::insert_iterator (disabled_inequality_set_, disabled_inequality_set_.begin())); - return *this; + return (*this); } settings_store& disable_local_vardef() { disable_vardef_ = true; - return *this; + return (*this); } bool replacer_enabled () const { return enable_replacer_; } @@ -19388,7 +19579,7 @@ namespace exprtk disabled_func_set_.insert(details::base_function_list[bf - 1]); } - return *this; + return (*this); } settings_store& disable_control_structure(settings_control_structs ctrl_struct) @@ -19401,7 +19592,7 @@ namespace exprtk disabled_ctrl_set_.insert(details::cntrl_struct_list[ctrl_struct - 1]); } - return *this; + return (*this); } settings_store& disable_logic_operation(settings_logic_opr logic) @@ -19414,7 +19605,7 @@ namespace exprtk disabled_logic_set_.insert(details::logic_ops_list[logic - 1]); } - return *this; + return (*this); } settings_store& disable_arithmetic_operation(settings_arithmetic_opr arithmetic) @@ -19427,7 +19618,7 @@ namespace exprtk disabled_arithmetic_set_.insert(details::arithmetic_ops_list[arithmetic - 1]); } - return *this; + return (*this); } settings_store& disable_assignment_operation(settings_assignment_opr assignment) @@ -19440,7 +19631,7 @@ namespace exprtk disabled_assignment_set_.insert(details::assignment_ops_list[assignment - 1]); } - return *this; + return (*this); } settings_store& disable_inequality_operation(settings_inequality_opr inequality) @@ -19453,7 +19644,7 @@ namespace exprtk disabled_inequality_set_.insert(details::inequality_ops_list[inequality - 1]); } - return *this; + return (*this); } settings_store& enable_base_function(settings_base_funcs bf) @@ -19463,7 +19654,7 @@ namespace exprtk (static_cast(bf) < (details::base_function_list_size + 1)) ) { - des_itr_t itr = disabled_func_set_.find(details::base_function_list[bf - 1]); + const des_itr_t itr = disabled_func_set_.find(details::base_function_list[bf - 1]); if (disabled_func_set_.end() != itr) { @@ -19471,7 +19662,7 @@ namespace exprtk } } - return *this; + return (*this); } settings_store& enable_control_structure(settings_control_structs ctrl_struct) @@ -19481,7 +19672,7 @@ namespace exprtk (static_cast(ctrl_struct) < (details::cntrl_struct_list_size + 1)) ) { - des_itr_t itr = disabled_ctrl_set_.find(details::cntrl_struct_list[ctrl_struct - 1]); + const des_itr_t itr = disabled_ctrl_set_.find(details::cntrl_struct_list[ctrl_struct - 1]); if (disabled_ctrl_set_.end() != itr) { @@ -19489,7 +19680,7 @@ namespace exprtk } } - return *this; + return (*this); } settings_store& enable_logic_operation(settings_logic_opr logic) @@ -19499,7 +19690,7 @@ namespace exprtk (static_cast(logic) < (details::logic_ops_list_size + 1)) ) { - des_itr_t itr = disabled_logic_set_.find(details::logic_ops_list[logic - 1]); + const des_itr_t itr = disabled_logic_set_.find(details::logic_ops_list[logic - 1]); if (disabled_logic_set_.end() != itr) { @@ -19507,7 +19698,7 @@ namespace exprtk } } - return *this; + return (*this); } settings_store& enable_arithmetic_operation(settings_arithmetic_opr arithmetic) @@ -19517,7 +19708,7 @@ namespace exprtk (static_cast(arithmetic) < (details::arithmetic_ops_list_size + 1)) ) { - des_itr_t itr = disabled_arithmetic_set_.find(details::arithmetic_ops_list[arithmetic - 1]); + const des_itr_t itr = disabled_arithmetic_set_.find(details::arithmetic_ops_list[arithmetic - 1]); if (disabled_arithmetic_set_.end() != itr) { @@ -19525,7 +19716,7 @@ namespace exprtk } } - return *this; + return (*this); } settings_store& enable_assignment_operation(settings_assignment_opr assignment) @@ -19535,7 +19726,7 @@ namespace exprtk (static_cast(assignment) < (details::assignment_ops_list_size + 1)) ) { - des_itr_t itr = disabled_assignment_set_.find(details::assignment_ops_list[assignment - 1]); + const des_itr_t itr = disabled_assignment_set_.find(details::assignment_ops_list[assignment - 1]); if (disabled_assignment_set_.end() != itr) { @@ -19543,7 +19734,7 @@ namespace exprtk } } - return *this; + return (*this); } settings_store& enable_inequality_operation(settings_inequality_opr inequality) @@ -19553,7 +19744,7 @@ namespace exprtk (static_cast(inequality) < (details::inequality_ops_list_size + 1)) ) { - des_itr_t itr = disabled_inequality_set_.find(details::inequality_ops_list[inequality - 1]); + const des_itr_t itr = disabled_inequality_set_.find(details::inequality_ops_list[inequality - 1]); if (disabled_inequality_set_.end() != itr) { @@ -19561,7 +19752,7 @@ namespace exprtk } } - return *this; + return (*this); } private: @@ -19769,7 +19960,8 @@ namespace exprtk { set_error( make_error(parser_error::e_syntax, - "ERR000 - Empty expression!")); + "ERR000 - Empty expression!", + exprtk_error_location)); return false; } @@ -19784,7 +19976,8 @@ namespace exprtk { set_error( make_error(parser_error::e_syntax, - "ERR001 - Empty expression!")); + "ERR001 - Empty expression!", + exprtk_error_location)); return false; } @@ -19830,7 +20023,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR002 - Invalid expression encountered")); + "ERR002 - Invalid expression encountered", + exprtk_error_location)); } dec_.clear (); @@ -19839,13 +20033,24 @@ namespace exprtk if ((0 != e) && branch_deletable(e)) { - delete e; + destroy_node(e); } return false; } } + inline expression_t compile(const std::string& expression_string, symbol_table_t& symtab) + { + expression_t expr; + + expr.register_symbol_table(symtab); + + compile(expression_string,expr); + + return expr; + } + void process_lexer_errors() { for (std::size_t i = 0; i < lexer().size(); ++i) @@ -19877,7 +20082,8 @@ namespace exprtk set_error( make_error(parser_error::e_lexer, lexer()[i], - diagnostic + ": " + lexer()[i].value)); + diagnostic + ": " + lexer()[i].value, + exprtk_error_location)); } } } @@ -19918,7 +20124,8 @@ namespace exprtk set_error( make_error(parser_error::e_token, bracket_checker_ptr->error_token(), - "ERR004 - Mismatched brackets: '" + bracket_checker_ptr->error_token().value + "'")); + "ERR004 - Mismatched brackets: '" + bracket_checker_ptr->error_token().value + "'", + exprtk_error_location)); } else if (0 != (numeric_checker_ptr = dynamic_cast(helper_assembly_.error_token_scanner))) { @@ -19929,7 +20136,8 @@ namespace exprtk set_error( make_error(parser_error::e_token, error_token, - "ERR005 - Invalid numeric token: '" + error_token.value + "'")); + "ERR005 - Invalid numeric token: '" + error_token.value + "'", + exprtk_error_location)); } if (numeric_checker_ptr->error_count()) @@ -19948,7 +20156,8 @@ namespace exprtk error_token.first, "ERR006 - Invalid token sequence: '" + error_token.first.value + "' and '" + - error_token.second.value + "'")); + error_token.second.value + "'", + exprtk_error_location)); } if (sequence_validator_ptr->error_count()) @@ -20118,7 +20327,7 @@ namespace exprtk expression_node_ptr result = error_node(); - scoped_vec_delete sdd(*this,arg_list); + scoped_vec_delete sdd((*this),arg_list); lexer::token begin_token; lexer::token end_token; @@ -20138,7 +20347,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR007 - Invalid expression encountered")); + "ERR007 - Invalid expression encountered", + exprtk_error_location)); } return error_node(); @@ -20278,6 +20488,7 @@ namespace exprtk 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"; if (details::imatch(current_token().value,s_and)) { @@ -20342,6 +20553,10 @@ namespace exprtk current_state.set(e_level04, e_level04, details::e_ilike); break; } + else if (details::imatch(current_token().value,s_not)) + { + break; + } } break_loop = true; @@ -20369,7 +20584,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, prev_token, - "ERR008 - Invalid arithmetic operation '" + details::to_str(current_state.operation) + "'")); + "ERR008 - Invalid arithmetic operation '" + details::to_str(current_state.operation) + "'", + exprtk_error_location)); return error_node(); } @@ -20380,7 +20596,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, prev_token, - "ERR009 - Invalid inequality operation '" + details::to_str(current_state.operation) + "'")); + "ERR009 - Invalid inequality operation '" + details::to_str(current_state.operation) + "'", + exprtk_error_location)); return error_node(); } @@ -20391,7 +20608,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, prev_token, - "ERR010 - Invalid assignment operation '" + details::to_str(current_state.operation) + "'")); + "ERR010 - Invalid assignment operation '" + details::to_str(current_state.operation) + "'", + exprtk_error_location)); return error_node(); } @@ -20409,7 +20627,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, prev_token, - "ERR011 - Return statements cannot be part of sub-expressions")); + "ERR011 - Return statements cannot be part of sub-expressions", + exprtk_error_location)); return error_node(); } @@ -20431,7 +20650,8 @@ namespace exprtk prev_token, !synthesis_error_.empty() ? synthesis_error_ : - "ERR012 - General parsing error at token: '" + prev_token.value + "'")); + "ERR012 - General parsing error at token: '" + prev_token.value + "'", + exprtk_error_location)); } free_node(node_allocator_,expression); @@ -20499,7 +20719,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR013 - Failed to find variable node in symbol table")); + "ERR013 - Failed to find variable node in symbol table", + exprtk_error_location)); free_node(node_allocator_,node); @@ -20678,7 +20899,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR014 - Invalid number of parameters for function: '" + function_name + "'")); + "ERR014 - Invalid number of parameters for function: '" + function_name + "'", + exprtk_error_location)); return error_node(); } @@ -20691,7 +20913,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR015 - Failed to generate call to function: '" + function_name + "'")); + "ERR015 - Failed to generate call to function: '" + function_name + "'", + exprtk_error_location)); return error_node(); } @@ -20709,7 +20932,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR016 - Expecting ifunction '" + function_name + "' to have non-zero parameter count")); + "ERR016 - Expecting ifunction '" + function_name + "' to have non-zero parameter count", + exprtk_error_location)); return error_node(); } @@ -20722,7 +20946,7 @@ namespace exprtk std::fill_n(branch, NumberofParameters, reinterpret_cast(0)); - scoped_delete sd(*this,branch); + scoped_delete sd((*this),branch); next_token(); @@ -20731,7 +20955,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR017 - Expecting argument list for function: '" + function_name + "'")); + "ERR017 - Expecting argument list for function: '" + function_name + "'", + exprtk_error_location)); return error_node(); } @@ -20745,7 +20970,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR018 - Failed to parse argument " + details::to_str(i) + " for function: '" + function_name + "'")); + "ERR018 - Failed to parse argument " + details::to_str(i) + " for function: '" + function_name + "'", + exprtk_error_location)); return error_node(); } @@ -20756,7 +20982,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR019 - Invalid number of arguments for function: '" + function_name + "'")); + "ERR019 - Invalid number of arguments for function: '" + function_name + "'", + exprtk_error_location)); return error_node(); } @@ -20768,7 +20995,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR020 - Invalid number of arguments for function: '" + function_name + "'")); + "ERR020 - Invalid number of arguments for function: '" + function_name + "'", + exprtk_error_location)); return error_node(); } @@ -20796,7 +21024,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR021 - Expecting '()' to proceed call to function: '" + function_name + "'")); + "ERR021 - Expecting '()' to proceed call to function: '" + function_name + "'", + exprtk_error_location)); free_node(node_allocator_,result); @@ -20807,11 +21036,11 @@ namespace exprtk } template - inline std::size_t parse_base_function_call(expression_node_ptr (¶m_list)[MaxNumberofParameters]) + inline std::size_t parse_base_function_call(expression_node_ptr (¶m_list)[MaxNumberofParameters], const std::string& function_name = "") { std::fill_n(param_list, MaxNumberofParameters, reinterpret_cast(0)); - scoped_delete sd(*this,param_list); + scoped_delete sd((*this),param_list); next_token(); @@ -20820,7 +21049,20 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR022 - Expected a '(' at start of function call, instead got: '" + current_token().value + "'")); + "ERR022 - Expected a '(' at start of function call to '" + function_name + + "', instead got: '" + current_token().value + "'", + exprtk_error_location)); + + return 0; + } + + if (token_is(token_t::e_rbracket, e_hold)) + { + set_error( + make_error(parser_error::e_syntax, + current_token(), + "ERR023 - Expected at least one input parameter for function call '" + function_name + "'", + exprtk_error_location)); return 0; } @@ -20834,7 +21076,10 @@ namespace exprtk if (0 == param_list[param_index]) return 0; else if (token_is(token_t::e_rbracket)) + { + sd.delete_ptr = false; break; + } else if (token_is(token_t::e_comma)) continue; else @@ -20842,13 +21087,23 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR023 - Expected a ',' between function input parameters, instead got: '" + current_token().value + "'")); + "ERR024 - Expected a ',' between function input parameters, instead got: '" + current_token().value + "'", + exprtk_error_location)); return 0; } } - sd.delete_ptr = false; + if (sd.delete_ptr) + { + set_error( + make_error(parser_error::e_syntax, + current_token(), + "ERR025 - Invalid number of input parameters passed to function '" + function_name + "'", + exprtk_error_location)); + + return 0; + } return (param_index + 1); } @@ -20857,7 +21112,8 @@ namespace exprtk { typedef std::pair map_range_t; - const std::string operation_name = current_token().value; + const std::string operation_name = current_token().value; + const token_t diagnostic_token = current_token(); map_range_t itr_range = base_ops_map_.equal_range(operation_name); @@ -20865,8 +21121,9 @@ namespace exprtk { set_error( make_error(parser_error::e_syntax, - current_token(), - "ERR024 - No entry found for base operation: " + operation_name)); + diagnostic_token, + "ERR026 - No entry found for base operation: " + operation_name, + exprtk_error_location)); return error_node(); } @@ -20874,13 +21131,9 @@ namespace exprtk static const std::size_t MaxNumberofParameters = 4; expression_node_ptr param_list[MaxNumberofParameters] = {0}; - const std::size_t parameter_count = parse_base_function_call(param_list); + const std::size_t parameter_count = parse_base_function_call(param_list, operation_name); - if (0 == parameter_count) - { - return error_node(); - } - else if (parameter_count <= MaxNumberofParameters) + if ((parameter_count > 0) && (parameter_count <= MaxNumberofParameters)) { for (base_ops_map_t::iterator itr = itr_range.first; itr != itr_range.second; ++itr) { @@ -20910,13 +21163,14 @@ namespace exprtk for (std::size_t i = 0; i < MaxNumberofParameters; ++i) { - free_node(node_allocator_,param_list[i]); + free_node(node_allocator_, param_list[i]); } set_error( make_error(parser_error::e_syntax, - current_token(), - "ERR025 - Invalid number of parameters for call to function: '" + operation_name + "'")); + diagnostic_token, + "ERR027 - Invalid number of input parameters for call to function: '" + operation_name + "'", + exprtk_error_location)); return error_node(); } @@ -20935,7 +21189,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR026 - Expected ',' between if-statement condition and consequent")); + "ERR028 - Expected ',' between if-statement condition and consequent", + exprtk_error_location)); result = false; } else if (0 == (consequent = parse_expression())) @@ -20943,7 +21198,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR027 - Failed to parse consequent for if-statement")); + "ERR029 - Failed to parse consequent for if-statement", + exprtk_error_location)); result = false; } else if (!token_is(token_t::e_comma)) @@ -20951,7 +21207,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR028 - Expected ',' between if-statement consequent and alternative")); + "ERR030 - Expected ',' between if-statement consequent and alternative", + exprtk_error_location)); result = false; } else if (0 == (alternative = parse_expression())) @@ -20959,7 +21216,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR029 - Failed to parse alternative for if-statement")); + "ERR031 - Failed to parse alternative for if-statement", + exprtk_error_location)); result = false; } else if (!token_is(token_t::e_rbracket)) @@ -20967,7 +21225,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR030 - Expected ')' at the end of if-statement")); + "ERR032 - Expected ')' at the end of if-statement", + exprtk_error_location)); result = false; } @@ -20988,7 +21247,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR031 - Return types of ternary if-statement differ")); + "ERR033 - Return types of ternary if-statement differ", + exprtk_error_location)); result = false; } @@ -21022,7 +21282,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR032 - Failed to parse body of consequent for if-statement")); + "ERR034 - Failed to parse body of consequent for if-statement", + exprtk_error_location)); + result = false; } } @@ -21043,7 +21305,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR033 - Expected ';' at the end of the consequent for if-statement")); + "ERR035 - Expected ';' at the end of the consequent for if-statement", + exprtk_error_location)); + result = false; } } @@ -21052,7 +21316,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR034 - Failed to parse body of consequent for if-statement")); + "ERR036 - Failed to parse body of consequent for if-statement", + exprtk_error_location)); + result = false; } } @@ -21070,7 +21336,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR035 - Failed to parse body of the 'else' for if-statement")); + "ERR037 - Failed to parse body of the 'else' for if-statement", + exprtk_error_location)); + result = false; } } @@ -21081,7 +21349,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR036 - Failed to parse body of if-else statement")); + "ERR038 - Failed to parse body of if-else statement", + exprtk_error_location)); + result = false; } } @@ -21092,7 +21362,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR037 - Expected ';' at the end of the 'else-if' for the if-statement")); + "ERR039 - Expected ';' at the end of the 'else-if' for the if-statement", + exprtk_error_location)); + result = false; } } @@ -21101,7 +21373,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR038 - Failed to parse body of the 'else' for if-statement")); + "ERR040 - Failed to parse body of the 'else' for if-statement", + exprtk_error_location)); + result = false; } } @@ -21124,7 +21398,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR039 - Return types of ternary if-statement differ")); + "ERR041 - Return types of ternary if-statement differ", + exprtk_error_location)); result = false; } @@ -21155,7 +21430,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR040 - Expected '(' at start of if-statement, instead got: '" + current_token().value + "'")); + "ERR042 - Expected '(' at start of if-statement, instead got: '" + current_token().value + "'", + exprtk_error_location)); return error_node(); } @@ -21164,7 +21440,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR041 - Failed to parse condition for if-statement")); + "ERR043 - Failed to parse condition for if-statement", + exprtk_error_location)); return error_node(); } @@ -21195,7 +21472,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR042 - Invalid if-statement")); + "ERR044 - Invalid if-statement", + exprtk_error_location)); free_node(node_allocator_,condition); @@ -21215,7 +21493,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR043 - Encountered invalid condition branch for ternary if-statement")); + "ERR045 - Encountered invalid condition branch for ternary if-statement", + exprtk_error_location)); return error_node(); } @@ -21224,7 +21503,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR044 - Expected '?' after condition of ternary if-statement")); + "ERR046 - Expected '?' after condition of ternary if-statement", + exprtk_error_location)); result = false; } @@ -21233,7 +21513,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR045 - Failed to parse consequent for ternary if-statement")); + "ERR047 - Failed to parse consequent for ternary if-statement", + exprtk_error_location)); result = false; } @@ -21242,7 +21523,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR046 - Expected ':' between ternary if-statement consequent and alternative")); + "ERR048 - Expected ':' between ternary if-statement consequent and alternative", + exprtk_error_location)); result = false; } @@ -21251,7 +21533,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR047 - Failed to parse alternative for ternary if-statement")); + "ERR049 - Failed to parse alternative for ternary if-statement", + exprtk_error_location)); result = false; } @@ -21273,7 +21556,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR048 - Return types of ternary if-statement differ")); + "ERR050 - Return types of ternary if-statement differ", + exprtk_error_location)); result = false; } @@ -21309,7 +21593,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR049 - Expected '(' at start of while-loop condition statement")); + "ERR051 - Expected '(' at start of while-loop condition statement", + exprtk_error_location)); return error_node(); } @@ -21318,7 +21603,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR050 - Failed to parse condition for while-loop")); + "ERR052 - Failed to parse condition for while-loop", + exprtk_error_location)); return error_node(); } @@ -21327,7 +21613,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR051 - Expected ')' at end of while-loop condition statement")); + "ERR053 - Expected ')' at end of while-loop condition statement", + exprtk_error_location)); + result = false; } @@ -21340,7 +21628,7 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR052 - Failed to parse body of while-loop")); + "ERR054 - Failed to parse body of while-loop")); result = false; } else if (0 == (result_node = expression_generator_.while_loop(condition, @@ -21350,7 +21638,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR053 - Failed to synthesize while-loop")); + "ERR055 - Failed to synthesize while-loop", + exprtk_error_location)); + result = false; } } @@ -21379,7 +21669,7 @@ namespace exprtk std::vector arg_list; std::vector side_effect_list; - scoped_vec_delete sdd(*this,arg_list); + scoped_vec_delete sdd((*this),arg_list); brkcnt_list_.push_front(false); @@ -21424,7 +21714,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR054 - Expected '" + token_t::to_str(seperator) + "' in body of repeat until loop")); + "ERR056 - Expected '" + token_t::to_str(seperator) + "' in body of repeat until loop", + exprtk_error_location)); return error_node(); } @@ -21447,7 +21738,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR055 - Failed to parse body of repeat until loop")); + "ERR057 - Failed to parse body of repeat until loop", + exprtk_error_location)); return error_node(); } @@ -21460,7 +21752,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR056 - Expected '(' before condition statement of repeat until loop")); + "ERR058 - Expected '(' before condition statement of repeat until loop", + exprtk_error_location)); free_node(node_allocator_,branch); @@ -21473,7 +21766,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR057 - Failed to parse condition for repeat until loop")); + "ERR059 - Failed to parse condition for repeat until loop", + exprtk_error_location)); free_node(node_allocator_,branch); @@ -21484,7 +21778,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR058 - Expected ')' after condition of repeat until loop")); + "ERR060 - Expected ')' after condition of repeat until loop", + exprtk_error_location)); free_node(node_allocator_, branch); free_node(node_allocator_, condition); @@ -21504,7 +21799,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR059 - Failed to synthesize repeat until loop")); + "ERR061 - Failed to synthesize repeat until loop", + exprtk_error_location)); free_node(node_allocator_,condition); @@ -21539,7 +21835,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR060 - Expected '(' at start of for-loop")); + "ERR062 - Expected '(' at start of for-loop", + exprtk_error_location)); return error_node(); } @@ -21558,7 +21855,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR061 - Expected a variable at the start of initialiser section of for-loop")); + "ERR063 - Expected a variable at the start of initialiser section of for-loop", + exprtk_error_location)); return error_node(); } @@ -21567,7 +21865,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR062 - Expected variable assignment of initialiser section of for-loop")); + "ERR064 - Expected variable assignment of initialiser section of for-loop", + exprtk_error_location)); return error_node(); } @@ -21581,7 +21880,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR063 - For-loop variable '" + loop_counter_symbol+ "' is being shadowed by a previous declaration")); + "ERR065 - For-loop variable '" + loop_counter_symbol+ "' is being shadowed by a previous declaration", + exprtk_error_location)); return error_node(); } @@ -21612,7 +21912,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR064 - Failed to add new local variable '" + loop_counter_symbol + "' to SEM")); + "ERR066 - Failed to add new local variable '" + loop_counter_symbol + "' to SEM", + exprtk_error_location)); sem_.free_element(nse); @@ -21633,7 +21934,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR065 - Failed to parse initialiser of for-loop")); + "ERR067 - Failed to parse initialiser of for-loop", + exprtk_error_location)); + result = false; } else if (!token_is(token_t::e_eof)) @@ -21641,7 +21944,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR066 - Expected ';' after initialiser of for-loop")); + "ERR068 - Expected ';' after initialiser of for-loop", + exprtk_error_location)); + result = false; } } @@ -21653,7 +21958,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR067 - Failed to parse condition of for-loop")); + "ERR069 - Failed to parse condition of for-loop", + exprtk_error_location)); + result = false; } else if (!token_is(token_t::e_eof)) @@ -21661,7 +21968,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR068 - Expected ';' after condition section of for-loop")); + "ERR070 - Expected ';' after condition section of for-loop", + exprtk_error_location)); + result = false; } } @@ -21673,7 +21982,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR069 - Failed to parse incrementor of for-loop")); + "ERR071 - Failed to parse incrementor of for-loop", + exprtk_error_location)); + result = false; } else if (!token_is(token_t::e_rbracket)) @@ -21681,7 +21992,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR070 - Expected ')' after incrementor section of for-loop")); + "ERR072 - Expected ')' after incrementor section of for-loop", + exprtk_error_location)); + result = false; } } @@ -21695,7 +22008,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR071 - Failed to parse body of for-loop")); + "ERR073 - Failed to parse body of for-loop", + exprtk_error_location)); + result = false; } } @@ -21745,12 +22060,13 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR072 - Expected keyword 'switch'")); + "ERR074 - Expected keyword 'switch'", + exprtk_error_location)); return error_node(); } - scoped_vec_delete svd(*this,arg_list); + scoped_vec_delete svd((*this),arg_list); next_token(); @@ -21759,7 +22075,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR073 - Expected '{' for call to switch statement")); + "ERR075 - Expected '{' for call to switch statement", + exprtk_error_location)); return error_node(); } @@ -21771,7 +22088,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR074 - Expected either a 'case' or 'default' statement")); + "ERR076 - Expected either a 'case' or 'default' statement", + exprtk_error_location)); return error_node(); } @@ -21787,7 +22105,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR075 - Expected ':' for case of switch statement")); + "ERR077 - Expected ':' for case of switch statement", + exprtk_error_location)); return error_node(); } @@ -21801,7 +22120,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR076 - Expected ';' at end of case for switch statement")); + "ERR078 - Expected ';' at end of case for switch statement", + exprtk_error_location)); return error_node(); } @@ -21826,7 +22146,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR077 - Expected ':' for default of switch statement")); + "ERR079 - Expected ':' for default of switch statement", + exprtk_error_location)); return error_node(); } @@ -21847,7 +22168,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR078 - Expected ';' at end of default for switch statement")); + "ERR080 - Expected ';' at end of default for switch statement", + exprtk_error_location)); return error_node(); } @@ -21862,7 +22184,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR079 - Expected '}' at end of switch statement")); + "ERR081 - Expected '}' at end of switch statement", + exprtk_error_location)); return error_node(); } @@ -21884,12 +22207,13 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR080 - Expected token '[*]'")); + "ERR082 - Expected token '[*]'", + exprtk_error_location)); return error_node(); } - scoped_vec_delete svd(*this,arg_list); + scoped_vec_delete svd((*this),arg_list); next_token(); @@ -21898,7 +22222,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR081 - Expected '{' for call to [*] statement")); + "ERR083 - Expected '{' for call to [*] statement", + exprtk_error_location)); return error_node(); } @@ -21910,7 +22235,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR082 - Expected a 'case' statement for multi-switch")); + "ERR084 - Expected a 'case' statement for multi-switch", + exprtk_error_location)); return error_node(); } @@ -21927,7 +22253,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR083 - Expected ':' for case of [*] statement")); + "ERR085 - Expected ':' for case of [*] statement", + exprtk_error_location)); return error_node(); } @@ -21942,7 +22269,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR084 - Expected ';' at end of case for [*] statement")); + "ERR086 - Expected ';' at end of case for [*] statement", + exprtk_error_location)); return error_node(); } @@ -21970,7 +22298,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR085 - Expected '}' at end of [*] statement")); + "ERR087 - Expected '}' at end of [*] statement", + exprtk_error_location)); return error_node(); } @@ -22011,12 +22340,13 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR086 - Unsupported vararg function: " + symbol)); + "ERR088 - Unsupported vararg function: " + symbol, + exprtk_error_location)); return error_node(); } - scoped_vec_delete sdd(*this,arg_list); + scoped_vec_delete sdd((*this),arg_list); lodge_symbol(symbol,e_st_function); @@ -22027,7 +22357,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR087 - Expected '(' for call to vararg function: " + symbol)); + "ERR089 - Expected '(' for call to vararg function: " + symbol, + exprtk_error_location)); return error_node(); } @@ -22048,7 +22379,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR088 - Expected ',' for call to vararg function: " + symbol)); + "ERR090 - Expected ',' for call to vararg function: " + symbol, + exprtk_error_location)); return error_node(); } @@ -22068,7 +22400,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR089 - Expected '[' as start of string range definition")); + "ERR091 - Expected '[' as start of string range definition", + exprtk_error_location)); free_node(node_allocator_,expression); @@ -22095,7 +22428,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR090 - Failed to generate string range node")); + "ERR092 - Failed to generate string range node", + exprtk_error_location)); free_node(node_allocator_,expression); } @@ -22230,8 +22564,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR091 - Expected '" + token_t::to_str(close_bracket) + "' for call to multi-sequence" + - ((!source.empty()) ? std::string(" section of " + source): ""))); + "ERR093 - Expected '" + token_t::to_str(close_bracket) + "' for call to multi-sequence" + + ((!source.empty()) ? std::string(" section of " + source): ""), + exprtk_error_location)); return error_node(); } @@ -22246,7 +22581,7 @@ namespace exprtk expression_node_ptr result = error_node(); - scoped_vec_delete sdd(*this,arg_list); + scoped_vec_delete sdd((*this),arg_list); scope_handler sh(*this); @@ -22276,7 +22611,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR092 - Expected '" + details::to_str(seperator) + "' for call to multi-sequence section of " + source)); + "ERR094 - Expected '" + details::to_str(seperator) + "' for call to multi-sequence section of " + source, + exprtk_error_location)); return error_node(); } @@ -22309,7 +22645,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR093 - Expected '[' for start of range")); + "ERR095 - Expected '[' for start of range", + exprtk_error_location)); return false; } @@ -22329,7 +22666,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR094 - Failed parse begin section of range")); + "ERR096 - Failed parse begin section of range", + exprtk_error_location)); return false; @@ -22352,7 +22690,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR095 - Range lower bound less than zero! Constraint: r0 >= 0")); + "ERR097 - Range lower bound less than zero! Constraint: r0 >= 0", + exprtk_error_location)); return false; } @@ -22368,9 +22707,11 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR096 - Expected ':' for break in range")); + "ERR098 - Expected ':' for break in range", + exprtk_error_location)); rp.free(); + return false; } } @@ -22389,9 +22730,11 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR097 - Failed parse end section of range")); + "ERR099 - Failed parse end section of range", + exprtk_error_location)); rp.free(); + return false; } @@ -22413,7 +22756,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR098 - Range upper bound less than zero! Constraint: r1 >= 0")); + "ERR100 - Range upper bound less than zero! Constraint: r1 >= 0", + exprtk_error_location)); return false; } @@ -22429,9 +22773,11 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR099 - Expected ']' for start of range")); + "ERR101 - Expected ']' for start of range", + exprtk_error_location)); rp.free(); + return false; } } @@ -22448,7 +22794,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR100 - Invalid range, Constraint: r0 <= r1")); + "ERR102 - Invalid range, Constraint: r0 <= r1", + exprtk_error_location)); return false; } @@ -22472,7 +22819,6 @@ namespace exprtk expression_node_ptr result = error_node(); strvar_node_t const_str_node = static_cast(0); - bool is_const_string = false; scope_element& se = sem_.get_active_element(symbol); @@ -22489,16 +22835,15 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR101 - Unknown string symbol")); + "ERR103 - Unknown string symbol", + exprtk_error_location)); return error_node(); } result = symtab_store_.get_stringvar(symbol); - is_const_string = symtab_store_.is_constant_string(symbol); - - if (is_const_string) + if (symtab_store_.is_constant_string(symbol)) { const_str_node = static_cast(result); result = expression_generator_(const_str_node->str()); @@ -22604,9 +22949,10 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR102 - Overflow in range for string: '" + const_str + "'[" + + "ERR104 - 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)) : "?") + "]")); + (rp.n1_c.first ? details::to_str(static_cast(rp.n1_c.second)) : "?") + "]", + exprtk_error_location)); return error_node(); } @@ -22647,7 +22993,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR103 - Symbol '" + symbol+ " not a vector")); + "ERR105 - Symbol '" + symbol+ " not a vector", + exprtk_error_location)); return error_node(); } @@ -22672,7 +23019,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR104 - Failed to parse index for vector: '" + symbol + "'")); + "ERR106 - Failed to parse index for vector: '" + symbol + "'", + exprtk_error_location)); return error_node(); } @@ -22681,7 +23029,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR105 - Expected ']' for index of vector: '" + symbol + "'")); + "ERR107 - Expected ']' for index of vector: '" + symbol + "'", + exprtk_error_location)); free_node(node_allocator_,index_expr); @@ -22699,8 +23048,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR106 - Index of " + details::to_str(index) + " out of range for " - "vector '" + symbol + "' of size " + details::to_str(vec_size))); + "ERR108 - Index of " + details::to_str(index) + " out of range for " + "vector '" + symbol + "' of size " + details::to_str(vec_size), + exprtk_error_location)); free_node(node_allocator_,index_expr); @@ -22717,7 +23067,7 @@ namespace exprtk expression_node_ptr result = error_node(); - scoped_vec_delete sdd(*this,arg_list); + scoped_vec_delete sdd((*this),arg_list); next_token(); @@ -22730,8 +23080,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR107 - Zero parameter call to vararg function: " - + vararg_function_name + " not allowed")); + "ERR109 - Zero parameter call to vararg function: " + + vararg_function_name + " not allowed", + exprtk_error_location)); return error_node(); } @@ -22754,8 +23105,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR108 - Expected ',' for call to vararg function: " - + vararg_function_name)); + "ERR110 - Expected ',' for call to vararg function: " + + vararg_function_name, + exprtk_error_location)); return error_node(); } @@ -22767,8 +23119,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR109 - Zero parameter call to vararg function: " - + vararg_function_name + " not allowed")); + "ERR111 - Zero parameter call to vararg function: " + + vararg_function_name + " not allowed", + exprtk_error_location)); return error_node(); } @@ -22778,9 +23131,10 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR110 - Invalid number of parameters to call to vararg function: " + "ERR112 - 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")); + + details::to_str(static_cast(vararg_function->min_num_args())) + " parameters", + exprtk_error_location)); return error_node(); } @@ -22789,9 +23143,10 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR111 - Invalid number of parameters to call to vararg function: " + "ERR113 - 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")); + + details::to_str(static_cast(vararg_function->max_num_args())) + " parameters", + exprtk_error_location)); return error_node(); } @@ -22851,8 +23206,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, parser_.current_token(), - "ERR112 - Failed parameter type check for function '" + function_name_ + "', " - "Expected '" + param_seq_list_[0] + "' call set: '" + param_seq +"'")); + "ERR114 - Failed parameter type check for function '" + function_name_ + "', " + "Expected '" + param_seq_list_[0] + "' call set: '" + param_seq +"'", + exprtk_error_location)); } else { @@ -22871,8 +23227,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, parser_.current_token(), - "ERR113 - Failed parameter type check for function '" + function_name_ + "', " - "Best match: '" + param_seq_list_[max_diff_index] + "' call set: '" + param_seq +"'")); + "ERR115 - Failed parameter type check for function '" + function_name_ + "', " + "Best match: '" + param_seq_list_[max_diff_index] + "' call set: '" + param_seq +"'", + exprtk_error_location)); } return false; @@ -22955,8 +23312,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, parser_.current_token(), - "ERR114 - Invalid parameter sequence of '" + err_param_seq + - "' for function: " + function_name_)); + "ERR116 - Invalid parameter sequence of '" + err_param_seq + + "' for function: " + function_name_, + exprtk_error_location)); return; } @@ -22976,8 +23334,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, parser_.current_token(), - "ERR115 - Invalid parameter sequence of '" + err_param_seq + - "' for function: " + function_name_)); + "ERR117 - Invalid parameter sequence of '" + err_param_seq + + "' for function: " + function_name_, + exprtk_error_location)); return; } } @@ -22996,20 +23355,21 @@ namespace exprtk { std::vector arg_list; - scoped_vec_delete sdd(*this,arg_list); + scoped_vec_delete sdd((*this),arg_list); next_token(); std::string param_type_list; - type_checker tc(*this,function_name,function->parameter_sequence); + type_checker tc((*this), function_name, function->parameter_sequence); if (tc.invalid()) { set_error( make_error(parser_error::e_syntax, current_token(), - "ERR116 - Type checker instantiation failure for generic function: " + function_name)); + "ERR118 - Type checker instantiation failure for generic function: " + function_name, + exprtk_error_location)); return error_node(); } @@ -23023,8 +23383,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR117 - Mismatch in zero parameter condition for generic function: " - + function_name)); + "ERR119 - Mismatch in zero parameter condition for generic function: " + + function_name, + exprtk_error_location)); return error_node(); } @@ -23041,8 +23402,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR118 - Zero parameter call to generic function: " - + function_name + " not allowed")); + "ERR120 - Zero parameter call to generic function: " + + function_name + " not allowed", + exprtk_error_location)); return error_node(); } @@ -23072,7 +23434,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR119 - Expected ',' for call to generic function: " + function_name)); + "ERR121 - Expected ',' for call to generic function: " + function_name, + exprtk_error_location)); return error_node(); } @@ -23088,8 +23451,9 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR120 - Zero parameter call to generic function: " - + function_name + " not allowed")); + "ERR122 - Zero parameter call to generic function: " + + function_name + " not allowed", + exprtk_error_location)); return error_node(); } @@ -23104,7 +23468,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR121 - Expected ',' for call to generic function: " + function_name)); + "ERR123 - Expected ',' for call to generic function: " + function_name, + exprtk_error_location)); return error_node(); } @@ -23128,13 +23493,13 @@ namespace exprtk { std::vector arg_list; - scoped_vec_delete sdd(*this,arg_list); + scoped_vec_delete sdd((*this),arg_list); next_token(); std::string param_type_list; - type_checker tc(*this,function_name,function->parameter_sequence); + type_checker tc((*this), function_name, function->parameter_sequence); if ( (!function->parameter_sequence.empty()) && @@ -23171,7 +23536,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR122 - Expected ',' for call to string function: " + function_name)); + "ERR124 - Expected ',' for call to string function: " + function_name, + exprtk_error_location)); return error_node(); } @@ -23186,7 +23552,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR123 - Expected ',' for call to string function: " + function_name)); + "ERR125 - Expected ',' for call to string function: " + function_name, + exprtk_error_location)); return error_node(); } @@ -23225,7 +23592,8 @@ namespace exprtk p.set_error( make_error(parser_error::e_syntax, p.current_token(), - "ERR124 - Expected '(' for special function")); + "ERR126 - Expected '(' for special function", + exprtk_error_location)); return error_node(); } @@ -23245,7 +23613,8 @@ namespace exprtk p.set_error( make_error(parser_error::e_syntax, p.current_token(), - "ERR125 - Expected ',' before next parameter of special function")); + "ERR127 - Expected ',' before next parameter of special function", + exprtk_error_location)); return p.error_node(); } @@ -23274,7 +23643,8 @@ namespace exprtk set_error( make_error(parser_error::e_token, current_token(), - "ERR126 - Invalid special function[1]: " + current_token().value)); + "ERR128 - Invalid special function[1]: " + current_token().value, + exprtk_error_location)); return error_node(); } @@ -23287,7 +23657,8 @@ namespace exprtk set_error( make_error(parser_error::e_token, current_token(), - "ERR127 - Invalid special function[2]: " + current_token().value)); + "ERR129 - Invalid special function[2]: " + current_token().value, + exprtk_error_location)); return error_node(); } @@ -23298,8 +23669,8 @@ namespace exprtk switch (NumberOfParameters) { - case 3 : return parse_special_function_impl::process(*this,opt_type); - case 4 : return parse_special_function_impl::process(*this,opt_type); + case 3 : return parse_special_function_impl::process((*this),opt_type); + case 4 : return parse_special_function_impl::process((*this),opt_type); default : return error_node(); } } @@ -23318,7 +23689,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR128 - Break call within a break call is not allowed")); + "ERR130 - Break call within a break call is not allowed", + exprtk_error_location)); return error_node(); } @@ -23340,7 +23712,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR129 - Failed to parse return expression for 'break' statement")); + "ERR131 - Failed to parse return expression for 'break' statement", + exprtk_error_location)); return error_node(); } @@ -23349,7 +23722,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR130 - Expected ']' at the completion of break's return expression")); + "ERR132 - Expected ']' at the completion of break's return expression", + exprtk_error_location)); free_node(node_allocator_,return_expr); @@ -23366,7 +23740,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR131 - Invalid use of 'break', allowed only in the scope of a loop")); + "ERR133 - Invalid use of 'break', allowed only in the scope of a loop", + exprtk_error_location)); } return error_node(); @@ -23388,7 +23763,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR132 - Invalid use of 'continue', allowed only in the scope of a loop")); + "ERR134 - Invalid use of 'continue', allowed only in the scope of a loop", + exprtk_error_location)); return error_node(); } @@ -23404,7 +23780,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR133 - Expected '[' as part of vector size definition")); + "ERR135 - Expected '[' as part of vector size definition", + exprtk_error_location)); return error_node(); } @@ -23413,7 +23790,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR134 - Failed to determine size of vector '" + vec_name + "'")); + "ERR136 - Failed to determine size of vector '" + vec_name + "'", + exprtk_error_location)); return error_node(); } @@ -23424,7 +23802,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR135 - Expected a literal number as size of vector '" + vec_name + "'")); + "ERR137 - Expected a literal number as size of vector '" + vec_name + "'", + exprtk_error_location)); return error_node(); } @@ -23442,15 +23821,16 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR136 - Invalid vector size. Must be an integer greater than zero, size: " + - details::to_str(details::numeric::to_int32(vector_size)))); + "ERR138 - Invalid vector size. Must be an integer greater than zero, size: " + + details::to_str(details::numeric::to_int32(vector_size)), + exprtk_error_location)); return error_node(); } std::vector vec_initilizer_list; - scoped_vec_delete svd(*this,vec_initilizer_list); + scoped_vec_delete svd((*this),vec_initilizer_list); bool single_value_initialiser = false; bool vec_to_vec_initialiser = false; @@ -23461,7 +23841,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR137 - Expected ']' as part of vector size definition")); + "ERR139 - Expected ']' as part of vector size definition", + exprtk_error_location)); return error_node(); } @@ -23472,7 +23853,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR138 - Expected ':=' as part of vector definition")); + "ERR140 - Expected ':=' as part of vector definition", + exprtk_error_location)); return error_node(); } @@ -23485,7 +23867,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR139 - Failed to parse single vector initialiser")); + "ERR141 - Failed to parse single vector initialiser", + exprtk_error_location)); return error_node(); } @@ -23497,7 +23880,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR140 - Expected ']' to close single value vector initialiser")); + "ERR142 - Expected ']' to close single value vector initialiser", + exprtk_error_location)); return error_node(); } @@ -23543,7 +23927,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR141 - Expected '{' as part of vector initialiser list")); + "ERR143 - Expected '{' as part of vector initialiser list", + exprtk_error_location)); return error_node(); } @@ -23562,7 +23947,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR142 - Expected '{' as part of vector initialiser list")); + "ERR144 - Expected '{' as part of vector initialiser list", + exprtk_error_location)); return error_node(); } @@ -23579,7 +23965,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR143 - Expected ',' between vector initialisers")); + "ERR145 - Expected ',' between vector initialisers", + exprtk_error_location)); return error_node(); } @@ -23600,7 +23987,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR144 - Expected ';' at end of vector definition")); + "ERR146 - Expected ';' at end of vector definition", + exprtk_error_location)); return error_node(); } @@ -23611,7 +23999,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR145 - Initialiser list larger than the number of elements in the vector: '" + vec_name + "'")); + "ERR147 - Initialiser list larger than the number of elements in the vector: '" + vec_name + "'", + exprtk_error_location)); return error_node(); } @@ -23630,7 +24019,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR146 - Illegal redefinition of local vector: '" + vec_name + "'")); + "ERR148 - Illegal redefinition of local vector: '" + vec_name + "'", + exprtk_error_location)); return error_node(); } @@ -23663,7 +24053,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR147 - Failed to add new local vector '" + vec_name + "' to SEM")); + "ERR149 - Failed to add new local vector '" + vec_name + "' to SEM", + exprtk_error_location)); sem_.free_element(nse); @@ -23717,7 +24108,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR148 - Illegal redefinition of local variable: '" + str_name + "'")); + "ERR150 - Illegal redefinition of local variable: '" + str_name + "'", + exprtk_error_location)); free_node(node_allocator_,initialisation_expression); @@ -23748,7 +24140,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR149 - Failed to add new local string variable '" + str_name + "' to SEM")); + "ERR151 - Failed to add new local string variable '" + str_name + "' to SEM", + exprtk_error_location)); free_node(node_allocator_,initialisation_expression); @@ -23793,7 +24186,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR150 - Illegal variable definition")); + "ERR152 - Illegal variable definition", + exprtk_error_location)); return error_node(); } @@ -23813,7 +24207,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR151 - Expected a symbol for variable definition")); + "ERR153 - Expected a symbol for variable definition", + exprtk_error_location)); return error_node(); } @@ -23822,7 +24217,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR152 - Illegal redefinition of reserved keyword: '" + var_name + "'")); + "ERR154 - Illegal redefinition of reserved keyword: '" + var_name + "'", + exprtk_error_location)); return error_node(); } @@ -23831,7 +24227,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR153 - Illegal redefinition of variable '" + var_name + "'")); + "ERR155 - Illegal redefinition of variable '" + var_name + "'", + exprtk_error_location)); return error_node(); } @@ -23840,7 +24237,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR154 - Illegal redefinition of local variable: '" + var_name + "'")); + "ERR156 - Illegal redefinition of local variable: '" + var_name + "'", + exprtk_error_location)); return error_node(); } @@ -23859,7 +24257,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR155 - Failed to parse initialisation expression")); + "ERR157 - Failed to parse initialisation expression", + exprtk_error_location)); return error_node(); } @@ -23876,7 +24275,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR156 - Expected ';' after variable definition")); + "ERR158 - Expected ';' after variable definition", + exprtk_error_location)); free_node(node_allocator_,initialisation_expression); @@ -23903,7 +24303,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR157 - Illegal redefinition of local variable: '" + var_name + "'")); + "ERR159 - Illegal redefinition of local variable: '" + var_name + "'", + exprtk_error_location)); free_node(node_allocator_, initialisation_expression); @@ -23934,7 +24335,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR158 - Failed to add new local variable '" + var_name + "' to SEM")); + "ERR160 - Failed to add new local variable '" + var_name + "' to SEM", + exprtk_error_location)); free_node(node_allocator_, initialisation_expression); @@ -23970,7 +24372,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR159 - Expected a '{}' for uninitialised var definition")); + "ERR161 - Expected a '{}' for uninitialised var definition", + exprtk_error_location)); return error_node(); } @@ -23979,7 +24382,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR160 - Expected ';' after uninitialised variable definition")); + "ERR162 - Expected ';' after uninitialised variable definition", + exprtk_error_location)); return error_node(); } @@ -23995,7 +24399,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR161 - Illegal redefinition of local variable: '" + var_name + "'")); + "ERR163 - Illegal redefinition of local variable: '" + var_name + "'", + exprtk_error_location)); return error_node(); } @@ -24024,7 +24429,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR162 - Failed to add new local variable '" + var_name + "' to SEM")); + "ERR164 - Failed to add new local variable '" + var_name + "' to SEM", + exprtk_error_location)); sem_.free_element(nse); @@ -24056,7 +24462,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR163 - Expected '(' at start of swap statement")); + "ERR165 - Expected '(' at start of swap statement", + exprtk_error_location)); return error_node(); } @@ -24074,7 +24481,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR164 - Expected a symbol for variable or vector element definition")); + "ERR166 - Expected a symbol for variable or vector element definition", + exprtk_error_location)); return error_node(); } @@ -24085,7 +24493,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR165 - First parameter to swap is an invalid vector element: '" + var0_name + "'")); + "ERR167 - First parameter to swap is an invalid vector element: '" + var0_name + "'", + exprtk_error_location)); return error_node(); } @@ -24117,7 +24526,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR166 - First parameter to swap is an invalid variable: '" + var0_name + "'")); + "ERR168 - First parameter to swap is an invalid variable: '" + var0_name + "'", + exprtk_error_location)); return error_node(); } @@ -24130,7 +24540,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR167 - Expected ',' between parameters to swap")); + "ERR169 - Expected ',' between parameters to swap", + exprtk_error_location)); if (variable0_generated) { @@ -24147,7 +24558,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR168 - Expected a symbol for variable or vector element definition")); + "ERR170 - Expected a symbol for variable or vector element definition", + exprtk_error_location)); if (variable0_generated) { @@ -24163,7 +24575,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR169 - Second parameter to swap is an invalid vector element: '" + var1_name + "'")); + "ERR171 - Second parameter to swap is an invalid vector element: '" + var1_name + "'", + exprtk_error_location)); if (variable0_generated) { @@ -24200,7 +24613,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR170 - Second parameter to swap is an invalid variable: '" + var1_name + "'")); + "ERR172 - Second parameter to swap is an invalid variable: '" + var1_name + "'", + exprtk_error_location)); if (variable0_generated) { @@ -24218,7 +24632,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR171 - Expected ')' at end of swap statement")); + "ERR173 - Expected ')' at end of swap statement", + exprtk_error_location)); if (variable0_generated) { @@ -24274,7 +24689,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR172 - Return call within a return call is not allowed")); + "ERR174 - Return call within a return call is not allowed", + exprtk_error_location)); return error_node(); } @@ -24283,7 +24699,7 @@ namespace exprtk std::vector arg_list; - scoped_vec_delete sdd(*this,arg_list); + scoped_vec_delete sdd((*this),arg_list); if (!details::imatch(current_token().value,"return")) { @@ -24297,7 +24713,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR173 - Expected '[' at start of return statement")); + "ERR175 - Expected '[' at start of return statement", + exprtk_error_location)); return error_node(); } @@ -24319,7 +24736,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR174 - Expected ',' between values during call to return")); + "ERR176 - Expected ',' between values during call to return", + exprtk_error_location)); return error_node(); } @@ -24330,7 +24748,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR175 - Zero parameter return statement not allowed")); + "ERR177 - Zero parameter return statement not allowed", + exprtk_error_location)); return error_node(); } @@ -24344,7 +24763,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, prev_token, - "ERR176 - Invalid ']' found during return call")); + "ERR178 - Invalid ']' found during return call", + exprtk_error_location)); return error_node(); } @@ -24396,7 +24816,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR177 - Invalid sequence of variable '"+ symbol + "' and bracket")); + "ERR179 - Invalid sequence of variable '"+ symbol + "' and bracket", + exprtk_error_location)); return false; } @@ -24443,7 +24864,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR178 - Invalid sequence of brackets")); + "ERR180 - Invalid sequence of brackets", + exprtk_error_location)); return false; } @@ -24539,7 +24961,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR179 - Failed to generate node for function: '" + symbol + "'")); + "ERR181 - Failed to generate node for function: '" + symbol + "'", + exprtk_error_location)); return error_node(); } @@ -24564,7 +24987,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR180 - Failed to generate node for vararg function: '" + symbol + "'")); + "ERR182 - Failed to generate node for vararg function: '" + symbol + "'", + exprtk_error_location)); return error_node(); } @@ -24589,7 +25013,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR181 - Failed to generate node for generic function: '" + symbol + "'")); + "ERR183 - Failed to generate node for generic function: '" + symbol + "'", + exprtk_error_location)); return error_node(); } @@ -24615,7 +25040,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR182 - Failed to generate node for string function: '" + symbol + "'")); + "ERR184 - Failed to generate node for string function: '" + symbol + "'", + exprtk_error_location)); return error_node(); } @@ -24640,7 +25066,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR183 - Invalid use of reserved symbol '" + symbol + "'")); + "ERR185 - Invalid use of reserved symbol '" + symbol + "'", + exprtk_error_location)); return error_node(); } @@ -24702,8 +25129,9 @@ namespace exprtk set_error( make_error(parser_error::e_symtab, current_token(), - "ERR184 - Failed to create variable: '" + symbol + "'" + - (error_message.empty() ? "" : " - " + error_message))); + "ERR186 - Failed to create variable: '" + symbol + "'" + + (error_message.empty() ? "" : " - " + error_message), + exprtk_error_location)); } else if (unknown_symbol_resolver::e_usrmode_extended == unknown_symbol_resolver_->mode) @@ -24721,8 +25149,9 @@ namespace exprtk set_error( make_error(parser_error::e_symtab, current_token(), - "ERR185 - Failed to resolve symbol: '" + symbol + "'" + - (error_message.empty() ? "" : " - " + error_message))); + "ERR187 - Failed to resolve symbol: '" + symbol + "'" + + (error_message.empty() ? "" : " - " + error_message), + exprtk_error_location)); } return error_node(); @@ -24732,7 +25161,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR186 - Undefined symbol: '" + symbol + "'")); + "ERR188 - Undefined symbol: '" + symbol + "'", + exprtk_error_location)); return error_node(); } @@ -24838,7 +25268,8 @@ namespace exprtk set_error( make_error(parser_error::e_symtab, current_token(), - "ERR187 - Variable or function detected, yet symbol-table is invalid, Symbol: " + current_token().value)); + "ERR189 - Variable or function detected, yet symbol-table is invalid, Symbol: " + current_token().value, + exprtk_error_location)); return error_node(); } @@ -24855,6 +25286,18 @@ namespace exprtk if (details::string_to_real(current_token().value, numeric_value)) { expression_node_ptr literal_exp = expression_generator_(numeric_value); + + if (0 == literal_exp) + { + set_error( + make_error(parser_error::e_numeric, + current_token(), + "ERR190 - Failed generate node for scalar: '" + current_token().value + "'", + exprtk_error_location)); + + return error_node(); + } + next_token(); branch = literal_exp; } @@ -24863,7 +25306,8 @@ namespace exprtk set_error( make_error(parser_error::e_numeric, current_token(), - "ERR188 - Failed to convert '" + current_token().value + "' to a number")); + "ERR191 - Failed to convert '" + current_token().value + "' to a number", + exprtk_error_location)); return error_node(); } @@ -24889,7 +25333,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR189 - Expected ')' instead of: '" + current_token().value + "'")); + "ERR192 - Expected ')' instead of: '" + current_token().value + "'", + exprtk_error_location)); free_node(node_allocator_,branch); @@ -24913,7 +25358,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR190 - Expected ']' instead of: '" + current_token().value + "'")); + "ERR193 - Expected ']' instead of: '" + current_token().value + "'", + exprtk_error_location)); free_node(node_allocator_,branch); @@ -24937,7 +25383,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR191 - Expected '}' instead of: '" + current_token().value + "'")); + "ERR194 - Expected '}' instead of: '" + current_token().value + "'", + exprtk_error_location)); free_node(node_allocator_,branch); @@ -24976,7 +25423,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR192 - Premature end of expression[1]")); + "ERR195 - Premature end of expression[1]", + exprtk_error_location)); return error_node(); } @@ -24985,7 +25433,8 @@ namespace exprtk set_error( make_error(parser_error::e_syntax, current_token(), - "ERR193 - Premature end of expression[2]")); + "ERR196 - Premature end of expression[2]", + exprtk_error_location)); return error_node(); } @@ -25163,28 +25612,28 @@ namespace exprtk return (*inv_binary_op_map_).find(bop)->second; } - inline expression_node_ptr operator()(const Type& v) const + inline expression_node_ptr operator() (const Type& v) const { return node_allocator_->allocate(v); } #ifndef exprtk_disable_string_capabilities - inline expression_node_ptr operator()(const std::string& s) const + inline expression_node_ptr operator() (const std::string& s) const { return node_allocator_->allocate(s); } - inline expression_node_ptr operator()(std::string& s, range_t& rp) const + inline expression_node_ptr operator() (std::string& s, range_t& rp) const { return node_allocator_->allocate_rr(s,rp); } - inline expression_node_ptr operator()(const std::string& s, range_t& rp) const + inline expression_node_ptr operator() (const std::string& s, range_t& rp) const { return node_allocator_->allocate_tt(s,rp); } - inline expression_node_ptr operator()(expression_node_ptr branch, range_t& rp) const + inline expression_node_ptr operator() (expression_node_ptr branch, range_t& rp) const { if (is_generally_string_node(branch)) return node_allocator_->allocate_tt(branch,rp); @@ -25265,22 +25714,36 @@ namespace exprtk return true; } - inline expression_node_ptr operator()(const details::operator_type& operation, expression_node_ptr (&branch)[1]) + inline expression_node_ptr operator() (const details::operator_type& operation, expression_node_ptr (&branch)[1]) { if (0 == branch[0]) + { return error_node(); + } else if (details::is_null_node(branch[0])) + { return branch[0]; + } else if (details::is_break_node(branch[0])) + { return error_node(); + } else if (details::is_continue_node(branch[0])) + { return error_node(); + } else if (details::is_constant_node(branch[0])) + { return synthesize_expression(operation,branch); + } else if (unary_optimisable(operation) && details::is_variable_node(branch[0])) + { return synthesize_uv_expression(operation,branch); + } else if (unary_optimisable(operation) && details::is_ivector_node(branch[0])) + { return synthesize_uvec_expression(operation,branch); + } else return synthesize_unary_expression(operation,branch); } @@ -25325,24 +25788,24 @@ namespace exprtk { switch (operation) { - case details::e_add : return "+"; - case details::e_sub : return "-"; - case details::e_mul : return "*"; - case details::e_div : return "/"; - case details::e_mod : return "%"; - case details::e_pow : return "^"; - case details::e_lt : return "<"; - case details::e_lte : return "<="; - case details::e_gt : return ">"; - case details::e_gte : return ">="; - case details::e_eq : return "=="; - case details::e_ne : return "!="; - case details::e_and : return "and"; - case details::e_nand : return "nand"; - case details::e_or : return "or"; - case details::e_nor : return "nor"; - case details::e_xor : return "xor"; - case details::e_xnor : return "xnor"; + case details::e_add : return "+" ; + case details::e_sub : return "-" ; + case details::e_mul : return "*" ; + case details::e_div : return "/" ; + case details::e_mod : return "%" ; + case details::e_pow : return "^" ; + case details::e_lt : return "<" ; + case details::e_lte : return "<=" ; + case details::e_gt : return ">" ; + case details::e_gte : return ">=" ; + case details::e_eq : return "==" ; + case details::e_ne : return "!=" ; + case details::e_and : return "and" ; + case details::e_nand : return "nand" ; + case details::e_or : return "or" ; + case details::e_nor : return "nor" ; + case details::e_xor : return "xor" ; + case details::e_xnor : return "xnor" ; default : return "UNKNOWN"; } } @@ -25693,42 +26156,70 @@ namespace exprtk ); } - inline expression_node_ptr operator()(const details::operator_type& operation, expression_node_ptr (&branch)[2]) + inline expression_node_ptr operator() (const details::operator_type& operation, expression_node_ptr (&branch)[2]) { if ((0 == branch[0]) || (0 == branch[1])) + { return error_node(); + } else if (is_invalid_string_op(operation,branch)) + { return error_node(); + } else if (is_invalid_assignment_op(operation,branch)) + { return error_node(); + } else if (is_invalid_break_continue_op(branch)) + { return error_node(); + } else if (details::e_assign == operation) - return synthesize_assignment_expression(operation,branch); + { + return synthesize_assignment_expression(operation, branch); + } else if (details::e_swap == operation) + { return synthesize_swap_expression(branch); + } else if (is_assignment_operation(operation)) - return synthesize_assignment_operation_expression(operation,branch); - else if (is_vector_eqineq_logic_operation(operation,branch)) - return synthesize_veceqineqlogic_operation_expression(operation,branch); - else if (is_vector_arithmetic_operation(operation,branch)) - return synthesize_vecarithmetic_operation_expression(operation,branch); + { + return synthesize_assignment_operation_expression(operation, branch); + } + else if (is_vector_eqineq_logic_operation(operation, branch)) + { + return synthesize_veceqineqlogic_operation_expression(operation, branch); + } + else if (is_vector_arithmetic_operation(operation, branch)) + { + return synthesize_vecarithmetic_operation_expression(operation, branch); + } else if (is_shortcircuit_expression(operation)) - return synthesize_shortcircuit_expression(operation,branch); - else if (is_string_operation(operation,branch)) - return synthesize_string_expression(operation,branch); + { + return synthesize_shortcircuit_expression(operation, branch); + } + else if (is_string_operation(operation, branch)) + { + return synthesize_string_expression(operation, branch); + } else if (is_null_present(branch)) + { return synthesize_null_expression(operation, branch); + } #ifndef exprtk_disable_cardinal_pow_optimisation else if (is_constpow_operation(operation, branch)) + { return cardinal_pow_optimisation(branch); + } #endif expression_node_ptr result = error_node(); #ifndef exprtk_disable_enhanced_features - if (synthesize_expression(operation,branch,result)) + if (synthesize_expression(operation, branch, result)) + { return result; + } else #endif @@ -25742,36 +26233,54 @@ namespace exprtk */ result = error_node(); - if (cocob_optimisable(operation,branch)) - result = synthesize_cocob_expression::process(*this,operation,branch); - else if (coboc_optimisable(operation,branch) && (0 == result)) - result = synthesize_coboc_expression::process(*this,operation,branch); + if (cocob_optimisable(operation, branch)) + { + result = synthesize_cocob_expression::process((*this), operation, branch); + } + else if (coboc_optimisable(operation, branch) && (0 == result)) + { + result = synthesize_coboc_expression::process((*this), operation, branch); + } if (result) return result; } - if (uvouv_optimisable(operation,branch)) - return synthesize_uvouv_expression(operation,branch); - else if (vob_optimisable(operation,branch)) - return synthesize_vob_expression::process(*this,operation,branch); - else if (bov_optimisable(operation,branch)) - return synthesize_bov_expression::process(*this,operation,branch); - else if (cob_optimisable(operation,branch)) - return synthesize_cob_expression::process(*this,operation,branch); - else if (boc_optimisable(operation,branch)) - return synthesize_boc_expression::process(*this,operation,branch); + if (uvouv_optimisable(operation, branch)) + { + return synthesize_uvouv_expression(operation, branch); + } + else if (vob_optimisable(operation, branch)) + { + return synthesize_vob_expression::process((*this), operation, branch); + } + else if (bov_optimisable(operation, branch)) + { + return synthesize_bov_expression::process((*this), operation, branch); + } + else if (cob_optimisable(operation, branch)) + { + return synthesize_cob_expression::process((*this), operation, branch); + } + else if (boc_optimisable(operation, branch)) + { + return synthesize_boc_expression::process((*this), operation, branch); + } #ifndef exprtk_disable_enhanced_features - else if (cov_optimisable(operation,branch)) - return synthesize_cov_expression::process(*this,operation,branch); + else if (cov_optimisable(operation, branch)) + { + return synthesize_cov_expression::process((*this), operation, branch); + } #endif - else if (binext_optimisable(operation,branch)) - return synthesize_binary_ext_expression::process(*this,operation,branch); + else if (binext_optimisable(operation, branch)) + { + return synthesize_binary_ext_expression::process((*this), operation, branch); + } else - return synthesize_expression(operation,branch); + return synthesize_expression(operation, branch); } - inline expression_node_ptr operator()(const details::operator_type& operation, expression_node_ptr (&branch)[3]) + inline expression_node_ptr operator() (const details::operator_type& operation, expression_node_ptr (&branch)[3]) { if ( (0 == branch[0]) || @@ -25783,26 +26292,30 @@ namespace exprtk return error_node(); } - else if (is_invalid_string_op(operation,branch)) + else if (is_invalid_string_op(operation, branch)) + { return error_node(); - else if (is_string_operation(operation,branch)) - return synthesize_string_expression(operation,branch); + } + else if (is_string_operation(operation, branch)) + { + return synthesize_string_expression(operation, branch); + } else - return synthesize_expression(operation,branch); + return synthesize_expression(operation, branch); } - inline expression_node_ptr operator()(const details::operator_type& operation, expression_node_ptr (&branch)[4]) + inline expression_node_ptr operator() (const details::operator_type& operation, expression_node_ptr (&branch)[4]) { return synthesize_expression(operation,branch); } - inline expression_node_ptr operator()(const details::operator_type& operation, expression_node_ptr b0) + inline expression_node_ptr operator() (const details::operator_type& operation, expression_node_ptr b0) { expression_node_ptr branch[1] = { b0 }; return (*this)(operation,branch); } - inline expression_node_ptr operator()(const details::operator_type& operation, expression_node_ptr b0, expression_node_ptr b1) + inline expression_node_ptr operator() (const details::operator_type& operation, expression_node_ptr b0, expression_node_ptr b1) { if ((0 == b0) || (0 == b1)) return error_node(); @@ -26119,6 +26632,7 @@ namespace exprtk static inline T process(const arg_list_t& arg) { case_stmt(0) + return arg.back()->value(); } }; @@ -26128,6 +26642,7 @@ namespace exprtk static inline T process(const arg_list_t& arg) { case_stmt(0) case_stmt(1) + return arg.back()->value(); } }; @@ -26138,6 +26653,7 @@ namespace exprtk { case_stmt(0) case_stmt(1) case_stmt(2) + return arg.back()->value(); } }; @@ -26148,6 +26664,7 @@ namespace exprtk { case_stmt(0) case_stmt(1) case_stmt(2) case_stmt(3) + return arg.back()->value(); } }; @@ -26159,6 +26676,7 @@ namespace exprtk case_stmt(0) case_stmt(1) case_stmt(2) case_stmt(3) case_stmt(4) + return arg.back()->value(); } }; @@ -26170,6 +26688,7 @@ namespace exprtk case_stmt(0) case_stmt(1) case_stmt(2) case_stmt(3) case_stmt(4) case_stmt(5) + return arg.back()->value(); } }; @@ -26182,6 +26701,7 @@ namespace exprtk case_stmt(2) case_stmt(3) case_stmt(4) case_stmt(5) case_stmt(6) + return arg.back()->value(); } }; @@ -26364,7 +26884,7 @@ namespace exprtk default : return error_node(); } - T v = temp_node->value(); + const T v = temp_node->value(); details::free_node(*node_allocator_,temp_node); @@ -26467,7 +26987,8 @@ namespace exprtk default : return error_node(); } - T v = temp_node->value(); + const T v = temp_node->value(); + details::free_node(*node_allocator_,temp_node); return node_allocator_->allocate(v); @@ -26566,7 +27087,8 @@ namespace exprtk default : return error_node(); } - T v = temp_node->value(); + const T v = temp_node->value(); + details::free_node(*node_allocator_,temp_node); return node_allocator_->allocate(v); @@ -26740,7 +27262,7 @@ namespace exprtk is_constant_foldable(arg_list) ) { - Type v = result->value(); + const Type v = result->value(); details::free_node(*node_allocator_,result); result = node_allocator_->allocate(v); } @@ -26782,13 +27304,17 @@ namespace exprtk ) { genfunc_node_ptr->init_branches(); - Type v = result->value(); + + const Type v = result->value(); + details::free_node(*node_allocator_,result); + return node_allocator_->allocate(v); } else if (genfunc_node_ptr->init_branches()) { parser_->state_.activate_side_effect("generic_function_call()"); + return result; } else @@ -26833,7 +27359,7 @@ namespace exprtk { strfunc_node_ptr->init_branches(); - Type v = result->value(); + const Type v = result->value(); details::free_node(*node_allocator_,result); @@ -26847,7 +27373,7 @@ namespace exprtk } else { - details::free_node(*node_allocator_,result); + details::free_node (*node_allocator_,result ); details::free_all_nodes(*node_allocator_,arg_list); return error_node(); @@ -26879,7 +27405,7 @@ namespace exprtk } else { - details::free_node(*node_allocator_,result); + details::free_node (*node_allocator_,result ); details::free_all_nodes(*node_allocator_,arg_list); return error_node(); @@ -27085,13 +27611,13 @@ namespace exprtk { lodge_assignment(e_st_string,branch[0]); - return synthesize_expression(operation,branch); + return synthesize_expression(operation, branch); } else if (details::is_string_range_node(branch[0])) { lodge_assignment(e_st_string,branch[0]); - return synthesize_expression(operation,branch); + return synthesize_expression(operation, branch); } #endif else if (details::is_vector_node(branch[0])) @@ -27099,9 +27625,9 @@ namespace exprtk lodge_assignment(e_st_vector,branch[0]); if (details::is_ivector_node(branch[1])) - return synthesize_expression(operation,branch); + return synthesize_expression(operation, branch); else - return synthesize_expression(operation,branch); + return synthesize_expression(operation, branch); } else { @@ -27387,8 +27913,8 @@ namespace exprtk const bool v0_is_ivar = details::is_ivariable_node(branch[0]); const bool v1_is_ivar = details::is_ivariable_node(branch[1]); - const bool v0_is_ivec = details::is_ivector_node(branch[0]); - const bool v1_is_ivec = details::is_ivector_node(branch[1]); + const bool v0_is_ivec = details::is_ivector_node (branch[0]); + const bool v1_is_ivec = details::is_ivector_node (branch[1]); #ifndef exprtk_disable_string_capabilities const bool v0_is_str = details::is_generally_string_node(branch[0]); @@ -27482,9 +28008,13 @@ namespace exprtk return result; } else if (details::e_scand == operation) - return synthesize_expression(operation,branch); + { + return synthesize_expression(operation, branch); + } else if (details::e_scor == operation) - return synthesize_expression(operation,branch); + { + return synthesize_expression(operation, branch); + } else return error_node(); } @@ -27749,7 +28279,7 @@ namespace exprtk #define case_stmt(op0,op1) \ case op0 : return expr_gen.node_allocator_-> \ template allocate > > \ - (branch[0],branch[1]); \ + (branch[0], branch[1]); \ basic_opr_switch_statements extended_opr_switch_statements @@ -27908,7 +28438,7 @@ namespace exprtk #define case_stmt(op0,op1) \ case op0 : return expr_gen.node_allocator_-> \ template allocate_cr > > \ - (branch[0],v); \ + (branch[0], v); \ basic_opr_switch_statements extended_opr_switch_statements @@ -28042,7 +28572,7 @@ namespace exprtk #define case_stmt(op0,op1) \ case op0 : return expr_gen.node_allocator_-> \ template allocate_tt > > \ - (c, branch[1]); \ + (c, branch[1]); \ basic_opr_switch_statements extended_opr_switch_statements @@ -28106,7 +28636,7 @@ namespace exprtk else if (operation == details::e_div) { details::boc_base_node* bocnode = static_cast*>(branch[0]); - details::operator_type boc_opr = bocnode->operation(); + details::operator_type boc_opr = bocnode->operation(); if ( (details::e_div == boc_opr) || @@ -28127,7 +28657,7 @@ namespace exprtk { // (v ^ c0) ^ c1 --> v ^(c0 * c1) details::boc_base_node* bocnode = static_cast*>(branch[0]); - details::operator_type boc_opr = bocnode->operation(); + details::operator_type boc_opr = bocnode->operation(); if (details::e_pow == boc_opr) { @@ -28202,16 +28732,19 @@ namespace exprtk else if (std::equal_to()(T(0),c) && (details::e_add == operation)) { free_node(*expr_gen.node_allocator_, branch[1]); + return branch[0]; } else if (std::equal_to()(T(1),c) && (details::e_mul == operation)) { free_node(*expr_gen.node_allocator_, branch[1]); + return branch[0]; } else if (std::equal_to()(T(1),c) && (details::e_div == operation)) { free_node(*expr_gen.node_allocator_, branch[1]); + return branch[0]; } @@ -28253,7 +28786,7 @@ namespace exprtk template allocate_tt > > (cobnode->c() / c, cobnode->move_branch(0)); - free_node(*expr_gen.node_allocator_,branch[0]); + free_node(*expr_gen.node_allocator_, branch[0]); } } @@ -28267,6 +28800,7 @@ namespace exprtk else if (details::is_cob_node(branch[1])) { details::cob_base_node* cobnode = static_cast*>(branch[1]); + const Type c = static_cast*>(branch[0])->value(); if (std::equal_to()(T(0),c) && (details::e_mul == operation)) @@ -28286,11 +28820,13 @@ namespace exprtk else if (std::equal_to()(T(0),c) && (details::e_add == operation)) { free_node(*expr_gen.node_allocator_, branch[0]); + return branch[1]; } else if (std::equal_to()(T(1),c) && (details::e_mul == operation)) { free_node(*expr_gen.node_allocator_, branch[0]); + return branch[1]; } @@ -28444,6 +28980,7 @@ namespace exprtk else if (details::is_boc_node(branch[1])) { details::boc_base_node* bocnode = static_cast*>(branch[1]); + const Type c = static_cast*>(branch[0])->value(); if (details::e_add == bocnode->operation()) @@ -28536,11 +29073,11 @@ namespace exprtk const std::string node_id = branch_to_id(branch); - typename synthesize_map_t::iterator itr = synthesize_map_.find(node_id); + const typename synthesize_map_t::iterator itr = synthesize_map_.find(node_id); if (synthesize_map_.end() != itr) { - result = itr->second(*this, operation, branch); + result = itr->second((*this), operation, branch); return true; } @@ -28579,7 +29116,7 @@ namespace exprtk expression_node_ptr (&branch)[2]) { const Type c = static_cast*> (branch[0])->value(); - const Type& v = static_cast*>(branch[1])->ref(); + const Type& v = static_cast*>(branch[1])->ref (); details::free_node(*(expr_gen.node_allocator_),branch[0]); @@ -28613,7 +29150,7 @@ namespace exprtk const details::operator_type& operation, expression_node_ptr (&branch)[2]) { - const Type& v = static_cast*>(branch[0])->ref(); + const Type& v = static_cast*>(branch[0])->ref (); const Type c = static_cast*> (branch[1])->value(); details::free_node(*(expr_gen.node_allocator_), branch[1]); @@ -28662,7 +29199,7 @@ namespace exprtk { #define case_stmt(op) \ case details::e_sf##op : return details::T0oT1oT2_sf3ext >:: \ - allocate(*(expr_gen.node_allocator_),t0,t1,t2); \ + allocate(*(expr_gen.node_allocator_), t0, t1, t2); \ case_stmt(00) case_stmt(01) case_stmt(02) case_stmt(03) case_stmt(04) case_stmt(05) case_stmt(06) case_stmt(07) @@ -29404,7 +29941,7 @@ namespace exprtk exprtk_debug(("(c0 + v) + c1 --> (cov) (c0 + c1) + v\n")); return expr_gen.node_allocator_-> - template allocate_cr > >(c0 + c1,v); + template allocate_cr > >(c0 + c1, v); } // (c0 + v) - c1 --> (cov) (c0 - c1) + v else if ((details::e_add == o0) && (details::e_sub == o1)) @@ -29412,7 +29949,7 @@ namespace exprtk exprtk_debug(("(c0 + v) - c1 --> (cov) (c0 - c1) + v\n")); return expr_gen.node_allocator_-> - template allocate_cr > >(c0 - c1,v); + template allocate_cr > >(c0 - c1, v); } // (c0 - v) + c1 --> (cov) (c0 + c1) - v else if ((details::e_sub == o0) && (details::e_add == o1)) @@ -29420,7 +29957,7 @@ namespace exprtk exprtk_debug(("(c0 - v) + c1 --> (cov) (c0 + c1) - v\n")); return expr_gen.node_allocator_-> - template allocate_cr > >(c0 + c1,v); + template allocate_cr > >(c0 + c1, v); } // (c0 - v) - c1 --> (cov) (c0 - c1) - v else if ((details::e_sub == o0) && (details::e_sub == o1)) @@ -29428,7 +29965,7 @@ namespace exprtk exprtk_debug(("(c0 - v) - c1 --> (cov) (c0 - c1) - v\n")); return expr_gen.node_allocator_-> - template allocate_cr > >(c0 - c1,v); + template allocate_cr > >(c0 - c1, v); } // (c0 * v) * c1 --> (cov) (c0 * c1) * v else if ((details::e_mul == o0) && (details::e_mul == o1)) @@ -29436,7 +29973,7 @@ namespace exprtk exprtk_debug(("(c0 * v) * c1 --> (cov) (c0 * c1) * v\n")); return expr_gen.node_allocator_-> - template allocate_cr > >(c0 * c1,v); + template allocate_cr > >(c0 * c1, v); } // (c0 * v) / c1 --> (cov) (c0 / c1) * v else if ((details::e_mul == o0) && (details::e_div == o1)) @@ -29444,7 +29981,7 @@ namespace exprtk exprtk_debug(("(c0 * v) / c1 --> (cov) (c0 / c1) * v\n")); return expr_gen.node_allocator_-> - template allocate_cr > >(c0 / c1,v); + template allocate_cr > >(c0 / c1, v); } // (c0 / v) * c1 --> (cov) (c0 * c1) / v else if ((details::e_div == o0) && (details::e_mul == o1)) @@ -29452,7 +29989,7 @@ namespace exprtk exprtk_debug(("(c0 / v) * c1 --> (cov) (c0 * c1) / v\n")); return expr_gen.node_allocator_-> - template allocate_cr > >(c0 * c1,v); + template allocate_cr > >(c0 * c1, v); } // (c0 / v) / c1 --> (cov) (c0 / c1) / v else if ((details::e_div == o0) && (details::e_div == o1)) @@ -29460,7 +29997,7 @@ namespace exprtk exprtk_debug(("(c0 / v) / c1 --> (cov) (c0 / c1) / v\n")); return expr_gen.node_allocator_-> - template allocate_cr > >(c0 / c1,v); + template allocate_cr > >(c0 / c1, v); } } @@ -29518,7 +30055,7 @@ namespace exprtk exprtk_debug(("(c0) + (v + c1) --> (cov) (c0 + c1) + v\n")); return expr_gen.node_allocator_-> - template allocate_cr > >(c0 + c1,v); + template allocate_cr > >(c0 + c1, v); } // (c0) + (v - c1) --> (cov) (c0 - c1) + v else if ((details::e_add == o0) && (details::e_sub == o1)) @@ -29526,7 +30063,7 @@ namespace exprtk exprtk_debug(("(c0) + (v - c1) --> (cov) (c0 - c1) + v\n")); return expr_gen.node_allocator_-> - template allocate_cr > >(c0 - c1,v); + template allocate_cr > >(c0 - c1, v); } // (c0) - (v + c1) --> (cov) (c0 - c1) - v else if ((details::e_sub == o0) && (details::e_add == o1)) @@ -29534,7 +30071,7 @@ namespace exprtk exprtk_debug(("(c0) - (v + c1) --> (cov) (c0 - c1) - v\n")); return expr_gen.node_allocator_-> - template allocate_cr > >(c0 - c1,v); + template allocate_cr > >(c0 - c1, v); } // (c0) - (v - c1) --> (cov) (c0 + c1) - v else if ((details::e_sub == o0) && (details::e_sub == o1)) @@ -29542,7 +30079,7 @@ namespace exprtk exprtk_debug(("(c0) - (v - c1) --> (cov) (c0 + c1) - v\n")); return expr_gen.node_allocator_-> - template allocate_cr > >(c0 + c1,v); + template allocate_cr > >(c0 + c1, v); } // (c0) * (v * c1) --> (voc) v * (c0 * c1) else if ((details::e_mul == o0) && (details::e_mul == o1)) @@ -29550,7 +30087,7 @@ namespace exprtk exprtk_debug(("(c0) * (v * c1) --> (voc) v * (c0 * c1)\n")); return expr_gen.node_allocator_-> - template allocate_cr > >(c0 * c1,v); + template allocate_cr > >(c0 * c1, v); } // (c0) * (v / c1) --> (cov) (c0 / c1) * v else if ((details::e_mul == o0) && (details::e_div == o1)) @@ -29558,7 +30095,7 @@ namespace exprtk exprtk_debug(("(c0) * (v / c1) --> (cov) (c0 / c1) * v\n")); return expr_gen.node_allocator_-> - template allocate_cr > >(c0 / c1,v); + template allocate_cr > >(c0 / c1, v); } // (c0) / (v * c1) --> (cov) (c0 / c1) / v else if ((details::e_div == o0) && (details::e_mul == o1)) @@ -29566,7 +30103,7 @@ namespace exprtk exprtk_debug(("(c0) / (v * c1) --> (cov) (c0 / c1) / v\n")); return expr_gen.node_allocator_-> - template allocate_cr > >(c0 / c1,v); + template allocate_cr > >(c0 / c1, v); } // (c0) / (v / c1) --> (cov) (c0 * c1) / v else if ((details::e_div == o0) && (details::e_div == o1)) @@ -29574,7 +30111,7 @@ namespace exprtk exprtk_debug(("(c0) / (v / c1) --> (cov) (c0 * c1) / v\n")); return expr_gen.node_allocator_-> - template allocate_cr > >(c0 * c1,v); + template allocate_cr > >(c0 * c1, v); } } @@ -29642,7 +30179,7 @@ namespace exprtk exprtk_debug(("(c0) + (c1 + v) --> (cov) (c0 + c1) + v\n")); return expr_gen.node_allocator_-> - template allocate_cr > >(c0 + c1,v); + template allocate_cr > >(c0 + c1, v); } // (c0) + (c1 - v) --> (cov) (c0 + c1) - v else if ((details::e_add == o0) && (details::e_sub == o1)) @@ -29650,7 +30187,7 @@ namespace exprtk exprtk_debug(("(c0) + (c1 - v) --> (cov) (c0 + c1) - v\n")); return expr_gen.node_allocator_-> - template allocate_cr > >(c0 + c1,v); + template allocate_cr > >(c0 + c1, v); } // (c0) - (c1 + v) --> (cov) (c0 - c1) - v else if ((details::e_sub == o0) && (details::e_add == o1)) @@ -29658,7 +30195,7 @@ namespace exprtk exprtk_debug(("(c0) - (c1 + v) --> (cov) (c0 - c1) - v\n")); return expr_gen.node_allocator_-> - template allocate_cr > >(c0 - c1,v); + template allocate_cr > >(c0 - c1, v); } // (c0) - (c1 - v) --> (cov) (c0 - c1) + v else if ((details::e_sub == o0) && (details::e_sub == o1)) @@ -29666,7 +30203,7 @@ namespace exprtk exprtk_debug(("(c0) - (c1 - v) --> (cov) (c0 - c1) + v\n")); return expr_gen.node_allocator_-> - template allocate_cr > >(c0 - c1,v); + template allocate_cr > >(c0 - c1, v); } // (c0) * (c1 * v) --> (cov) (c0 * c1) * v else if ((details::e_mul == o0) && (details::e_mul == o1)) @@ -29674,7 +30211,7 @@ namespace exprtk exprtk_debug(("(c0) * (c1 * v) --> (cov) (c0 * c1) * v\n")); return expr_gen.node_allocator_-> - template allocate_cr > >(c0 * c1,v); + template allocate_cr > >(c0 * c1, v); } // (c0) * (c1 / v) --> (cov) (c0 * c1) / v else if ((details::e_mul == o0) && (details::e_div == o1)) @@ -29682,7 +30219,7 @@ namespace exprtk exprtk_debug(("(c0) * (c1 / v) --> (cov) (c0 * c1) / v\n")); return expr_gen.node_allocator_-> - template allocate_cr > >(c0 * c1,v); + template allocate_cr > >(c0 * c1, v); } // (c0) / (c1 * v) --> (cov) (c0 / c1) / v else if ((details::e_div == o0) && (details::e_mul == o1)) @@ -29690,7 +30227,7 @@ namespace exprtk exprtk_debug(("(c0) / (c1 * v) --> (cov) (c0 / c1) / v\n")); return expr_gen.node_allocator_-> - template allocate_cr > >(c0 / c1,v); + template allocate_cr > >(c0 / c1, v); } // (c0) / (c1 / v) --> (cov) (c0 / c1) * v else if ((details::e_div == o0) && (details::e_div == o1)) @@ -29698,7 +30235,7 @@ namespace exprtk exprtk_debug(("(c0) / (c1 / v) --> (cov) (c0 / c1) * v\n")); return expr_gen.node_allocator_-> - template allocate_cr > >(c0 / c1,v); + template allocate_cr > >(c0 / c1, v); } } @@ -29755,7 +30292,7 @@ namespace exprtk exprtk_debug(("(v + c0) + c1 --> (voc) v + (c0 + c1)\n")); return expr_gen.node_allocator_-> - template allocate_rc > >(v,c0 + c1); + template allocate_rc > >(v, c0 + c1); } // (v + c0) - c1 --> (voc) v + (c0 - c1) else if ((details::e_add == o0) && (details::e_sub == o1)) @@ -29763,7 +30300,7 @@ namespace exprtk exprtk_debug(("(v + c0) - c1 --> (voc) v + (c0 - c1)\n")); return expr_gen.node_allocator_-> - template allocate_rc > >(v,c0 - c1); + template allocate_rc > >(v, c0 - c1); } // (v - c0) + c1 --> (voc) v - (c0 + c1) else if ((details::e_sub == o0) && (details::e_add == o1)) @@ -29771,7 +30308,7 @@ namespace exprtk exprtk_debug(("(v - c0) + c1 --> (voc) v - (c0 + c1)\n")); return expr_gen.node_allocator_-> - template allocate_rc > >(v,c1 - c0); + template allocate_rc > >(v, c1 - c0); } // (v - c0) - c1 --> (voc) v - (c0 + c1) else if ((details::e_sub == o0) && (details::e_sub == o1)) @@ -29779,7 +30316,7 @@ namespace exprtk exprtk_debug(("(v - c0) - c1 --> (voc) v - (c0 + c1)\n")); return expr_gen.node_allocator_-> - template allocate_rc > >(v,c0 + c1); + template allocate_rc > >(v, c0 + c1); } // (v * c0) * c1 --> (voc) v * (c0 * c1) else if ((details::e_mul == o0) && (details::e_mul == o1)) @@ -29787,7 +30324,7 @@ namespace exprtk exprtk_debug(("(v * c0) * c1 --> (voc) v * (c0 * c1)\n")); return expr_gen.node_allocator_-> - template allocate_rc > >(v,c0 * c1); + template allocate_rc > >(v, c0 * c1); } // (v * c0) / c1 --> (voc) v * (c0 / c1) else if ((details::e_mul == o0) && (details::e_div == o1)) @@ -29795,7 +30332,7 @@ namespace exprtk exprtk_debug(("(v * c0) / c1 --> (voc) v * (c0 / c1)\n")); return expr_gen.node_allocator_-> - template allocate_rc > >(v,c0 / c1); + template allocate_rc > >(v, c0 / c1); } // (v / c0) * c1 --> (voc) v * (c1 / c0) else if ((details::e_div == o0) && (details::e_mul == o1)) @@ -29803,7 +30340,7 @@ namespace exprtk exprtk_debug(("(v / c0) * c1 --> (voc) v * (c1 / c0)\n")); return expr_gen.node_allocator_-> - template allocate_rc > >(v,c1 / c0); + template allocate_rc > >(v, c1 / c0); } // (v / c0) / c1 --> (voc) v / (c0 * c1) else if ((details::e_div == o0) && (details::e_div == o1)) @@ -29811,7 +30348,7 @@ namespace exprtk exprtk_debug(("(v / c0) / c1 --> (voc) v / (c0 * c1)\n")); return expr_gen.node_allocator_-> - template allocate_rc > >(v,c0 * c1); + template allocate_rc > >(v, c0 * c1); } // (v ^ c0) ^ c1 --> (voc) v ^ (c0 * c1) else if ((details::e_pow == o0) && (details::e_pow == o1)) @@ -29819,7 +30356,7 @@ namespace exprtk exprtk_debug(("(v ^ c0) ^ c1 --> (voc) v ^ (c0 * c1)\n")); return expr_gen.node_allocator_-> - template allocate_rc > >(v,c0 * c1); + template allocate_rc > >(v, c0 * c1); } } @@ -33090,28 +33627,28 @@ namespace exprtk case details::e_add : result = (*this)(details::e_neg, node_allocator_-> allocate_rr > >(v0,v1)); + vov_node > >(v0, v1)); exprtk_debug(("(-v0 + -v1) --> -(v0 + v1)\n")); break; // (-v0 - -v1) --> (v1 - v0) case details::e_sub : result = node_allocator_-> allocate_rr > >(v1,v0); + vov_node > >(v1, v0); exprtk_debug(("(-v0 - -v1) --> (v1 - v0)\n")); break; // (-v0 * -v1) --> (v0 * v1) case details::e_mul : result = node_allocator_-> allocate_rr > >(v0,v1); + vov_node > >(v0, v1); exprtk_debug(("(-v0 * -v1) --> (v0 * v1)\n")); break; // (-v0 / -v1) --> (v0 / v1) case details::e_div : result = node_allocator_-> allocate_rr > >(v0,v1); + vov_node > >(v0, v1); exprtk_debug(("(-v0 / -v1) --> (v0 / v1)\n")); break; @@ -33122,7 +33659,7 @@ namespace exprtk if (0 == result) { result = node_allocator_-> - allocate_rrrrr >(v0,v1,u0,u1,f); + allocate_rrrrr >(v0, v1, u0, u1, f); } details::free_all_nodes(*node_allocator_,branch); @@ -33156,7 +33693,7 @@ namespace exprtk #define case_stmt(op0,op1) \ case op0 : return node_allocator_-> \ allocate_ttt >,T0,T1> \ - (s0,s1,rp0); \ + (s0, s1, rp0); \ string_opr_switch_statements #undef case_stmt @@ -33174,7 +33711,7 @@ namespace exprtk #define case_stmt(op0,op1) \ case op0 : return node_allocator_-> \ allocate_ttt >,T0,T1> \ - (s0,s1,rp1); \ + (s0, s1, rp1); \ string_opr_switch_statements #undef case_stmt @@ -33192,7 +33729,7 @@ namespace exprtk #define case_stmt(op0,op1) \ case op0 : return node_allocator_-> \ allocate_tttt >,T0,T1> \ - (s0,s1,rp0,rp1); \ + (s0, s1, rp0, rp1); \ string_opr_switch_statements #undef case_stmt @@ -33205,9 +33742,9 @@ namespace exprtk { switch (opr) { - #define case_stmt(op0,op1) \ - case op0 : return node_allocator_-> \ - allocate_tt >,T0,T1>(s0,s1); \ + #define case_stmt(op0,op1) \ + case op0 : return node_allocator_-> \ + allocate_tt >,T0,T1>(s0, s1); \ string_opr_switch_statements #undef case_stmt @@ -33220,7 +33757,7 @@ namespace exprtk std::string& s0 = static_cast*>(branch[0])->ref(); std::string& s1 = static_cast*>(branch[1])->ref(); - return synthesize_sos_expression_impl(opr,s0,s1); + return synthesize_sos_expression_impl(opr, s0, s1); } inline expression_node_ptr synthesize_sros_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) @@ -33233,7 +33770,7 @@ namespace exprtk free_node(*node_allocator_,branch[0]); - return synthesize_str_xrox_expression_impl(opr,s0,s1,rp0); + return synthesize_str_xrox_expression_impl(opr, s0, s1, rp0); } inline expression_node_ptr synthesize_sosr_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) @@ -33246,7 +33783,7 @@ namespace exprtk free_node(*node_allocator_,branch[1]); - return synthesize_str_xoxr_expression_impl(opr,s0,s1,rp1); + return synthesize_str_xoxr_expression_impl(opr, s0, s1, rp1); } inline expression_node_ptr synthesize_socsr_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) @@ -33259,7 +33796,7 @@ namespace exprtk free_node(*node_allocator_,branch[1]); - return synthesize_str_xoxr_expression_impl(opr,s0,s1,rp1); + return synthesize_str_xoxr_expression_impl(opr, s0, s1, rp1); } inline expression_node_ptr synthesize_srosr_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) @@ -33275,7 +33812,7 @@ namespace exprtk details::free_node(*node_allocator_,branch[0]); details::free_node(*node_allocator_,branch[1]); - return synthesize_str_xroxr_expression_impl(opr,s0,s1,rp0,rp1); + return synthesize_str_xroxr_expression_impl(opr, s0, s1, rp0, rp1); } inline expression_node_ptr synthesize_socs_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) @@ -33285,7 +33822,7 @@ namespace exprtk details::free_node(*node_allocator_,branch[1]); - return synthesize_sos_expression_impl(opr,s0,s1); + return synthesize_sos_expression_impl(opr, s0, s1); } inline expression_node_ptr synthesize_csos_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) @@ -33295,7 +33832,7 @@ namespace exprtk details::free_node(*node_allocator_,branch[0]); - return synthesize_sos_expression_impl(opr,s0,s1); + return synthesize_sos_expression_impl(opr, s0, s1); } inline expression_node_ptr synthesize_csosr_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) @@ -33309,7 +33846,7 @@ namespace exprtk details::free_node(*node_allocator_,branch[0]); details::free_node(*node_allocator_,branch[1]); - return synthesize_str_xoxr_expression_impl(opr,s0,s1,rp1); + return synthesize_str_xoxr_expression_impl(opr, s0, s1, rp1); } inline expression_node_ptr synthesize_srocs_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) @@ -33323,7 +33860,7 @@ namespace exprtk details::free_node(*node_allocator_,branch[0]); details::free_node(*node_allocator_,branch[1]); - return synthesize_str_xrox_expression_impl(opr,s0,s1,rp0); + return synthesize_str_xrox_expression_impl(opr, s0, s1, rp0); } inline expression_node_ptr synthesize_srocsr_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) @@ -33339,7 +33876,7 @@ namespace exprtk details::free_node(*node_allocator_,branch[0]); details::free_node(*node_allocator_,branch[1]); - return synthesize_str_xroxr_expression_impl(opr,s0,s1,rp0,rp1); + return synthesize_str_xroxr_expression_impl(opr, s0, s1, rp0, rp1); } inline expression_node_ptr synthesize_csocs_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) @@ -33352,16 +33889,19 @@ namespace exprtk if (details::e_add == opr) result = node_allocator_->allocate_c >(s0 + s1); else if (details::e_in == opr) - result = node_allocator_->allocate_c >(details::in_op::process(s0,s1)); + result = node_allocator_->allocate_c >(details::in_op ::process(s0,s1)); else if (details::e_like == opr) - result = node_allocator_->allocate_c >(details::like_op::process(s0,s1)); + result = node_allocator_->allocate_c >(details::like_op ::process(s0,s1)); else if (details::e_ilike == opr) result = node_allocator_->allocate_c >(details::ilike_op::process(s0,s1)); else { - expression_node_ptr temp = synthesize_sos_expression_impl(opr,s0,s1); - Type v = temp->value(); + expression_node_ptr temp = synthesize_sos_expression_impl(opr, s0, s1); + + const Type v = temp->value(); + details::free_node(*node_allocator_,temp); + result = node_allocator_->allocate(v); } @@ -33381,7 +33921,7 @@ namespace exprtk free_node(*node_allocator_,branch[0]); free_node(*node_allocator_,branch[1]); - return synthesize_str_xoxr_expression_impl(opr,s0,s1,rp1); + return synthesize_str_xoxr_expression_impl(opr, s0, s1, rp1); } inline expression_node_ptr synthesize_csros_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) @@ -33394,7 +33934,7 @@ namespace exprtk free_node(*node_allocator_,branch[0]); - return synthesize_str_xrox_expression_impl(opr,s0,s1,rp0); + return synthesize_str_xrox_expression_impl(opr, s0, s1, rp0); } inline expression_node_ptr synthesize_csrosr_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) @@ -33410,7 +33950,7 @@ namespace exprtk free_node(*node_allocator_,branch[0]); free_node(*node_allocator_,branch[1]); - return synthesize_str_xroxr_expression_impl(opr,s0,s1,rp0,rp1); + return synthesize_str_xroxr_expression_impl(opr, s0, s1, rp0, rp1); } inline expression_node_ptr synthesize_csrocs_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) @@ -33423,7 +33963,7 @@ namespace exprtk details::free_all_nodes(*node_allocator_,branch); - return synthesize_str_xrox_expression_impl(opr,s0,s1,rp0); + return synthesize_str_xrox_expression_impl(opr, s0, s1, rp0); } inline expression_node_ptr synthesize_csrocsr_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) @@ -33438,7 +33978,7 @@ namespace exprtk details::free_all_nodes(*node_allocator_,branch); - return synthesize_str_xroxr_expression_impl(opr,s0,s1,rp0,rp1); + return synthesize_str_xroxr_expression_impl(opr, s0, s1, rp0, rp1); } inline expression_node_ptr synthesize_strogen_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) @@ -33448,7 +33988,7 @@ namespace exprtk #define case_stmt(op0,op1) \ case op0 : return node_allocator_-> \ allocate_ttt > > \ - (opr,branch[0],branch[1]); \ + (opr, branch[0], branch[1]); \ string_opr_switch_statements #undef case_stmt @@ -33565,7 +34105,8 @@ namespace exprtk const std::string s1 = static_cast*>(branch[1])->str(); const std::string s2 = static_cast*>(branch[2])->str(); - Type v = (((s0 <= s1) && (s1 <= s2)) ? Type(1) : Type(0)); + const Type v = (((s0 <= s1) && (s1 <= s2)) ? Type(1) : Type(0)); + details::free_all_nodes(*node_allocator_,branch); return node_allocator_->allocate_c >(v); @@ -33763,7 +34304,11 @@ namespace exprtk (details::e_like == operation) || (details::e_ilike == operation) ) + { + free_all_nodes(*node_allocator_,branch); + return error_node(); + } else if (!details::all_nodes_valid(branch)) { free_all_nodes(*node_allocator_,branch); @@ -33828,15 +34373,15 @@ namespace exprtk return expression_point; } - bool strength_reduction_enabled_; + bool strength_reduction_enabled_; details::node_allocator* node_allocator_; - synthesize_map_t synthesize_map_; - unary_op_map_t* unary_op_map_; - binary_op_map_t* binary_op_map_; - inv_binary_op_map_t* inv_binary_op_map_; - sf3_map_t* sf3_map_; - sf4_map_t* sf4_map_; - parser_t* parser_; + synthesize_map_t synthesize_map_; + unary_op_map_t* unary_op_map_; + binary_op_map_t* binary_op_map_; + inv_binary_op_map_t* inv_binary_op_map_; + sf3_map_t* sf3_map_; + sf4_map_t* sf4_map_; + parser_t* parser_; }; inline void set_error(const parser_error::type& error_type) @@ -33878,7 +34423,7 @@ namespace exprtk if (se.data) { - e.register_local_data(se.data,1,0); + e.register_local_data(se.data, 1, 0); } } else if (scope_element::e_vector == se.type) @@ -33890,7 +34435,7 @@ namespace exprtk if (se.data) { - e.register_local_data(se.data,se.size,1); + e.register_local_data(se.data, se.size, 1); } } #ifndef exprtk_disable_string_capabilities @@ -33903,7 +34448,7 @@ namespace exprtk if (se.data) { - e.register_local_data(se.data,se.size,2); + e.register_local_data(se.data, se.size, 2); } } #endif @@ -34780,79 +35325,79 @@ namespace exprtk #define poly_rtrn(NN) \ return (NN != N) ? std::numeric_limits::quiet_NaN() : - inline virtual T operator()(const T& x, const T& c1, const T& c0) + inline virtual T operator() (const T& x, const T& c1, const T& 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) + 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); } - inline virtual T operator()(const T& x, const T& c3, const T& c2, const T& c1, const T& 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); } - inline virtual T operator()(const T& x, const T& c4, const T& c3, const T& c2, const T& c1, const T& 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); } - 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) + 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); } - 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) + 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); } - 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) + 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); } - 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) + 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); } - 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) + 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); } - 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) + 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); } - 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) + 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); } - 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) + 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); } #undef poly_rtrn - inline virtual T operator()() + inline virtual T operator() () { return std::numeric_limits::quiet_NaN(); } - inline virtual T operator()(const T&) + inline virtual T operator() (const T&) { return std::numeric_limits::quiet_NaN(); } - inline virtual T operator()(const T&, const T&) + inline virtual T operator() (const T&, const T&) { return std::numeric_limits::quiet_NaN(); } @@ -35183,7 +35728,7 @@ namespace exprtk func_0param() : base_func(0) {} - inline T operator()() + inline T operator() () { return this->value(base_func::expression); } @@ -35211,13 +35756,11 @@ namespace exprtk func_1param() : base_func(1) {} - inline T operator()(type v0) + inline T operator() (type v0) { scoped_bft sb(*this); base_func::update(v0); - T result = this->value(base_func::expression); - - return result; + return this->value(base_func::expression); } }; @@ -35227,13 +35770,11 @@ namespace exprtk func_2param() : base_func(2) {} - inline T operator()(type v0, type v1) + inline T operator() (type v0, type v1) { scoped_bft sb(*this); - base_func::update(v0,v1); - T result = this->value(base_func::expression); - - return result; + base_func::update(v0, v1); + return this->value(base_func::expression); } }; @@ -35243,13 +35784,11 @@ namespace exprtk func_3param() : base_func(3) {} - inline T operator()(type v0, type v1, type v2) + inline T operator() (type v0, type v1, type v2) { scoped_bft sb(*this); - base_func::update(v0,v1,v2); - T result = this->value(base_func::expression); - - return result; + base_func::update(v0, v1, v2); + return this->value(base_func::expression); } }; @@ -35259,13 +35798,11 @@ namespace exprtk func_4param() : base_func(4) {} - inline T operator()(type v0, type v1, type v2, type v3) + inline T operator() (type v0, type v1, type v2, type v3) { scoped_bft sb(*this); - base_func::update(v0,v1,v2,v3); - T result = this->value(base_func::expression); - - return result; + base_func::update(v0, v1, v2, v3); + return this->value(base_func::expression); } }; @@ -35275,13 +35812,11 @@ namespace exprtk func_5param() : base_func(5) {} - inline T operator()(type v0, type v1, type v2, type v3, type v4) + inline T operator() (type v0, type v1, type v2, type v3, type v4) { scoped_bft sb(*this); - base_func::update(v0,v1,v2,v3,v4); - T result = this->value(base_func::expression); - - return result; + base_func::update(v0, v1, v2, v3, v4); + return this->value(base_func::expression); } }; @@ -35291,13 +35826,11 @@ namespace exprtk func_6param() : base_func(6) {} - inline T operator()(type v0, type v1, type v2, type v3, type v4, type v5) + inline T operator() (type v0, type v1, type v2, type v3, type v4, type v5) { scoped_bft sb(*this); - base_func::update(v0,v1,v2,v3,v4,v5); - T result = this->value(base_func::expression); - - return result; + base_func::update(v0, v1, v2, v3, v4, v5); + return this->value(base_func::expression); } }; @@ -35344,9 +35877,7 @@ namespace exprtk const Sequence& var_list, const bool override = false) { - const std::size_t n = var_list.size(); - - typename std::map::iterator itr = expr_map_.find(name); + const typename std::map::iterator itr = expr_map_.find(name); if (expr_map_.end() != itr) { @@ -35363,6 +35894,8 @@ namespace exprtk if (compile_expression(name,expression,var_list)) { + const std::size_t n = var_list.size(); + fp_map_[n][name]->setup(expr_map_[name]); return true; @@ -35428,7 +35961,7 @@ namespace exprtk inline bool add(const function& f, const bool override = false) { - return add(f.name_,f.expression_,f.v_,override); + return add(f.name_, f.expression_, f.v_,override); } private: @@ -35491,7 +36024,7 @@ namespace exprtk { remove(name,input_var_list.size()); - return compile_expression(name,expression,input_var_list,true); + return compile_expression(name, expression, input_var_list, true); } // Make sure every return point has a scalar as its first parameter @@ -35586,14 +36119,14 @@ namespace exprtk if (arg_count > 6) return; - typename std::map::iterator em_itr = expr_map_.find(name); + const typename std::map::iterator em_itr = expr_map_.find(name); if (expr_map_.end() != em_itr) { expr_map_.erase(em_itr); } - typename funcparam_t::iterator fp_itr = fp_map_[arg_count].find(name); + const typename funcparam_t::iterator fp_itr = fp_map_[arg_count].find(name); if (fp_map_[arg_count].end() != fp_itr) { @@ -36003,7 +36536,7 @@ namespace exprtk exprtk::enable_zero_parameters(*this); } - inline T operator()(parameter_list_t parameters) + inline T operator() (parameter_list_t parameters) { details::print_impl::process(scalar_format_,parameters); return T(0); @@ -36025,7 +36558,7 @@ namespace exprtk exprtk::enable_zero_parameters(*this); } - inline T operator()(parameter_list_t parameters) + inline T operator() (parameter_list_t parameters) { details::print_impl::process(scalar_format_,parameters); printf("\n"); @@ -36289,6 +36822,7 @@ namespace exprtk #pragma warning(pop) #endif } + } // namespace exprtk::rtl::io::file::details template @@ -36307,7 +36841,7 @@ namespace exprtk : exprtk::igeneric_function("S|SS") { details::perform_check(); } - inline T operator()(const std::size_t& ps_index, parameter_list_t parameters) + inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) { std::string file_name; std::string access; @@ -36352,7 +36886,7 @@ namespace exprtk : exprtk::ifunction(1) { details::perform_check(); } - inline T operator()(const T& v) + inline T operator() (const T& v) { details::file_descriptor* fd = details::make_handle(v); @@ -36383,7 +36917,7 @@ namespace exprtk : igfun_t("TS|TST|TV|TVT") { details::perform_check(); } - inline T operator()(const std::size_t& ps_index, parameter_list_t parameters) + inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) { details::file_descriptor* fd = details::make_handle(scalar_t(parameters[0])()); @@ -36392,26 +36926,26 @@ namespace exprtk switch (ps_index) { case 0 : { - string_t buffer(parameters[1]); + const string_t buffer(parameters[1]); amount = buffer.size(); return T(fd->write(buffer,amount) ? 1 : 0); } case 1 : { - string_t buffer(parameters[1]); + const string_t buffer(parameters[1]); amount = std::min(buffer.size(), static_cast(scalar_t(parameters[2])())); return T(fd->write(buffer,amount) ? 1 : 0); } case 2 : { - vector_t vec(parameters[1]); + const vector_t vec(parameters[1]); amount = vec.size(); return T(fd->write(vec,amount) ? 1 : 0); } case 3 : { - vector_t vec(parameters[1]); + const vector_t vec(parameters[1]); amount = std::min(vec.size(), static_cast(scalar_t(parameters[2])())); return T(fd->write(vec,amount) ? 1 : 0); @@ -36440,7 +36974,7 @@ namespace exprtk : igfun_t("TS|TST|TV|TVT") { details::perform_check(); } - inline T operator()(const std::size_t& ps_index, parameter_list_t parameters) + inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) { details::file_descriptor* fd = details::make_handle(scalar_t(parameters[0])()); @@ -36496,8 +37030,8 @@ namespace exprtk : igfun_t("T",igfun_t::e_rtrn_string) { details::perform_check(); } - inline T operator()(std::string& result, - parameter_list_t parameters) + inline T operator() (std::string& result, + parameter_list_t parameters) { details::file_descriptor* fd = details::make_handle(scalar_t(parameters[0])()); return T(fd->getline(result) ? 1 : 0); @@ -36513,7 +37047,7 @@ namespace exprtk : exprtk::ifunction(1) { details::perform_check(); } - inline T operator()(const T& v) + inline T operator() (const T& v) { details::file_descriptor* fd = details::make_handle(v); @@ -36646,9 +37180,9 @@ namespace exprtk */ {} - inline T operator()(const std::size_t& ps_index, parameter_list_t parameters) + inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) { - const vector_t& vec(parameters[0]); + const vector_t vec(parameters[0]); std::size_t r0 = 0; std::size_t r1 = vec.size() - 1; @@ -36692,9 +37226,9 @@ namespace exprtk */ {} - inline T operator()(const std::size_t& ps_index, parameter_list_t parameters) + inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) { - const vector_t& vec(parameters[0]); + const vector_t vec(parameters[0]); std::size_t r0 = 0; std::size_t r1 = vec.size() - 1; @@ -36738,9 +37272,9 @@ namespace exprtk */ {} - inline T operator()(const std::size_t& ps_index, parameter_list_t parameters) + inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) { - const vector_t& vec(parameters[0]); + const vector_t vec(parameters[0]); std::size_t r0 = 0; std::size_t r1 = vec.size() - 1; @@ -36784,9 +37318,9 @@ namespace exprtk */ {} - inline T operator()(const std::size_t& ps_index, parameter_list_t parameters) + inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) { - const vector_t& vec(parameters[0]); + const vector_t vec(parameters[0]); std::size_t r0 = 0; std::size_t r1 = vec.size() - 1; @@ -36830,9 +37364,9 @@ namespace exprtk */ {} - inline T operator()(const std::size_t& ps_index, parameter_list_t parameters) + inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) { - const vector_t& vec(parameters[0]); + const vector_t vec(parameters[0]); std::size_t r0 = 0; std::size_t r1 = vec.size() - 1; @@ -36876,10 +37410,10 @@ namespace exprtk */ {} - inline T operator()(const std::size_t& ps_index, parameter_list_t parameters) + inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) { - vector_t x(parameters[0]); - vector_t y(parameters[(0 == ps_index) ? 1 : 3]); + const vector_t x(parameters[0]); + vector_t y(parameters[(0 == ps_index) ? 1 : 3]); std::size_t xr0 = 0; std::size_t xr1 = x.size() - 1; @@ -36926,7 +37460,7 @@ namespace exprtk */ {} - inline T operator()(const std::size_t& ps_index, parameter_list_t parameters) + inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) { vector_t vec(parameters[0]); @@ -36974,7 +37508,7 @@ namespace exprtk */ {} - inline T operator()(const std::size_t& ps_index, parameter_list_t parameters) + inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) { vector_t vec(parameters[0]); @@ -37022,7 +37556,7 @@ namespace exprtk */ {} - inline T operator()(const std::size_t& ps_index, parameter_list_t parameters) + inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) { vector_t vec(parameters[0]); @@ -37077,7 +37611,7 @@ namespace exprtk */ {} - inline T operator()(const std::size_t& ps_index, parameter_list_t parameters) + inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) { vector_t vec(parameters[0]); @@ -37136,7 +37670,7 @@ namespace exprtk */ {} - inline T operator()(const std::size_t& ps_index, parameter_list_t parameters) + inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) { vector_t vec(parameters[0]); @@ -37191,7 +37725,7 @@ namespace exprtk */ {} - inline T operator()(const std::size_t& ps_index, parameter_list_t parameters) + inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) { vector_t vec(parameters[0]); @@ -37235,7 +37769,7 @@ namespace exprtk */ {} - inline T operator()(const std::size_t& ps_index, parameter_list_t parameters) + inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) { vector_t vec(parameters[0]); @@ -37284,9 +37818,9 @@ namespace exprtk */ {} - inline T operator()(const std::size_t& ps_index, parameter_list_t parameters) + inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) { - vector_t vec(parameters[0]); + const vector_t vec(parameters[0]); std::size_t r0 = 0; std::size_t r1 = vec.size() - 1; @@ -37299,7 +37833,7 @@ namespace exprtk for (std::size_t i = r0; i <= r1; ++i) { - details::kahan_sum(result,error,vec[i]); + details::kahan_sum(result, error, vec[i]); } return result; @@ -37329,10 +37863,10 @@ namespace exprtk */ {} - inline T operator()(const std::size_t& ps_index, parameter_list_t parameters) + inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) { - vector_t x(parameters[1]); - vector_t y(parameters[2]); + const vector_t x(parameters[1]); + vector_t y(parameters[2]); std::size_t r0 = 0; std::size_t r1 = std::min(x.size(),y.size()) - 1; @@ -37346,7 +37880,7 @@ namespace exprtk for (std::size_t i = r0; i <= r1; ++i) { - y[i] = a * x[i] + y[i]; + y[i] = (a * x[i]) + y[i]; } return T(1); @@ -37376,10 +37910,10 @@ namespace exprtk */ {} - inline T operator()(const std::size_t& ps_index, parameter_list_t parameters) + inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) { - vector_t x(parameters[1]); - vector_t y(parameters[3]); + const vector_t x(parameters[1]); + vector_t y(parameters[3]); std::size_t r0 = 0; std::size_t r1 = std::min(x.size(),y.size()) - 1; @@ -37424,11 +37958,11 @@ namespace exprtk */ {} - inline T operator()(const std::size_t& ps_index, parameter_list_t parameters) + inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) { - vector_t x(parameters[1]); - vector_t y(parameters[2]); - vector_t z(parameters[3]); + const vector_t x(parameters[1]); + const vector_t y(parameters[2]); + vector_t z(parameters[3]); std::size_t r0 = 0; std::size_t r1 = std::min(x.size(),y.size()) - 1; @@ -37444,7 +37978,7 @@ namespace exprtk for (std::size_t i = r0; i <= r1; ++i) { - z[i] = a * x[i] + y[i]; + z[i] = (a * x[i]) + y[i]; } return T(1); @@ -37474,11 +38008,11 @@ namespace exprtk */ {} - inline T operator()(const std::size_t& ps_index, parameter_list_t parameters) + inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) { - vector_t x(parameters[1]); - vector_t y(parameters[3]); - vector_t z(parameters[4]); + const vector_t x(parameters[1]); + const vector_t y(parameters[3]); + vector_t z(parameters[4]); std::size_t r0 = 0; std::size_t r1 = std::min(x.size(),y.size()) - 1; @@ -37525,10 +38059,10 @@ namespace exprtk */ {} - inline T operator()(const std::size_t& ps_index, parameter_list_t parameters) + inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) { - vector_t x(parameters[1]); - vector_t z(parameters[3]); + const vector_t x(parameters[1]); + vector_t z(parameters[3]); std::size_t r0 = 0; std::size_t r1 = x.size() - 1; @@ -37543,7 +38077,7 @@ namespace exprtk for (std::size_t i = r0; i <= r1; ++i) { - z[i] = a * x[i] + b; + z[i] = (a * x[i]) + b; } return T(1); @@ -37572,10 +38106,10 @@ namespace exprtk */ {} - inline T operator()(const std::size_t& ps_index, parameter_list_t parameters) + inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) { - vector_t x(parameters[0]); - vector_t y(parameters[1]); + const vector_t x(parameters[0]); + const vector_t y(parameters[1]); std::size_t r0 = 0; std::size_t r1 = std::min(x.size(),y.size()) - 1; @@ -37618,10 +38152,10 @@ namespace exprtk */ {} - inline T operator()(const std::size_t& ps_index, parameter_list_t parameters) + inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) { - vector_t x(parameters[0]); - vector_t y(parameters[1]); + const vector_t x(parameters[0]); + const vector_t y(parameters[1]); std::size_t r0 = 0; std::size_t r1 = std::min(x.size(),y.size()) - 1; @@ -37636,7 +38170,7 @@ namespace exprtk for (std::size_t i = r0; i <= r1; ++i) { - details::kahan_sum(result,error,(x[i] * y[i])); + details::kahan_sum(result, error, (x[i] * y[i])); } return result; @@ -37732,6 +38266,22 @@ namespace exprtk } // namespace information + #ifdef exprtk_debug + #undef exprtk_debug + #endif + + #ifdef exprtk_error_location + #undef exprtk_error_location + #endif + + #ifdef exprtk_disable_fallthrough_begin + #undef exprtk_disable_fallthrough_begin + #endif + + #ifdef exprtk_disable_fallthrough_end + #undef exprtk_disable_fallthrough_end + #endif + } // namespace exprtk #endif diff --git a/exprtk_simple_example_02.cpp b/exprtk_simple_example_02.cpp index cb18b35..71b2069 100644 --- a/exprtk_simple_example_02.cpp +++ b/exprtk_simple_example_02.cpp @@ -39,14 +39,14 @@ void square_wave() static const T pi = T(3.141592653589793238462643383279502); - T f = pi / T(10); - T t = T(0); - T a = T(10); + const T f = pi / T(10); + const T a = T(10); + T t = T(0); symbol_table_t symbol_table; - symbol_table.add_variable("f",f); symbol_table.add_variable("t",t); - symbol_table.add_variable("a",a); + symbol_table.add_constant("f",f); + symbol_table.add_constant("a",a); symbol_table.add_constants(); expression_t expression; diff --git a/exprtk_simple_example_03.cpp b/exprtk_simple_example_03.cpp index 16b627f..924e404 100644 --- a/exprtk_simple_example_03.cpp +++ b/exprtk_simple_example_03.cpp @@ -30,9 +30,9 @@ void polynomial() std::string expression_string = "25x^5 - 35x^4 - 15x^3 + 40x^2 - 15x + 1"; - T r0 = T(0); - T r1 = T(1); - T x = T(0); + const T r0 = T(0); + const T r1 = T(1); + T x = T(0); symbol_table_t symbol_table; symbol_table.add_variable("x",x); diff --git a/exprtk_simple_example_04.cpp b/exprtk_simple_example_04.cpp index 7cf9393..801feae 100644 --- a/exprtk_simple_example_04.cpp +++ b/exprtk_simple_example_04.cpp @@ -70,7 +70,7 @@ void fibonacci() for (std::size_t i = 0; i < 40; ++i) { - x = i; + x = static_cast(i); T result = expression.value(); diff --git a/exprtk_simple_example_09.cpp b/exprtk_simple_example_09.cpp index 469c910..5f68703 100644 --- a/exprtk_simple_example_09.cpp +++ b/exprtk_simple_example_09.cpp @@ -130,7 +130,7 @@ void primes() for (std::size_t i = 0; i < 100; ++i) { - x = i; + x = static_cast(i); T result1 = expression1.value(); T result2 = expression2.value(); diff --git a/exprtk_simple_example_10.cpp b/exprtk_simple_example_10.cpp index 43cb0b1..9a2e4c1 100644 --- a/exprtk_simple_example_10.cpp +++ b/exprtk_simple_example_10.cpp @@ -72,7 +72,7 @@ void newton_sqrt() for (std::size_t i = 0; i < 100; ++i) { - x = i; + x = static_cast(i); T result = expression.value(); diff --git a/exprtk_test.cpp b/exprtk_test.cpp index 4fcdbe4..9867f33 100644 --- a/exprtk_test.cpp +++ b/exprtk_test.cpp @@ -4848,7 +4848,7 @@ inline std::size_t load_expressions(const std::string& file_name, std::size_t line_count = 0; - while (std::getline(stream,buffer)) + while (std::getline(stream,(buffer))) { if (buffer.empty()) continue; @@ -7685,7 +7685,7 @@ struct my_usr_ext : public exprtk::parser::unknown_symbol_resolver { static T var_default_value = 1.0; - if (!(result = symbol_table.create_variable(unknown_symbol, var_default_value++))) + if ((result = symbol_table.create_variable(unknown_symbol, var_default_value++)) == false) { error_message = "Failed to create variable(" + unknown_symbol + ") in primary symbol table"; } @@ -7694,7 +7694,7 @@ struct my_usr_ext : public exprtk::parser::unknown_symbol_resolver { static T cvar_default_value = 1.0; - if (!(result = symbol_table.add_constant(unknown_symbol, cvar_default_value++))) + if ((result = symbol_table.add_constant(unknown_symbol, cvar_default_value++)) == false) { error_message = "Failed to create const variable(" + unknown_symbol + ") in primary symbol table"; } diff --git a/readme.txt b/readme.txt index 485791b..a819125 100644 --- a/readme.txt +++ b/readme.txt @@ -224,7 +224,7 @@ of C++ compilers: +----------+---------------------------------------------------------+ | true | True state or any value other than zero (typically 1). | +----------+---------------------------------------------------------+ -| false | False state, value of zero. | +| false | False state, value of exactly zero. | +----------+---------------------------------------------------------+ | and | Logical AND, True only if x and y are both true. | | | (eg: x and y) | @@ -275,7 +275,7 @@ of C++ compilers: | clamp | Clamp x in range between r0 and r1, where r0 < r1. | | | (eg: clamp(r0,x,r1)) | +----------+---------------------------------------------------------+ -| equal | Equality test between x and y using normalized epsilon | +| equal | Equality test between x and y using normalised epsilon | +----------+---------------------------------------------------------+ | erf | Error function of x. (eg: erf(x)) | +----------+---------------------------------------------------------+ @@ -321,7 +321,7 @@ of C++ compilers: +----------+---------------------------------------------------------+ | ncdf | Normal cumulative distribution function. (eg: ncdf(x)) | +----------+---------------------------------------------------------+ -| nequal | Not-equal test between x and y using normalized epsilon | +| nequal | Not-equal test between x and y using normalised epsilon | +----------+---------------------------------------------------------+ | pow | x to the power of y. (eg: pow(x,y) == x ^ y) | +----------+---------------------------------------------------------+ @@ -499,7 +499,7 @@ of C++ compilers: | | eg: | | | 1. if (x > y) z; else w; | | | 2. if (x > y) z; else if (w != u) v; | -| | 3. if (x < y) {z; w + 1;} else u; | +| | 3. if (x < y) { z; w + 1; } else u; | | | 4. if ((x != y) and (z > w)) | | | { | | | y := sin(x) / u; | @@ -651,7 +651,7 @@ expressions. The types are as follows: (1) Scalar Type The scalar type is a singular numeric value. The underlying type is -that used to specialize the ExprTk components (float, double, long +that used to specialise the ExprTk components (float, double, long double, MPFR et al). @@ -673,7 +673,7 @@ however can not interact with scalar or vector types. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [SECTION 10 - COMPONENTS] -There are three primary components, that are specialized upon a given +There are three primary components, that are specialised upon a given numeric type, which make up the core of ExprTk. The components are as follows: @@ -791,8 +791,9 @@ methods: 4. bool add_vector (const std::string& name, vector_type&) -The 'vector' type must consist of a contiguous array of scalars which -can be one of the following: +Note: The 'vector' type must be comprised from a contiguous array of +scalars with a size that is larger than zero. The vector type itself +can be any one of the following: 1. std::vector 2. scalar_t(&v)[N] @@ -800,6 +801,18 @@ can be one of the following: 4. exprtk::vector_view +When registering a variable, vector, string or function with an +instance of a symbol_table, the call to 'add_...' may fail and return +a false result due to one or more of the following reasons: + + 1. Variable name contains invalid characters or is ill-formed + 2. Variable name conflicts with a reserved word (eg: 'while') + 3. Variable name conflicts with a previously registered variable + 4. A vector of size (length) zero is being registered + 5. A free function exceeding fifteen parameters is being registered + 6. The symbol_table instance is in an invalid state + + (2) Expression A structure that holds an abstract syntax tree or AST for a specified expression and is used to evaluate said expression. Evaluation of the @@ -920,8 +933,8 @@ including which control block each expression references and their associated reference counts. - exprtk::expression e0; // constructed expression, eg: x + 1 - exprtk::expression e1; // constructed expression, eg: 2z + y + exprtk::expression e0; // constructed expression, eg: x + 1 + exprtk::expression e1; // constructed expression, eg: 2z + y +-----[ e0 cntrl block]----+ +-----[ e1 cntrl block]-----+ | 1. Expression Node 'x+1' | | 1. Expression Node '2z+y' | @@ -934,7 +947,7 @@ associated reference counts. +--------------------+ +--------------------+ - e0 = e1; // e0 and e1 are now 2z+y + e0 = e1; // e0 and e1 are now 2z+y +-----[ e1 cntrl block]-----+ | 1. Expression Node '2z+y' | @@ -1226,7 +1239,7 @@ In the following example, the return value of the expression will be within the loop body on its last iteration: var x := 1; - x + for (var i := i; i < 10; i += 1) + x + for (var i := x; i < 10; i += 1) { i / 2; i + 1; @@ -1303,7 +1316,7 @@ lets review the following expression: var x := 2; // Statement 1 var y := x + 2; // Statement 2 - x + y // Statement 3 + x + y; // Statement 3 y := x + 3y; // Statement 4 x - y; // Statement 5 @@ -1332,9 +1345,9 @@ ExprTk support two forms of conditional branching or otherwise known as if-statements. The first form, is a simple function based conditional statement, that takes exactly three input expressions: condition, consequent and alternative. The following is an example -expression that utilizes the function based if-statement. +expression that utilises the function based if-statement. - x := if (y < z, y + 1, 2* z) + x := if (y < z, y + 1, 2 * z) In the example above, if the condition 'y < z' is true, then the @@ -1345,7 +1358,7 @@ essentially the simplest form of an if-then-else statement. A simple variation of the expression where the value of the if-statement is used within another statement is as follows: - x := 3 * if (y < z, y + 1, 2* z) / 2 + x := 3 * if (y < z, y + 1, 2 * z) / 2 The second form of if-statement resembles the standard syntax found in @@ -1401,37 +1414,29 @@ The second variation of the if-statement is to allow for the use of Else and If-Else cascading statements. Examples of such statements are as follows: - Example 1: Example 2: - if (x < y) if (x < y) - z := x + 3; { - else y := z + x; - y := x - z; z := x + 3; - } - else - y := x - z; + Example 1: Example 2: Example 3: + if (x < y) if (x < y) if (x > y + 1) + z := x + 3; { y := abs(x - z); + else y := z + x; else + y := x - z; z := x + 3; { + } y := z + x; + else z := x + 3; + y := x - z; }; - Example 3: Example 4: - if (x > y + 1) if (2 * x < max(y,3)) - y := abs(x - z); { - else y := z + x; - { z := x + 3; - y := z + x; } - z := x + 3; else if (2y - z) - }; y := x - z; - Example 5: Example 6: - if (x < y) if (x < y or (x + z) > y) - z := x + 3; { - else if (2y != z) z := x + 3; - { y := x - z; - z := x + 3; } - y := x - z; else if (abs(2y - z) >= 3) - } y := x - z; - else else - x * x; { - z := abs(x * x); - x * y * z; - }; + Example 4: Example 5: Example 6: + if (2 * x < max(y,3)) if (x < y) if (x < y or (x + z) > y) + { z := x + 3; { + y := z + x; else if (2y != z) z := x + 3; + z := x + 3; { y := x - z; + } z := x + 3; } + else if (2y - z) y := x - z; else if (abs(2y - z) >= 3) + y := x - z; } y := x - z; + else else + x * x; { + z := abs(x * x); + x * y * z; + }; In the case where there is no final else statement and the flow @@ -1451,7 +1456,7 @@ Special functions dramatically decrease the total evaluation time of expressions which would otherwise have been written using the common form by reducing the total number of nodes in the evaluation tree of an expression and by also leveraging the compiler's ability to -correctly optimize such expressions for a given architecture. +correctly optimise such expressions for a given architecture. 3-Parameter 4-Parameter +-------------+-------------+ +--------------+------------------+ @@ -1581,25 +1586,28 @@ examples of string variable definitions: (a) Initialise to a string var x := 'abc'; - (b) Initialise to a string expression + (b) Initialise to an empty string + var x := ''; + + (c) Initialise to a string expression var x := 'abc' + '123'; - (c) Initialise to a string range + (d) Initialise to a string range var x := 'abc123'[2:4]; - (d) Initialise to another string variable + (e) Initialise to another string variable var x := 'abc'; var y := x; - (e) Initialise to another string variable range + (f) Initialise to another string variable range var x := 'abc123'; var y := x[2:4]; - (f) Initialise to a string expression + (g) Initialise to a string expression var x := 'abc'; var y := x + '123'; - (g) Initialise to a string expression range + (h) Initialise to a string expression range var x := 'abc'; var y := (x + '123')[1:3]; @@ -1775,7 +1783,7 @@ needs to be 'updated' to either another vector or sub-range, the vector_view instance can be efficiently rebased, and the expression evaluated as normal. - exprtk::vector_view view = exprtk::make_vector_view(v, v.size()); + exprtk::vector_view view = exprtk::make_vector_view(v,v.size()); symbol_table_t symbol_table; symbol_table.add_vector("v",view); @@ -1794,7 +1802,7 @@ evaluated as normal. [SECTION 15 - USER DEFINED FUNCTIONS] ExprTk provides a means whereby custom functions can be defined and -utilized within expressions. The concept requires the user to +utilised within expressions. The concept requires the user to provide a reference to the function coupled with an associated name that will be invoked within expressions. Functions may take numerous inputs but will always return a single value of the underlying numeric @@ -1840,7 +1848,7 @@ function called 'foo': (2) ivararg_function This interface supports a variable number of scalar arguments as input into the function. The function operator interface uses a std::vector -specialized upon type T to facilitate parameter passing. The following +specialised upon type T to facilitate parameter passing. The following example defines a vararg function called 'boo': template @@ -1863,7 +1871,7 @@ example defines a vararg function called 'boo': (3) igeneric_function This interface supports a variable number of arguments and types as input into the function. The function operator interface uses a -std::vector specialized upon the type_store type to facilitate +std::vector specialised upon the type_store type to facilitate parameter passing. Scalar <-- function(i_0, i_1, i_2....., i_N) @@ -2335,6 +2343,42 @@ Note: For the igeneric_function type, there also needs to be a 'Z' parameter sequence defined in order for the zero parameter trait to properly take effect otherwise a compilation error will occur. + +(9) Free Functions +The ExprTk symbol table supports the registration of free functions +and lambdas (anonymous functors) for use in expressions. The basic +requirements are similar to those found in ifunction derived user +defined functions. This includes support for free functions using +anywhere from zero up to fifteen input parameters of scalar type, with +a return type that is also scalar. Furthermore such functions will by +default be assumed to have side-effects and hence will not participate +in constant folding optimisations. + +In the following example, a two input parameter free function named +'compute', and a three input parameter lambda will be registered with +the given symbol_table instance: + + + double compute(double v0, double v1) + { + return 2.0 * v0 + v1 / 3.0; + } + + . + . + . + + typedef exprtk::symbol_table symbol_table_t; + + symbol_table_t symbol_table; + + symbol_table.add_function("compute", compute); + + symbol_table.add_function("lambda", + [](double v0, double v1, double v2) -> double + { return v0 / v1 + v2; }); + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [SECTION 16 - EXPRESSION DEPENDENTS] @@ -2443,7 +2487,7 @@ associated assignments: (5) None x + y + z -Note: In expression 4, both variables 'z' and 'w' are denoted as being +Note: In expression 4, both variables 'w' and 'z' are denoted as being assignments even though only one of them can ever be modified at the time of evaluation. Furthermore the determination of which of the two variables the modification will occur upon can only be known with @@ -2489,7 +2533,7 @@ associated with a given expression instance. However as an expression can have more than one symbol table instance associated with itself, when building more complex systems that -utilize many expressions where each can in turn utilize one or more +utilise many expressions where each can in turn utilise one or more variables from a large set of potential variables, functions or constants, it becomes evident that grouping variables into layers of symbol_tables will simplify and streamline the overall process. @@ -2559,7 +2603,7 @@ own instances of those variables. Examples of such variables could be: (2) customer_name -The following is a diagram depicting the possible version of the +The following is a diagram depicting the possible version of the denoted symbol table hierarchies. In the diagram there are two unique expressions, each of which have a reference to the Global constant, functions and variables symbol tables and an exclusive reference to a @@ -2589,8 +2633,8 @@ local symbol table. Bringing all of the above together, in the following example the -hierarchy of symbol tables are instantiated and initialised. An -expression that makes use of various elements of each symbol table is +hierarchy of symbol tables are instantiated and initialised. An +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; @@ -2722,7 +2766,7 @@ expressions: In this scenario one can use the 'dependent_entity_collector' component as described in [Section 16] to further determine which of the registered variables were actually used in the given expression. -As an example once the set of utilized variables are known, any +As an example once the set of utilised variables are known, any further 'attention' can be restricted to only those variables when evaluating the expression. This can be quite useful when dealing with expressions that can draw from a set of hundreds or even thousands of @@ -3427,8 +3471,8 @@ values. expression.value(); - printf("Result0: %15.5f\n",result0 ); - printf("Result1: %s\n" ,result1.c_str()); + printf("Result0: %15.5f\n", result0 ); + printf("Result1: %s\n" , result1.c_str()); In the example above, the expression will compute two results. As such @@ -3436,7 +3480,7 @@ two result variables are defined to hold the values named result0 and result1 respectively. The first is of scalar type (double), the second is of string type. Once the expression has been evaluated, the two variables will have been updated with the new result values, and can -then be further utilized from within the calling program. +then be further utilised from within the calling program. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -3753,12 +3797,12 @@ overloads, the definitions of which are: (1) No variables (2) One variable called x - (3) Two variable called x and y - (3) Three variable called x, y and z + (3) Two variables called x and y + (3) Three variables called x, y and z -An example use of each of the three overloads for the compute routine -is as follows: +Example uses of each of the three overloads for the compute routine +are as follows: T result = T(0); @@ -3803,11 +3847,11 @@ is as follows: (d) integrate This free function will attempt to perform a numerical integration of -a single variable compiled expression over a defined range and given -step size. The numerical integration is based on the three point form -of the Simpson's rule. The integrate function has two overloads, where -the variable of integration can either be passed as a reference or as -a name in string form. Example usage of the function is as follows: +a single variable compiled expression over a specified range and step +size. The numerical integration is based on the three point form of +Simpson's rule. The integrate function has two overloads, where the +variable of integration can either be passed as a reference or as a +name in string form. Example usage of the function is as follows: typedef exprtk::parser parser_t; typedef exprtk::expression expression_t; @@ -3863,7 +3907,7 @@ function is as follows: .... - // Differentiate expression where value of x = 12.3 using a reference + // Differentiate expression at value of x = 12.3 using a reference // to the x variable x = T(12.3); T derivative1 = exprtk::derivative(expression,x); @@ -4047,7 +4091,7 @@ expressions. As an example, lets take the following expression: 1 / sqrt(2x) * e^(3y) -Let's say we would like to determine which sub-part of the expression +Lets say we would like to determine which sub-part of the expression takes the most time to evaluate and perhaps attempt to rework the expression based on the results. In order to do this we will create a text file called 'test.txt' and then proceed to make some educated @@ -4133,7 +4177,7 @@ into account when using ExprTk: (09) The life-time of objects registered with or created from a specific symbol-table must span at least the life-time of the - compiled expressions which utilize objects, such as variables, + compiled expressions which utilise objects, such as variables, of that symbol-table, otherwise the result will be undefined behavior. @@ -4289,7 +4333,15 @@ into account when using ExprTk: performance critical code paths, and should instead occur entirely either before or after such code paths. - (32) Before jumping in and using ExprTk, do take the time to peruse + (32) Deep copying an expression instance for the purposes of + persisting to disk or otherwise transmitting elsewhere with the + intent to 'resurrect' the expression instance later on is not + possible due to the reasons described in the final note of + Section 10. The recommendation is to instead simply persist the + string form of the expression and compile the expression at + run-time on the target. + + (33) Before jumping in and using ExprTk, do take the time to peruse the documentation and all of the examples, both in the main and the extras distributions. Having an informed general view of what can and can't be done, and how something should be done