00000 | /* 00001 | ****************************************************************** 00002 | * C++ Mathematical Expression Toolkit Library * 00003 | * * 00004 | * Author: Arash Partow (1999-2025) * 00005 | * URL: https://www.partow.net/programming/exprtk/index.html * 00006 | * * 00007 | * Copyright notice: * 00008 | * Free use of the C++ Mathematical Expression Toolkit Library is * 00009 | * permitted under the guidelines and in accordance with the most * 00010 | * current version of the MIT License. * 00011 | * https://www.opensource.org/licenses/MIT * 00012 | * SPDX-License-Identifier: MIT * 00013 | * * 00014 | * Example expressions: * 00015 | * (00) (y + x / y) * (x - y / x) * 00016 | * (01) (x^2 / sin(2 * pi / y)) - x / 2 * 00017 | * (02) sqrt(1 - (x^2)) * 00018 | * (03) 1 - sin(2 * x) + cos(pi / y) * 00019 | * (04) a * exp(2 * t) + c * 00020 | * (05) if(((x + 2) == 3) and ((y + 5) <= 9), 1 + w, 2 / z) * 00021 | * (06) (avg(x,y) <= x + y ? x - y : x * y) + 2 * pi / x * 00022 | * (07) z := x + sin(2 * pi / y) * 00023 | * (08) u := 2 * (pi * z) / (w := x + cos(y / pi)) * 00024 | * (09) clamp(-1, sin(2 * pi * x) + cos(y / 2 * pi), +1) * 00025 | * (10) inrange(-2, m, +2) == if(({-2 <= m} and [m <= +2]), 1, 0) * 00026 | * (11) (2sin(x)cos(2y)7 + 1) == (2 * sin(x) * cos(2*y) * 7 + 1) * 00027 | * (12) (x ilike 's*ri?g') and [y < (3 z^7 + w)] * 00028 | * * 00029 | ****************************************************************** 00030 | */ 00031 | 00032 | 00033 | #ifndef INCLUDE_EXPRTK_HPP 00034 | #define INCLUDE_EXPRTK_HPP 00035 | 00036 | 00037 | #include00038 | #include 00039 | #include 00040 | #include 00041 | #include 00042 | #include 00043 | #include 00044 | #include 00045 | #include 00046 | #include 00047 | #include 00048 | #include 00049 | #include 00050 | #include
00051 | #include 00052 | #include 00053 | #include 00054 | #include 00055 | #include 00056 | 00057 | 00058 | namespace exprtk 00059 | { 00060 | #ifdef exprtk_enable_debugging 00061 | #define exprtk_debug(params) printf params 00062 | #else 00063 | #define exprtk_debug(params) (void)0 00064 | #endif 00065 | 00066 | #define exprtk_error_location \ 00067 | "exprtk.hpp:" + details::to_str(__LINE__) \ 00068 | 00069 | #if __cplusplus >= 201103L 00070 | #define exprtk_override override 00071 | #define exprtk_final final 00072 | #define exprtk_delete = delete 00073 | #else 00074 | #define exprtk_override 00075 | #define exprtk_final 00076 | #define exprtk_delete 00077 | #endif 00078 | 00079 | #if __cplusplus >= 201603L 00080 | #define exprtk_fallthrough [[fallthrough]]; 00081 | #elif (__cplusplus >= 201103L) && (defined(__GNUC__) && !defined(__clang__)) 00082 | #define exprtk_fallthrough [[gnu::fallthrough]]; 00083 | #else 00084 | #ifndef _MSC_VER 00085 | #define exprtk_fallthrough __attribute__ ((fallthrough)); 00086 | #else 00087 | #define exprtk_fallthrough 00088 | #endif 00089 | #endif 00090 | 00091 | namespace details 00092 | { 00093 | typedef char char_t; 00094 | typedef char_t* char_ptr; 00095 | typedef char_t const* char_cptr; 00096 | typedef unsigned char uchar_t; 00097 | typedef uchar_t* uchar_ptr; 00098 | typedef uchar_t const* uchar_cptr; 00099 | typedef unsigned long long int _uint64_t; 00100 | typedef long long int _int64_t; 00101 | 00102 | inline bool is_whitespace(const char_t c) 00103 | { 00104 | return (' ' == c) || ('\n' == c) || 00105 | ('\r' == c) || ('\t' == c) || 00106 | ('\b' == c) || ('\v' == c) || 00107 | ('\f' == c) ; 00108 | } 00109 | 00110 | inline bool is_operator_char(const char_t c) 00111 | { 00112 | return ('+' == c) || ('-' == c) || 00113 | ('*' == c) || ('/' == c) || 00114 | ('^' == c) || ('<' == c) || 00115 | ('>' == c) || ('=' == c) || 00116 | (',' == c) || ('!' == c) || 00117 | ('(' == c) || (')' == c) || 00118 | ('[' == c) || (']' == c) || 00119 | ('{' == c) || ('}' == c) || 00120 | ('%' == c) || (':' == c) || 00121 | ('?' == c) || ('&' == c) || 00122 | ('|' == c) || (';' == c) ; 00123 | } 00124 | 00125 | inline bool is_letter(const char_t c) 00126 | { 00127 | return (('a' <= c) && (c <= 'z')) || 00128 | (('A' <= c) && (c <= 'Z')) ; 00129 | } 00130 | 00131 | inline bool is_digit(const char_t c) 00132 | { 00133 | return ('0' <= c) && (c <= '9'); 00134 | } 00135 | 00136 | inline bool is_letter_or_digit(const char_t c) 00137 | { 00138 | return is_letter(c) || is_digit(c); 00139 | } 00140 | 00141 | inline bool is_left_bracket(const char_t c) 00142 | { 00143 | return ('(' == c) || ('[' == c) || ('{' == c); 00144 | } 00145 | 00146 | inline bool is_right_bracket(const char_t c) 00147 | { 00148 | return (')' == c) || (']' == c) || ('}' == c); 00149 | } 00150 | 00151 | inline bool is_bracket(const char_t c) 00152 | { 00153 | return is_left_bracket(c) || is_right_bracket(c); 00154 | } 00155 | 00156 | inline bool is_sign(const char_t c) 00157 | { 00158 | return ('+' == c) || ('-' == c); 00159 | } 00160 | 00161 | inline bool is_invalid(const char_t c) 00162 | { 00163 | return !is_whitespace (c) && 00164 | !is_operator_char(c) && 00165 | !is_letter (c) && 00166 | !is_digit (c) && 00167 | ('.' != c) && 00168 | ('_' != c) && 00169 | ('$' != c) && 00170 | ('~' != c) && 00171 | ('\'' != c); 00172 | } 00173 | 00174 | inline bool is_valid_string_char(const char_t c) 00175 | { 00176 | return std::isprint(static_cast<uchar_t>(c)) || 00177 | is_whitespace(c); 00178 | } 00179 | 00180 | #ifndef exprtk_disable_caseinsensitivity 00181 | inline void case_normalise(std::string& s) 00182 | { 00183 | for (std::size_t i = 0; i < s.size(); ++i) 00184 | { 00185 | s[i] = static_cast<std::string::value_type>(std::tolower(s[i])); 00186 | } 00187 | } 00188 | 00189 | inline bool imatch(const char_t c1, const char_t c2) 00190 | { 00191 | return std::tolower(c1) == std::tolower(c2); 00192 | } 00193 | 00194 | inline bool imatch(const std::string& s1, const std::string& s2) 00195 | { 00196 | if (s1.size() == s2.size()) 00197 | { 00198 | for (std::size_t i = 0; i < s1.size(); ++i) 00199 | { 00200 | if (std::tolower(s1[i]) != std::tolower(s2[i])) 00201 | { 00202 | return false; 00203 | } 00204 | } 00205 | 00206 | return true; 00207 | } 00208 | 00209 | return false; 00210 | } 00211 | 00212 | struct ilesscompare 00213 | { 00214 | inline bool operator() (const std::string& s1, const std::string& s2) const 00215 | { 00216 | const std::size_t length = std::min(s1.size(),s2.size()); 00217 | 00218 | for (std::size_t i = 0; i < length; ++i) 00219 | { 00220 | const char_t c1 = static_cast<char_t>(std::tolower(s1[i])); 00221 | const char_t c2 = static_cast<char_t>(std::tolower(s2[i])); 00222 | 00223 | if (c1 < c2) 00224 | return true; 00225 | else if (c2 < c1) 00226 | return false; 00227 | } 00228 | 00229 | return s1.size() < s2.size(); 00230 | } 00231 | }; 00232 | 00233 | #else 00234 | inline void case_normalise(std::string&) 00235 | {} 00236 | 00237 | inline bool imatch(const char_t c1, const char_t c2) 00238 | { 00239 | return c1 == c2; 00240 | } 00241 | 00242 | inline bool imatch(const std::string& s1, const std::string& s2) 00243 | { 00244 | return s1 == s2; 00245 | } 00246 | 00247 | struct ilesscompare 00248 | { 00249 | inline bool operator() (const std::string& s1, const std::string& s2) const 00250 | { 00251 | return s1 < s2; 00252 | } 00253 | }; 00254 | #endif 00255 | 00256 | inline bool is_valid_sf_symbol(const std::string& symbol) 00257 | { 00258 | // Special function: $f12 or $F34 00259 | return (4 == symbol.size()) && 00260 | ('$' == symbol[0]) && 00261 | imatch('f',symbol[1]) && 00262 | is_digit(symbol[2]) && 00263 | is_digit(symbol[3]); 00264 | } 00265 | 00266 | inline const char_t& front(const std::string& s) 00267 | { 00268 | return s[0]; 00269 | } 00270 | 00271 | inline const char_t& back(const std::string& s) 00272 | { 00273 | return s[s.size() - 1]; 00274 | } 00275 | 00276 | template <typename SignedType> 00277 | inline std::string to_str_impl(SignedType i) 00278 | { 00279 | if (0 == i) 00280 | return std::string("0"); 00281 | 00282 | std::string result; 00283 | 00284 | const int sign = (i < 0) ? -1 : 1; 00285 | 00286 | for ( ; i; i /= 10) 00287 | { 00288 | result += '0' + static_cast<char_t>(sign * (i % 10)); 00289 | } 00290 | 00291 | if (sign < 0) 00292 | { 00293 | result += '-'; 00294 | } 00295 | 00296 | std::reverse(result.begin(), result.end()); 00297 | 00298 | return result; 00299 | } 00300 | 00301 | inline std::string to_str(int i) 00302 | { 00303 | return to_str_impl(i); 00304 | } 00305 | 00306 | inline std::string to_str(std::size_t i) 00307 | { 00308 | return to_str_impl(static_cast<long long int>(i)); 00309 | } 00310 | 00311 | inline bool is_hex_digit(const uchar_t digit) 00312 | { 00313 | return (('0' <= digit) && (digit <= '9')) || 00314 | (('A' <= digit) && (digit <= 'F')) || 00315 | (('a' <= digit) && (digit <= 'f')) ; 00316 | } 00317 | 00318 | inline uchar_t hex_to_bin(uchar_t h) 00319 | { 00320 | if (('0' <= h) && (h <= '9')) 00321 | return (h - '0'); 00322 | else 00323 | return static_cast<uchar_t>(std::toupper(h) - 'A' + 10); 00324 | } 00325 | 00326 | template <typename Iterator> 00327 | inline bool parse_hex(Iterator& itr, Iterator end, 00328 | char_t& result) 00329 | { 00330 | if ( 00331 | (end == (itr )) || 00332 | (end == (itr + 1)) || 00333 | (end == (itr + 2)) || 00334 | (end == (itr + 3)) || 00335 | ('0' != *(itr )) || 00336 | ('X' != std::toupper(*(itr + 1))) || 00337 | (!is_hex_digit(*(itr + 2))) || 00338 | (!is_hex_digit(*(itr + 3))) 00339 | ) 00340 | { 00341 | return false; 00342 | } 00343 | 00344 | result = static_cast<char_t>( 00345 | hex_to_bin(static_cast<uchar_t>(*(itr + 2))) << 4 | 00346 | hex_to_bin(static_cast<uchar_t>(*(itr + 3)))) ; 00347 | 00348 | return true; 00349 | } 00350 | 00351 | inline bool cleanup_escapes(std::string& s) 00352 | { 00353 | typedef std::string::iterator str_itr_t; 00354 | 00355 | str_itr_t itr1 = s.begin(); 00356 | str_itr_t itr2 = s.begin(); 00357 | str_itr_t end = s.end (); 00358 | 00359 | std::size_t removal_count = 0; 00360 | 00361 | while (end != itr1) 00362 | { 00363 | if ('\\' == (*itr1)) 00364 | { 00365 | if (end == ++itr1) 00366 | { 00367 | return false; 00368 | } 00369 | else if (parse_hex(itr1, end, *itr2)) 00370 | { 00371 | itr1 += 4; 00372 | itr2 += 1; 00373 | removal_count += 4; 00374 | } 00375 | else if ('a' == (*itr1)) { (*itr2++) = '\a'; ++itr1; ++removal_count; } 00376 | else if ('b' == (*itr1)) { (*itr2++) = '\b'; ++itr1; ++removal_count; } 00377 | else if ('f' == (*itr1)) { (*itr2++) = '\f'; ++itr1; ++removal_count; } 00378 | else if ('n' == (*itr1)) { (*itr2++) = '\n'; ++itr1; ++removal_count; } 00379 | else if ('r' == (*itr1)) { (*itr2++) = '\r'; ++itr1; ++removal_count; } 00380 | else if ('t' == (*itr1)) { (*itr2++) = '\t'; ++itr1; ++removal_count; } 00381 | else if ('v' == (*itr1)) { (*itr2++) = '\v'; ++itr1; ++removal_count; } 00382 | else if ('0' == (*itr1)) { (*itr2++) = '\0'; ++itr1; ++removal_count; } 00383 | else 00384 | { 00385 | (*itr2++) = (*itr1++); 00386 | ++removal_count; 00387 | } 00388 | 00389 | continue; 00390 | } 00391 | else 00392 | (*itr2++) = (*itr1++); 00393 | } 00394 | 00395 | if ((removal_count > s.size()) || (0 == removal_count)) 00396 | return false; 00397 | 00398 | s.resize(s.size() - removal_count); 00399 | 00400 | return true; 00401 | } 00402 | 00403 | class build_string 00404 | { 00405 | public: 00406 | 00407 | explicit build_string(const std::size_t& initial_size = 64) 00408 | { 00409 | data_.reserve(initial_size); 00410 | } 00411 | 00412 | inline build_string& operator << (const std::string& s) 00413 | { 00414 | data_ += s; 00415 | return (*this); 00416 | } 00417 | 00418 | inline build_string& operator << (char_cptr s) 00419 | { 00420 | data_ += std::string(s); 00421 | return (*this); 00422 | } 00423 | 00424 | inline operator std::string () const 00425 | { 00426 | return data_; 00427 | } 00428 | 00429 | inline std::string as_string() const 00430 | { 00431 | return data_; 00432 | } 00433 | 00434 | private: 00435 | 00436 | std::string data_; 00437 | }; 00438 | 00439 | static const std::string reserved_words[] = 00440 | { 00441 | "assert", "break", "case", "continue", "const", "default", 00442 | "false", "for", "if", "else", "ilike", "in", "like", "and", 00443 | "nand", "nor", "not", "null", "or", "repeat", "return", 00444 | "shl", "shr", "swap", "switch", "true", "until", "var", 00445 | "while", "xnor", "xor", "&", "|" 00446 | }; 00447 | 00448 | static const std::size_t reserved_words_size = sizeof(reserved_words) / sizeof(std::string); 00449 | 00450 | static const std::string reserved_symbols[] = 00451 | { 00452 | "abs", "acos", "acosh", "and", "asin", "asinh", "assert", 00453 | "atan", "atanh", "atan2", "avg", "break", "case", "ceil", 00454 | "clamp", "continue", "const", "cos", "cosh", "cot", "csc", 00455 | "default", "deg2grad", "deg2rad", "equal", "erf", "erfc", 00456 | "exp", "expm1", "false", "floor", "for", "frac", "grad2deg", 00457 | "hypot", "iclamp", "if", "else", "ilike", "in", "inrange", 00458 | "like", "log", "log10", "log2", "logn", "log1p", "mand", 00459 | "max", "min", "mod", "mor", "mul", "ncdf", "nand", "nor", 00460 | "not", "not_equal", "null", "or", "pow", "rad2deg", 00461 | "repeat", "return", "root", "round", "roundn", "sec", "sgn", 00462 | "shl", "shr", "sin", "sinc", "sinh", "sqrt", "sum", "swap", 00463 | "switch", "tan", "tanh", "true", "trunc", "until", "var", 00464 | "while", "xnor", "xor", "&", "|" 00465 | }; 00466 | 00467 | static const std::size_t reserved_symbols_size = sizeof(reserved_symbols) / sizeof(std::string); 00468 | 00469 | static const std::string base_function_list[] = 00470 | { 00471 | "abs", "acos", "acosh", "asin", "asinh", "atan", "atanh", 00472 | "atan2", "avg", "ceil", "clamp", "cos", "cosh", "cot", 00473 | "csc", "equal", "erf", "erfc", "exp", "expm1", "floor", 00474 | "frac", "hypot", "iclamp", "like", "log", "log10", "log2", 00475 | "logn", "log1p", "mand", "max", "min", "mod", "mor", "mul", 00476 | "ncdf", "pow", "root", "round", "roundn", "sec", "sgn", 00477 | "sin", "sinc", "sinh", "sqrt", "sum", "swap", "tan", "tanh", 00478 | "trunc", "not_equal", "inrange", "deg2grad", "deg2rad", 00479 | "rad2deg", "grad2deg" 00480 | }; 00481 | 00482 | static const std::size_t base_function_list_size = sizeof(base_function_list) / sizeof(std::string); 00483 | 00484 | static const std::string logic_ops_list[] = 00485 | { 00486 | "and", "nand", "nor", "not", "or", "xnor", "xor", "&", "|" 00487 | }; 00488 | 00489 | static const std::size_t logic_ops_list_size = sizeof(logic_ops_list) / sizeof(std::string); 00490 | 00491 | static const std::string cntrl_struct_list[] = 00492 | { 00493 | "if", "switch", "for", "while", "repeat", "return" 00494 | }; 00495 | 00496 | static const std::size_t cntrl_struct_list_size = sizeof(cntrl_struct_list) / sizeof(std::string); 00497 | 00498 | static const std::string arithmetic_ops_list[] = 00499 | { 00500 | "+", "-", "*", "/", "%", "^" 00501 | }; 00502 | 00503 | static const std::size_t arithmetic_ops_list_size = sizeof(arithmetic_ops_list) / sizeof(std::string); 00504 | 00505 | static const std::string assignment_ops_list[] = 00506 | { 00507 | ":=", "+=", "-=", 00508 | "*=", "/=", "%=" 00509 | }; 00510 | 00511 | static const std::size_t assignment_ops_list_size = sizeof(assignment_ops_list) / sizeof(std::string); 00512 | 00513 | static const std::string inequality_ops_list[] = 00514 | { 00515 | "<", "<=", "==", 00516 | "=", "!=", "<>", 00517 | ">=", ">" 00518 | }; 00519 | 00520 | static const std::size_t inequality_ops_list_size = sizeof(inequality_ops_list) / sizeof(std::string); 00521 | 00522 | inline bool is_reserved_word(const std::string& symbol) 00523 | { 00524 | for (std::size_t i = 0; i < reserved_words_size; ++i) 00525 | { 00526 | if (imatch(symbol, reserved_words[i])) 00527 | { 00528 | return true; 00529 | } 00530 | } 00531 | 00532 | return false; 00533 | } 00534 | 00535 | inline bool is_reserved_symbol(const std::string& symbol) 00536 | { 00537 | for (std::size_t i = 0; i < reserved_symbols_size; ++i) 00538 | { 00539 | if (imatch(symbol, reserved_symbols[i])) 00540 | { 00541 | return true; 00542 | } 00543 | } 00544 | 00545 | return false; 00546 | } 00547 | 00548 | inline bool is_base_function(const std::string& function_name) 00549 | { 00550 | for (std::size_t i = 0; i < base_function_list_size; ++i) 00551 | { 00552 | if (imatch(function_name, base_function_list[i])) 00553 | { 00554 | return true; 00555 | } 00556 | } 00557 | 00558 | return false; 00559 | } 00560 | 00561 | inline bool is_control_struct(const std::string& cntrl_strct) 00562 | { 00563 | for (std::size_t i = 0; i < cntrl_struct_list_size; ++i) 00564 | { 00565 | if (imatch(cntrl_strct, cntrl_struct_list[i])) 00566 | { 00567 | return true; 00568 | } 00569 | } 00570 | 00571 | return false; 00572 | } 00573 | 00574 | inline bool is_logic_opr(const std::string& lgc_opr) 00575 | { 00576 | for (std::size_t i = 0; i < logic_ops_list_size; ++i) 00577 | { 00578 | if (imatch(lgc_opr, logic_ops_list[i])) 00579 | { 00580 | return true; 00581 | } 00582 | } 00583 | 00584 | return false; 00585 | } 00586 | 00587 | struct cs_match 00588 | { 00589 | static inline bool cmp(const char_t c0, const char_t c1) 00590 | { 00591 | return (c0 == c1); 00592 | } 00593 | }; 00594 | 00595 | struct cis_match 00596 | { 00597 | static inline bool cmp(const char_t c0, const char_t c1) 00598 | { 00599 | return (std::tolower(c0) == std::tolower(c1)); 00600 | } 00601 | }; 00602 | 00603 | template <typename Iterator, typename Compare> 00604 | inline bool match_impl(const Iterator pattern_begin, 00605 | const Iterator pattern_end , 00606 | const Iterator data_begin , 00607 | const Iterator data_end , 00608 | const typename std::iterator_traits<Iterator>::value_type& zero_or_more, 00609 | const typename std::iterator_traits<Iterator>::value_type& exactly_one ) 00610 | { 00611 | typedef typename std::iterator_traits<Iterator>::value_type type; 00612 | 00613 | const Iterator null_itr(0); 00614 | 00615 | Iterator p_itr = pattern_begin; 00616 | Iterator d_itr = data_begin; 00617 | Iterator np_itr = null_itr; 00618 | Iterator nd_itr = null_itr; 00619 | 00620 | for ( ; ; ) 00621 | { 00622 | if (p_itr != pattern_end) 00623 | { 00624 | const type c = *(p_itr); 00625 | 00626 | if ((data_end != d_itr) && (Compare::cmp(c,*(d_itr)) || (exactly_one == c))) 00627 | { 00628 | ++d_itr; 00629 | ++p_itr; 00630 | continue; 00631 | } 00632 | else if (zero_or_more == c) 00633 | { 00634 | while ((pattern_end != p_itr) && (zero_or_more == *(p_itr))) 00635 | { 00636 | ++p_itr; 00637 | } 00638 | 00639 | const type d = *(p_itr); 00640 | 00641 | while ((data_end != d_itr) && !(Compare::cmp(d,*(d_itr)) || (exactly_one == d))) 00642 | { 00643 | ++d_itr; 00644 | } 00645 | 00646 | // set backtrack iterators 00647 | np_itr = p_itr - 1; 00648 | nd_itr = d_itr + 1; 00649 | 00650 | continue; 00651 | } 00652 | } 00653 | else if (data_end == d_itr) 00654 | break; 00655 | 00656 | if ((data_end == d_itr) || (null_itr == nd_itr)) 00657 | return false; 00658 | 00659 | p_itr = np_itr; 00660 | d_itr = nd_itr; 00661 | } 00662 | 00663 | return true; 00664 | } 00665 | 00666 | inline bool wc_match(const std::string& wild_card, 00667 | const std::string& str) 00668 | { 00669 | return match_impl<char_cptr,cs_match> 00670 | ( 00671 | wild_card.data(), 00672 | wild_card.data() + wild_card.size(), 00673 | str.data(), 00674 | str.data() + str.size(), 00675 | '*', '?' 00676 | ); 00677 | } 00678 | 00679 | inline bool wc_imatch(const std::string& wild_card, 00680 | const std::string& str) 00681 | { 00682 | return match_impl<char_cptr,cis_match> 00683 | ( 00684 | wild_card.data(), 00685 | wild_card.data() + wild_card.size(), 00686 | str.data(), 00687 | str.data() + str.size(), 00688 | '*', '?' 00689 | ); 00690 | } 00691 | 00692 | inline bool sequence_match(const std::string& pattern, 00693 | const std::string& str, 00694 | std::size_t& diff_index, 00695 | char_t& diff_value) 00696 | { 00697 | if (str.empty()) 00698 | { 00699 | return ("Z" == pattern); 00700 | } 00701 | else if ('*' == pattern[0]) 00702 | return false; 00703 | 00704 | typedef std::string::const_iterator itr_t; 00705 | 00706 | itr_t p_itr = pattern.begin(); 00707 | itr_t s_itr = str .begin(); 00708 | 00709 | const itr_t p_end = pattern.end(); 00710 | const itr_t s_end = str .end(); 00711 | 00712 | while ((s_end != s_itr) && (p_end != p_itr)) 00713 | { 00714 | if ('*' == (*p_itr)) 00715 | { 00716 | const char_t target = static_cast<char_t>(std::toupper(*(p_itr - 1))); 00717 | 00718 | if ('*' == target) 00719 | { 00720 | diff_index = static_cast<std::size_t>(std::distance(str.begin(),s_itr)); 00721 | diff_value = static_cast<char_t>(std::toupper(*p_itr)); 00722 | 00723 | return false; 00724 | } 00725 | else 00726 | ++p_itr; 00727 | 00728 | while (s_itr != s_end) 00729 | { 00730 | if (target != std::toupper(*s_itr)) 00731 | break; 00732 | else 00733 | ++s_itr; 00734 | } 00735 | 00736 | continue; 00737 | } 00738 | else if ( 00739 | ('?' != *p_itr) && 00740 | std::toupper(*p_itr) != std::toupper(*s_itr) 00741 | ) 00742 | { 00743 | diff_index = static_cast<std::size_t>(std::distance(str.begin(),s_itr)); 00744 | diff_value = static_cast<char_t>(std::toupper(*p_itr)); 00745 | 00746 | return false; 00747 | } 00748 | 00749 | ++p_itr; 00750 | ++s_itr; 00751 | } 00752 | 00753 | return ( 00754 | (s_end == s_itr) && 00755 | ( 00756 | (p_end == p_itr) || 00757 | ('*' == *p_itr) 00758 | ) 00759 | ); 00760 | } 00761 | 00762 | template<typename T> 00763 | struct set_zero_value_impl 00764 | { 00765 | static inline void process(T* base_ptr, const std::size_t size) 00766 | { 00767 | const T zero = T(0); 00768 | for (std::size_t i = 0; i < size; ++i) 00769 | { 00770 | base_ptr[i] = zero; 00771 | } 00772 | } 00773 | }; 00774 | 00775 | #define pod_set_zero_value(T) \ 00776 | template <> \ 00777 | struct set_zero_value_impl<T> \ 00778 | { \ 00779 | static inline void process(T* base_ptr, const std::size_t size) \ 00780 | { std::memset(base_ptr, 0x00, size * sizeof(T)); } \ 00781 | }; \ 00782 | 00783 | pod_set_zero_value(float ) 00784 | pod_set_zero_value(double ) 00785 | pod_set_zero_value(long double) 00786 | 00787 | #ifdef pod_set_zero_value 00788 | #undef pod_set_zero_value 00789 | #endif 00790 | 00791 | template<typename T> 00792 | inline void set_zero_value(T* data, const std::size_t size) 00793 | { 00794 | set_zero_value_impl<T>::process(data,size); 00795 | } 00796 | 00797 | template<typename T> 00798 | inline void set_zero_value(std::vector<T>& v) 00799 | { 00800 | set_zero_value(v.data(),v.size()); 00801 | } 00802 | 00803 | static const double pow10[] = 00804 | { 00805 | 1.0, 00806 | 1.0E+001, 1.0E+002, 1.0E+003, 1.0E+004, 00807 | 1.0E+005, 1.0E+006, 1.0E+007, 1.0E+008, 00808 | 1.0E+009, 1.0E+010, 1.0E+011, 1.0E+012, 00809 | 1.0E+013, 1.0E+014, 1.0E+015, 1.0E+016 00810 | }; 00811 | 00812 | static const std::size_t pow10_size = sizeof(pow10) / sizeof(double); 00813 | 00814 | namespace numeric 00815 | { 00816 | namespace constant 00817 | { 00818 | static const double e = 2.71828182845904523536028747135266249775724709369996; 00819 | static const double pi = 3.14159265358979323846264338327950288419716939937510; 00820 | static const double pi_2 = 1.57079632679489661923132169163975144209858469968755; 00821 | static const double pi_4 = 0.78539816339744830961566084581987572104929234984378; 00822 | static const double pi_180 = 0.01745329251994329576923690768488612713442871888542; 00823 | static const double _1_pi = 0.31830988618379067153776752674502872406891929148091; 00824 | static const double _2_pi = 0.63661977236758134307553505349005744813783858296183; 00825 | static const double _180_pi = 57.29577951308232087679815481410517033240547246656443; 00826 | static const double log2 = 0.69314718055994530941723212145817656807550013436026; 00827 | static const double sqrt2 = 1.41421356237309504880168872420969807856967187537695; 00828 | } 00829 | 00830 | namespace details 00831 | { 00832 | struct unknown_type_tag { unknown_type_tag() {} }; 00833 | struct real_type_tag { real_type_tag () {} }; 00834 | struct int_type_tag { int_type_tag () {} }; 00835 | 00836 | template <typename T> 00837 | struct number_type 00838 | { 00839 | typedef unknown_type_tag type; 00840 | number_type() {} 00841 | }; 00842 | 00843 | #define exprtk_register_real_type_tag(T) \ 00844 | template <> struct number_type<T> \ 00845 | { typedef real_type_tag type; number_type() {} }; \ 00846 | 00847 | #define exprtk_register_int_type_tag(T) \ 00848 | template <> struct number_type<T> \ 00849 | { typedef int_type_tag type; number_type() {} }; \ 00850 | 00851 | exprtk_register_real_type_tag(float ) 00852 | exprtk_register_real_type_tag(double ) 00853 | exprtk_register_real_type_tag(long double) 00854 | 00855 | exprtk_register_int_type_tag(short ) 00856 | exprtk_register_int_type_tag(int ) 00857 | exprtk_register_int_type_tag(_int64_t ) 00858 | exprtk_register_int_type_tag(unsigned short) 00859 | exprtk_register_int_type_tag(unsigned int ) 00860 | exprtk_register_int_type_tag(_uint64_t ) 00861 | 00862 | #undef exprtk_register_real_type_tag 00863 | #undef exprtk_register_int_type_tag 00864 | 00865 | template <typename T> 00866 | struct epsilon_type {}; 00867 | 00868 | #define exprtk_define_epsilon_type(Type, Epsilon) \ 00869 | template <> struct epsilon_type<Type> \ 00870 | { \ 00871 | static inline Type value() \ 00872 | { \ 00873 | const Type epsilon = static_cast<Type>(Epsilon); \ 00874 | return epsilon; \ 00875 | } \ 00876 | }; \ 00877 | 00878 | exprtk_define_epsilon_type(float , 0.00000100000f) 00879 | exprtk_define_epsilon_type(double , 0.000000000100) 00880 | exprtk_define_epsilon_type(long double, 0.000000000001) 00881 | 00882 | #undef exprtk_define_epsilon_type 00883 | 00884 | template <typename T> 00885 | inline bool is_nan_impl(const T v, real_type_tag) 00886 | { 00887 | return std::not_equal_to<T>()(v,v); 00888 | } 00889 | 00890 | template <typename T> 00891 | inline int to_int32_impl(const T v, real_type_tag) 00892 | { 00893 | return static_cast<int>(v); 00894 | } 00895 | 00896 | template <typename T> 00897 | inline _int64_t to_int64_impl(const T v, real_type_tag) 00898 | { 00899 | return static_cast<_int64_t>(v); 00900 | } 00901 | 00902 | template <typename T> 00903 | inline _uint64_t to_uint64_impl(const T v, real_type_tag) 00904 | { 00905 | return static_cast<_uint64_t>(v); 00906 | } 00907 | 00908 | template <typename T> 00909 | inline bool is_true_impl(const T v) 00910 | { 00911 | return std::not_equal_to<T>()(T(0),v); 00912 | } 00913 | 00914 | template <typename T> 00915 | inline bool is_false_impl(const T v) 00916 | { 00917 | return std::equal_to<T>()(T(0),v); 00918 | } 00919 | 00920 | template <typename T> 00921 | inline T abs_impl(const T v, real_type_tag) 00922 | { 00923 | return ((v < T(0)) ? -v : v); 00924 | } 00925 | 00926 | template <typename T> 00927 | inline T min_impl(const T v0, const T v1, real_type_tag) 00928 | { 00929 | return std::min<T>(v0,v1); 00930 | } 00931 | 00932 | template <typename T> 00933 | inline T max_impl(const T v0, const T v1, real_type_tag) 00934 | { 00935 | return std::max<T>(v0,v1); 00936 | } 00937 | 00938 | template <typename T> 00939 | inline T equal_impl(const T v0, const T v1, real_type_tag) 00940 | { 00941 | const T epsilon = epsilon_type<T>::value(); 00942 | return (abs_impl(v0 - v1,real_type_tag()) <= (std::max(T(1),std::max(abs_impl(v0,real_type_tag()),abs_impl(v1,real_type_tag()))) * epsilon)) ? T(1) : T(0); 00943 | } 00944 | 00945 | inline float equal_impl(const float v0, const float v1, real_type_tag) 00946 | { 00947 | const float epsilon = epsilon_type<float>::value(); 00948 | return (abs_impl(v0 - v1,real_type_tag()) <= (std::max(1.0f,std::max(abs_impl(v0,real_type_tag()),abs_impl(v1,real_type_tag()))) * epsilon)) ? 1.0f : 0.0f; 00949 | } 00950 | 00951 | template <typename T> 00952 | inline T equal_impl(const T v0, const T v1, int_type_tag) 00953 | { 00954 | return (v0 == v1) ? 1 : 0; 00955 | } 00956 | 00957 | template <typename T> 00958 | inline T nequal_impl(const T v0, const T v1, real_type_tag) 00959 | { 00960 | typedef real_type_tag rtg; 00961 | const T epsilon = epsilon_type<T>::value(); 00962 | return (abs_impl(v0 - v1,rtg()) > (std::max(T(1),std::max(abs_impl(v0,rtg()),abs_impl(v1,rtg()))) * epsilon)) ? T(1) : T(0); 00963 | } 00964 | 00965 | inline float nequal_impl(const float v0, const float v1, real_type_tag) 00966 | { 00967 | typedef real_type_tag rtg; 00968 | const float epsilon = epsilon_type<float>::value(); 00969 | return (abs_impl(v0 - v1,rtg()) > (std::max(1.0f,std::max(abs_impl(v0,rtg()),abs_impl(v1,rtg()))) * epsilon)) ? 1.0f : 0.0f; 00970 | } 00971 | 00972 | template <typename T> 00973 | inline T nequal_impl(const T v0, const T v1, int_type_tag) 00974 | { 00975 | return (v0 != v1) ? 1 : 0; 00976 | } 00977 | 00978 | template <typename T> 00979 | inline T modulus_impl(const T v0, const T v1, real_type_tag) 00980 | { 00981 | return std::fmod(v0,v1); 00982 | } 00983 | 00984 | template <typename T> 00985 | inline T modulus_impl(const T v0, const T v1, int_type_tag) 00986 | { 00987 | return v0 % v1; 00988 | } 00989 | 00990 | template <typename T> 00991 | inline T pow_impl(const T v0, const T v1, real_type_tag) 00992 | { 00993 | return std::pow(v0,v1); 00994 | } 00995 | 00996 | template <typename T> 00997 | inline T pow_impl(const T v0, const T v1, int_type_tag) 00998 | { 00999 | return std::pow(static_cast<double>(v0),static_cast<double>(v1)); 01000 | } 01001 | 01002 | template <typename T> 01003 | inline T logn_impl(const T v0, const T v1, real_type_tag) 01004 | { 01005 | return std::log(v0) / std::log(v1); 01006 | } 01007 | 01008 | template <typename T> 01009 | inline T logn_impl(const T v0, const T v1, int_type_tag) 01010 | { 01011 | return static_cast<T>(logn_impl<double>(static_cast<double>(v0),static_cast<double>(v1),real_type_tag())); 01012 | } 01013 | 01014 | template <typename T> 01015 | inline T root_impl(const T v0, const T v1, real_type_tag) 01016 | { 01017 | if (v0 < T(0)) 01018 | { 01019 | return (v1 == trunc_impl(v1, real_type_tag())) && 01020 | (modulus_impl(v1, T(2), real_type_tag()) != T(0)) ? 01021 | -std::pow(abs_impl(v0, real_type_tag()), T(1) / v1) : 01022 | std::numeric_limits<T>::quiet_NaN(); 01023 | } 01024 | 01025 | return std::pow(v0, T(1) / v1); 01026 | } 01027 | 01028 | template <typename T> 01029 | inline T root_impl(const T v0, const T v1, int_type_tag) 01030 | { 01031 | return root_impl<double>(static_cast<double>(v0),static_cast<double>(v1),real_type_tag()); 01032 | } 01033 | 01034 | template <typename T> 01035 | inline T round_impl(const T v, real_type_tag) 01036 | { 01037 | return ((v < T(0)) ? std::ceil(v - T(0.5)) : std::floor(v + T(0.5))); 01038 | } 01039 | 01040 | template <typename T> 01041 | inline T roundn_impl(const T v0, const T v1, real_type_tag) 01042 | { 01043 | const int index = std::max<int>(0, std::min<int>(pow10_size - 1, static_cast<int>(std::floor(v1)))); 01044 | const T p10 = T(pow10[index]); 01045 | 01046 | if (v0 < T(0)) 01047 | return T(std::ceil ((v0 * p10) - T(0.5)) / p10); 01048 | else 01049 | return T(std::floor((v0 * p10) + T(0.5)) / p10); 01050 | } 01051 | 01052 | template <typename T> 01053 | inline T roundn_impl(const T v0, const T, int_type_tag) 01054 | { 01055 | return v0; 01056 | } 01057 | 01058 | template <typename T> 01059 | inline T hypot_impl(const T v0, const T v1, real_type_tag) 01060 | { 01061 | return std::sqrt((v0 * v0) + (v1 * v1)); 01062 | } 01063 | 01064 | template <typename T> 01065 | inline T hypot_impl(const T v0, const T v1, int_type_tag) 01066 | { 01067 | return static_cast<T>(std::sqrt(static_cast<double>((v0 * v0) + (v1 * v1)))); 01068 | } 01069 | 01070 | template <typename T> 01071 | inline T atan2_impl(const T v0, const T v1, real_type_tag) 01072 | { 01073 | return std::atan2(v0,v1); 01074 | } 01075 | 01076 | template <typename T> 01077 | inline T atan2_impl(const T, const T, int_type_tag) 01078 | { 01079 | return 0; 01080 | } 01081 | 01082 | template <typename T> 01083 | inline T shr_impl(const T v0, const T v1, real_type_tag) 01084 | { 01085 | return v0 * (T(1) / std::pow(T(2),static_cast<T>(static_cast<int>(v1)))); 01086 | } 01087 | 01088 | template <typename T> 01089 | inline T shr_impl(const T v0, const T v1, int_type_tag) 01090 | { 01091 | return v0 >> v1; 01092 | } 01093 | 01094 | template <typename T> 01095 | inline T shl_impl(const T v0, const T v1, real_type_tag) 01096 | { 01097 | return v0 * std::pow(T(2),static_cast<T>(static_cast<int>(v1))); 01098 | } 01099 | 01100 | template <typename T> 01101 | inline T shl_impl(const T v0, const T v1, int_type_tag) 01102 | { 01103 | return v0 << v1; 01104 | } 01105 | 01106 | template <typename T> 01107 | inline T sgn_impl(const T v, real_type_tag) 01108 | { 01109 | if (v > T(0)) return T(+1); 01110 | else if (v < T(0)) return T(-1); 01111 | else return T( 0); 01112 | } 01113 | 01114 | template <typename T> 01115 | inline T sgn_impl(const T v, int_type_tag) 01116 | { 01117 | if (v > T(0)) return T(+1); 01118 | else if (v < T(0)) return T(-1); 01119 | else return T( 0); 01120 | } 01121 | 01122 | template <typename T> 01123 | inline T and_impl(const T v0, const T v1, real_type_tag) 01124 | { 01125 | return (is_true_impl(v0) && is_true_impl(v1)) ? T(1) : T(0); 01126 | } 01127 | 01128 | template <typename T> 01129 | inline T and_impl(const T v0, const T v1, int_type_tag) 01130 | { 01131 | return v0 && v1; 01132 | } 01133 | 01134 | template <typename T> 01135 | inline T nand_impl(const T v0, const T v1, real_type_tag) 01136 | { 01137 | return (is_false_impl(v0) || is_false_impl(v1)) ? T(1) : T(0); 01138 | } 01139 | 01140 | template <typename T> 01141 | inline T nand_impl(const T v0, const T v1, int_type_tag) 01142 | { 01143 | return !(v0 && v1); 01144 | } 01145 | 01146 | template <typename T> 01147 | inline T or_impl(const T v0, const T v1, real_type_tag) 01148 | { 01149 | return (is_true_impl(v0) || is_true_impl(v1)) ? T(1) : T(0); 01150 | } 01151 | 01152 | template <typename T> 01153 | inline T or_impl(const T v0, const T v1, int_type_tag) 01154 | { 01155 | return (v0 || v1); 01156 | } 01157 | 01158 | template <typename T> 01159 | inline T nor_impl(const T v0, const T v1, real_type_tag) 01160 | { 01161 | return (is_false_impl(v0) && is_false_impl(v1)) ? T(1) : T(0); 01162 | } 01163 | 01164 | template <typename T> 01165 | inline T nor_impl(const T v0, const T v1, int_type_tag) 01166 | { 01167 | return !(v0 || v1); 01168 | } 01169 | 01170 | template <typename T> 01171 | inline T xor_impl(const T v0, const T v1, real_type_tag) 01172 | { 01173 | return (is_false_impl(v0) != is_false_impl(v1)) ? T(1) : T(0); 01174 | } 01175 | 01176 | template <typename T> 01177 | inline T xor_impl(const T v0, const T v1, int_type_tag) 01178 | { 01179 | return v0 ^ v1; 01180 | } 01181 | 01182 | template <typename T> 01183 | inline T xnor_impl(const T v0, const T v1, real_type_tag) 01184 | { 01185 | const bool v0_true = is_true_impl(v0); 01186 | const bool v1_true = is_true_impl(v1); 01187 | 01188 | if ((v0_true && v1_true) || (!v0_true && !v1_true)) 01189 | return T(1); 01190 | else 01191 | return T(0); 01192 | } 01193 | 01194 | template <typename T> 01195 | inline T xnor_impl(const T v0, const T v1, int_type_tag) 01196 | { 01197 | const bool v0_true = is_true_impl(v0); 01198 | const bool v1_true = is_true_impl(v1); 01199 | 01200 | if ((v0_true && v1_true) || (!v0_true && !v1_true)) 01201 | return T(1); 01202 | else 01203 | return T(0); 01204 | } 01205 | 01206 | #if (defined(_MSC_VER) && (_MSC_VER >= 1900)) || !defined(_MSC_VER) 01207 | #define exprtk_define_erf(TT, impl) \ 01208 | inline TT erf_impl(const TT v) { return impl(v); } \ 01209 | 01210 | exprtk_define_erf(float , ::erff) 01211 | exprtk_define_erf(double , ::erf ) 01212 | exprtk_define_erf(long double, ::erfl) 01213 | #undef exprtk_define_erf 01214 | #endif 01215 | 01216 | template <typename T> 01217 | inline T erf_impl(const T v, real_type_tag) 01218 | { 01219 | #if defined(_MSC_VER) && (_MSC_VER < 1900) 01220 | // Credits: Abramowitz & Stegun Equations 7.1.25-28 01221 | static const T c[] = 01222 | { 01223 | T( 1.26551223), T(1.00002368), 01224 | T( 0.37409196), T(0.09678418), 01225 | T(-0.18628806), T(0.27886807), 01226 | T(-1.13520398), T(1.48851587), 01227 | T(-0.82215223), T(0.17087277) 01228 | }; 01229 | 01230 | const T t = T(1) / (T(1) + T(0.5) * abs_impl(v,real_type_tag())); 01231 | 01232 | const T result = T(1) - t * std::exp((-v * v) - 01233 | c[0] + t * (c[1] + t * 01234 | (c[2] + t * (c[3] + t * 01235 | (c[4] + t * (c[5] + t * 01236 | (c[6] + t * (c[7] + t * 01237 | (c[8] + t * (c[9])))))))))); 01238 | 01239 | return (v >= T(0)) ? result : -result; 01240 | #else 01241 | return erf_impl(v); 01242 | #endif 01243 | } 01244 | 01245 | template <typename T> 01246 | inline T erf_impl(const T v, int_type_tag) 01247 | { 01248 | return erf_impl(static_cast<double>(v),real_type_tag()); 01249 | } 01250 | 01251 | #if (defined(_MSC_VER) && (_MSC_VER >= 1900)) || !defined(_MSC_VER) 01252 | #define exprtk_define_erfc(TT, impl) \ 01253 | inline TT erfc_impl(const TT v) { return impl(v); } \ 01254 | 01255 | exprtk_define_erfc(float ,::erfcf) 01256 | exprtk_define_erfc(double ,::erfc ) 01257 | exprtk_define_erfc(long double,::erfcl) 01258 | #undef exprtk_define_erfc 01259 | #endif 01260 | 01261 | template <typename T> 01262 | inline T erfc_impl(const T v, real_type_tag) 01263 | { 01264 | #if defined(_MSC_VER) && (_MSC_VER < 1900) 01265 | return T(1) - erf_impl(v,real_type_tag()); 01266 | #else 01267 | return erfc_impl(v); 01268 | #endif 01269 | } 01270 | 01271 | template <typename T> 01272 | inline T erfc_impl(const T v, int_type_tag) 01273 | { 01274 | return erfc_impl(static_cast<double>(v),real_type_tag()); 01275 | } 01276 | 01277 | template <typename T> 01278 | inline T ncdf_impl(const T v, real_type_tag) 01279 | { 01280 | return T(0.5) * erfc_impl(-(v / T(numeric::constant::sqrt2)),real_type_tag()); 01281 | } 01282 | 01283 | template <typename T> 01284 | inline T ncdf_impl(const T v, int_type_tag) 01285 | { 01286 | return ncdf_impl(static_cast<double>(v),real_type_tag()); 01287 | } 01288 | 01289 | template <typename T> 01290 | inline T sinc_impl(const T v, real_type_tag) 01291 | { 01292 | if (std::abs(v) >= std::numeric_limits<T>::epsilon()) 01293 | return(std::sin(v) / v); 01294 | else 01295 | return T(1); 01296 | } 01297 | 01298 | template <typename T> 01299 | inline T sinc_impl(const T v, int_type_tag) 01300 | { 01301 | return sinc_impl(static_cast<double>(v),real_type_tag()); 01302 | } 01303 | 01304 | #if __cplusplus >= 201103L 01305 | template <typename T> 01306 | inline T acosh_impl(const T v, real_type_tag) 01307 | { 01308 | return std::acosh(v); 01309 | } 01310 | 01311 | template <typename T> 01312 | inline T asinh_impl(const T v, real_type_tag) 01313 | { 01314 | return std::asinh(v); 01315 | } 01316 | 01317 | template <typename T> 01318 | inline T atanh_impl(const T v, real_type_tag) 01319 | { 01320 | return std::atanh(v); 01321 | } 01322 | 01323 | template <typename T> 01324 | inline T trunc_impl(const T v, real_type_tag) 01325 | { 01326 | return std::trunc(v); 01327 | } 01328 | 01329 | template <typename T> 01330 | inline T expm1_impl(const T v, real_type_tag) 01331 | { 01332 | return std::expm1(v); 01333 | } 01334 | 01335 | template <typename T> 01336 | inline T expm1_impl(const T v, int_type_tag) 01337 | { 01338 | return std::expm1(v); 01339 | } 01340 | 01341 | template <typename T> 01342 | inline T log1p_impl(const T v, real_type_tag) 01343 | { 01344 | return std::log1p(v); 01345 | } 01346 | 01347 | template <typename T> 01348 | inline T log1p_impl(const T v, int_type_tag) 01349 | { 01350 | return std::log1p(v); 01351 | } 01352 | #else 01353 | template <typename T> 01354 | inline T acosh_impl(const T v, real_type_tag) 01355 | { 01356 | return std::log(v + std::sqrt((v * v) - T(1))); 01357 | } 01358 | 01359 | template <typename T> 01360 | inline T asinh_impl(const T v, real_type_tag) 01361 | { 01362 | return std::log(v + std::sqrt((v * v) + T(1))); 01363 | } 01364 | 01365 | template <typename T> 01366 | inline T atanh_impl(const T v, real_type_tag) 01367 | { 01368 | return (std::log(T(1) + v) - std::log(T(1) - v)) / T(2); 01369 | } 01370 | 01371 | template <typename T> 01372 | inline T trunc_impl(const T v, real_type_tag) 01373 | { 01374 | return T(static_cast<long long>(v)); 01375 | } 01376 | 01377 | template <typename T> 01378 | inline T expm1_impl(const T v, real_type_tag) 01379 | { 01380 | if (abs_impl(v,real_type_tag()) < T(0.00001)) 01381 | return v + (T(0.5) * v * v); 01382 | else 01383 | return std::exp(v) - T(1); 01384 | } 01385 | 01386 | template <typename T> 01387 | inline T expm1_impl(const T v, int_type_tag) 01388 | { 01389 | return T(std::exp<double>(v)) - T(1); 01390 | } 01391 | 01392 | template <typename T> 01393 | inline T log1p_impl(const T v, real_type_tag) 01394 | { 01395 | if (v > T(-1)) 01396 | { 01397 | if (abs_impl(v,real_type_tag()) > T(0.0001)) 01398 | { 01399 | return std::log(T(1) + v); 01400 | } 01401 | else 01402 | return (T(-0.5) * v + T(1)) * v; 01403 | } 01404 | 01405 | return std::numeric_limits<T>::quiet_NaN(); 01406 | } 01407 | 01408 | template <typename T> 01409 | inline T log1p_impl(const T v, int_type_tag) 01410 | { 01411 | if (v > T(-1)) 01412 | { 01413 | return std::log(T(1) + v); 01414 | } 01415 | 01416 | return std::numeric_limits<T>::quiet_NaN(); 01417 | } 01418 | #endif 01419 | 01420 | template <typename T> inline T acos_impl(const T v, real_type_tag) { return std::acos (v); } 01421 | template <typename T> inline T asin_impl(const T v, real_type_tag) { return std::asin (v); } 01422 | template <typename T> inline T atan_impl(const T v, real_type_tag) { return std::atan (v); } 01423 | template <typename T> inline T ceil_impl(const T v, real_type_tag) { return std::ceil (v); } 01424 | template <typename T> inline T cos_impl(const T v, real_type_tag) { return std::cos (v); } 01425 | template <typename T> inline T cosh_impl(const T v, real_type_tag) { return std::cosh (v); } 01426 | template <typename T> inline T exp_impl(const T v, real_type_tag) { return std::exp (v); } 01427 | template <typename T> inline T floor_impl(const T v, real_type_tag) { return std::floor(v); } 01428 | template <typename T> inline T log_impl(const T v, real_type_tag) { return std::log (v); } 01429 | template <typename T> inline T log10_impl(const T v, real_type_tag) { return std::log10(v); } 01430 | template <typename T> inline T log2_impl(const T v, real_type_tag) { return std::log(v)/T(numeric::constant::log2); } 01431 | template <typename T> inline T neg_impl(const T v, real_type_tag) { return -v; } 01432 | template <typename T> inline T pos_impl(const T v, real_type_tag) { return +v; } 01433 | template <typename T> inline T sin_impl(const T v, real_type_tag) { return std::sin (v); } 01434 | template <typename T> inline T sinh_impl(const T v, real_type_tag) { return std::sinh (v); } 01435 | template <typename T> inline T sqrt_impl(const T v, real_type_tag) { return std::sqrt (v); } 01436 | template <typename T> inline T tan_impl(const T v, real_type_tag) { return std::tan (v); } 01437 | template <typename T> inline T tanh_impl(const T v, real_type_tag) { return std::tanh (v); } 01438 | template <typename T> inline T cot_impl(const T v, real_type_tag) { return T(1) / std::tan(v); } 01439 | template <typename T> inline T sec_impl(const T v, real_type_tag) { return T(1) / std::cos(v); } 01440 | template <typename T> inline T csc_impl(const T v, real_type_tag) { return T(1) / std::sin(v); } 01441 | template <typename T> inline T r2d_impl(const T v, real_type_tag) { return (v * T(numeric::constant::_180_pi)); } 01442 | template <typename T> inline T d2r_impl(const T v, real_type_tag) { return (v * T(numeric::constant::pi_180)); } 01443 | template <typename T> inline T d2g_impl(const T v, real_type_tag) { return (v * T(10.0/9.0)); } 01444 | template <typename T> inline T g2d_impl(const T v, real_type_tag) { return (v * T(9.0/10.0)); } 01445 | template <typename T> inline T notl_impl(const T v, real_type_tag) { return (std::not_equal_to<T>()(T(0),v) ? T(0) : T(1)); } 01446 | template <typename T> inline T frac_impl(const T v, real_type_tag) { return (v - trunc_impl(v,real_type_tag())); } 01447 | 01448 | template <typename T> inline T const_pi_impl(real_type_tag) { return T(numeric::constant::pi); } 01449 | template <typename T> inline T const_e_impl(real_type_tag) { return T(numeric::constant::e); } 01450 | template <typename T> inline T const_qnan_impl(real_type_tag) { return std::numeric_limits<T>::quiet_NaN(); } 01451 | 01452 | template <typename T> inline T abs_impl(const T v, int_type_tag) { return ((v >= T(0)) ? v : -v); } 01453 | template <typename T> inline T exp_impl(const T v, int_type_tag) { return std::exp (v); } 01454 | template <typename T> inline T log_impl(const T v, int_type_tag) { return std::log (v); } 01455 | template <typename T> inline T log10_impl(const T v, int_type_tag) { return std::log10(v); } 01456 | template <typename T> inline T log2_impl(const T v, int_type_tag) { return std::log(v)/T(numeric::constant::log2); } 01457 | template <typename T> inline T neg_impl(const T v, int_type_tag) { return -v; } 01458 | template <typename T> inline T pos_impl(const T v, int_type_tag) { return +v; } 01459 | template <typename T> inline T ceil_impl(const T v, int_type_tag) { return v; } 01460 | template <typename T> inline T floor_impl(const T v, int_type_tag) { return v; } 01461 | template <typename T> inline T round_impl(const T v, int_type_tag) { return v; } 01462 | template <typename T> inline T notl_impl(const T v, int_type_tag) { return !v; } 01463 | template <typename T> inline T sqrt_impl(const T v, int_type_tag) { return std::sqrt (v); } 01464 | template <typename T> inline T frac_impl(const T , int_type_tag) { return T(0); } 01465 | template <typename T> inline T trunc_impl(const T v, int_type_tag) { return v; } 01466 | template <typename T> inline T acos_impl(const T , int_type_tag) { return std::numeric_limits<T>::quiet_NaN(); } 01467 | template <typename T> inline T acosh_impl(const T , int_type_tag) { return std::numeric_limits<T>::quiet_NaN(); } 01468 | template <typename T> inline T asin_impl(const T , int_type_tag) { return std::numeric_limits<T>::quiet_NaN(); } 01469 | template <typename T> inline T asinh_impl(const T , int_type_tag) { return std::numeric_limits<T>::quiet_NaN(); } 01470 | template <typename T> inline T atan_impl(const T , int_type_tag) { return std::numeric_limits<T>::quiet_NaN(); } 01471 | template <typename T> inline T atanh_impl(const T , int_type_tag) { return std::numeric_limits<T>::quiet_NaN(); } 01472 | template <typename T> inline T cos_impl(const T , int_type_tag) { return std::numeric_limits<T>::quiet_NaN(); } 01473 | template <typename T> inline T cosh_impl(const T , int_type_tag) { return std::numeric_limits<T>::quiet_NaN(); } 01474 | template <typename T> inline T sin_impl(const T , int_type_tag) { return std::numeric_limits<T>::quiet_NaN(); } 01475 | template <typename T> inline T sinh_impl(const T , int_type_tag) { return std::numeric_limits<T>::quiet_NaN(); } 01476 | template <typename T> inline T tan_impl(const T , int_type_tag) { return std::numeric_limits<T>::quiet_NaN(); } 01477 | template <typename T> inline T tanh_impl(const T , int_type_tag) { return std::numeric_limits<T>::quiet_NaN(); } 01478 | template <typename T> inline T cot_impl(const T , int_type_tag) { return std::numeric_limits<T>::quiet_NaN(); } 01479 | template <typename T> inline T sec_impl(const T , int_type_tag) { return std::numeric_limits<T>::quiet_NaN(); } 01480 | template <typename T> inline T csc_impl(const T , int_type_tag) { return std::numeric_limits<T>::quiet_NaN(); } 01481 | 01482 | template <typename T> 01483 | inline bool is_integer_impl(const T& v, real_type_tag) 01484 | { 01485 | return std::equal_to<T>()(T(0),std::fmod(v,T(1))); 01486 | } 01487 | 01488 | template <typename T> 01489 | inline bool is_integer_impl(const T&, int_type_tag) 01490 | { 01491 | return true; 01492 | } 01493 | } 01494 | 01495 | template <typename Type> 01496 | struct numeric_info { enum { length = 0, size = 32, bound_length = 0, min_exp = 0, max_exp = 0 }; }; 01497 | 01498 | template <> struct numeric_info<int > { enum { length = 10, size = 16, bound_length = 9 }; }; 01499 | template <> struct numeric_info<float > { enum { min_exp = -38, max_exp = +38 }; }; 01500 | template <> struct numeric_info<double > { enum { min_exp = -308, max_exp = +308 }; }; 01501 | template <> struct numeric_info<long double> { enum { min_exp = -308, max_exp = +308 }; }; 01502 | 01503 | template <typename T> 01504 | inline int to_int32(const T v) 01505 | { 01506 | const typename details::number_type<T>::type num_type; 01507 | return to_int32_impl(v, num_type); 01508 | } 01509 | 01510 | template <typename T> 01511 | inline _int64_t to_int64(const T v) 01512 | { 01513 | const typename details::number_type<T>::type num_type; 01514 | return to_int64_impl(v, num_type); 01515 | } 01516 | 01517 | template <typename T> 01518 | inline _uint64_t to_uint64(const T v) 01519 | { 01520 | const typename details::number_type<T>::type num_type; 01521 | return to_uint64_impl(v, num_type); 01522 | } 01523 | 01524 | template <typename T> 01525 | inline bool is_nan(const T v) 01526 | { 01527 | const typename details::number_type<T>::type num_type; 01528 | return is_nan_impl(v, num_type); 01529 | } 01530 | 01531 | template <typename T> 01532 | inline T min(const T v0, const T v1) 01533 | { 01534 | const typename details::number_type<T>::type num_type; 01535 | return min_impl(v0, v1, num_type); 01536 | } 01537 | 01538 | template <typename T> 01539 | inline T max(const T v0, const T v1) 01540 | { 01541 | const typename details::number_type<T>::type num_type; 01542 | return max_impl(v0, v1, num_type); 01543 | } 01544 | 01545 | template <typename T> 01546 | inline T equal(const T v0, const T v1) 01547 | { 01548 | const typename details::number_type<T>::type num_type; 01549 | return equal_impl(v0, v1, num_type); 01550 | } 01551 | 01552 | template <typename T> 01553 | inline T nequal(const T v0, const T v1) 01554 | { 01555 | const typename details::number_type<T>::type num_type; 01556 | return nequal_impl(v0, v1, num_type); 01557 | } 01558 | 01559 | template <typename T> 01560 | inline T modulus(const T v0, const T v1) 01561 | { 01562 | const typename details::number_type<T>::type num_type; 01563 | return modulus_impl(v0, v1, num_type); 01564 | } 01565 | 01566 | template <typename T> 01567 | inline T pow(const T v0, const T v1) 01568 | { 01569 | const typename details::number_type<T>::type num_type; 01570 | return pow_impl(v0, v1, num_type); 01571 | } 01572 | 01573 | template <typename T> 01574 | inline T logn(const T v0, const T v1) 01575 | { 01576 | const typename details::number_type<T>::type num_type; 01577 | return logn_impl(v0, v1, num_type); 01578 | } 01579 | 01580 | template <typename T> 01581 | inline T root(const T v0, const T v1) 01582 | { 01583 | const typename details::number_type<T>::type num_type; 01584 | return root_impl(v0, v1, num_type); 01585 | } 01586 | 01587 | template <typename T> 01588 | inline T roundn(const T v0, const T v1) 01589 | { 01590 | const typename details::number_type<T>::type num_type; 01591 | return roundn_impl(v0, v1, num_type); 01592 | } 01593 | 01594 | template <typename T> 01595 | inline T hypot(const T v0, const T v1) 01596 | { 01597 | const typename details::number_type<T>::type num_type; 01598 | return hypot_impl(v0, v1, num_type); 01599 | } 01600 | 01601 | template <typename T> 01602 | inline T atan2(const T v0, const T v1) 01603 | { 01604 | const typename details::number_type<T>::type num_type; 01605 | return atan2_impl(v0, v1, num_type); 01606 | } 01607 | 01608 | template <typename T> 01609 | inline T shr(const T v0, const T v1) 01610 | { 01611 | const typename details::number_type<T>::type num_type; 01612 | return shr_impl(v0, v1, num_type); 01613 | } 01614 | 01615 | template <typename T> 01616 | inline T shl(const T v0, const T v1) 01617 | { 01618 | const typename details::number_type<T>::type num_type; 01619 | return shl_impl(v0, v1, num_type); 01620 | } 01621 | 01622 | template <typename T> 01623 | inline T and_opr(const T v0, const T v1) 01624 | { 01625 | const typename details::number_type<T>::type num_type; 01626 | return and_impl(v0, v1, num_type); 01627 | } 01628 | 01629 | template <typename T> 01630 | inline T nand_opr(const T v0, const T v1) 01631 | { 01632 | const typename details::number_type<T>::type num_type; 01633 | return nand_impl(v0, v1, num_type); 01634 | } 01635 | 01636 | template <typename T> 01637 | inline T or_opr(const T v0, const T v1) 01638 | { 01639 | const typename details::number_type<T>::type num_type; 01640 | return or_impl(v0, v1, num_type); 01641 | } 01642 | 01643 | template <typename T> 01644 | inline T nor_opr(const T v0, const T v1) 01645 | { 01646 | const typename details::number_type<T>::type num_type; 01647 | return nor_impl(v0, v1, num_type); 01648 | } 01649 | 01650 | template <typename T> 01651 | inline T xor_opr(const T v0, const T v1) 01652 | { 01653 | const typename details::number_type<T>::type num_type; 01654 | return xor_impl(v0, v1, num_type); 01655 | } 01656 | 01657 | template <typename T> 01658 | inline T xnor_opr(const T v0, const T v1) 01659 | { 01660 | const typename details::number_type<T>::type num_type; 01661 | return xnor_impl(v0, v1, num_type); 01662 | } 01663 | 01664 | template <typename T> 01665 | inline bool is_integer(const T v) 01666 | { 01667 | const typename details::number_type<T>::type num_type; 01668 | return is_integer_impl(v, num_type); 01669 | } 01670 | 01671 | template <typename T, unsigned int N> 01672 | struct fast_exp 01673 | { 01674 | static inline T result(T v) 01675 | { 01676 | unsigned int k = N; 01677 | T l = T(1); 01678 | 01679 | while (k) 01680 | { 01681 | if (1 == (k % 2)) 01682 | { 01683 | l *= v; 01684 | --k; 01685 | } 01686 | 01687 | v *= v; 01688 | k /= 2; 01689 | } 01690 | 01691 | return l; 01692 | } 01693 | }; 01694 | 01695 | template <typename T> struct fast_exp<T,10> { static inline T result(const T v) { T v_5 = fast_exp<T,5>::result(v); return v_5 * v_5; } }; 01696 | template <typename T> struct fast_exp<T, 9> { static inline T result(const T v) { return fast_exp<T,8>::result(v) * v; } }; 01697 | template <typename T> struct fast_exp<T, 8> { static inline T result(const T v) { T v_4 = fast_exp<T,4>::result(v); return v_4 * v_4; } }; 01698 | template <typename T> struct fast_exp<T, 7> { static inline T result(const T v) { return fast_exp<T,6>::result(v) * v; } }; 01699 | template <typename T> struct fast_exp<T, 6> { static inline T result(const T v) { T v_3 = fast_exp<T,3>::result(v); return v_3 * v_3; } }; 01700 | template <typename T> struct fast_exp<T, 5> { static inline T result(const T v) { return fast_exp<T,4>::result(v) * v; } }; 01701 | template <typename T> struct fast_exp<T, 4> { static inline T result(const T v) { T v_2 = v * v; return v_2 * v_2; } }; 01702 | template <typename T> struct fast_exp<T, 3> { static inline T result(const T v) { return v * v * v; } }; 01703 | template <typename T> struct fast_exp<T, 2> { static inline T result(const T v) { return v * v; } }; 01704 | template <typename T> struct fast_exp<T, 1> { static inline T result(const T v) { return v; } }; 01705 | template <typename T> struct fast_exp<T, 0> { static inline T result(const T ) { return T(1); } }; 01706 | 01707 | #define exprtk_define_unary_function(FunctionName) \ 01708 | template <typename T> \ 01709 | inline T FunctionName (const T v) \ 01710 | { \ 01711 | const typename details::number_type<T>::type num_type; \ 01712 | return FunctionName##_impl(v,num_type); \ 01713 | } \ 01714 | 01715 | exprtk_define_unary_function(abs ) 01716 | exprtk_define_unary_function(acos ) 01717 | exprtk_define_unary_function(acosh) 01718 | exprtk_define_unary_function(asin ) 01719 | exprtk_define_unary_function(asinh) 01720 | exprtk_define_unary_function(atan ) 01721 | exprtk_define_unary_function(atanh) 01722 | exprtk_define_unary_function(ceil ) 01723 | exprtk_define_unary_function(cos ) 01724 | exprtk_define_unary_function(cosh ) 01725 | exprtk_define_unary_function(exp ) 01726 | exprtk_define_unary_function(expm1) 01727 | exprtk_define_unary_function(floor) 01728 | exprtk_define_unary_function(log ) 01729 | exprtk_define_unary_function(log10) 01730 | exprtk_define_unary_function(log2 ) 01731 | exprtk_define_unary_function(log1p) 01732 | exprtk_define_unary_function(neg ) 01733 | exprtk_define_unary_function(pos ) 01734 | exprtk_define_unary_function(round) 01735 | exprtk_define_unary_function(sin ) 01736 | exprtk_define_unary_function(sinc ) 01737 | exprtk_define_unary_function(sinh ) 01738 | exprtk_define_unary_function(sqrt ) 01739 | exprtk_define_unary_function(tan ) 01740 | exprtk_define_unary_function(tanh ) 01741 | exprtk_define_unary_function(cot ) 01742 | exprtk_define_unary_function(sec ) 01743 | exprtk_define_unary_function(csc ) 01744 | exprtk_define_unary_function(r2d ) 01745 | exprtk_define_unary_function(d2r ) 01746 | exprtk_define_unary_function(d2g ) 01747 | exprtk_define_unary_function(g2d ) 01748 | exprtk_define_unary_function(notl ) 01749 | exprtk_define_unary_function(sgn ) 01750 | exprtk_define_unary_function(erf ) 01751 | exprtk_define_unary_function(erfc ) 01752 | exprtk_define_unary_function(ncdf ) 01753 | exprtk_define_unary_function(frac ) 01754 | exprtk_define_unary_function(trunc) 01755 | #undef exprtk_define_unary_function 01756 | } 01757 | 01758 | template <typename T> 01759 | inline T compute_pow10(T d, const int exponent) 01760 | { 01761 | static const double fract10[] = 01762 | { 01763 | 0.0, 01764 | 1.0E+001, 1.0E+002, 1.0E+003, 1.0E+004, 1.0E+005, 1.0E+006, 1.0E+007, 1.0E+008, 1.0E+009, 1.0E+010, 01765 | 1.0E+011, 1.0E+012, 1.0E+013, 1.0E+014, 1.0E+015, 1.0E+016, 1.0E+017, 1.0E+018, 1.0E+019, 1.0E+020, 01766 | 1.0E+021, 1.0E+022, 1.0E+023, 1.0E+024, 1.0E+025, 1.0E+026, 1.0E+027, 1.0E+028, 1.0E+029, 1.0E+030, 01767 | 1.0E+031, 1.0E+032, 1.0E+033, 1.0E+034, 1.0E+035, 1.0E+036, 1.0E+037, 1.0E+038, 1.0E+039, 1.0E+040, 01768 | 1.0E+041, 1.0E+042, 1.0E+043, 1.0E+044, 1.0E+045, 1.0E+046, 1.0E+047, 1.0E+048, 1.0E+049, 1.0E+050, 01769 | 1.0E+051, 1.0E+052, 1.0E+053, 1.0E+054, 1.0E+055, 1.0E+056, 1.0E+057, 1.0E+058, 1.0E+059, 1.0E+060, 01770 | 1.0E+061, 1.0E+062, 1.0E+063, 1.0E+064, 1.0E+065, 1.0E+066, 1.0E+067, 1.0E+068, 1.0E+069, 1.0E+070, 01771 | 1.0E+071, 1.0E+072, 1.0E+073, 1.0E+074, 1.0E+075, 1.0E+076, 1.0E+077, 1.0E+078, 1.0E+079, 1.0E+080, 01772 | 1.0E+081, 1.0E+082, 1.0E+083, 1.0E+084, 1.0E+085, 1.0E+086, 1.0E+087, 1.0E+088, 1.0E+089, 1.0E+090, 01773 | 1.0E+091, 1.0E+092, 1.0E+093, 1.0E+094, 1.0E+095, 1.0E+096, 1.0E+097, 1.0E+098, 1.0E+099, 1.0E+100, 01774 | 1.0E+101, 1.0E+102, 1.0E+103, 1.0E+104, 1.0E+105, 1.0E+106, 1.0E+107, 1.0E+108, 1.0E+109, 1.0E+110, 01775 | 1.0E+111, 1.0E+112, 1.0E+113, 1.0E+114, 1.0E+115, 1.0E+116, 1.0E+117, 1.0E+118, 1.0E+119, 1.0E+120, 01776 | 1.0E+121, 1.0E+122, 1.0E+123, 1.0E+124, 1.0E+125, 1.0E+126, 1.0E+127, 1.0E+128, 1.0E+129, 1.0E+130, 01777 | 1.0E+131, 1.0E+132, 1.0E+133, 1.0E+134, 1.0E+135, 1.0E+136, 1.0E+137, 1.0E+138, 1.0E+139, 1.0E+140, 01778 | 1.0E+141, 1.0E+142, 1.0E+143, 1.0E+144, 1.0E+145, 1.0E+146, 1.0E+147, 1.0E+148, 1.0E+149, 1.0E+150, 01779 | 1.0E+151, 1.0E+152, 1.0E+153, 1.0E+154, 1.0E+155, 1.0E+156, 1.0E+157, 1.0E+158, 1.0E+159, 1.0E+160, 01780 | 1.0E+161, 1.0E+162, 1.0E+163, 1.0E+164, 1.0E+165, 1.0E+166, 1.0E+167, 1.0E+168, 1.0E+169, 1.0E+170, 01781 | 1.0E+171, 1.0E+172, 1.0E+173, 1.0E+174, 1.0E+175, 1.0E+176, 1.0E+177, 1.0E+178, 1.0E+179, 1.0E+180, 01782 | 1.0E+181, 1.0E+182, 1.0E+183, 1.0E+184, 1.0E+185, 1.0E+186, 1.0E+187, 1.0E+188, 1.0E+189, 1.0E+190, 01783 | 1.0E+191, 1.0E+192, 1.0E+193, 1.0E+194, 1.0E+195, 1.0E+196, 1.0E+197, 1.0E+198, 1.0E+199, 1.0E+200, 01784 | 1.0E+201, 1.0E+202, 1.0E+203, 1.0E+204, 1.0E+205, 1.0E+206, 1.0E+207, 1.0E+208, 1.0E+209, 1.0E+210, 01785 | 1.0E+211, 1.0E+212, 1.0E+213, 1.0E+214, 1.0E+215, 1.0E+216, 1.0E+217, 1.0E+218, 1.0E+219, 1.0E+220, 01786 | 1.0E+221, 1.0E+222, 1.0E+223, 1.0E+224, 1.0E+225, 1.0E+226, 1.0E+227, 1.0E+228, 1.0E+229, 1.0E+230, 01787 | 1.0E+231, 1.0E+232, 1.0E+233, 1.0E+234, 1.0E+235, 1.0E+236, 1.0E+237, 1.0E+238, 1.0E+239, 1.0E+240, 01788 | 1.0E+241, 1.0E+242, 1.0E+243, 1.0E+244, 1.0E+245, 1.0E+246, 1.0E+247, 1.0E+248, 1.0E+249, 1.0E+250, 01789 | 1.0E+251, 1.0E+252, 1.0E+253, 1.0E+254, 1.0E+255, 1.0E+256, 1.0E+257, 1.0E+258, 1.0E+259, 1.0E+260, 01790 | 1.0E+261, 1.0E+262, 1.0E+263, 1.0E+264, 1.0E+265, 1.0E+266, 1.0E+267, 1.0E+268, 1.0E+269, 1.0E+270, 01791 | 1.0E+271, 1.0E+272, 1.0E+273, 1.0E+274, 1.0E+275, 1.0E+276, 1.0E+277, 1.0E+278, 1.0E+279, 1.0E+280, 01792 | 1.0E+281, 1.0E+282, 1.0E+283, 1.0E+284, 1.0E+285, 1.0E+286, 1.0E+287, 1.0E+288, 1.0E+289, 1.0E+290, 01793 | 1.0E+291, 1.0E+292, 1.0E+293, 1.0E+294, 1.0E+295, 1.0E+296, 1.0E+297, 1.0E+298, 1.0E+299, 1.0E+300, 01794 | 1.0E+301, 1.0E+302, 1.0E+303, 1.0E+304, 1.0E+305, 1.0E+306, 1.0E+307, 1.0E+308 01795 | }; 01796 | 01797 | static const int fract10_size = static_cast<int>(sizeof(fract10) / sizeof(double)); 01798 | 01799 | const int e = std::abs(exponent); 01800 | 01801 | if (exponent >= std::numeric_limits<T>::min_exponent10) 01802 | { 01803 | if (e < fract10_size) 01804 | { 01805 | if (exponent > 0) 01806 | return T(d * fract10[e]); 01807 | else 01808 | return T(d / fract10[e]); 01809 | } 01810 | else 01811 | return T(d * std::pow(10.0, 10.0 * exponent)); 01812 | } 01813 | else 01814 | { 01815 | d /= T(fract10[ -std::numeric_limits<T>::min_exponent10]); 01816 | return T(d / fract10[-exponent + std::numeric_limits<T>::min_exponent10]); 01817 | } 01818 | } 01819 | 01820 | template <typename Iterator, typename T> 01821 | inline bool string_to_type_converter_impl_ref(Iterator& itr, const Iterator end, T& result) 01822 | { 01823 | if (itr == end) 01824 | return false; 01825 | 01826 | const bool negative = ('-' == (*itr)); 01827 | 01828 | if (negative || ('+' == (*itr))) 01829 | { 01830 | if (end == ++itr) 01831 | return false; 01832 | } 01833 | 01834 | static const uchar_t zero = static_cast<uchar_t>('0'); 01835 | 01836 | while ((end != itr) && (zero == (*itr))) ++itr; 01837 | 01838 | bool return_result = true; 01839 | unsigned int digit = 0; 01840 | const std::size_t length = static_cast<std::size_t>(std::distance(itr,end)); 01841 | 01842 | if (length <= 4) 01843 | { 01844 | switch (length) 01845 | { 01846 | #ifdef exprtk_use_lut 01847 | 01848 | #define exprtk_process_digit \ 01849 | if ((digit = details::digit_table[(int)*itr++]) < 10) \ 01850 | result = result * 10 + (digit); \ 01851 | else \ 01852 | { \ 01853 | return_result = false; \ 01854 | break; \ 01855 | } \ 01856 | exprtk_fallthrough \ 01857 | 01858 | #else 01859 | 01860 | #define exprtk_process_digit \ 01861 | if ((digit = (*itr++ - zero)) < 10) \ 01862 | result = result * T(10) + digit; \ 01863 | else \ 01864 | { \ 01865 | return_result = false; \ 01866 | break; \ 01867 | } \ 01868 | exprtk_fallthrough \ 01869 | 01870 | #endif 01871 | 01872 | case 4 : exprtk_process_digit 01873 | case 3 : exprtk_process_digit 01874 | case 2 : exprtk_process_digit 01875 | case 1 : if ((digit = (*itr - zero)) >= 10) 01876 | { 01877 | digit = 0; 01878 | return_result = false; 01879 | } 01880 | 01881 | #undef exprtk_process_digit 01882 | } 01883 | } 01884 | else 01885 | return_result = false; 01886 | 01887 | if (length && return_result) 01888 | { 01889 | result = result * 10 + static_cast<T>(digit); 01890 | ++itr; 01891 | } 01892 | 01893 | result = negative ? -result : result; 01894 | return return_result; 01895 | } 01896 | 01897 | template <typename Iterator, typename T> 01898 | static inline bool parse_nan(Iterator& itr, const Iterator end, T& t) 01899 | { 01900 | typedef typename std::iterator_traits<Iterator>::value_type type; 01901 | 01902 | static const std::size_t nan_length = 3; 01903 | 01904 | if (std::distance(itr,end) != static_cast<int>(nan_length)) 01905 | return false; 01906 | 01907 | if (static_cast<type>('n') == (*itr)) 01908 | { 01909 | if ( 01910 | (static_cast<type>('a') != *(itr + 1)) || 01911 | (static_cast<type>('n') != *(itr + 2)) 01912 | ) 01913 | { 01914 | return false; 01915 | } 01916 | } 01917 | else if ( 01918 | (static_cast<type>('A') != *(itr + 1)) || 01919 | (static_cast<type>('N') != *(itr + 2)) 01920 | ) 01921 | { 01922 | return false; 01923 | } 01924 | 01925 | t = std::numeric_limits<T>::quiet_NaN(); 01926 | 01927 | return true; 01928 | } 01929 | 01930 | template <typename Iterator, typename T> 01931 | static inline bool parse_inf(Iterator& itr, const Iterator end, T& t, const bool negative) 01932 | { 01933 | static const char_t inf_uc[] = "INFINITY" 01934 | static const char_t inf_lc[] = "infinity" 01935 | static const std::size_t inf_length = 8; 01936 | 01937 | const std::size_t length = static_cast<std::size_t>(std::distance(itr,end)); 01938 | 01939 | if ((3 != length) && (inf_length != length)) 01940 | return false; 01941 | 01942 | char_cptr inf_itr = ('i' == (*itr)) ? inf_lc : inf_uc; 01943 | 01944 | while (end != itr) 01945 | { 01946 | if (*inf_itr == static_cast<char_t>(*itr)) 01947 | { 01948 | ++itr; 01949 | ++inf_itr; 01950 | continue; 01951 | } 01952 | else 01953 | return false; 01954 | } 01955 | 01956 | if (negative) 01957 | t = -std::numeric_limits<T>::infinity(); 01958 | else 01959 | t = std::numeric_limits<T>::infinity(); 01960 | 01961 | return true; 01962 | } 01963 | 01964 | template <typename T> 01965 | inline bool valid_exponent(const int exponent, numeric::details::real_type_tag) 01966 | { 01967 | using namespace details::numeric; 01968 | return (numeric_info<T>::min_exp <= exponent) && (exponent <= numeric_info<T>::max_exp); 01969 | } 01970 | 01971 | template <typename Iterator, typename T> 01972 | inline bool string_to_real(Iterator& itr_external, const Iterator end, T& t, numeric::details::real_type_tag) 01973 | { 01974 | if (end == itr_external) return false; 01975 | 01976 | Iterator itr = itr_external; 01977 | 01978 | T d = T(0); 01979 | 01980 | const bool negative = ('-' == (*itr)); 01981 | 01982 | if (negative || '+' == (*itr)) 01983 | { 01984 | if (end == ++itr) 01985 | return false; 01986 | } 01987 | 01988 | bool instate = false; 01989 | 01990 | static const char_t zero = static_cast<uchar_t>('0'); 01991 | 01992 | #define parse_digit_1(d) \ 01993 | if ((digit = (*itr - zero)) < 10) \ 01994 | { d = d * T(10) + digit; } \ 01995 | else \ 01996 | { break; } \ 01997 | if (end == ++itr) break; \ 01998 | 01999 | #define parse_digit_2(d) \ 02000 | if ((digit = (*itr - zero)) < 10) \ 02001 | { d = d * T(10) + digit; } \ 02002 | else \ 02003 | { break; } \ 02004 | ++itr; \ 02005 | 02006 | if ('.' != (*itr)) 02007 | { 02008 | const Iterator curr = itr; 02009 | 02010 | while ((end != itr) && (zero == (*itr))) ++itr; 02011 | 02012 | while (end != itr) 02013 | { 02014 | unsigned int digit; 02015 | parse_digit_1(d) 02016 | parse_digit_1(d) 02017 | parse_digit_2(d) 02018 | } 02019 | 02020 | if (curr != itr) instate = true; 02021 | } 02022 | 02023 | int exponent = 0; 02024 | 02025 | if (end != itr) 02026 | { 02027 | if ('.' == (*itr)) 02028 | { 02029 | const Iterator curr = ++itr; 02030 | T tmp_d = T(0); 02031 | 02032 | while (end != itr) 02033 | { 02034 | unsigned int digit; 02035 | parse_digit_1(tmp_d) 02036 | parse_digit_1(tmp_d) 02037 | parse_digit_2(tmp_d) 02038 | } 02039 | 02040 | if (curr != itr) 02041 | { 02042 | instate = true; 02043 | 02044 | const int frac_exponent = static_cast<int>(-std::distance(curr, itr)); 02045 | 02046 | if (!valid_exponent<T>(frac_exponent, numeric::details::real_type_tag())) 02047 | return false; 02048 | 02049 | d += compute_pow10(tmp_d, frac_exponent); 02050 | } 02051 | 02052 | #undef parse_digit_1 02053 | #undef parse_digit_2 02054 | } 02055 | 02056 | if (end != itr) 02057 | { 02058 | typename std::iterator_traits<Iterator>::value_type c = (*itr); 02059 | 02060 | if (('e' == c) || ('E' == c)) 02061 | { 02062 | int exp = 0; 02063 | 02064 | if (!details::string_to_type_converter_impl_ref(++itr, end, exp)) 02065 | { 02066 | if (end == itr) 02067 | return false; 02068 | else 02069 | c = (*itr); 02070 | } 02071 | 02072 | exponent += exp; 02073 | } 02074 | 02075 | if (end != itr) 02076 | { 02077 | if (('f' == c) || ('F' == c) || ('l' == c) || ('L' == c)) 02078 | ++itr; 02079 | else if ('#' == c) 02080 | { 02081 | if (end == ++itr) 02082 | return false; 02083 | 02084 | if (('I' <= (*itr)) && ((*itr) <= 'n')) 02085 | { 02086 | if (('i' == (*itr)) || ('I' == (*itr))) 02087 | { 02088 | return parse_inf(itr, end, t, negative); 02089 | } 02090 | else if (('n' == (*itr)) || ('N' == (*itr))) 02091 | { 02092 | return parse_nan(itr, end, t); 02093 | } 02094 | else 02095 | return false; 02096 | } 02097 | else 02098 | return false; 02099 | } 02100 | else if (('I' <= (*itr)) && ((*itr) <= 'n')) 02101 | { 02102 | if (('i' == (*itr)) || ('I' == (*itr))) 02103 | { 02104 | return parse_inf(itr, end, t, negative); 02105 | } 02106 | else if (('n' == (*itr)) || ('N' == (*itr))) 02107 | { 02108 | return parse_nan(itr, end, t); 02109 | } 02110 | else 02111 | return false; 02112 | } 02113 | else 02114 | return false; 02115 | } 02116 | } 02117 | } 02118 | 02119 | if ((end != itr) || (!instate)) 02120 | return false; 02121 | else if (!valid_exponent<T>(exponent, numeric::details::real_type_tag())) 02122 | return false; 02123 | else if (exponent) 02124 | d = compute_pow10(d,exponent); 02125 | 02126 | t = static_cast<T>((negative) ? -d : d); 02127 | return true; 02128 | } 02129 | 02130 | template <typename T> 02131 | inline bool string_to_real(const std::string& s, T& t) 02132 | { 02133 | const typename numeric::details::number_type<T>::type num_type; 02134 | 02135 | char_cptr begin = s.data(); 02136 | char_cptr end = s.data() + s.size(); 02137 | 02138 | return string_to_real(begin, end, t, num_type); 02139 | } 02140 | 02141 | template <typename T> 02142 | struct functor_t 02143 | { 02144 | /* 02145 | Note: The following definitions for Type, may require tweaking 02146 | based on the compiler and target architecture. The benchmark 02147 | should provide enough information to make the right choice. 02148 | */ 02149 | //typedef T Type; 02150 | //typedef const T Type; 02151 | typedef const T& Type; 02152 | typedef T& RefType; 02153 | typedef T (*qfunc_t)(Type t0, Type t1, Type t2, Type t3); 02154 | typedef T (*tfunc_t)(Type t0, Type t1, Type t2); 02155 | typedef T (*bfunc_t)(Type t0, Type t1); 02156 | typedef T (*ufunc_t)(Type t0); 02157 | }; 02158 | 02159 | } // namespace details 02160 | 02161 | struct loop_runtime_check 02162 | { 02163 | enum loop_types 02164 | { 02165 | e_invalid = 0, 02166 | e_for_loop = 1, 02167 | e_while_loop = 2, 02168 | e_repeat_until_loop = 4, 02169 | e_all_loops = 7 02170 | }; 02171 | 02172 | enum violation_type 02173 | { 02174 | e_unknown = 0, 02175 | e_iteration_count = 1, 02176 | e_timeout = 2 02177 | }; 02178 | 02179 | loop_types loop_set; 02180 | 02181 | loop_runtime_check() 02182 | : loop_set(e_invalid) 02183 | , max_loop_iterations(0) 02184 | {} 02185 | 02186 | details::_uint64_t max_loop_iterations; 02187 | 02188 | struct violation_context 02189 | { 02190 | loop_types loop; 02191 | violation_type violation; 02192 | details::_uint64_t iteration_count; 02193 | }; 02194 | 02195 | virtual bool check() 02196 | { 02197 | return true; 02198 | } 02199 | 02200 | virtual void handle_runtime_violation(const violation_context&) 02201 | { 02202 | throw std::runtime_error("ExprTk Loop runtime violation."); 02203 | } 02204 | 02205 | virtual ~loop_runtime_check() 02206 | {} 02207 | }; 02208 | 02209 | typedef loop_runtime_check* loop_runtime_check_ptr; 02210 | 02211 | struct vector_access_runtime_check 02212 | { 02213 | struct violation_context 02214 | { 02215 | void* base_ptr; 02216 | void* end_ptr; 02217 | void* access_ptr; 02218 | std::size_t type_size; 02219 | }; 02220 | 02221 | virtual ~vector_access_runtime_check() 02222 | {} 02223 | 02224 | virtual bool handle_runtime_violation(violation_context& /*context*/) 02225 | { 02226 | throw std::runtime_error("ExprTk runtime vector access violation."); 02227 | #if !defined(_MSC_VER) && !defined(__NVCOMPILER) 02228 | return false; 02229 | #endif 02230 | } 02231 | }; 02232 | 02233 | typedef vector_access_runtime_check* vector_access_runtime_check_ptr; 02234 | 02235 | struct assert_check 02236 | { 02237 | struct assert_context 02238 | { 02239 | std::string condition; 02240 | std::string message; 02241 | std::string id; 02242 | std::size_t offet; 02243 | }; 02244 | 02245 | virtual ~assert_check() 02246 | {} 02247 | 02248 | virtual void handle_assert(const assert_context& /*context*/) 02249 | {} 02250 | }; 02251 | 02252 | typedef assert_check* assert_check_ptr; 02253 | 02254 | struct compilation_check 02255 | { 02256 | struct compilation_context 02257 | { 02258 | std::string error_message; 02259 | }; 02260 | 02261 | virtual bool continue_compilation(compilation_context& /*context*/) = 0; 02262 | 02263 | virtual ~compilation_check() 02264 | {} 02265 | }; 02266 | 02267 | typedef compilation_check* compilation_check_ptr; 02268 | 02269 | namespace lexer 02270 | { 02271 | struct token 02272 | { 02273 | enum token_type 02274 | { 02275 | e_none = 0, e_error = 1, e_err_symbol = 2, 02276 | e_err_number = 3, e_err_string = 4, e_err_sfunc = 5, 02277 | e_eof = 6, e_number = 7, e_symbol = 8, 02278 | e_string = 9, e_assign = 10, e_addass = 11, 02279 | e_subass = 12, e_mulass = 13, e_divass = 14, 02280 | e_modass = 15, e_shr = 16, e_shl = 17, 02281 | e_lte = 18, e_ne = 19, e_gte = 20, 02282 | e_swap = 21, e_lt = '<', e_gt = '>', 02283 | e_eq = '=', e_rbracket = ')', e_lbracket = '(', 02284 | e_rsqrbracket = ']', e_lsqrbracket = '[', e_rcrlbracket = '}', 02285 | e_lcrlbracket = '{', e_comma = ',', e_add = '+', 02286 | e_sub = '-', e_div = '/', e_mul = '*', 02287 | e_mod = '%', e_pow = '^', e_colon = ':', 02288 | e_ternary = '?' 02289 | }; 02290 | 02291 | token() 02292 | : type(e_none) 02293 | , value("") 02294 | , position(std::numeric_limits<std::size_t>::max()) 02295 | {} 02296 | 02297 | void clear() 02298 | { 02299 | type = e_none; 02300 | value = "" 02301 | position = std::numeric_limits<std::size_t>::max(); 02302 | } 02303 | 02304 | template <typename Iterator> 02305 | inline token& set_operator(const token_type tt, 02306 | const Iterator begin, const Iterator end, 02307 | const Iterator base_begin = Iterator(0)) 02308 | { 02309 | type = tt; 02310 | value.assign(begin,end); 02311 | if (base_begin) 02312 | position = static_cast<std::size_t>(std::distance(base_begin,begin)); 02313 | return (*this); 02314 | } 02315 | 02316 | template <typename Iterator> 02317 | inline token& set_symbol(const Iterator begin, const Iterator end, const Iterator base_begin = Iterator(0)) 02318 | { 02319 | type = e_symbol; 02320 | value.assign(begin,end); 02321 | if (base_begin) 02322 | position = static_cast<std::size_t>(std::distance(base_begin,begin)); 02323 | return (*this); 02324 | } 02325 | 02326 | template <typename Iterator> 02327 | inline token& set_numeric(const Iterator begin, const Iterator end, const Iterator base_begin = Iterator(0)) 02328 | { 02329 | type = e_number; 02330 | value.assign(begin,end); 02331 | if (base_begin) 02332 | position = static_cast<std::size_t>(std::distance(base_begin,begin)); 02333 | return (*this); 02334 | } 02335 | 02336 | template <typename Iterator> 02337 | inline token& set_string(const Iterator begin, const Iterator end, const Iterator base_begin = Iterator(0)) 02338 | { 02339 | type = e_string; 02340 | value.assign(begin,end); 02341 | if (base_begin) 02342 | position = static_cast<std::size_t>(std::distance(base_begin,begin)); 02343 | return (*this); 02344 | } 02345 | 02346 | inline token& set_string(const std::string& s, const std::size_t p) 02347 | { 02348 | type = e_string; 02349 | value = s; 02350 | position = p; 02351 | return (*this); 02352 | } 02353 | 02354 | template <typename Iterator> 02355 | inline token& set_error(const token_type et, 02356 | const Iterator begin, const Iterator end, 02357 | const Iterator base_begin = Iterator(0)) 02358 | { 02359 | if ( 02360 | (e_error == et) || 02361 | (e_err_symbol == et) || 02362 | (e_err_number == et) || 02363 | (e_err_string == et) || 02364 | (e_err_sfunc == et) 02365 | ) 02366 | { 02367 | type = et; 02368 | } 02369 | else 02370 | type = e_error; 02371 | 02372 | value.assign(begin,end); 02373 | 02374 | if (base_begin) 02375 | position = static_cast<std::size_t>(std::distance(base_begin,begin)); 02376 | 02377 | return (*this); 02378 | } 02379 | 02380 | static inline std::string to_str(const token_type t) 02381 | { 02382 | switch (t) 02383 | { 02384 | case e_none : return "NONE" 02385 | case e_error : return "ERROR" 02386 | case e_err_symbol : return "ERROR_SYMBOL" 02387 | case e_err_number : return "ERROR_NUMBER" 02388 | case e_err_string : return "ERROR_STRING" 02389 | case e_eof : return "EOF" 02390 | case e_number : return "NUMBER" 02391 | case e_symbol : return "SYMBOL" 02392 | case e_string : return "STRING" 02393 | case e_assign : return ":=" 02394 | case e_addass : return "+=" 02395 | case e_subass : return "-=" 02396 | case e_mulass : return "*=" 02397 | case e_divass : return "/=" 02398 | case e_modass : return "%=" 02399 | case e_shr : return ">>" 02400 | case e_shl : return "<<" 02401 | case e_lte : return "<=" 02402 | case e_ne : return "!=" 02403 | case e_gte : return ">=" 02404 | case e_lt : return "<" 02405 | case e_gt : return ">" 02406 | case e_eq : return "=" 02407 | case e_rbracket : return ")" 02408 | case e_lbracket : return "(" 02409 | case e_rsqrbracket : return "]" 02410 | case e_lsqrbracket : return "[" 02411 | case e_rcrlbracket : return "}" 02412 | case e_lcrlbracket : return "{" 02413 | case e_comma : return "," 02414 | case e_add : return "+" 02415 | case e_sub : return "-" 02416 | case e_div : return "/" 02417 | case e_mul : return "*" 02418 | case e_mod : return "%" 02419 | case e_pow : return "^" 02420 | case e_colon : return ":" 02421 | case e_ternary : return "?" 02422 | case e_swap : return "<=>" 02423 | default : return "UNKNOWN" 02424 | } 02425 | } 02426 | 02427 | static inline std::string seperator_to_str(const token_type t) 02428 | { 02429 | switch (t) 02430 | { 02431 | case e_comma : return "," 02432 | case e_colon : return ":" 02433 | case e_eof : return "" 02434 | default : return "UNKNOWN" 02435 | } 02436 | 02437 | #if !defined(_MSC_VER) && !defined(__NVCOMPILER) 02438 | return "UNKNOWN" 02439 | #endif 02440 | } 02441 | 02442 | inline bool is_error() const 02443 | { 02444 | return (e_error == type) || 02445 | (e_err_symbol == type) || 02446 | (e_err_number == type) || 02447 | (e_err_string == type) || 02448 | (e_err_sfunc == type) ; 02449 | } 02450 | 02451 | token_type type; 02452 | std::string value; 02453 | std::size_t position; 02454 | }; 02455 | 02456 | class generator 02457 | { 02458 | public: 02459 | 02460 | typedef token token_t; 02461 | typedef std::vector<token_t> token_list_t; 02462 | typedef token_list_t::iterator token_list_itr_t; 02463 | typedef details::char_t char_t; 02464 | 02465 | generator() 02466 | : base_itr_(0) 02467 | , s_itr_ (0) 02468 | , s_end_ (0) 02469 | { 02470 | clear(); 02471 | } 02472 | 02473 | inline void clear() 02474 | { 02475 | base_itr_ = 0; 02476 | s_itr_ = 0; 02477 | s_end_ = 0; 02478 | token_list_.clear(); 02479 | token_itr_ = token_list_.end(); 02480 | store_token_itr_ = token_list_.end(); 02481 | } 02482 | 02483 | inline bool process(const std::string& str) 02484 | { 02485 | base_itr_ = str.data(); 02486 | s_itr_ = str.data(); 02487 | s_end_ = str.data() + str.size(); 02488 | 02489 | eof_token_.set_operator(token_t::e_eof, s_end_, s_end_, base_itr_); 02490 | token_list_.clear(); 02491 | 02492 | while (!is_end(s_itr_)) 02493 | { 02494 | scan_token(); 02495 | 02496 | if (!token_list_.empty() && token_list_.back().is_error()) 02497 | return false; 02498 | } 02499 | 02500 | return true; 02501 | } 02502 | 02503 | inline bool empty() const 02504 | { 02505 | return token_list_.empty(); 02506 | } 02507 | 02508 | inline std::size_t size() const 02509 | { 02510 | return token_list_.size(); 02511 | } 02512 | 02513 | inline void begin() 02514 | { 02515 | token_itr_ = token_list_.begin(); 02516 | store_token_itr_ = token_list_.begin(); 02517 | } 02518 | 02519 | inline void store() 02520 | { 02521 | store_token_itr_ = token_itr_; 02522 | } 02523 | 02524 | inline void restore() 02525 | { 02526 | token_itr_ = store_token_itr_; 02527 | } 02528 | 02529 | inline token_t& next_token() 02530 | { 02531 | if (token_list_.end() != token_itr_) 02532 | { 02533 | return *token_itr_++; 02534 | } 02535 | else 02536 | return eof_token_; 02537 | } 02538 | 02539 | inline token_t& peek_next_token() 02540 | { 02541 | if (token_list_.end() != token_itr_) 02542 | { 02543 | return *token_itr_; 02544 | } 02545 | else 02546 | return eof_token_; 02547 | } 02548 | 02549 | inline token_t& operator[](const std::size_t& index) 02550 | { 02551 | if (index < token_list_.size()) 02552 | { 02553 | return token_list_[index]; 02554 | } 02555 | else 02556 | return eof_token_; 02557 | } 02558 | 02559 | inline token_t operator[](const std::size_t& index) const 02560 | { 02561 | if (index < token_list_.size()) 02562 | { 02563 | return token_list_[index]; 02564 | } 02565 | else 02566 | return eof_token_; 02567 | } 02568 | 02569 | inline bool finished() const 02570 | { 02571 | return (token_list_.end() == token_itr_); 02572 | } 02573 | 02574 | inline void insert_front(token_t::token_type tk_type) 02575 | { 02576 | if ( 02577 | !token_list_.empty() && 02578 | (token_list_.end() != token_itr_) 02579 | ) 02580 | { 02581 | token_t t = *token_itr_; 02582 | 02583 | t.type = tk_type; 02584 | token_itr_ = token_list_.insert(token_itr_,t); 02585 | } 02586 | } 02587 | 02588 | inline std::string substr(const std::size_t& begin, const std::size_t& end) const 02589 | { 02590 | const details::char_cptr begin_itr = ((base_itr_ + begin) < s_end_) ? (base_itr_ + begin) : s_end_; 02591 | const details::char_cptr end_itr = ((base_itr_ + end ) < s_end_) ? (base_itr_ + end ) : s_end_; 02592 | 02593 | return std::string(begin_itr,end_itr); 02594 | } 02595 | 02596 | inline std::string remaining() const 02597 | { 02598 | if (finished()) 02599 | return "" 02600 | else if (token_list_.begin() != token_itr_) 02601 | return std::string(base_itr_ + (token_itr_ - 1)->position, s_end_); 02602 | else 02603 | return std::string(base_itr_ + token_itr_->position, s_end_); 02604 | } 02605 | 02606 | private: 02607 | 02608 | inline bool is_end(details::char_cptr itr) const 02609 | { 02610 | return (s_end_ == itr); 02611 | } 02612 | 02613 | #ifndef exprtk_disable_comments 02614 | inline bool is_comment_start(details::char_cptr itr) const 02615 | { 02616 | const char_t c0 = *(itr + 0); 02617 | const char_t c1 = *(itr + 1); 02618 | 02619 | if ('#' == c0) 02620 | return true; 02621 | else if (!is_end(itr + 1)) 02622 | { 02623 | if (('/' == c0) && ('/' == c1)) return true; 02624 | if (('/' == c0) && ('*' == c1)) return true; 02625 | } 02626 | return false; 02627 | } 02628 | #else 02629 | inline bool is_comment_start(details::char_cptr) const 02630 | { 02631 | return false; 02632 | } 02633 | #endif 02634 | 02635 | inline void skip_whitespace() 02636 | { 02637 | while (!is_end(s_itr_) && details::is_whitespace(*s_itr_)) 02638 | { 02639 | ++s_itr_; 02640 | } 02641 | } 02642 | 02643 | inline void skip_comments() 02644 | { 02645 | #ifndef exprtk_disable_comments 02646 | // The following comment styles are supported: 02647 | // 1. // .... \n 02648 | // 2. # .... \n 02649 | // 3. /* .... */ 02650 | struct test 02651 | { 02652 | static inline bool comment_start(const char_t c0, const char_t c1, int& mode, int& incr) 02653 | { 02654 | mode = 0; 02655 | if ('#' == c0) { mode = 1; incr = 1; } 02656 | else if ('/' == c0) 02657 | { 02658 | if ('/' == c1) { mode = 1; incr = 2; } 02659 | else if ('*' == c1) { mode = 2; incr = 2; } 02660 | } 02661 | return (0 != mode); 02662 | } 02663 | 02664 | static inline bool comment_end(const char_t c0, const char_t c1, int& mode) 02665 | { 02666 | if ( 02667 | ((1 == mode) && ('\n' == c0)) || 02668 | ((2 == mode) && ( '*' == c0) && ('/' == c1)) 02669 | ) 02670 | { 02671 | mode = 0; 02672 | return true; 02673 | } 02674 | else 02675 | return false; 02676 | } 02677 | }; 02678 | 02679 | int mode = 0; 02680 | int increment = 0; 02681 | 02682 | if (is_end(s_itr_)) 02683 | return; 02684 | else if (!test::comment_start(*s_itr_, *(s_itr_ + 1), mode, increment)) 02685 | return; 02686 | 02687 | details::char_cptr cmt_start = s_itr_; 02688 | 02689 | s_itr_ += increment; 02690 | 02691 | while (!is_end(s_itr_)) 02692 | { 02693 | if (details::is_invalid(*s_itr_)) 02694 | { 02695 | token_t t; 02696 | t.set_error(token::e_error, s_itr_, s_itr_ + 1, base_itr_); 02697 | token_list_.push_back(t); 02698 | return; 02699 | } 02700 | 02701 | if ((1 == mode) && test::comment_end(*s_itr_, 0, mode)) 02702 | { 02703 | ++s_itr_; 02704 | return; 02705 | } 02706 | 02707 | if ((2 == mode)) 02708 | { 02709 | if (!is_end((s_itr_ + 1)) && test::comment_end(*s_itr_, *(s_itr_ + 1), mode)) 02710 | { 02711 | s_itr_ += 2; 02712 | return; 02713 | } 02714 | } 02715 | 02716 | ++s_itr_; 02717 | } 02718 | 02719 | if (2 == mode) 02720 | { 02721 | token_t t; 02722 | t.set_error(token::e_error, cmt_start, cmt_start + mode, base_itr_); 02723 | token_list_.push_back(t); 02724 | } 02725 | #endif 02726 | } 02727 | 02728 | inline bool next_is_digit(const details::char_cptr itr) const 02729 | { 02730 | return ((itr + 1) != s_end_) && 02731 | details::is_digit(*(itr + 1)); 02732 | } 02733 | 02734 | inline void scan_token() 02735 | { 02736 | const char_t c = *s_itr_; 02737 | 02738 | if (details::is_whitespace(c)) 02739 | { 02740 | skip_whitespace(); 02741 | return; 02742 | } 02743 | else if (is_comment_start(s_itr_)) 02744 | { 02745 | skip_comments(); 02746 | return; 02747 | } 02748 | else if (details::is_operator_char(c)) 02749 | { 02750 | scan_operator(); 02751 | return; 02752 | } 02753 | else if (details::is_letter(c)) 02754 | { 02755 | scan_symbol(); 02756 | return; 02757 | } 02758 | else if (('.' == c) && !next_is_digit(s_itr_)) 02759 | { 02760 | scan_operator(); 02761 | return; 02762 | } 02763 | else if (details::is_digit(c) || ('.' == c)) 02764 | { 02765 | scan_number(); 02766 | return; 02767 | } 02768 | else if ('$' == c) 02769 | { 02770 | scan_special_function(); 02771 | return; 02772 | } 02773 | #ifndef exprtk_disable_string_capabilities 02774 | else if ('\'' == c) 02775 | { 02776 | scan_string(); 02777 | return; 02778 | } 02779 | #endif 02780 | else if ('~' == c) 02781 | { 02782 | token_t t; 02783 | t.set_symbol(s_itr_, s_itr_ + 1, base_itr_); 02784 | token_list_.push_back(t); 02785 | ++s_itr_; 02786 | return; 02787 | } 02788 | else 02789 | { 02790 | token_t t; 02791 | t.set_error(token::e_error, s_itr_, s_itr_ + 2, base_itr_); 02792 | token_list_.push_back(t); 02793 | ++s_itr_; 02794 | } 02795 | } 02796 | 02797 | inline void scan_operator() 02798 | { 02799 | token_t t; 02800 | 02801 | const char_t c0 = s_itr_[0]; 02802 | 02803 | if (!is_end(s_itr_ + 1)) 02804 | { 02805 | const char_t c1 = s_itr_[1]; 02806 | 02807 | if (!is_end(s_itr_ + 2)) 02808 | { 02809 | const char_t c2 = s_itr_[2]; 02810 | 02811 | if ((c0 == '<') && (c1 == '=') && (c2 == '>')) 02812 | { 02813 | t.set_operator(token_t::e_swap, s_itr_, s_itr_ + 3, base_itr_); 02814 | token_list_.push_back(t); 02815 | s_itr_ += 3; 02816 | return; 02817 | } 02818 | } 02819 | 02820 | token_t::token_type ttype = token_t::e_none; 02821 | 02822 | if ((c0 == '<') && (c1 == '=')) ttype = token_t::e_lte; 02823 | else if ((c0 == '>') && (c1 == '=')) ttype = token_t::e_gte; 02824 | else if ((c0 == '<') && (c1 == '>')) ttype = token_t::e_ne; 02825 | else if ((c0 == '!') && (c1 == '=')) ttype = token_t::e_ne; 02826 | else if ((c0 == '=') && (c1 == '=')) ttype = token_t::e_eq; 02827 | else if ((c0 == ':') && (c1 == '=')) ttype = token_t::e_assign; 02828 | else if ((c0 == '<') && (c1 == '<')) ttype = token_t::e_shl; 02829 | else if ((c0 == '>') && (c1 == '>')) ttype = token_t::e_shr; 02830 | else if ((c0 == '+') && (c1 == '=')) ttype = token_t::e_addass; 02831 | else if ((c0 == '-') && (c1 == '=')) ttype = token_t::e_subass; 02832 | else if ((c0 == '*') && (c1 == '=')) ttype = token_t::e_mulass; 02833 | else if ((c0 == '/') && (c1 == '=')) ttype = token_t::e_divass; 02834 | else if ((c0 == '%') && (c1 == '=')) ttype = token_t::e_modass; 02835 | 02836 | if (token_t::e_none != ttype) 02837 | { 02838 | t.set_operator(ttype, s_itr_, s_itr_ + 2, base_itr_); 02839 | token_list_.push_back(t); 02840 | s_itr_ += 2; 02841 | return; 02842 | } 02843 | } 02844 | 02845 | if ('<' == c0) 02846 | t.set_operator(token_t::e_lt , s_itr_, s_itr_ + 1, base_itr_); 02847 | else if ('>' == c0) 02848 | t.set_operator(token_t::e_gt , s_itr_, s_itr_ + 1, base_itr_); 02849 | else if (';' == c0) 02850 | t.set_operator(token_t::e_eof, s_itr_, s_itr_ + 1, base_itr_); 02851 | else if ('&' == c0) 02852 | t.set_symbol(s_itr_, s_itr_ + 1, base_itr_); 02853 | else if ('|' == c0) 02854 | t.set_symbol(s_itr_, s_itr_ + 1, base_itr_); 02855 | else 02856 | t.set_operator(token_t::token_type(c0), s_itr_, s_itr_ + 1, base_itr_); 02857 | 02858 | token_list_.push_back(t); 02859 | ++s_itr_; 02860 | } 02861 | 02862 | inline void scan_symbol() 02863 | { 02864 | details::char_cptr initial_itr = s_itr_; 02865 | 02866 | while (!is_end(s_itr_)) 02867 | { 02868 | if (!details::is_letter_or_digit(*s_itr_) && ('_' != (*s_itr_))) 02869 | { 02870 | if ('.' != (*s_itr_)) 02871 | break; 02872 | /* 02873 | Permit symbols that contain a 'dot' 02874 | Allowed : abc.xyz, a123.xyz, abc.123, abc_.xyz a123_.xyz abc._123 02875 | Disallowed: .abc, abc.<white-space>, abc.<eof>, abc.<operator +,-,*,/...> 02876 | */ 02877 | if ( 02878 | (s_itr_ != initial_itr) && 02879 | !is_end(s_itr_ + 1) && 02880 | !details::is_letter_or_digit(*(s_itr_ + 1)) && 02881 | ('_' != (*(s_itr_ + 1))) 02882 | ) 02883 | break; 02884 | } 02885 | 02886 | ++s_itr_; 02887 | } 02888 | 02889 | token_t t; 02890 | t.set_symbol(initial_itr, s_itr_, base_itr_); 02891 | token_list_.push_back(t); 02892 | } 02893 | 02894 | inline void scan_number() 02895 | { 02896 | /* 02897 | Attempt to match a valid numeric value in one of the following formats: 02898 | (01) 123456 02899 | (02) 123456. 02900 | (03) 123.456 02901 | (04) 123.456e3 02902 | (05) 123.456E3 02903 | (06) 123.456e+3 02904 | (07) 123.456E+3 02905 | (08) 123.456e-3 02906 | (09) 123.456E-3 02907 | (00) .1234 02908 | (11) .1234e3 02909 | (12) .1234E+3 02910 | (13) .1234e+3 02911 | (14) .1234E-3 02912 | (15) .1234e-3 02913 | */ 02914 | 02915 | details::char_cptr initial_itr = s_itr_; 02916 | bool dot_found = false; 02917 | bool e_found = false; 02918 | bool post_e_sign_found = false; 02919 | bool post_e_digit_found = false; 02920 | token_t t; 02921 | 02922 | while (!is_end(s_itr_)) 02923 | { 02924 | if ('.' == (*s_itr_)) 02925 | { 02926 | if (dot_found) 02927 | { 02928 | t.set_error(token::e_err_number, initial_itr, s_itr_, base_itr_); 02929 | token_list_.push_back(t); 02930 | 02931 | return; 02932 | } 02933 | 02934 | dot_found = true; 02935 | ++s_itr_; 02936 | 02937 | continue; 02938 | } 02939 | else if ('e' == std::tolower(*s_itr_)) 02940 | { 02941 | const char_t& c = *(s_itr_ + 1); 02942 | 02943 | if (is_end(s_itr_ + 1)) 02944 | { 02945 | t.set_error(token::e_err_number, initial_itr, s_itr_, base_itr_); 02946 | token_list_.push_back(t); 02947 | 02948 | return; 02949 | } 02950 | else if ( 02951 | ('+' != c) && 02952 | ('-' != c) && 02953 | !details::is_digit(c) 02954 | ) 02955 | { 02956 | t.set_error(token::e_err_number, initial_itr, s_itr_, base_itr_); 02957 | token_list_.push_back(t); 02958 | 02959 | return; 02960 | } 02961 | 02962 | e_found = true; 02963 | ++s_itr_; 02964 | 02965 | continue; 02966 | } 02967 | else if (e_found && details::is_sign(*s_itr_) && !post_e_digit_found) 02968 | { 02969 | if (post_e_sign_found) 02970 | { 02971 | t.set_error(token::e_err_number, initial_itr, s_itr_, base_itr_); 02972 | token_list_.push_back(t); 02973 | 02974 | return; 02975 | } 02976 | 02977 | post_e_sign_found = true; 02978 | ++s_itr_; 02979 | 02980 | continue; 02981 | } 02982 | else if (e_found && details::is_digit(*s_itr_)) 02983 | { 02984 | post_e_digit_found = true; 02985 | ++s_itr_; 02986 | 02987 | continue; 02988 | } 02989 | else if (('.' != (*s_itr_)) && !details::is_digit(*s_itr_)) 02990 | break; 02991 | else 02992 | ++s_itr_; 02993 | } 02994 | 02995 | t.set_numeric(initial_itr, s_itr_, base_itr_); 02996 | token_list_.push_back(t); 02997 | 02998 | return; 02999 | } 03000 | 03001 | inline void scan_special_function() 03002 | { 03003 | details::char_cptr initial_itr = s_itr_; 03004 | token_t t; 03005 | 03006 | // $fdd(x,x,x) = at least 11 chars 03007 | if (std::distance(s_itr_,s_end_) < 11) 03008 | { 03009 | t.set_error( 03010 | token::e_err_sfunc, 03011 | initial_itr, std::min(initial_itr + 11, s_end_), 03012 | base_itr_); 03013 | token_list_.push_back(t); 03014 | 03015 | return; 03016 | } 03017 | 03018 | if ( 03019 | !(('$' == *s_itr_) && 03020 | (details::imatch ('f',*(s_itr_ + 1))) && 03021 | (details::is_digit(*(s_itr_ + 2))) && 03022 | (details::is_digit(*(s_itr_ + 3)))) 03023 | ) 03024 | { 03025 | t.set_error( 03026 | token::e_err_sfunc, 03027 | initial_itr, std::min(initial_itr + 4, s_end_), 03028 | base_itr_); 03029 | token_list_.push_back(t); 03030 | 03031 | return; 03032 | } 03033 | 03034 | s_itr_ += 4; // $fdd = 4chars 03035 | 03036 | t.set_symbol(initial_itr, s_itr_, base_itr_); 03037 | token_list_.push_back(t); 03038 | 03039 | return; 03040 | } 03041 | 03042 | #ifndef exprtk_disable_string_capabilities 03043 | inline void scan_string() 03044 | { 03045 | details::char_cptr initial_itr = s_itr_ + 1; 03046 | token_t t; 03047 | 03048 | if (std::distance(s_itr_,s_end_) < 2) 03049 | { 03050 | t.set_error(token::e_err_string, s_itr_, s_end_, base_itr_); 03051 | token_list_.push_back(t); 03052 | 03053 | return; 03054 | } 03055 | 03056 | ++s_itr_; 03057 | 03058 | bool escaped_found = false; 03059 | bool escaped = false; 03060 | 03061 | while (!is_end(s_itr_)) 03062 | { 03063 | if (!details::is_valid_string_char(*s_itr_)) 03064 | { 03065 | t.set_error(token::e_err_string, initial_itr, s_itr_, base_itr_); 03066 | token_list_.push_back(t); 03067 | 03068 | return; 03069 | } 03070 | else if (!escaped && ('\\' == *s_itr_)) 03071 | { 03072 | escaped_found = true; 03073 | escaped = true; 03074 | ++s_itr_; 03075 | 03076 | continue; 03077 | } 03078 | else if (!escaped) 03079 | { 03080 | if ('\'' == *s_itr_) 03081 | break; 03082 | } 03083 | else if (escaped) 03084 | { 03085 | if ( 03086 | !is_end(s_itr_) && ('0' == *(s_itr_)) && 03087 | ((s_itr_ + 4) <= s_end_) 03088 | ) 03089 | { 03090 | const bool x_separator = ('X' == std::toupper(*(s_itr_ + 1))); 03091 | 03092 | const bool both_digits = details::is_hex_digit(*(s_itr_ + 2)) && 03093 | details::is_hex_digit(*(s_itr_ + 3)) ; 03094 | 03095 | if (!(x_separator && both_digits)) 03096 | { 03097 | t.set_error(token::e_err_string, initial_itr, s_itr_, base_itr_); 03098 | token_list_.push_back(t); 03099 | 03100 | return; 03101 | } 03102 | else 03103 | s_itr_ += 3; 03104 | } 03105 | 03106 | escaped = false; 03107 | } 03108 | 03109 | ++s_itr_; 03110 | } 03111 | 03112 | if (is_end(s_itr_)) 03113 | { 03114 | t.set_error(token::e_err_string, initial_itr, s_itr_, base_itr_); 03115 | token_list_.push_back(t); 03116 | 03117 | return; 03118 | } 03119 | 03120 | if (!escaped_found) 03121 | t.set_string(initial_itr, s_itr_, base_itr_); 03122 | else 03123 | { 03124 | std::string parsed_string(initial_itr,s_itr_); 03125 | 03126 | if (!details::cleanup_escapes(parsed_string)) 03127 | { 03128 | t.set_error(token::e_err_string, initial_itr, s_itr_, base_itr_); 03129 | token_list_.push_back(t); 03130 | 03131 | return; 03132 | } 03133 | 03134 | t.set_string( 03135 | parsed_string, 03136 | static_cast<std::size_t>(std::distance(base_itr_,initial_itr))); 03137 | } 03138 | 03139 | token_list_.push_back(t); 03140 | ++s_itr_; 03141 | 03142 | return; 03143 | } 03144 | #endif 03145 | 03146 | private: 03147 | 03148 | token_list_t token_list_; 03149 | token_list_itr_t token_itr_; 03150 | token_list_itr_t store_token_itr_; 03151 | token_t eof_token_; 03152 | details::char_cptr base_itr_; 03153 | details::char_cptr s_itr_; 03154 | details::char_cptr s_end_; 03155 | 03156 | friend class token_scanner; 03157 | friend class token_modifier; 03158 | friend class token_inserter; 03159 | friend class token_joiner; 03160 | }; // class generator 03161 | 03162 | class helper_interface 03163 | { 03164 | public: 03165 | 03166 | virtual void init() { } 03167 | virtual void reset() { } 03168 | virtual bool result() { return true; } 03169 | virtual std::size_t process(generator&) { return 0; } 03170 | virtual ~helper_interface() { } 03171 | }; 03172 | 03173 | class token_scanner : public helper_interface 03174 | { 03175 | public: 03176 | 03177 | virtual ~token_scanner() exprtk_override 03178 | {} 03179 | 03180 | explicit token_scanner(const std::size_t& stride) 03181 | : stride_(stride) 03182 | { 03183 | if (stride > 4) 03184 | { 03185 | throw std::invalid_argument("token_scanner() - Invalid stride value"); 03186 | } 03187 | } 03188 | 03189 | inline std::size_t process(generator& g) exprtk_override 03190 | { 03191 | if (g.token_list_.size() >= stride_) 03192 | { 03193 | for (std::size_t i = 0; i < (g.token_list_.size() - stride_ + 1); ++i) 03194 | { 03195 | token t; 03196 | 03197 | switch (stride_) 03198 | { 03199 | case 1 : 03200 | { 03201 | const token& t0 = g.token_list_[i]; 03202 | 03203 | if (!operator()(t0)) 03204 | { 03205 | return 0; 03206 | } 03207 | } 03208 | break; 03209 | 03210 | case 2 : 03211 | { 03212 | const token& t0 = g.token_list_[i ]; 03213 | const token& t1 = g.token_list_[i + 1]; 03214 | 03215 | if (!operator()(t0, t1)) 03216 | { 03217 | return 0; 03218 | } 03219 | } 03220 | break; 03221 | 03222 | case 3 : 03223 | { 03224 | const token& t0 = g.token_list_[i ]; 03225 | const token& t1 = g.token_list_[i + 1]; 03226 | const token& t2 = g.token_list_[i + 2]; 03227 | 03228 | if (!operator()(t0, t1, t2)) 03229 | { 03230 | return 0; 03231 | } 03232 | } 03233 | break; 03234 | 03235 | case 4 : 03236 | { 03237 | const token& t0 = g.token_list_[i ]; 03238 | const token& t1 = g.token_list_[i + 1]; 03239 | const token& t2 = g.token_list_[i + 2]; 03240 | const token& t3 = g.token_list_[i + 3]; 03241 | 03242 | if (!operator()(t0, t1, t2, t3)) 03243 | { 03244 | return 0; 03245 | } 03246 | } 03247 | break; 03248 | 03249 | default: continue; 03250 | } 03251 | } 03252 | } 03253 | 03254 | return 0; 03255 | } 03256 | 03257 | virtual bool operator() (const token&) 03258 | { 03259 | return false; 03260 | } 03261 | 03262 | virtual bool operator() (const token&, const token&) 03263 | { 03264 | return false; 03265 | } 03266 | 03267 | virtual bool operator() (const token&, const token&, const token&) 03268 | { 03269 | return false; 03270 | } 03271 | 03272 | virtual bool operator() (const token&, const token&, const token&, const token&) 03273 | { 03274 | return false; 03275 | } 03276 | 03277 | private: 03278 | 03279 | const std::size_t stride_; 03280 | }; // class token_scanner 03281 | 03282 | class token_modifier : public helper_interface 03283 | { 03284 | public: 03285 | 03286 | inline std::size_t process(generator& g) exprtk_override 03287 | { 03288 | std::size_t changes = 0; 03289 | 03290 | for (std::size_t i = 0; i < g.token_list_.size(); ++i) 03291 | { 03292 | if (modify(g.token_list_[i])) changes++; 03293 | } 03294 | 03295 | return changes; 03296 | } 03297 | 03298 | virtual bool modify(token& t) = 0; 03299 | }; 03300 | 03301 | class token_inserter : public helper_interface 03302 | { 03303 | public: 03304 | 03305 | explicit token_inserter(const std::size_t& stride) 03306 | : stride_(stride) 03307 | { 03308 | if (stride > 5) 03309 | { 03310 | throw std::invalid_argument("token_inserter() - Invalid stride value"); 03311 | } 03312 | } 03313 | 03314 | inline std::size_t process(generator& g) exprtk_override 03315 | { 03316 | if (g.token_list_.empty()) 03317 | return 0; 03318 | else if (g.token_list_.size() < stride_) 03319 | return 0; 03320 | 03321 | std::size_t changes = 0; 03322 | 03323 | typedef std::pair<std::size_t, token> insert_t; 03324 | std::vector<insert_t> insert_list; 03325 | insert_list.reserve(10000); 03326 | 03327 | for (std::size_t i = 0; i < (g.token_list_.size() - stride_ + 1); ++i) 03328 | { 03329 | int insert_index = -1; 03330 | token t; 03331 | 03332 | switch (stride_) 03333 | { 03334 | case 1 : insert_index = insert(g.token_list_[i],t); 03335 | break; 03336 | 03337 | case 2 : insert_index = insert(g.token_list_[i], g.token_list_[i + 1], t); 03338 | break; 03339 | 03340 | case 3 : insert_index = insert(g.token_list_[i], g.token_list_[i + 1], g.token_list_[i + 2], t); 03341 | break; 03342 | 03343 | case 4 : insert_index = insert(g.token_list_[i], g.token_list_[i + 1], g.token_list_[i + 2], g.token_list_[i + 3], t); 03344 | break; 03345 | 03346 | case 5 : insert_index = insert(g.token_list_[i], g.token_list_[i + 1], g.token_list_[i + 2], g.token_list_[i + 3], g.token_list_[i + 4], t); 03347 | break; 03348 | } 03349 | 03350 | if ((insert_index >= 0) && (insert_index <= (static_cast<int>(stride_) + 1))) 03351 | { 03352 | insert_list.push_back(insert_t(i, t)); 03353 | changes++; 03354 | } 03355 | } 03356 | 03357 | if (!insert_list.empty()) 03358 | { 03359 | generator::token_list_t token_list; 03360 | 03361 | std::size_t insert_index = 0; 03362 | 03363 | for (std::size_t i = 0; i < g.token_list_.size(); ++i) 03364 | { 03365 | token_list.push_back(g.token_list_[i]); 03366 | 03367 | if ( 03368 | (insert_index < insert_list.size()) && 03369 | (insert_list[insert_index].first == i) 03370 | ) 03371 | { 03372 | token_list.push_back(insert_list[insert_index].second); 03373 | insert_index++; 03374 | } 03375 | } 03376 | 03377 | std::swap(g.token_list_,token_list); 03378 | } 03379 | 03380 | return changes; 03381 | } 03382 | 03383 | #define token_inserter_empty_body \ 03384 | { \ 03385 | return -1; \ 03386 | } \ 03387 | 03388 | inline virtual int insert(const token&, token&) 03389 | token_inserter_empty_body 03390 | 03391 | inline virtual int insert(const token&, const token&, token&) 03392 | token_inserter_empty_body 03393 | 03394 | inline virtual int insert(const token&, const token&, const token&, token&) 03395 | token_inserter_empty_body 03396 | 03397 | inline virtual int insert(const token&, const token&, const token&, const token&, token&) 03398 | token_inserter_empty_body 03399 | 03400 | inline virtual int insert(const token&, const token&, const token&, const token&, const token&, token&) 03401 | token_inserter_empty_body 03402 | 03403 | #undef token_inserter_empty_body 03404 | 03405 | private: 03406 | 03407 | const std::size_t stride_; 03408 | }; 03409 | 03410 | class token_joiner : public helper_interface 03411 | { 03412 | public: 03413 | 03414 | explicit token_joiner(const std::size_t& stride) 03415 | : stride_(stride) 03416 | {} 03417 | 03418 | inline std::size_t process(generator& g) exprtk_override 03419 | { 03420 | if (g.token_list_.empty()) 03421 | return 0; 03422 | 03423 | switch (stride_) 03424 | { 03425 | case 2 : return process_stride_2(g); 03426 | case 3 : return process_stride_3(g); 03427 | default : return 0; 03428 | } 03429 | } 03430 | 03431 | virtual bool join(const token&, const token&, token&) { return false; } 03432 | virtual bool join(const token&, const token&, const token&, token&) { return false; } 03433 | 03434 | private: 03435 | 03436 | inline std::size_t process_stride_2(generator& g) 03437 | { 03438 | if (g.token_list_.size() < 2) 03439 | return 0; 03440 | 03441 | std::size_t changes = 0; 03442 | 03443 | generator::token_list_t token_list; 03444 | token_list.reserve(10000); 03445 | 03446 | for (int i = 0; i < static_cast<int>(g.token_list_.size() - 1); ++i) 03447 | { 03448 | token t; 03449 | 03450 | for ( ; ; ) 03451 | { 03452 | if (!join(g[i], g[i + 1], t)) 03453 | { 03454 | token_list.push_back(g[i]); 03455 | break; 03456 | } 03457 | 03458 | token_list.push_back(t); 03459 | 03460 | ++changes; 03461 | 03462 | i += 2; 03463 | 03464 | if (static_cast<std::size_t>(i) >= (g.token_list_.size() - 1)) 03465 | break; 03466 | } 03467 | } 03468 | 03469 | token_list.push_back(g.token_list_.back()); 03470 | 03471 | assert(token_list.size() <= g.token_list_.size()); 03472 | 03473 | std::swap(token_list, g.token_list_); 03474 | 03475 | return changes; 03476 | } 03477 | 03478 | inline std::size_t process_stride_3(generator& g) 03479 | { 03480 | if (g.token_list_.size() < 3) 03481 | return 0; 03482 | 03483 | std::size_t changes = 0; 03484 | 03485 | generator::token_list_t token_list; 03486 | token_list.reserve(10000); 03487 | 03488 | for (int i = 0; i < static_cast<int>(g.token_list_.size() - 2); ++i) 03489 | { 03490 | token t; 03491 | 03492 | for ( ; ; ) 03493 | { 03494 | if (!join(g[i], g[i + 1], g[i + 2], t)) 03495 | { 03496 | token_list.push_back(g[i]); 03497 | break; 03498 | } 03499 | 03500 | token_list.push_back(t); 03501 | 03502 | ++changes; 03503 | 03504 | i += 3; 03505 | 03506 | if (static_cast<std::size_t>(i) >= (g.token_list_.size() - 2)) 03507 | break; 03508 | } 03509 | } 03510 | 03511 | token_list.push_back(*(g.token_list_.begin() + g.token_list_.size() - 2)); 03512 | token_list.push_back(*(g.token_list_.begin() + g.token_list_.size() - 1)); 03513 | 03514 | assert(token_list.size() <= g.token_list_.size()); 03515 | 03516 | std::swap(token_list, g.token_list_); 03517 | 03518 | return changes; 03519 | } 03520 | 03521 | const std::size_t stride_; 03522 | }; 03523 | 03524 | namespace helper 03525 | { 03526 | 03527 | inline void dump(const lexer::generator& generator) 03528 | { 03529 | for (std::size_t i = 0; i < generator.size(); ++i) 03530 | { 03531 | const lexer::token& t = generator[i]; 03532 | printf("Token[%02d] @ %03d %6s --> '%s'\n", 03533 | static_cast<int>(i), 03534 | static_cast<int>(t.position), 03535 | t.to_str(t.type).c_str(), 03536 | t.value.c_str()); 03537 | } 03538 | } 03539 | 03540 | class commutative_inserter : public lexer::token_inserter 03541 | { 03542 | public: 03543 | 03544 | using lexer::token_inserter::insert; 03545 | 03546 | commutative_inserter() 03547 | : lexer::token_inserter(2) 03548 | {} 03549 | 03550 | inline void ignore_symbol(const std::string& symbol) 03551 | { 03552 | ignore_set_.insert(symbol); 03553 | } 03554 | 03555 | inline int insert(const lexer::token& t0, const lexer::token& t1, lexer::token& new_token) exprtk_override 03556 | { 03557 | bool match = false; 03558 | new_token.type = lexer::token::e_mul; 03559 | new_token.value = "*" 03560 | new_token.position = t1.position; 03561 | 03562 | if (t0.type == lexer::token::e_symbol) 03563 | { 03564 | if (ignore_set_.end() != ignore_set_.find(t0.value)) 03565 | { 03566 | return -1; 03567 | } 03568 | else if (!t0.value.empty() && ('$' == t0.value[0])) 03569 | { 03570 | return -1; 03571 | } 03572 | } 03573 | 03574 | if (t1.type == lexer::token::e_symbol) 03575 | { 03576 | if (ignore_set_.end() != ignore_set_.find(t1.value)) 03577 | { 03578 | return -1; 03579 | } 03580 | } 03581 | if ((t0.type == lexer::token::e_number ) && (t1.type == lexer::token::e_symbol )) match = true; 03582 | else if ((t0.type == lexer::token::e_number ) && (t1.type == lexer::token::e_lbracket )) match = true; 03583 | else if ((t0.type == lexer::token::e_number ) && (t1.type == lexer::token::e_lcrlbracket)) match = true; 03584 | else if ((t0.type == lexer::token::e_number ) && (t1.type == lexer::token::e_lsqrbracket)) match = true; 03585 | else if ((t0.type == lexer::token::e_symbol ) && (t1.type == lexer::token::e_number )) match = true; 03586 | else if ((t0.type == lexer::token::e_rbracket ) && (t1.type == lexer::token::e_number )) match = true; 03587 | else if ((t0.type == lexer::token::e_rcrlbracket) && (t1.type == lexer::token::e_number )) match = true; 03588 | else if ((t0.type == lexer::token::e_rsqrbracket) && (t1.type == lexer::token::e_number )) match = true; 03589 | else if ((t0.type == lexer::token::e_rbracket ) && (t1.type == lexer::token::e_symbol )) match = true; 03590 | else if ((t0.type == lexer::token::e_rcrlbracket) && (t1.type == lexer::token::e_symbol )) match = true; 03591 | else if ((t0.type == lexer::token::e_rsqrbracket) && (t1.type == lexer::token::e_symbol )) match = true; 03592 | else if ((t0.type == lexer::token::e_symbol ) && (t1.type == lexer::token::e_symbol )) match = true; 03593 | 03594 | return (match) ? 1 : -1; 03595 | } 03596 | 03597 | private: 03598 | 03599 | std::set<std::string,details::ilesscompare> ignore_set_; 03600 | }; 03601 | 03602 | class operator_joiner exprtk_final : public token_joiner 03603 | { 03604 | public: 03605 | 03606 | explicit operator_joiner(const std::size_t& stride) 03607 | : token_joiner(stride) 03608 | {} 03609 | 03610 | inline bool join(const lexer::token& t0, const lexer::token& t1, lexer::token& t) exprtk_override 03611 | { 03612 | // ': =' --> ':=' 03613 | if ((t0.type == lexer::token::e_colon) && (t1.type == lexer::token::e_eq)) 03614 | { 03615 | t.type = lexer::token::e_assign; 03616 | t.value = ":=" 03617 | t.position = t0.position; 03618 | 03619 | return true; 03620 | } 03621 | // '+ =' --> '+=' 03622 | else if ((t0.type == lexer::token::e_add) && (t1.type == lexer::token::e_eq)) 03623 | { 03624 | t.type = lexer::token::e_addass; 03625 | t.value = "+=" 03626 | t.position = t0.position; 03627 | 03628 | return true; 03629 | } 03630 | // '- =' --> '-=' 03631 | else if ((t0.type == lexer::token::e_sub) && (t1.type == lexer::token::e_eq)) 03632 | { 03633 | t.type = lexer::token::e_subass; 03634 | t.value = "-=" 03635 | t.position = t0.position; 03636 | 03637 | return true; 03638 | } 03639 | // '* =' --> '*=' 03640 | else if ((t0.type == lexer::token::e_mul) && (t1.type == lexer::token::e_eq)) 03641 | { 03642 | t.type = lexer::token::e_mulass; 03643 | t.value = "*=" 03644 | t.position = t0.position; 03645 | 03646 | return true; 03647 | } 03648 | // '/ =' --> '/=' 03649 | else if ((t0.type == lexer::token::e_div) && (t1.type == lexer::token::e_eq)) 03650 | { 03651 | t.type = lexer::token::e_divass; 03652 | t.value = "/=" 03653 | t.position = t0.position; 03654 | 03655 | return true; 03656 | } 03657 | // '% =' --> '%=' 03658 | else if ((t0.type == lexer::token::e_mod) && (t1.type == lexer::token::e_eq)) 03659 | { 03660 | t.type = lexer::token::e_modass; 03661 | t.value = "%=" 03662 | t.position = t0.position; 03663 | 03664 | return true; 03665 | } 03666 | // '> =' --> '>=' 03667 | else if ((t0.type == lexer::token::e_gt) && (t1.type == lexer::token::e_eq)) 03668 | { 03669 | t.type = lexer::token::e_gte; 03670 | t.value = ">=" 03671 | t.position = t0.position; 03672 | 03673 | return true; 03674 | } 03675 | // '< =' --> '<=' 03676 | else if ((t0.type == lexer::token::e_lt) && (t1.type == lexer::token::e_eq)) 03677 | { 03678 | t.type = lexer::token::e_lte; 03679 | t.value = "<=" 03680 | t.position = t0.position; 03681 | 03682 | return true; 03683 | } 03684 | // '= =' --> '==' 03685 | else if ((t0.type == lexer::token::e_eq) && (t1.type == lexer::token::e_eq)) 03686 | { 03687 | t.type = lexer::token::e_eq; 03688 | t.value = "==" 03689 | t.position = t0.position; 03690 | 03691 | return true; 03692 | } 03693 | // '! =' --> '!=' 03694 | else if ((static_cast<details::char_t>(t0.type) == '!') && (t1.type == lexer::token::e_eq)) 03695 | { 03696 | t.type = lexer::token::e_ne; 03697 | t.value = "!=" 03698 | t.position = t0.position; 03699 | 03700 | return true; 03701 | } 03702 | // '< >' --> '<>' 03703 | else if ((t0.type == lexer::token::e_lt) && (t1.type == lexer::token::e_gt)) 03704 | { 03705 | t.type = lexer::token::e_ne; 03706 | t.value = "<>" 03707 | t.position = t0.position; 03708 | 03709 | return true; 03710 | } 03711 | // '<= >' --> '<=>' 03712 | else if ((t0.type == lexer::token::e_lte) && (t1.type == lexer::token::e_gt)) 03713 | { 03714 | t.type = lexer::token::e_swap; 03715 | t.value = "<=>" 03716 | t.position = t0.position; 03717 | 03718 | return true; 03719 | } 03720 | // '+ -' --> '-' 03721 | else if ((t0.type == lexer::token::e_add) && (t1.type == lexer::token::e_sub)) 03722 | { 03723 | t.type = lexer::token::e_sub; 03724 | t.value = "-" 03725 | t.position = t0.position; 03726 | 03727 | return true; 03728 | } 03729 | // '- +' --> '-' 03730 | else if ((t0.type == lexer::token::e_sub) && (t1.type == lexer::token::e_add)) 03731 | { 03732 | t.type = lexer::token::e_sub; 03733 | t.value = "-" 03734 | t.position = t0.position; 03735 | 03736 | return true; 03737 | } 03738 | // '- -' --> '+' 03739 | else if ((t0.type == lexer::token::e_sub) && (t1.type == lexer::token::e_sub)) 03740 | { 03741 | /* 03742 | Note: May need to reconsider this when wanting to implement 03743 | pre/postfix decrement operator 03744 | */ 03745 | t.type = lexer::token::e_add; 03746 | t.value = "+" 03747 | t.position = t0.position; 03748 | 03749 | return true; 03750 | } 03751 | else 03752 | return false; 03753 | } 03754 | 03755 | inline bool join(const lexer::token& t0, 03756 | const lexer::token& t1, 03757 | const lexer::token& t2, 03758 | lexer::token& t) exprtk_override 03759 | { 03760 | // '[ * ]' --> '[*]' 03761 | if ( 03762 | (t0.type == lexer::token::e_lsqrbracket) && 03763 | (t1.type == lexer::token::e_mul ) && 03764 | (t2.type == lexer::token::e_rsqrbracket) 03765 | ) 03766 | { 03767 | t.type = lexer::token::e_symbol; 03768 | t.value = "[*]" 03769 | t.position = t0.position; 03770 | 03771 | return true; 03772 | } 03773 | else 03774 | return false; 03775 | } 03776 | }; 03777 | 03778 | class bracket_checker exprtk_final : public lexer::token_scanner 03779 | { 03780 | public: 03781 | 03782 | using lexer::token_scanner::operator(); 03783 | 03784 | bracket_checker() 03785 | : token_scanner(1) 03786 | , state_(true) 03787 | {} 03788 | 03789 | bool result() exprtk_override 03790 | { 03791 | if (!stack_.empty()) 03792 | { 03793 | lexer::token t; 03794 | t.value = stack_.top().first; 03795 | t.position = stack_.top().second; 03796 | error_token_ = t; 03797 | state_ = false; 03798 | 03799 | return false; 03800 | } 03801 | else 03802 | return state_; 03803 | } 03804 | 03805 | lexer::token error_token() const 03806 | { 03807 | return error_token_; 03808 | } 03809 | 03810 | void reset() exprtk_override 03811 | { 03812 | // Why? because msvc doesn't support swap properly. 03813 | stack_ = std::stack<std::pair<char,std::size_t> >(); 03814 | state_ = true; 03815 | error_token_.clear(); 03816 | } 03817 | 03818 | bool operator() (const lexer::token& t) exprtk_override 03819 | { 03820 | if ( 03821 | !t.value.empty() && 03822 | (lexer::token::e_string != t.type) && 03823 | (lexer::token::e_symbol != t.type) && 03824 | exprtk::details::is_bracket(t.value[0]) 03825 | ) 03826 | { 03827 | details::char_t c = t.value[0]; 03828 | 03829 | if (t.type == lexer::token::e_lbracket ) stack_.push(std::make_pair(')',t.position)); 03830 | else if (t.type == lexer::token::e_lcrlbracket) stack_.push(std::make_pair('}',t.position)); 03831 | else if (t.type == lexer::token::e_lsqrbracket) stack_.push(std::make_pair(']',t.position)); 03832 | else if (exprtk::details::is_right_bracket(c)) 03833 | { 03834 | if (stack_.empty()) 03835 | { 03836 | state_ = false; 03837 | error_token_ = t; 03838 | 03839 | return false; 03840 | } 03841 | else if (c != stack_.top().first) 03842 | { 03843 | state_ = false; 03844 | error_token_ = t; 03845 | 03846 | return false; 03847 | } 03848 | else 03849 | stack_.pop(); 03850 | } 03851 | } 03852 | 03853 | return true; 03854 | } 03855 | 03856 | private: 03857 | 03858 | bool state_; 03859 | std::stack<std::pair<char,std::size_t> > stack_; 03860 | lexer::token error_token_; 03861 | }; 03862 | 03863 | template <typename T> 03864 | class numeric_checker exprtk_final : public lexer::token_scanner 03865 | { 03866 | public: 03867 | 03868 | using lexer::token_scanner::operator(); 03869 | 03870 | numeric_checker() 03871 | : token_scanner (1) 03872 | , current_index_(0) 03873 | {} 03874 | 03875 | bool result() exprtk_override 03876 | { 03877 | return error_list_.empty(); 03878 | } 03879 | 03880 | void reset() exprtk_override 03881 | { 03882 | error_list_.clear(); 03883 | current_index_ = 0; 03884 | } 03885 | 03886 | bool operator() (const lexer::token& t) exprtk_override 03887 | { 03888 | if (token::e_number == t.type) 03889 | { 03890 | T v; 03891 | 03892 | if (!exprtk::details::string_to_real(t.value,v)) 03893 | { 03894 | error_list_.push_back(current_index_); 03895 | } 03896 | } 03897 | 03898 | ++current_index_; 03899 | 03900 | return true; 03901 | } 03902 | 03903 | std::size_t error_count() const 03904 | { 03905 | return error_list_.size(); 03906 | } 03907 | 03908 | std::size_t error_index(const std::size_t& i) const 03909 | { 03910 | if (i < error_list_.size()) 03911 | return error_list_[i]; 03912 | else 03913 | return std::numeric_limits<std::size_t>::max(); 03914 | } 03915 | 03916 | void clear_errors() 03917 | { 03918 | error_list_.clear(); 03919 | } 03920 | 03921 | private: 03922 | 03923 | std::size_t current_index_; 03924 | std::vector<std::size_t> error_list_; 03925 | }; 03926 | 03927 | class symbol_replacer exprtk_final : public lexer::token_modifier 03928 | { 03929 | private: 03930 | 03931 | typedef std::map<std::string,std::pair<std::string,token::token_type>,details::ilesscompare> replace_map_t; 03932 | 03933 | public: 03934 | 03935 | bool remove(const std::string& target_symbol) 03936 | { 03937 | const replace_map_t::iterator itr = replace_map_.find(target_symbol); 03938 | 03939 | if (replace_map_.end() == itr) 03940 | return false; 03941 | 03942 | replace_map_.erase(itr); 03943 | 03944 | return true; 03945 | } 03946 | 03947 | bool add_replace(const std::string& target_symbol, 03948 | const std::string& replace_symbol, 03949 | const lexer::token::token_type token_type = lexer::token::e_symbol) 03950 | { 03951 | const replace_map_t::iterator itr = replace_map_.find(target_symbol); 03952 | 03953 | if (replace_map_.end() != itr) 03954 | { 03955 | return false; 03956 | } 03957 | 03958 | replace_map_[target_symbol] = std::make_pair(replace_symbol,token_type); 03959 | 03960 | return true; 03961 | } 03962 | 03963 | void clear() 03964 | { 03965 | replace_map_.clear(); 03966 | } 03967 | 03968 | private: 03969 | 03970 | bool modify(lexer::token& t) exprtk_override 03971 | { 03972 | if (lexer::token::e_symbol == t.type) 03973 | { 03974 | if (replace_map_.empty()) 03975 | return false; 03976 | 03977 | const replace_map_t::iterator itr = replace_map_.find(t.value); 03978 | 03979 | if (replace_map_.end() != itr) 03980 | { 03981 | t.value = itr->second.first; 03982 | t.type = itr->second.second; 03983 | 03984 | return true; 03985 | } 03986 | } 03987 | 03988 | return false; 03989 | } 03990 | 03991 | replace_map_t replace_map_; 03992 | }; 03993 | 03994 | class sequence_validator exprtk_final : public lexer::token_scanner 03995 | { 03996 | private: 03997 | 03998 | typedef std::pair<lexer::token::token_type,lexer::token::token_type> token_pair_t; 03999 | typedef std::set<token_pair_t> set_t; 04000 | 04001 | public: 04002 | 04003 | using lexer::token_scanner::operator(); 04004 | 04005 | sequence_validator() 04006 | : lexer::token_scanner(2) 04007 | { 04008 | add_invalid(lexer::token::e_number, lexer::token::e_number); 04009 | add_invalid(lexer::token::e_string, lexer::token::e_string); 04010 | add_invalid(lexer::token::e_number, lexer::token::e_string); 04011 | add_invalid(lexer::token::e_string, lexer::token::e_number); 04012 | 04013 | add_invalid_set1(lexer::token::e_assign ); 04014 | add_invalid_set1(lexer::token::e_shr ); 04015 | add_invalid_set1(lexer::token::e_shl ); 04016 | add_invalid_set1(lexer::token::e_lte ); 04017 | add_invalid_set1(lexer::token::e_ne ); 04018 | add_invalid_set1(lexer::token::e_gte ); 04019 | add_invalid_set1(lexer::token::e_lt ); 04020 | add_invalid_set1(lexer::token::e_gt ); 04021 | add_invalid_set1(lexer::token::e_eq ); 04022 | add_invalid_set1(lexer::token::e_comma ); 04023 | add_invalid_set1(lexer::token::e_add ); 04024 | add_invalid_set1(lexer::token::e_sub ); 04025 | add_invalid_set1(lexer::token::e_div ); 04026 | add_invalid_set1(lexer::token::e_mul ); 04027 | add_invalid_set1(lexer::token::e_mod ); 04028 | add_invalid_set1(lexer::token::e_pow ); 04029 | add_invalid_set1(lexer::token::e_colon ); 04030 | add_invalid_set1(lexer::token::e_ternary); 04031 | } 04032 | 04033 | bool result() exprtk_override 04034 | { 04035 | return error_list_.empty(); 04036 | } 04037 | 04038 | bool operator() (const lexer::token& t0, const lexer::token& t1) exprtk_override 04039 | { 04040 | const set_t::value_type p = std::make_pair(t0.type,t1.type); 04041 | 04042 | if (invalid_bracket_check(t0.type,t1.type)) 04043 | { 04044 | error_list_.push_back(std::make_pair(t0,t1)); 04045 | } 04046 | else if (invalid_comb_.find(p) != invalid_comb_.end()) 04047 | { 04048 | error_list_.push_back(std::make_pair(t0,t1)); 04049 | } 04050 | 04051 | return true; 04052 | } 04053 | 04054 | std::size_t error_count() const 04055 | { 04056 | return error_list_.size(); 04057 | } 04058 | 04059 | std::pair<lexer::token,lexer::token> error(const std::size_t index) 04060 | { 04061 | if (index < error_list_.size()) 04062 | { 04063 | return error_list_[index]; 04064 | } 04065 | else 04066 | { 04067 | static const lexer::token error_token; 04068 | return std::make_pair(error_token,error_token); 04069 | } 04070 | } 04071 | 04072 | void clear_errors() 04073 | { 04074 | error_list_.clear(); 04075 | } 04076 | 04077 | private: 04078 | 04079 | void add_invalid(const lexer::token::token_type base, const lexer::token::token_type t) 04080 | { 04081 | invalid_comb_.insert(std::make_pair(base,t)); 04082 | } 04083 | 04084 | void add_invalid_set1(const lexer::token::token_type t) 04085 | { 04086 | add_invalid(t, lexer::token::e_assign); 04087 | add_invalid(t, lexer::token::e_shr ); 04088 | add_invalid(t, lexer::token::e_shl ); 04089 | add_invalid(t, lexer::token::e_lte ); 04090 | add_invalid(t, lexer::token::e_ne ); 04091 | add_invalid(t, lexer::token::e_gte ); 04092 | add_invalid(t, lexer::token::e_lt ); 04093 | add_invalid(t, lexer::token::e_gt ); 04094 | add_invalid(t, lexer::token::e_eq ); 04095 | add_invalid(t, lexer::token::e_comma ); 04096 | add_invalid(t, lexer::token::e_div ); 04097 | add_invalid(t, lexer::token::e_mul ); 04098 | add_invalid(t, lexer::token::e_mod ); 04099 | add_invalid(t, lexer::token::e_pow ); 04100 | add_invalid(t, lexer::token::e_colon ); 04101 | } 04102 | 04103 | bool invalid_bracket_check(const lexer::token::token_type base, const lexer::token::token_type t) 04104 | { 04105 | if (details::is_right_bracket(static_cast<details::char_t>(base))) 04106 | { 04107 | switch (t) 04108 | { 04109 | case lexer::token::e_assign : return (']' != base); 04110 | case lexer::token::e_string : return (')' != base); 04111 | default : return false; 04112 | } 04113 | } 04114 | else if (details::is_left_bracket(static_cast<details::char_t>(base))) 04115 | { 04116 | if (details::is_right_bracket(static_cast<details::char_t>(t))) 04117 | return false; 04118 | else if (details::is_left_bracket(static_cast<details::char_t>(t))) 04119 | return false; 04120 | else 04121 | { 04122 | switch (t) 04123 | { 04124 | case lexer::token::e_number : return false; 04125 | case lexer::token::e_symbol : return false; 04126 | case lexer::token::e_string : return false; 04127 | case lexer::token::e_add : return false; 04128 | case lexer::token::e_sub : return false; 04129 | case lexer::token::e_colon : return false; 04130 | case lexer::token::e_ternary : return false; 04131 | default : return true ; 04132 | } 04133 | } 04134 | } 04135 | else if (details::is_right_bracket(static_cast<details::char_t>(t))) 04136 | { 04137 | switch (base) 04138 | { 04139 | case lexer::token::e_number : return false; 04140 | case lexer::token::e_symbol : return false; 04141 | case lexer::token::e_string : return false; 04142 | case lexer::token::e_eof : return false; 04143 | case lexer::token::e_colon : return false; 04144 | case lexer::token::e_ternary : return false; 04145 | default : return true ; 04146 | } 04147 | } 04148 | else if (details::is_left_bracket(static_cast<details::char_t>(t))) 04149 | { 04150 | switch (base) 04151 | { 04152 | case lexer::token::e_rbracket : return true; 04153 | case lexer::token::e_rsqrbracket : return true; 04154 | case lexer::token::e_rcrlbracket : return true; 04155 | default : return false; 04156 | } 04157 | } 04158 | 04159 | return false; 04160 | } 04161 | 04162 | set_t invalid_comb_; 04163 | std::vector<std::pair<lexer::token,lexer::token> > error_list_; 04164 | }; 04165 | 04166 | class sequence_validator_3tokens exprtk_final : public lexer::token_scanner 04167 | { 04168 | private: 04169 | 04170 | typedef lexer::token::token_type token_t; 04171 | typedef std::pair<token_t,std::pair<token_t,token_t> > token_triplet_t; 04172 | typedef std::set<token_triplet_t> set_t; 04173 | 04174 | public: 04175 | 04176 | using lexer::token_scanner::operator(); 04177 | 04178 | sequence_validator_3tokens() 04179 | : lexer::token_scanner(3) 04180 | { 04181 | add_invalid(lexer::token::e_number , lexer::token::e_number , lexer::token::e_number); 04182 | add_invalid(lexer::token::e_string , lexer::token::e_string , lexer::token::e_string); 04183 | add_invalid(lexer::token::e_comma , lexer::token::e_comma , lexer::token::e_comma ); 04184 | 04185 | add_invalid(lexer::token::e_add , lexer::token::e_add , lexer::token::e_add ); 04186 | add_invalid(lexer::token::e_sub , lexer::token::e_sub , lexer::token::e_sub ); 04187 | add_invalid(lexer::token::e_div , lexer::token::e_div , lexer::token::e_div ); 04188 | add_invalid(lexer::token::e_mul , lexer::token::e_mul , lexer::token::e_mul ); 04189 | add_invalid(lexer::token::e_mod , lexer::token::e_mod , lexer::token::e_mod ); 04190 | add_invalid(lexer::token::e_pow , lexer::token::e_pow , lexer::token::e_pow ); 04191 | 04192 | add_invalid(lexer::token::e_add , lexer::token::e_sub , lexer::token::e_add ); 04193 | add_invalid(lexer::token::e_sub , lexer::token::e_add , lexer::token::e_sub ); 04194 | add_invalid(lexer::token::e_div , lexer::token::e_mul , lexer::token::e_div ); 04195 | add_invalid(lexer::token::e_mul , lexer::token::e_div , lexer::token::e_mul ); 04196 | add_invalid(lexer::token::e_mod , lexer::token::e_pow , lexer::token::e_mod ); 04197 | add_invalid(lexer::token::e_pow , lexer::token::e_mod , lexer::token::e_pow ); 04198 | } 04199 | 04200 | bool result() exprtk_override 04201 | { 04202 | return error_list_.empty(); 04203 | } 04204 | 04205 | bool operator() (const lexer::token& t0, const lexer::token& t1, const lexer::token& t2) exprtk_override 04206 | { 04207 | const set_t::value_type p = std::make_pair(t0.type,std::make_pair(t1.type,t2.type)); 04208 | 04209 | if (invalid_comb_.find(p) != invalid_comb_.end()) 04210 | { 04211 | error_list_.push_back(std::make_pair(t0,t1)); 04212 | } 04213 | 04214 | return true; 04215 | } 04216 | 04217 | std::size_t error_count() const 04218 | { 04219 | return error_list_.size(); 04220 | } 04221 | 04222 | std::pair<lexer::token,lexer::token> error(const std::size_t index) 04223 | { 04224 | if (index < error_list_.size()) 04225 | { 04226 | return error_list_[index]; 04227 | } 04228 | else 04229 | { 04230 | static const lexer::token error_token; 04231 | return std::make_pair(error_token,error_token); 04232 | } 04233 | } 04234 | 04235 | void clear_errors() 04236 | { 04237 | error_list_.clear(); 04238 | } 04239 | 04240 | private: 04241 | 04242 | void add_invalid(const token_t t0, const token_t t1, const token_t t2) 04243 | { 04244 | invalid_comb_.insert(std::make_pair(t0,std::make_pair(t1,t2))); 04245 | } 04246 | 04247 | set_t invalid_comb_; 04248 | std::vector<std::pair<lexer::token,lexer::token> > error_list_; 04249 | }; 04250 | 04251 | struct helper_assembly 04252 | { 04253 | inline bool register_scanner(lexer::token_scanner* scanner) 04254 | { 04255 | if (token_scanner_list.end() != std::find(token_scanner_list.begin(), 04256 | token_scanner_list.end (), 04257 | scanner)) 04258 | { 04259 | return false; 04260 | } 04261 | 04262 | token_scanner_list.push_back(scanner); 04263 | 04264 | return true; 04265 | } 04266 | 04267 | inline bool register_modifier(lexer::token_modifier* modifier) 04268 | { 04269 | if (token_modifier_list.end() != std::find(token_modifier_list.begin(), 04270 | token_modifier_list.end (), 04271 | modifier)) 04272 | { 04273 | return false; 04274 | } 04275 | 04276 | token_modifier_list.push_back(modifier); 04277 | 04278 | return true; 04279 | } 04280 | 04281 | inline bool register_joiner(lexer::token_joiner* joiner) 04282 | { 04283 | if (token_joiner_list.end() != std::find(token_joiner_list.begin(), 04284 | token_joiner_list.end (), 04285 | joiner)) 04286 | { 04287 | return false; 04288 | } 04289 | 04290 | token_joiner_list.push_back(joiner); 04291 | 04292 | return true; 04293 | } 04294 | 04295 | inline bool register_inserter(lexer::token_inserter* inserter) 04296 | { 04297 | if (token_inserter_list.end() != std::find(token_inserter_list.begin(), 04298 | token_inserter_list.end (), 04299 | inserter)) 04300 | { 04301 | return false; 04302 | } 04303 | 04304 | token_inserter_list.push_back(inserter); 04305 | 04306 | return true; 04307 | } 04308 | 04309 | inline bool run_modifiers(lexer::generator& g) 04310 | { 04311 | error_token_modifier = reinterpret_cast<lexer::token_modifier*>(0); 04312 | 04313 | for (std::size_t i = 0; i < token_modifier_list.size(); ++i) 04314 | { 04315 | lexer::token_modifier& modifier = (*token_modifier_list[i]); 04316 | 04317 | modifier.reset(); 04318 | modifier.process(g); 04319 | 04320 | if (!modifier.result()) 04321 | { 04322 | error_token_modifier = token_modifier_list[i]; 04323 | 04324 | return false; 04325 | } 04326 | } 04327 | 04328 | return true; 04329 | } 04330 | 04331 | inline bool run_joiners(lexer::generator& g) 04332 | { 04333 | error_token_joiner = reinterpret_cast<lexer::token_joiner*>(0); 04334 | 04335 | for (std::size_t i = 0; i < token_joiner_list.size(); ++i) 04336 | { 04337 | lexer::token_joiner& joiner = (*token_joiner_list[i]); 04338 | 04339 | joiner.reset(); 04340 | joiner.process(g); 04341 | 04342 | if (!joiner.result()) 04343 | { 04344 | error_token_joiner = token_joiner_list[i]; 04345 | 04346 | return false; 04347 | } 04348 | } 04349 | 04350 | return true; 04351 | } 04352 | 04353 | inline bool run_inserters(lexer::generator& g) 04354 | { 04355 | error_token_inserter = reinterpret_cast<lexer::token_inserter*>(0); 04356 | 04357 | for (std::size_t i = 0; i < token_inserter_list.size(); ++i) 04358 | { 04359 | lexer::token_inserter& inserter = (*token_inserter_list[i]); 04360 | 04361 | inserter.reset(); 04362 | inserter.process(g); 04363 | 04364 | if (!inserter.result()) 04365 | { 04366 | error_token_inserter = token_inserter_list[i]; 04367 | 04368 | return false; 04369 | } 04370 | } 04371 | 04372 | return true; 04373 | } 04374 | 04375 | inline bool run_scanners(lexer::generator& g) 04376 | { 04377 | error_token_scanner = reinterpret_cast<lexer::token_scanner*>(0); 04378 | 04379 | for (std::size_t i = 0; i < token_scanner_list.size(); ++i) 04380 | { 04381 | lexer::token_scanner& scanner = (*token_scanner_list[i]); 04382 | 04383 | scanner.reset(); 04384 | scanner.process(g); 04385 | 04386 | if (!scanner.result()) 04387 | { 04388 | error_token_scanner = token_scanner_list[i]; 04389 | 04390 | return false; 04391 | } 04392 | } 04393 | 04394 | return true; 04395 | } 04396 | 04397 | std::vector<lexer::token_scanner*> token_scanner_list; 04398 | std::vector<lexer::token_modifier*> token_modifier_list; 04399 | std::vector<lexer::token_joiner*> token_joiner_list; 04400 | std::vector<lexer::token_inserter*> token_inserter_list; 04401 | 04402 | lexer::token_scanner* error_token_scanner; 04403 | lexer::token_modifier* error_token_modifier; 04404 | lexer::token_joiner* error_token_joiner; 04405 | lexer::token_inserter* error_token_inserter; 04406 | }; 04407 | } 04408 | 04409 | class parser_helper 04410 | { 04411 | public: 04412 | 04413 | typedef token token_t; 04414 | typedef generator generator_t; 04415 | 04416 | inline bool init(const std::string& str) 04417 | { 04418 | if (!lexer_.process(str)) 04419 | { 04420 | return false; 04421 | } 04422 | 04423 | lexer_.begin(); 04424 | 04425 | next_token(); 04426 | 04427 | return true; 04428 | } 04429 | 04430 | inline generator_t& lexer() 04431 | { 04432 | return lexer_; 04433 | } 04434 | 04435 | inline const generator_t& lexer() const 04436 | { 04437 | return lexer_; 04438 | } 04439 | 04440 | inline void store_token() 04441 | { 04442 | lexer_.store(); 04443 | store_current_token_ = current_token_; 04444 | } 04445 | 04446 | inline void restore_token() 04447 | { 04448 | lexer_.restore(); 04449 | current_token_ = store_current_token_; 04450 | } 04451 | 04452 | inline void next_token() 04453 | { 04454 | current_token_ = lexer_.next_token(); 04455 | } 04456 | 04457 | inline const token_t& current_token() const 04458 | { 04459 | return current_token_; 04460 | } 04461 | 04462 | inline const token_t& peek_next_token() 04463 | { 04464 | return lexer_.peek_next_token(); 04465 | } 04466 | 04467 | enum token_advance_mode 04468 | { 04469 | e_hold = 0, 04470 | e_advance = 1 04471 | }; 04472 | 04473 | inline void advance_token(const token_advance_mode mode) 04474 | { 04475 | if (e_advance == mode) 04476 | { 04477 | next_token(); 04478 | } 04479 | } 04480 | 04481 | inline bool token_is(const token_t::token_type& ttype, const token_advance_mode mode = e_advance) 04482 | { 04483 | if (current_token().type != ttype) 04484 | { 04485 | return false; 04486 | } 04487 | 04488 | advance_token(mode); 04489 | 04490 | return true; 04491 | } 04492 | 04493 | inline bool token_is(const token_t::token_type& ttype, 04494 | const std::string& value, 04495 | const token_advance_mode mode = e_advance) 04496 | { 04497 | if ( 04498 | (current_token().type != ttype) || 04499 | !exprtk::details::imatch(value,current_token().value) 04500 | ) 04501 | { 04502 | return false; 04503 | } 04504 | 04505 | advance_token(mode); 04506 | 04507 | return true; 04508 | } 04509 | 04510 | inline bool token_is(const std::string& value, 04511 | const token_advance_mode mode = e_advance) 04512 | { 04513 | if (!exprtk::details::imatch(value,current_token().value)) 04514 | { 04515 | return false; 04516 | } 04517 | 04518 | advance_token(mode); 04519 | 04520 | return true; 04521 | } 04522 | 04523 | inline bool token_is_arithmetic_opr(const token_advance_mode mode = e_advance) 04524 | { 04525 | switch (current_token().type) 04526 | { 04527 | case token_t::e_add : 04528 | case token_t::e_sub : 04529 | case token_t::e_div : 04530 | case token_t::e_mul : 04531 | case token_t::e_mod : 04532 | case token_t::e_pow : break; 04533 | default : return false; 04534 | } 04535 | 04536 | advance_token(mode); 04537 | 04538 | return true; 04539 | } 04540 | 04541 | inline bool token_is_ineq_opr(const token_advance_mode mode = e_advance) 04542 | { 04543 | switch (current_token().type) 04544 | { 04545 | case token_t::e_eq : 04546 | case token_t::e_lte : 04547 | case token_t::e_ne : 04548 | case token_t::e_gte : 04549 | case token_t::e_lt : 04550 | case token_t::e_gt : break; 04551 | default : return false; 04552 | } 04553 | 04554 | advance_token(mode); 04555 | 04556 | return true; 04557 | } 04558 | 04559 | inline bool token_is_left_bracket(const token_advance_mode mode = e_advance) 04560 | { 04561 | switch (current_token().type) 04562 | { 04563 | case token_t::e_lbracket : 04564 | case token_t::e_lcrlbracket : 04565 | case token_t::e_lsqrbracket : break; 04566 | default : return false; 04567 | } 04568 | 04569 | advance_token(mode); 04570 | 04571 | return true; 04572 | } 04573 | 04574 | inline bool token_is_right_bracket(const token_advance_mode mode = e_advance) 04575 | { 04576 | switch (current_token().type) 04577 | { 04578 | case token_t::e_rbracket : 04579 | case token_t::e_rcrlbracket : 04580 | case token_t::e_rsqrbracket : break; 04581 | default : return false; 04582 | } 04583 | 04584 | advance_token(mode); 04585 | 04586 | return true; 04587 | } 04588 | 04589 | inline bool token_is_bracket(const token_advance_mode mode = e_advance) 04590 | { 04591 | switch (current_token().type) 04592 | { 04593 | case token_t::e_rbracket : 04594 | case token_t::e_rcrlbracket : 04595 | case token_t::e_rsqrbracket : 04596 | case token_t::e_lbracket : 04597 | case token_t::e_lcrlbracket : 04598 | case token_t::e_lsqrbracket : break; 04599 | default : return false; 04600 | } 04601 | 04602 | advance_token(mode); 04603 | 04604 | return true; 04605 | } 04606 | 04607 | inline bool token_is_loop(const token_advance_mode mode = e_advance) 04608 | { 04609 | return token_is("for" , mode) || 04610 | token_is("while" , mode) || 04611 | token_is("repeat", mode) ; 04612 | } 04613 | 04614 | inline bool peek_token_is(const token_t::token_type& ttype) 04615 | { 04616 | return (lexer_.peek_next_token().type == ttype); 04617 | } 04618 | 04619 | inline bool peek_token_is(const std::string& s) 04620 | { 04621 | return (exprtk::details::imatch(lexer_.peek_next_token().value,s)); 04622 | } 04623 | 04624 | private: 04625 | 04626 | generator_t lexer_; 04627 | token_t current_token_; 04628 | token_t store_current_token_; 04629 | }; 04630 | } 04631 | 04632 | template <typename T> 04633 | class vector_view 04634 | { 04635 | public: 04636 | 04637 | typedef T* data_ptr_t; 04638 | 04639 | vector_view(data_ptr_t data, const std::size_t& size) 04640 | : base_size_(size) 04641 | , size_(size) 04642 | , data_(data) 04643 | , data_ref_(0) 04644 | { 04645 | assert(size_ > 0); 04646 | } 04647 | 04648 | vector_view(const vector_view<T>& vv) 04649 | : base_size_(vv.base_size_) 04650 | , size_(vv.size_) 04651 | , data_(vv.data_) 04652 | , data_ref_(0) 04653 | { 04654 | assert(size_ > 0); 04655 | } 04656 | 04657 | inline void rebase(data_ptr_t data) 04658 | { 04659 | data_ = data; 04660 | 04661 | if (!data_ref_.empty()) 04662 | { 04663 | for (std::size_t i = 0; i < data_ref_.size(); ++i) 04664 | { 04665 | (*data_ref_[i]) = data; 04666 | } 04667 | } 04668 | } 04669 | 04670 | inline data_ptr_t data() const 04671 | { 04672 | return data_; 04673 | } 04674 | 04675 | inline std::size_t base_size() const 04676 | { 04677 | return base_size_; 04678 | } 04679 | 04680 | inline std::size_t size() const 04681 | { 04682 | return size_; 04683 | } 04684 | 04685 | inline const T& operator[](const std::size_t index) const 04686 | { 04687 | assert(index < size_); 04688 | return data_[index]; 04689 | } 04690 | 04691 | inline T& operator[](const std::size_t index) 04692 | { 04693 | assert(index < size_); 04694 | return data_[index]; 04695 | } 04696 | 04697 | void set_ref(data_ptr_t* data_ref) 04698 | { 04699 | data_ref_.push_back(data_ref); 04700 | exprtk_debug(("vector_view::set_ref() - data_ref: %p data_ref_.size(): %d\n", 04701 | reinterpret_cast<void*>(data_ref), 04702 | static_cast<int>(data_ref_.size()))); 04703 | } 04704 | 04705 | void set_size_ref(std::size_t* size_ref) 04706 | { 04707 | size_ref_.push_back(size_ref); 04708 | exprtk_debug(("vector_view::set_size_ref() - size_ref: %p size_ref_.size(): %d\n", 04709 | reinterpret_cast<void*>(size_ref), 04710 | static_cast<int>(size_ref_.size()))); 04711 | } 04712 | 04713 | void remove_ref(data_ptr_t* data_ref) 04714 | { 04715 | data_ref_.erase( 04716 | std::remove(data_ref_.begin(), data_ref_.end(), data_ref), 04717 | data_ref_.end()); 04718 | exprtk_debug(("vector_view::remove_ref() - data_ref: %p data_ref_.size(): %d\n", 04719 | reinterpret_cast<void*>(data_ref), 04720 | static_cast<int>(data_ref_.size()))); 04721 | } 04722 | 04723 | void remove_size_ref(std::size_t* size_ref) 04724 | { 04725 | size_ref_.erase( 04726 | std::remove(size_ref_.begin(), size_ref_.end(), size_ref), 04727 | size_ref_.end()); 04728 | exprtk_debug(("vector_view::remove_size_ref() - size_ref: %p size_ref_.size(): %d\n", 04729 | reinterpret_cast<void*>(size_ref), 04730 | static_cast<int>(size_ref_.size()))); 04731 | } 04732 | 04733 | bool set_size(const std::size_t new_size) 04734 | { 04735 | if ((new_size > 0) && (new_size <= base_size_)) 04736 | { 04737 | size_ = new_size; 04738 | exprtk_debug(("vector_view::set_size() - data_: %p size: %lu\n", 04739 | reinterpret_cast<void*>(data_), 04740 | size_)); 04741 | 04742 | if (!size_ref_.empty()) 04743 | { 04744 | for (std::size_t i = 0; i < size_ref_.size(); ++i) 04745 | { 04746 | (*size_ref_[i]) = new_size; 04747 | } 04748 | } 04749 | 04750 | return true; 04751 | } 04752 | 04753 | exprtk_debug(("vector_view::set_size() - error invalid new_size: %lu base_size: %lu\n", 04754 | new_size, 04755 | base_size_)); 04756 | return false; 04757 | } 04758 | 04759 | private: 04760 | 04761 | const std::size_t base_size_; 04762 | std::size_t size_; 04763 | data_ptr_t data_; 04764 | std::vector<data_ptr_t*> data_ref_; 04765 | std::vector<std::size_t*> size_ref_; 04766 | }; 04767 | 04768 | template <typename T> 04769 | inline vector_view<T> make_vector_view(T* data, 04770 | const std::size_t size, const std::size_t offset = 0) 04771 | { 04772 | return vector_view<T>(data + offset, size); 04773 | } 04774 | 04775 | template <typename T> 04776 | inline vector_view<T> make_vector_view(std::vector<T>& v, 04777 | const std::size_t size, const std::size_t offset = 0) 04778 | { 04779 | return vector_view<T>(v.data() + offset, size); 04780 | } 04781 | 04782 | template <typename T> class results_context; 04783 | namespace details { template <typename T> class vector_interface; } 04784 | 04785 | template <typename T> 04786 | struct type_store 04787 | { 04788 | enum store_type 04789 | { 04790 | e_unknown, 04791 | e_scalar , 04792 | e_vector , 04793 | e_string 04794 | }; 04795 | 04796 | type_store() 04797 | : data(0) 04798 | , size(0) 04799 | , type(e_unknown) 04800 | , ivec(0) 04801 | {} 04802 | 04803 | union 04804 | { 04805 | void* data; 04806 | T* vec_data; 04807 | }; 04808 | 04809 | typedef details::vector_interface<T>* ivec_t; 04810 | 04811 | std::size_t size; 04812 | store_type type; 04813 | ivec_t ivec; 04814 | 04815 | class parameter_list 04816 | { 04817 | public: 04818 | 04819 | explicit parameter_list(std::vector<type_store>& pl) 04820 | : parameter_list_(pl) 04821 | {} 04822 | 04823 | inline bool empty() const 04824 | { 04825 | return parameter_list_.empty(); 04826 | } 04827 | 04828 | inline std::size_t size() const 04829 | { 04830 | return parameter_list_.size(); 04831 | } 04832 | 04833 | inline type_store& operator[](const std::size_t& index) 04834 | { 04835 | return parameter_list_[index]; 04836 | } 04837 | 04838 | inline const type_store& operator[](const std::size_t& index) const 04839 | { 04840 | return parameter_list_[index]; 04841 | } 04842 | 04843 | inline type_store& front() 04844 | { 04845 | return parameter_list_[0]; 04846 | } 04847 | 04848 | inline const type_store& front() const 04849 | { 04850 | return parameter_list_[0]; 04851 | } 04852 | 04853 | inline type_store& back() 04854 | { 04855 | return parameter_list_.back(); 04856 | } 04857 | 04858 | inline const type_store& back() const 04859 | { 04860 | return parameter_list_.back(); 04861 | } 04862 | 04863 | inline typename std::vector<type_store>::const_iterator begin() const 04864 | { 04865 | return parameter_list_.begin(); 04866 | } 04867 | 04868 | inline typename std::vector<type_store>::const_iterator end() const 04869 | { 04870 | return parameter_list_.end(); 04871 | } 04872 | 04873 | inline typename std::vector<type_store>::iterator begin() 04874 | { 04875 | return parameter_list_.begin(); 04876 | } 04877 | 04878 | inline typename std::vector<type_store>::iterator end() 04879 | { 04880 | return parameter_list_.end(); 04881 | } 04882 | 04883 | private: 04884 | 04885 | std::vector<type_store>& parameter_list_; 04886 | 04887 | friend class results_context<T>; 04888 | }; 04889 | 04890 | template <typename ViewType> 04891 | struct type_view 04892 | { 04893 | typedef type_store<T> type_store_t; 04894 | typedef ViewType value_t; 04895 | 04896 | explicit type_view(type_store_t& ts) 04897 | : ts_(ts) 04898 | , data_(reinterpret_cast<value_t*>(ts_.data)) 04899 | {} 04900 | 04901 | explicit type_view(const type_store_t& ts) 04902 | : ts_(const_cast<type_store_t&>(ts)) 04903 | , data_(reinterpret_cast<value_t*>(ts_.data)) 04904 | {} 04905 | 04906 | inline std::size_t size() const 04907 | { 04908 | return ts_.size; 04909 | } 04910 | 04911 | inline value_t& operator[](const std::size_t& i) 04912 | { 04913 | return data_[i]; 04914 | } 04915 | 04916 | inline const value_t& operator[](const std::size_t& i) const 04917 | { 04918 | return data_[i]; 04919 | } 04920 | 04921 | inline const value_t* begin() const { return data_; } 04922 | inline value_t* begin() { return data_; } 04923 | 04924 | inline const value_t* end() const 04925 | { 04926 | return static_cast<value_t*>(data_ + ts_.size); 04927 | } 04928 | 04929 | inline value_t* end() 04930 | { 04931 | return static_cast<value_t*>(data_ + ts_.size); 04932 | } 04933 | 04934 | type_store_t& ts_; 04935 | value_t* data_; 04936 | }; 04937 | 04938 | typedef type_view<T> vector_view; 04939 | typedef type_view<char> string_view; 04940 | 04941 | struct scalar_view 04942 | { 04943 | typedef type_store<T> type_store_t; 04944 | typedef T value_t; 04945 | 04946 | explicit scalar_view(type_store_t& ts) 04947 | : v_(*reinterpret_cast<value_t*>(ts.data)) 04948 | {} 04949 | 04950 | explicit scalar_view(const type_store_t& ts) 04951 | : v_(*reinterpret_cast<value_t*>(const_cast<type_store_t&>(ts).data)) 04952 | {} 04953 | 04954 | inline value_t& operator() () 04955 | { 04956 | return v_; 04957 | } 04958 | 04959 | inline const value_t& operator() () const 04960 | { 04961 | return v_; 04962 | } 04963 | 04964 | inline operator value_t() const 04965 | { 04966 | return v_; 04967 | } 04968 | 04969 | inline operator value_t() 04970 | { 04971 | return v_; 04972 | } 04973 | 04974 | template <typename IntType> 04975 | inline bool to_int(IntType& i) const 04976 | { 04977 | if (!exprtk::details::numeric::is_integer(v_)) 04978 | return false; 04979 | 04980 | i = static_cast<IntType>(v_); 04981 | 04982 | return true; 04983 | } 04984 | 04985 | template <typename UIntType> 04986 | inline bool to_uint(UIntType& u) const 04987 | { 04988 | if (v_ < T(0)) 04989 | return false; 04990 | else if (!exprtk::details::numeric::is_integer(v_)) 04991 | return false; 04992 | 04993 | u = static_cast<UIntType>(v_); 04994 | 04995 | return true; 04996 | } 04997 | 04998 | T& v_; 04999 | }; 05000 | }; 05001 | 05002 | template <typename StringView> 05003 | inline std::string to_str(const StringView& view) 05004 | { 05005 | return std::string(view.begin(),view.size()); 05006 | } 05007 | 05008 | #ifndef exprtk_disable_return_statement 05009 | namespace details 05010 | { 05011 | template <typename T> class return_node; 05012 | template <typename T> class return_envelope_node; 05013 | } 05014 | #endif 05015 | 05016 | template <typename T> 05017 | class results_context 05018 | { 05019 | public: 05020 | 05021 | typedef type_store<T> type_store_t; 05022 | typedef typename type_store_t::scalar_view scalar_t; 05023 | typedef typename type_store_t::vector_view vector_t; 05024 | typedef typename type_store_t::string_view string_t; 05025 | 05026 | results_context() 05027 | : results_available_(false) 05028 | {} 05029 | 05030 | inline std::size_t count() const 05031 | { 05032 | if (results_available_) 05033 | return parameter_list_.size(); 05034 | else 05035 | return 0; 05036 | } 05037 | 05038 | inline type_store_t& operator[](const std::size_t& index) 05039 | { 05040 | return parameter_list_[index]; 05041 | } 05042 | 05043 | inline const type_store_t& operator[](const std::size_t& index) const 05044 | { 05045 | return parameter_list_[index]; 05046 | } 05047 | 05048 | inline bool get_scalar(const std::size_t& index, T& out) const 05049 | { 05050 | if ( 05051 | (index < parameter_list_.size()) && 05052 | (parameter_list_[index].type == type_store_t::e_scalar) 05053 | ) 05054 | { 05055 | const scalar_t scalar(parameter_list_[index]); 05056 | out = scalar(); 05057 | return true; 05058 | } 05059 | 05060 | return false; 05061 | } 05062 | 05063 | template <typename OutputIterator> 05064 | inline bool get_vector(const std::size_t& index, OutputIterator out_itr) const 05065 | { 05066 | if ( 05067 | (index < parameter_list_.size()) && 05068 | (parameter_list_[index].type == type_store_t::e_vector) 05069 | ) 05070 | { 05071 | const vector_t vector(parameter_list_[index]); 05072 | for (std::size_t i = 0; i < vector.size(); ++i) 05073 | { 05074 | *(out_itr++) = vector[i]; 05075 | } 05076 | 05077 | return true; 05078 | } 05079 | 05080 | return false; 05081 | } 05082 | 05083 | inline bool get_vector(const std::size_t& index, std::vector<T>& out) const 05084 | { 05085 | return get_vector(index,std::back_inserter(out)); 05086 | } 05087 | 05088 | inline bool get_string(const std::size_t& index, std::string& out) const 05089 | { 05090 | if ( 05091 | (index < parameter_list_.size()) && 05092 | (parameter_list_[index].type == type_store_t::e_string) 05093 | ) 05094 | { 05095 | const string_t str(parameter_list_[index]); 05096 | out.assign(str.begin(),str.size()); 05097 | return true; 05098 | } 05099 | 05100 | return false; 05101 | } 05102 | 05103 | private: 05104 | 05105 | inline void clear() 05106 | { 05107 | results_available_ = false; 05108 | } 05109 | 05110 | typedef std::vector<type_store_t> ts_list_t; 05111 | typedef typename type_store_t::parameter_list parameter_list_t; 05112 | 05113 | inline void assign(const parameter_list_t& pl) 05114 | { 05115 | parameter_list_ = pl.parameter_list_; 05116 | results_available_ = true; 05117 | } 05118 | 05119 | bool results_available_; 05120 | ts_list_t parameter_list_; 05121 | 05122 | #ifndef exprtk_disable_return_statement 05123 | friend class details::return_node<T>; 05124 | friend class details::return_envelope_node<T>; 05125 | #endif 05126 | }; 05127 | 05128 | namespace details 05129 | { 05130 | enum operator_type 05131 | { 05132 | e_default , e_null , e_add , e_sub , 05133 | e_mul , e_div , e_mod , e_pow , 05134 | e_atan2 , e_min , e_max , e_avg , 05135 | e_sum , e_prod , e_lt , e_lte , 05136 | e_eq , e_equal , e_ne , e_nequal , 05137 | e_gte , e_gt , e_and , e_nand , 05138 | e_or , e_nor , e_xor , e_xnor , 05139 | e_mand , e_mor , e_scand , e_scor , 05140 | e_shr , e_shl , e_abs , e_acos , 05141 | e_acosh , e_asin , e_asinh , e_atan , 05142 | e_atanh , e_ceil , e_cos , e_cosh , 05143 | e_exp , e_expm1 , e_floor , e_log , 05144 | e_log10 , e_log2 , e_log1p , e_logn , 05145 | e_neg , e_pos , e_round , e_roundn , 05146 | e_root , e_sqrt , e_sin , e_sinc , 05147 | e_sinh , e_sec , e_csc , e_tan , 05148 | e_tanh , e_cot , e_clamp , e_iclamp , 05149 | e_inrange , e_sgn , e_r2d , e_d2r , 05150 | e_d2g , e_g2d , e_hypot , e_notl , 05151 | e_erf , e_erfc , e_ncdf , e_frac , 05152 | e_trunc , e_assign , e_addass , e_subass , 05153 | e_mulass , e_divass , e_modass , e_in , 05154 | e_like , e_ilike , e_multi , e_smulti , 05155 | e_swap , 05156 | 05157 | // Do not add new functions/operators after this point. 05158 | e_sf00 = 1000, e_sf01 = 1001, e_sf02 = 1002, e_sf03 = 1003, 05159 | e_sf04 = 1004, e_sf05 = 1005, e_sf06 = 1006, e_sf07 = 1007, 05160 | e_sf08 = 1008, e_sf09 = 1009, e_sf10 = 1010, e_sf11 = 1011, 05161 | e_sf12 = 1012, e_sf13 = 1013, e_sf14 = 1014, e_sf15 = 1015, 05162 | e_sf16 = 1016, e_sf17 = 1017, e_sf18 = 1018, e_sf19 = 1019, 05163 | e_sf20 = 1020, e_sf21 = 1021, e_sf22 = 1022, e_sf23 = 1023, 05164 | e_sf24 = 1024, e_sf25 = 1025, e_sf26 = 1026, e_sf27 = 1027, 05165 | e_sf28 = 1028, e_sf29 = 1029, e_sf30 = 1030, e_sf31 = 1031, 05166 | e_sf32 = 1032, e_sf33 = 1033, e_sf34 = 1034, e_sf35 = 1035, 05167 | e_sf36 = 1036, e_sf37 = 1037, e_sf38 = 1038, e_sf39 = 1039, 05168 | e_sf40 = 1040, e_sf41 = 1041, e_sf42 = 1042, e_sf43 = 1043, 05169 | e_sf44 = 1044, e_sf45 = 1045, e_sf46 = 1046, e_sf47 = 1047, 05170 | e_sf48 = 1048, e_sf49 = 1049, e_sf50 = 1050, e_sf51 = 1051, 05171 | e_sf52 = 1052, e_sf53 = 1053, e_sf54 = 1054, e_sf55 = 1055, 05172 | e_sf56 = 1056, e_sf57 = 1057, e_sf58 = 1058, e_sf59 = 1059, 05173 | e_sf60 = 1060, e_sf61 = 1061, e_sf62 = 1062, e_sf63 = 1063, 05174 | e_sf64 = 1064, e_sf65 = 1065, e_sf66 = 1066, e_sf67 = 1067, 05175 | e_sf68 = 1068, e_sf69 = 1069, e_sf70 = 1070, e_sf71 = 1071, 05176 | e_sf72 = 1072, e_sf73 = 1073, e_sf74 = 1074, e_sf75 = 1075, 05177 | e_sf76 = 1076, e_sf77 = 1077, e_sf78 = 1078, e_sf79 = 1079, 05178 | e_sf80 = 1080, e_sf81 = 1081, e_sf82 = 1082, e_sf83 = 1083, 05179 | e_sf84 = 1084, e_sf85 = 1085, e_sf86 = 1086, e_sf87 = 1087, 05180 | e_sf88 = 1088, e_sf89 = 1089, e_sf90 = 1090, e_sf91 = 1091, 05181 | e_sf92 = 1092, e_sf93 = 1093, e_sf94 = 1094, e_sf95 = 1095, 05182 | e_sf96 = 1096, e_sf97 = 1097, e_sf98 = 1098, e_sf99 = 1099, 05183 | e_sffinal = 1100, 05184 | e_sf4ext00 = 2000, e_sf4ext01 = 2001, e_sf4ext02 = 2002, e_sf4ext03 = 2003, 05185 | e_sf4ext04 = 2004, e_sf4ext05 = 2005, e_sf4ext06 = 2006, e_sf4ext07 = 2007, 05186 | e_sf4ext08 = 2008, e_sf4ext09 = 2009, e_sf4ext10 = 2010, e_sf4ext11 = 2011, 05187 | e_sf4ext12 = 2012, e_sf4ext13 = 2013, e_sf4ext14 = 2014, e_sf4ext15 = 2015, 05188 | e_sf4ext16 = 2016, e_sf4ext17 = 2017, e_sf4ext18 = 2018, e_sf4ext19 = 2019, 05189 | e_sf4ext20 = 2020, e_sf4ext21 = 2021, e_sf4ext22 = 2022, e_sf4ext23 = 2023, 05190 | e_sf4ext24 = 2024, e_sf4ext25 = 2025, e_sf4ext26 = 2026, e_sf4ext27 = 2027, 05191 | e_sf4ext28 = 2028, e_sf4ext29 = 2029, e_sf4ext30 = 2030, e_sf4ext31 = 2031, 05192 | e_sf4ext32 = 2032, e_sf4ext33 = 2033, e_sf4ext34 = 2034, e_sf4ext35 = 2035, 05193 | e_sf4ext36 = 2036, e_sf4ext37 = 2037, e_sf4ext38 = 2038, e_sf4ext39 = 2039, 05194 | e_sf4ext40 = 2040, e_sf4ext41 = 2041, e_sf4ext42 = 2042, e_sf4ext43 = 2043, 05195 | e_sf4ext44 = 2044, e_sf4ext45 = 2045, e_sf4ext46 = 2046, e_sf4ext47 = 2047, 05196 | e_sf4ext48 = 2048, e_sf4ext49 = 2049, e_sf4ext50 = 2050, e_sf4ext51 = 2051, 05197 | e_sf4ext52 = 2052, e_sf4ext53 = 2053, e_sf4ext54 = 2054, e_sf4ext55 = 2055, 05198 | e_sf4ext56 = 2056, e_sf4ext57 = 2057, e_sf4ext58 = 2058, e_sf4ext59 = 2059, 05199 | e_sf4ext60 = 2060, e_sf4ext61 = 2061 05200 | }; 05201 | 05202 | inline std::string to_str(const operator_type opr) 05203 | { 05204 | switch (opr) 05205 | { 05206 | case e_add : return "+" ; 05207 | case e_sub : return "-" ; 05208 | case e_mul : return "*" ; 05209 | case e_div : return "/" ; 05210 | case e_mod : return "%" ; 05211 | case e_pow : return "^" ; 05212 | case e_assign : return ":=" ; 05213 | case e_addass : return "+=" ; 05214 | case e_subass : return "-=" ; 05215 | case e_mulass : return "*=" ; 05216 | case e_divass : return "/=" ; 05217 | case e_modass : return "%=" ; 05218 | case e_lt : return "<" ; 05219 | case e_lte : return "<=" ; 05220 | case e_eq : return "==" ; 05221 | case e_equal : return "=" ; 05222 | case e_ne : return "!=" ; 05223 | case e_nequal : return "<>" ; 05224 | case e_gte : return ">=" ; 05225 | case e_gt : return ">" ; 05226 | case e_and : return "and" ; 05227 | case e_or : return "or" ; 05228 | case e_xor : return "xor" ; 05229 | case e_nand : return "nand" 05230 | case e_nor : return "nor" ; 05231 | case e_xnor : return "xnor" 05232 | default : return "N/A" ; 05233 | } 05234 | } 05235 | 05236 | struct base_operation_t 05237 | { 05238 | base_operation_t(const operator_type t, const unsigned int& np) 05239 | : type(t) 05240 | , num_params(np) 05241 | {} 05242 | 05243 | operator_type type; 05244 | unsigned int num_params; 05245 | }; 05246 | 05247 | namespace loop_unroll 05248 | { 05249 | const unsigned int global_loop_batch_size = 05250 | #ifndef exprtk_disable_superscalar_unroll 05251 | 16; 05252 | #else 05253 | 4; 05254 | #endif 05255 | 05256 | struct details 05257 | { 05258 | explicit details(const std::size_t& vsize, 05259 | const unsigned int loop_batch_size = global_loop_batch_size) 05260 | : batch_size(loop_batch_size ) 05261 | , remainder (vsize % batch_size) 05262 | , upper_bound(static_cast<int>(vsize - (remainder ? loop_batch_size : 0))) 05263 | {} 05264 | 05265 | unsigned int batch_size; 05266 | int remainder; 05267 | int upper_bound; 05268 | }; 05269 | } 05270 | 05271 | #ifdef exprtk_enable_debugging 05272 | inline void dump_ptr(const std::string& s, const void* ptr, const std::size_t size = 0) 05273 | { 05274 | if (size) 05275 | exprtk_debug(("%s - addr: %p size: %d\n", 05276 | s.c_str(), 05277 | ptr, 05278 | static_cast<unsigned int>(size))); 05279 | else 05280 | exprtk_debug(("%s - addr: %p\n", s.c_str(), ptr)); 05281 | } 05282 | 05283 | template <typename T> 05284 | inline void dump_vector(const std::string& vec_name, const T* data, const std::size_t size) 05285 | { 05286 | printf("----- %s (%p) -----\n", 05287 | vec_name.c_str(), 05288 | static_cast<const void*>(data)); 05289 | printf("[ "); 05290 | for (std::size_t i = 0; i < size; ++i) 05291 | { 05292 | printf("%8.3f\t", data[i]); 05293 | } 05294 | printf(" ]\n"); 05295 | printf("---------------------\n"); 05296 | } 05297 | #else 05298 | inline void dump_ptr(const std::string&, const void*) {} 05299 | inline void dump_ptr(const std::string&, const void*, const std::size_t) {} 05300 | template <typename T> 05301 | inline void dump_vector(const std::string&, const T*, const std::size_t) {} 05302 | #endif 05303 | 05304 | template <typename T> 05305 | class vec_data_store 05306 | { 05307 | public: 05308 | 05309 | typedef vec_data_store<T> type; 05310 | typedef T* data_t; 05311 | 05312 | private: 05313 | 05314 | struct control_block 05315 | { 05316 | control_block() 05317 | : ref_count(1) 05318 | , size (0) 05319 | , data (0) 05320 | , destruct (true) 05321 | {} 05322 | 05323 | explicit control_block(const std::size_t& dsize) 05324 | : ref_count(1 ) 05325 | , size (dsize) 05326 | , data (0 ) 05327 | , destruct (true ) 05328 | { create_data(); } 05329 | 05330 | control_block(const std::size_t& dsize, data_t dptr, bool dstrct = false) 05331 | : ref_count(1 ) 05332 | , size (dsize ) 05333 | , data (dptr ) 05334 | , destruct (dstrct) 05335 | {} 05336 | 05337 | ~control_block() 05338 | { 05339 | if (data && destruct && (0 == ref_count)) 05340 | { 05341 | dump_ptr("~vec_data_store::control_block() data",data); 05342 | delete[] data; 05343 | data = reinterpret_cast<data_t>(0); 05344 | } 05345 | } 05346 | 05347 | static inline control_block* create(const std::size_t& dsize, data_t data_ptr = data_t(0), bool dstrct = false) 05348 | { 05349 | if (dsize) 05350 | { 05351 | if (0 == data_ptr) 05352 | return (new control_block(dsize)); 05353 | else 05354 | return (new control_block(dsize, data_ptr, dstrct)); 05355 | } 05356 | else 05357 | return (new control_block); 05358 | } 05359 | 05360 | static inline void destroy(control_block*& cntrl_blck) 05361 | { 05362 | if (cntrl_blck) 05363 | { 05364 | if ( 05365 | (0 != cntrl_blck->ref_count) && 05366 | (0 == --cntrl_blck->ref_count) 05367 | ) 05368 | { 05369 | delete cntrl_blck; 05370 | } 05371 | 05372 | cntrl_blck = 0; 05373 | } 05374 | } 05375 | 05376 | std::size_t ref_count; 05377 | std::size_t size; 05378 | data_t data; 05379 | bool destruct; 05380 | 05381 | private: 05382 | 05383 | control_block(const control_block&) exprtk_delete; 05384 | control_block& operator=(const control_block&) exprtk_delete; 05385 | 05386 | inline void create_data() 05387 | { 05388 | destruct = true; 05389 | data = new T[size]; 05390 | std::fill_n(data, size, T(0)); 05391 | dump_ptr("control_block::create_data() - data", data, size); 05392 | } 05393 | }; 05394 | 05395 | public: 05396 | 05397 | vec_data_store() 05398 | : control_block_(control_block::create(0)) 05399 | {} 05400 | 05401 | explicit vec_data_store(const std::size_t& size) 05402 | : control_block_(control_block::create(size,reinterpret_cast<data_t>(0),true)) 05403 | {} 05404 | 05405 | vec_data_store(const std::size_t& size, data_t data, bool dstrct = false) 05406 | : control_block_(control_block::create(size, data, dstrct)) 05407 | {} 05408 | 05409 | vec_data_store(const type& vds) 05410 | { 05411 | control_block_ = vds.control_block_; 05412 | control_block_->ref_count++; 05413 | } 05414 | 05415 | ~vec_data_store() 05416 | { 05417 | control_block::destroy(control_block_); 05418 | } 05419 | 05420 | type& operator=(const type& vds) 05421 | { 05422 | if (this != &vds) 05423 | { 05424 | const std::size_t final_size = min_size(control_block_, vds.control_block_); 05425 | 05426 | vds.control_block_->size = final_size; 05427 | control_block_->size = final_size; 05428 | 05429 | if (control_block_->destruct || (0 == control_block_->data)) 05430 | { 05431 | control_block::destroy(control_block_); 05432 | 05433 | control_block_ = vds.control_block_; 05434 | control_block_->ref_count++; 05435 | } 05436 | } 05437 | 05438 | return (*this); 05439 | } 05440 | 05441 | inline data_t data() 05442 | { 05443 | return control_block_->data; 05444 | } 05445 | 05446 | inline data_t data() const 05447 | { 05448 | return control_block_->data; 05449 | } 05450 | 05451 | inline std::size_t size() const 05452 | { 05453 | return control_block_->size; 05454 | } 05455 | 05456 | inline data_t& ref() 05457 | { 05458 | return control_block_->data; 05459 | } 05460 | 05461 | inline void dump() const 05462 | { 05463 | #ifdef exprtk_enable_debugging 05464 | exprtk_debug(("size: %d\taddress:%p\tdestruct:%c\n", 05465 | size(), 05466 | data(), 05467 | (control_block_->destruct ? 'T' : 'F'))); 05468 | 05469 | for (std::size_t i = 0; i < size(); ++i) 05470 | { 05471 | if (5 == i) 05472 | exprtk_debug(("\n")); 05473 | 05474 | exprtk_debug(("%15.10f ", data()[i])); 05475 | } 05476 | exprtk_debug(("\n")); 05477 | #endif 05478 | } 05479 | 05480 | static inline void match_sizes(type& vds0, type& vds1) 05481 | { 05482 | const std::size_t size = min_size(vds0.control_block_,vds1.control_block_); 05483 | vds0.control_block_->size = size; 05484 | vds1.control_block_->size = size; 05485 | } 05486 | 05487 | private: 05488 | 05489 | static inline std::size_t min_size(const control_block* cb0, const control_block* cb1) 05490 | { 05491 | const std::size_t size0 = cb0->size; 05492 | const std::size_t size1 = cb1->size; 05493 | 05494 | if (size0 && size1) 05495 | return std::min(size0,size1); 05496 | else 05497 | return (size0) ? size0 : size1; 05498 | } 05499 | 05500 | control_block* control_block_; 05501 | }; 05502 | 05503 | namespace numeric 05504 | { 05505 | namespace details 05506 | { 05507 | template <typename T> 05508 | inline T process_impl(const operator_type operation, const T arg) 05509 | { 05510 | switch (operation) 05511 | { 05512 | case e_abs : return numeric::abs (arg); 05513 | case e_acos : return numeric::acos (arg); 05514 | case e_acosh : return numeric::acosh(arg); 05515 | case e_asin : return numeric::asin (arg); 05516 | case e_asinh : return numeric::asinh(arg); 05517 | case e_atan : return numeric::atan (arg); 05518 | case e_atanh : return numeric::atanh(arg); 05519 | case e_ceil : return numeric::ceil (arg); 05520 | case e_cos : return numeric::cos (arg); 05521 | case e_cosh : return numeric::cosh (arg); 05522 | case e_exp : return numeric::exp (arg); 05523 | case e_expm1 : return numeric::expm1(arg); 05524 | case e_floor : return numeric::floor(arg); 05525 | case e_log : return numeric::log (arg); 05526 | case e_log10 : return numeric::log10(arg); 05527 | case e_log2 : return numeric::log2 (arg); 05528 | case e_log1p : return numeric::log1p(arg); 05529 | case e_neg : return numeric::neg (arg); 05530 | case e_pos : return numeric::pos (arg); 05531 | case e_round : return numeric::round(arg); 05532 | case e_sin : return numeric::sin (arg); 05533 | case e_sinc : return numeric::sinc (arg); 05534 | case e_sinh : return numeric::sinh (arg); 05535 | case e_sqrt : return numeric::sqrt (arg); 05536 | case e_tan : return numeric::tan (arg); 05537 | case e_tanh : return numeric::tanh (arg); 05538 | case e_cot : return numeric::cot (arg); 05539 | case e_sec : return numeric::sec (arg); 05540 | case e_csc : return numeric::csc (arg); 05541 | case e_r2d : return numeric::r2d (arg); 05542 | case e_d2r : return numeric::d2r (arg); 05543 | case e_d2g : return numeric::d2g (arg); 05544 | case e_g2d : return numeric::g2d (arg); 05545 | case e_notl : return numeric::notl (arg); 05546 | case e_sgn : return numeric::sgn (arg); 05547 | case e_erf : return numeric::erf (arg); 05548 | case e_erfc : return numeric::erfc (arg); 05549 | case e_ncdf : return numeric::ncdf (arg); 05550 | case e_frac : return numeric::frac (arg); 05551 | case e_trunc : return numeric::trunc(arg); 05552 | 05553 | default : exprtk_debug(("numeric::details::process_impl<T> - Invalid unary operation.\n")); 05554 | return std::numeric_limits<T>::quiet_NaN(); 05555 | } 05556 | } 05557 | 05558 | template <typename T> 05559 | inline T process_impl(const operator_type operation, const T arg0, const T arg1) 05560 | { 05561 | switch (operation) 05562 | { 05563 | case e_add : return (arg0 + arg1); 05564 | case e_sub : return (arg0 - arg1); 05565 | case e_mul : return (arg0 * arg1); 05566 | case e_div : return (arg0 / arg1); 05567 | case e_mod : return modulus<T>(arg0,arg1); 05568 | case e_pow : return pow<T>(arg0,arg1); 05569 | case e_atan2 : return atan2<T>(arg0,arg1); 05570 | case e_min : return std::min<T>(arg0,arg1); 05571 | case e_max : return std::max<T>(arg0,arg1); 05572 | case e_logn : return logn<T>(arg0,arg1); 05573 | case e_lt : return (arg0 < arg1) ? T(1) : T(0); 05574 | case e_lte : return (arg0 <= arg1) ? T(1) : T(0); 05575 | case e_eq : return std::equal_to<T>()(arg0,arg1) ? T(1) : T(0); 05576 | case e_ne : return std::not_equal_to<T>()(arg0,arg1) ? T(1) : T(0); 05577 | case e_gte : return (arg0 >= arg1) ? T(1) : T(0); 05578 | case e_gt : return (arg0 > arg1) ? T(1) : T(0); 05579 | case e_and : return and_opr <T>(arg0,arg1); 05580 | case e_nand : return nand_opr<T>(arg0,arg1); 05581 | case e_or : return or_opr <T>(arg0,arg1); 05582 | case e_nor : return nor_opr <T>(arg0,arg1); 05583 | case e_xor : return xor_opr <T>(arg0,arg1); 05584 | case e_xnor : return xnor_opr<T>(arg0,arg1); 05585 | case e_root : return root <T>(arg0,arg1); 05586 | case e_roundn : return roundn <T>(arg0,arg1); 05587 | case e_equal : return equal <T>(arg0,arg1); 05588 | case e_nequal : return nequal <T>(arg0,arg1); 05589 | case e_hypot : return hypot <T>(arg0,arg1); 05590 | case e_shr : return shr <T>(arg0,arg1); 05591 | case e_shl : return shl <T>(arg0,arg1); 05592 | 05593 | default : exprtk_debug(("numeric::details::process_impl<T> - Invalid binary operation.\n")); 05594 | return std::numeric_limits<T>::quiet_NaN(); 05595 | } 05596 | } 05597 | 05598 | template <typename T> 05599 | inline T process_impl(const operator_type operation, const T arg0, const T arg1, int_type_tag) 05600 | { 05601 | switch (operation) 05602 | { 05603 | case e_add : return (arg0 + arg1); 05604 | case e_sub : return (arg0 - arg1); 05605 | case e_mul : return (arg0 * arg1); 05606 | case e_div : return (arg0 / arg1); 05607 | case e_mod : return arg0 % arg1; 05608 | case e_pow : return pow<T>(arg0,arg1); 05609 | case e_min : return std::min<T>(arg0,arg1); 05610 | case e_max : return std::max<T>(arg0,arg1); 05611 | case e_logn : return logn<T>(arg0,arg1); 05612 | case e_lt : return (arg0 < arg1) ? T(1) : T(0); 05613 | case e_lte : return (arg0 <= arg1) ? T(1) : T(0); 05614 | case e_eq : return (arg0 == arg1) ? T(1) : T(0); 05615 | case e_ne : return (arg0 != arg1) ? T(1) : T(0); 05616 | case e_gte : return (arg0 >= arg1) ? T(1) : T(0); 05617 | case e_gt : return (arg0 > arg1) ? T(1) : T(0); 05618 | case e_and : return ((arg0 != T(0)) && (arg1 != T(0))) ? T(1) : T(0); 05619 | case e_nand : return ((arg0 != T(0)) && (arg1 != T(0))) ? T(0) : T(1); 05620 | case e_or : return ((arg0 != T(0)) || (arg1 != T(0))) ? T(1) : T(0); 05621 | case e_nor : return ((arg0 != T(0)) || (arg1 != T(0))) ? T(0) : T(1); 05622 | case e_xor : return arg0 ^ arg1; 05623 | case e_xnor : return !(arg0 ^ arg1); 05624 | case e_root : return root<T>(arg0,arg1); 05625 | case e_equal : return arg0 == arg1; 05626 | case e_nequal : return arg0 != arg1; 05627 | case e_hypot : return hypot<T>(arg0,arg1); 05628 | case e_shr : return arg0 >> arg1; 05629 | case e_shl : return arg0 << arg1; 05630 | 05631 | default : exprtk_debug(("numeric::details::process_impl<IntType> - Invalid binary operation.\n")); 05632 | return std::numeric_limits<T>::quiet_NaN(); 05633 | } 05634 | } 05635 | } 05636 | 05637 | template <typename T> 05638 | inline T process(const operator_type operation, const T arg) 05639 | { 05640 | return exprtk::details::numeric::details::process_impl(operation,arg); 05641 | } 05642 | 05643 | template <typename T> 05644 | inline T process(const operator_type operation, const T arg0, const T arg1) 05645 | { 05646 | return exprtk::details::numeric::details::process_impl(operation, arg0, arg1); 05647 | } 05648 | } 05649 | 05650 | template <typename Node> 05651 | struct node_collector_interface 05652 | { 05653 | typedef Node* node_ptr_t; 05654 | typedef Node** node_pp_t; 05655 | typedef std::vector<node_pp_t> noderef_list_t; 05656 | 05657 | virtual ~node_collector_interface() 05658 | {} 05659 | 05660 | virtual void collect_nodes(noderef_list_t&) 05661 | {} 05662 | }; 05663 | 05664 | template <typename Node> 05665 | struct node_depth_base; 05666 | 05667 | template <typename T> 05668 | class expression_node : public node_collector_interface<expression_node<T> > 05669 | , public node_depth_base<expression_node<T> > 05670 | { 05671 | public: 05672 | 05673 | enum node_type 05674 | { 05675 | e_none , e_null , e_constant , e_unary , 05676 | e_binary , e_binary_ext , e_trinary , e_quaternary , 05677 | e_vararg , e_conditional , e_while , e_repeat , 05678 | e_for , e_switch , e_mswitch , e_return , 05679 | e_retenv , e_variable , e_stringvar , e_stringconst , 05680 | e_stringvarrng , e_cstringvarrng , e_strgenrange , e_strconcat , 05681 | e_stringvarsize , e_strswap , e_stringsize , e_stringvararg , 05682 | e_function , e_vafunction , e_genfunction , e_strfunction , 05683 | e_strcondition , e_strccondition , e_add , e_sub , 05684 | e_mul , e_div , e_mod , e_pow , 05685 | e_lt , e_lte , e_gt , e_gte , 05686 | e_eq , e_ne , e_and , e_nand , 05687 | e_or , e_nor , e_xor , e_xnor , 05688 | e_in , e_like , e_ilike , e_inranges , 05689 | e_ipow , e_ipowinv , e_abs , e_acos , 05690 | e_acosh , e_asin , e_asinh , e_atan , 05691 | e_atanh , e_ceil , e_cos , e_cosh , 05692 | e_exp , e_expm1 , e_floor , e_log , 05693 | e_log10 , e_log2 , e_log1p , e_neg , 05694 | e_pos , e_round , e_sin , e_sinc , 05695 | e_sinh , e_sqrt , e_tan , e_tanh , 05696 | e_cot , e_sec , e_csc , e_r2d , 05697 | e_d2r , e_d2g , e_g2d , e_notl , 05698 | e_sgn , e_erf , e_erfc , e_ncdf , 05699 | e_frac , e_trunc , e_uvouv , e_vov , 05700 | e_cov , e_voc , e_vob , e_bov , 05701 | e_cob , e_boc , e_vovov , e_vovoc , 05702 | e_vocov , e_covov , e_covoc , e_vovovov , 05703 | e_vovovoc , e_vovocov , e_vocovov , e_covovov , 05704 | e_covocov , e_vocovoc , e_covovoc , e_vococov , 05705 | e_sf3ext , e_sf4ext , e_nulleq , e_strass , 05706 | e_vector , e_vecsize , e_vecelem , e_veccelem , 05707 | e_vecelemrtc , e_veccelemrtc , e_rbvecelem , e_rbvecelemrtc , 05708 | e_rbveccelem , e_rbveccelemrtc , e_vecinit , e_vecvalass , 05709 | e_vecvecass , e_vecopvalass , e_vecopvecass , e_vecfunc , 05710 | e_vecvecswap , e_vecvecineq , e_vecvalineq , e_valvecineq , 05711 | e_vecvecarith , e_vecvalarith , e_valvecarith , e_vecunaryop , 05712 | e_vecondition , e_break , e_continue , e_swap , 05713 | e_assert 05714 | }; 05715 | 05716 | typedef T value_type; 05717 | typedef expression_node<T>* expression_ptr; 05718 | typedef node_collector_interface<expression_node<T> > nci_t; 05719 | typedef typename nci_t::noderef_list_t noderef_list_t; 05720 | typedef node_depth_base<expression_node<T> > ndb_t; 05721 | 05722 | virtual ~expression_node() 05723 | {} 05724 | 05725 | inline virtual T value() const 05726 | { 05727 | return std::numeric_limits<T>::quiet_NaN(); 05728 | } 05729 | 05730 | inline virtual expression_node<T>* branch(const std::size_t& index = 0) const 05731 | { 05732 | return reinterpret_cast<expression_ptr>(index * 0); 05733 | } 05734 | 05735 | inline virtual node_type type() const 05736 | { 05737 | return e_none; 05738 | } 05739 | 05740 | inline virtual bool valid() const 05741 | { 05742 | return true; 05743 | } 05744 | }; // class expression_node 05745 | 05746 | template <typename T> 05747 | inline bool is_generally_string_node(const expression_node<T>* node); 05748 | 05749 | inline bool is_true(const double v) 05750 | { 05751 | return std::not_equal_to<double>()(0.0,v); 05752 | } 05753 | 05754 | inline bool is_true(const long double v) 05755 | { 05756 | return std::not_equal_to<long double>()(0.0L,v); 05757 | } 05758 | 05759 | inline bool is_true(const float v) 05760 | { 05761 | return std::not_equal_to<float>()(0.0f,v); 05762 | } 05763 | 05764 | template <typename T> 05765 | inline bool is_true(const expression_node<T>* node) 05766 | { 05767 | return std::not_equal_to<T>()(T(0),node->value()); 05768 | } 05769 | 05770 | template <typename T> 05771 | inline bool is_true(const std::pair<expression_node<T>*,bool>& node) 05772 | { 05773 | return std::not_equal_to<T>()(T(0),node.first->value()); 05774 | } 05775 | 05776 | template <typename T> 05777 | inline bool is_false(const expression_node<T>* node) 05778 | { 05779 | return std::equal_to<T>()(T(0),node->value()); 05780 | } 05781 | 05782 | template <typename T> 05783 | inline bool is_false(const std::pair<expression_node<T>*,bool>& node) 05784 | { 05785 | return std::equal_to<T>()(T(0),node.first->value()); 05786 | } 05787 | 05788 | template <typename T> 05789 | inline bool is_literal_node(const expression_node<T>* node) 05790 | { 05791 | return node && (details::expression_node<T>::e_constant == node->type()); 05792 | } 05793 | 05794 | template <typename T> 05795 | inline bool is_unary_node(const expression_node<T>* node) 05796 | { 05797 | return node && (details::expression_node<T>::e_unary == node->type()); 05798 | } 05799 | 05800 | template <typename T> 05801 | inline bool is_neg_unary_node(const expression_node<T>* node) 05802 | { 05803 | return node && (details::expression_node<T>::e_neg == node->type()); 05804 | } 05805 | 05806 | template <typename T> 05807 | inline bool is_binary_node(const expression_node<T>* node) 05808 | { 05809 | return node && (details::expression_node<T>::e_binary == node->type()); 05810 | } 05811 | 05812 | template <typename T> 05813 | inline bool is_variable_node(const expression_node<T>* node) 05814 | { 05815 | return node && (details::expression_node<T>::e_variable == node->type()); 05816 | } 05817 | 05818 | template <typename T> 05819 | inline bool is_ivariable_node(const expression_node<T>* node) 05820 | { 05821 | return node && 05822 | ( 05823 | details::expression_node<T>::e_variable == node->type() || 05824 | details::expression_node<T>::e_vecelem == node->type() || 05825 | details::expression_node<T>::e_veccelem == node->type() || 05826 | details::expression_node<T>::e_vecelemrtc == node->type() || 05827 | details::expression_node<T>::e_veccelemrtc == node->type() || 05828 | details::expression_node<T>::e_rbvecelem == node->type() || 05829 | details::expression_node<T>::e_rbveccelem == node->type() || 05830 | details::expression_node<T>::e_rbvecelemrtc == node->type() || 05831 | details::expression_node<T>::e_rbveccelemrtc == node->type() 05832 | ); 05833 | } 05834 | 05835 | template <typename T> 05836 | inline bool is_vector_elem_node(const expression_node<T>* node) 05837 | { 05838 | return node && (details::expression_node<T>::e_vecelem == node->type()); 05839 | } 05840 | 05841 | template <typename T> 05842 | inline bool is_vector_celem_node(const expression_node<T>* node) 05843 | { 05844 | return node && (details::expression_node<T>::e_veccelem == node->type()); 05845 | } 05846 | 05847 | template <typename T> 05848 | inline bool is_vector_elem_rtc_node(const expression_node<T>* node) 05849 | { 05850 | return node && (details::expression_node<T>::e_vecelemrtc == node->type()); 05851 | } 05852 | 05853 | template <typename T> 05854 | inline bool is_vector_celem_rtc_node(const expression_node<T>* node) 05855 | { 05856 | return node && (details::expression_node<T>::e_veccelemrtc == node->type()); 05857 | } 05858 | 05859 | template <typename T> 05860 | inline bool is_rebasevector_elem_node(const expression_node<T>* node) 05861 | { 05862 | return node && (details::expression_node<T>::e_rbvecelem == node->type()); 05863 | } 05864 | 05865 | template <typename T> 05866 | inline bool is_rebasevector_elem_rtc_node(const expression_node<T>* node) 05867 | { 05868 | return node && (details::expression_node<T>::e_rbvecelemrtc == node->type()); 05869 | } 05870 | 05871 | template <typename T> 05872 | inline bool is_rebasevector_celem_rtc_node(const expression_node<T>* node) 05873 | { 05874 | return node && (details::expression_node<T>::e_rbveccelemrtc == node->type()); 05875 | } 05876 | 05877 | template <typename T> 05878 | inline bool is_rebasevector_celem_node(const expression_node<T>* node) 05879 | { 05880 | return node && (details::expression_node<T>::e_rbveccelem == node->type()); 05881 | } 05882 | 05883 | template <typename T> 05884 | inline bool is_vector_node(const expression_node<T>* node) 05885 | { 05886 | return node && (details::expression_node<T>::e_vector == node->type()); 05887 | } 05888 | 05889 | template <typename T> 05890 | inline bool is_ivector_node(const expression_node<T>* node) 05891 | { 05892 | if (node) 05893 | { 05894 | switch (node->type()) 05895 | { 05896 | case details::expression_node<T>::e_vector : 05897 | case details::expression_node<T>::e_vecvalass : 05898 | case details::expression_node<T>::e_vecvecass : 05899 | case details::expression_node<T>::e_vecopvalass : 05900 | case details::expression_node<T>::e_vecopvecass : 05901 | case details::expression_node<T>::e_vecvecswap : 05902 | case details::expression_node<T>::e_vecvecarith : 05903 | case details::expression_node<T>::e_vecvalarith : 05904 | case details::expression_node<T>::e_valvecarith : 05905 | case details::expression_node<T>::e_vecunaryop : 05906 | case details::expression_node<T>::e_vecondition : return true; 05907 | default : return false; 05908 | } 05909 | } 05910 | else 05911 | return false; 05912 | } 05913 | 05914 | template <typename T> 05915 | inline bool amalgamated_vecop(const expression_node<T>* node) 05916 | { 05917 | if (node) 05918 | { 05919 | switch (node->type()) 05920 | { 05921 | case details::expression_node<T>::e_vecvecarith : 05922 | case details::expression_node<T>::e_vecvalarith : 05923 | case details::expression_node<T>::e_valvecarith : 05924 | case details::expression_node<T>::e_vecunaryop : return true; 05925 | default : return false; 05926 | } 05927 | } 05928 | else 05929 | return false; 05930 | } 05931 | 05932 | template <typename T> 05933 | inline bool is_constant_node(const expression_node<T>* node) 05934 | { 05935 | return node && 05936 | ( 05937 | details::expression_node<T>::e_constant == node->type() || 05938 | details::expression_node<T>::e_stringconst == node->type() 05939 | ); 05940 | } 05941 | 05942 | template <typename T> 05943 | inline bool is_null_node(const expression_node<T>* node) 05944 | { 05945 | return node && (details::expression_node<T>::e_null == node->type()); 05946 | } 05947 | 05948 | template <typename T> 05949 | inline bool is_break_node(const expression_node<T>* node) 05950 | { 05951 | return node && (details::expression_node<T>::e_break == node->type()); 05952 | } 05953 | 05954 | template <typename T> 05955 | inline bool is_continue_node(const expression_node<T>* node) 05956 | { 05957 | return node && (details::expression_node<T>::e_continue == node->type()); 05958 | } 05959 | 05960 | template <typename T> 05961 | inline bool is_swap_node(const expression_node<T>* node) 05962 | { 05963 | return node && (details::expression_node<T>::e_swap == node->type()); 05964 | } 05965 | 05966 | template <typename T> 05967 | inline bool is_function(const expression_node<T>* node) 05968 | { 05969 | return node && (details::expression_node<T>::e_function == node->type()); 05970 | } 05971 | 05972 | template <typename T> 05973 | inline bool is_vararg_node(const expression_node<T>* node) 05974 | { 05975 | return node && (details::expression_node<T>::e_vararg == node->type()); 05976 | } 05977 | 05978 | template <typename T> 05979 | inline bool is_return_node(const expression_node<T>* node) 05980 | { 05981 | return node && (details::expression_node<T>::e_return == node->type()); 05982 | } 05983 | 05984 | template <typename T> class unary_node; 05985 | 05986 | template <typename T> 05987 | inline bool is_negate_node(const expression_node<T>* node) 05988 | { 05989 | if (node && is_unary_node(node)) 05990 | { 05991 | return (details::e_neg == static_cast<const unary_node<T>*>(node)->operation()); 05992 | } 05993 | else 05994 | return false; 05995 | } 05996 | 05997 | template <typename T> 05998 | inline bool is_assert_node(const expression_node<T>* node) 05999 | { 06000 | return node && (details::expression_node<T>::e_assert == node->type()); 06001 | } 06002 | 06003 | template <typename T> 06004 | inline bool branch_deletable(const expression_node<T>* node) 06005 | { 06006 | return (0 != node) && 06007 | !is_variable_node(node) && 06008 | !is_string_node (node) ; 06009 | } 06010 | 06011 | template <std::size_t N, typename T> 06012 | inline bool all_nodes_valid(expression_node<T>* const (&b)[N]) 06013 | { 06014 | for (std::size_t i = 0; i < N; ++i) 06015 | { 06016 | if (0 == b[i]) return false; 06017 | } 06018 | 06019 | return true; 06020 | } 06021 | 06022 | template <typename T, 06023 | typename Allocator, 06024 | template <typename, typename> class Sequence> 06025 | inline bool all_nodes_valid(const Sequence<expression_node<T>*,Allocator>& b) 06026 | { 06027 | for (std::size_t i = 0; i < b.size(); ++i) 06028 | { 06029 | if (0 == b[i]) return false; 06030 | } 06031 | 06032 | return true; 06033 | } 06034 | 06035 | template <std::size_t N, typename T> 06036 | inline bool all_nodes_variables(expression_node<T>* const (&b)[N]) 06037 | { 06038 | for (std::size_t i = 0; i < N; ++i) 06039 | { 06040 | if (0 == b[i]) 06041 | return false; 06042 | else if (!is_variable_node(b[i])) 06043 | return false; 06044 | } 06045 | 06046 | return true; 06047 | } 06048 | 06049 | template <typename T, 06050 | typename Allocator, 06051 | template <typename, typename> class Sequence> 06052 | inline bool all_nodes_variables(const Sequence<expression_node<T>*,Allocator>& b) 06053 | { 06054 | for (std::size_t i = 0; i < b.size(); ++i) 06055 | { 06056 | if (0 == b[i]) 06057 | return false; 06058 | else if (!is_variable_node(b[i])) 06059 | return false; 06060 | } 06061 | 06062 | return true; 06063 | } 06064 | 06065 | template <typename Node> 06066 | class node_collection_destructor 06067 | { 06068 | public: 06069 | 06070 | typedef node_collector_interface<Node> nci_t; 06071 | 06072 | typedef typename nci_t::node_ptr_t node_ptr_t; 06073 | typedef typename nci_t::node_pp_t node_pp_t; 06074 | typedef typename nci_t::noderef_list_t noderef_list_t; 06075 | 06076 | static void delete_nodes(node_ptr_t& root) 06077 | { 06078 | std::vector<node_pp_t> node_delete_list; 06079 | node_delete_list.reserve(1000); 06080 | 06081 | collect_nodes(root, node_delete_list); 06082 | 06083 | for (std::size_t i = 0; i < node_delete_list.size(); ++i) 06084 | { 06085 | node_ptr_t& node = *node_delete_list[i]; 06086 | exprtk_debug(("ncd::delete_nodes() - deleting: %p\n", reinterpret_cast<void*>(node))); 06087 | delete node; 06088 | node = reinterpret_cast<node_ptr_t>(0); 06089 | } 06090 | } 06091 | 06092 | private: 06093 | 06094 | static void collect_nodes(node_ptr_t& root, noderef_list_t& node_delete_list) 06095 | { 06096 | std::deque<node_ptr_t> node_list; 06097 | node_list.push_back(root); 06098 | node_delete_list.push_back(&root); 06099 | 06100 | noderef_list_t child_node_delete_list; 06101 | child_node_delete_list.reserve(1000); 06102 | 06103 | while (!node_list.empty()) 06104 | { 06105 | node_list.front()->collect_nodes(child_node_delete_list); 06106 | 06107 | if (!child_node_delete_list.empty()) 06108 | { 06109 | for (std::size_t i = 0; i < child_node_delete_list.size(); ++i) 06110 | { 06111 | node_pp_t& node = child_node_delete_list[i]; 06112 | 06113 | if (0 == (*node)) 06114 | { 06115 | exprtk_debug(("ncd::collect_nodes() - null node encountered.\n")); 06116 | } 06117 | 06118 | node_list.push_back(*node); 06119 | } 06120 | 06121 | node_delete_list.insert( 06122 | node_delete_list.end(), 06123 | child_node_delete_list.begin(), child_node_delete_list.end()); 06124 | 06125 | child_node_delete_list.clear(); 06126 | } 06127 | 06128 | node_list.pop_front(); 06129 | } 06130 | 06131 | std::reverse(node_delete_list.begin(), node_delete_list.end()); 06132 | } 06133 | }; 06134 | 06135 | template <typename NodeAllocator, typename T, std::size_t N> 06136 | inline void free_all_nodes(NodeAllocator& node_allocator, expression_node<T>* (&b)[N]) 06137 | { 06138 | for (std::size_t i = 0; i < N; ++i) 06139 | { 06140 | free_node(node_allocator,b[i]); 06141 | } 06142 | } 06143 | 06144 | template <typename NodeAllocator, 06145 | typename T, 06146 | typename Allocator, 06147 | template <typename, typename> class Sequence> 06148 | inline void free_all_nodes(NodeAllocator& node_allocator, Sequence<expression_node<T>*,Allocator>& b) 06149 | { 06150 | for (std::size_t i = 0; i < b.size(); ++i) 06151 | { 06152 | free_node(node_allocator,b[i]); 06153 | } 06154 | 06155 | b.clear(); 06156 | } 06157 | 06158 | template <typename NodeAllocator, typename T> 06159 | inline void free_node(NodeAllocator&, expression_node<T>*& node) 06160 | { 06161 | if ((0 == node) || is_variable_node(node) || is_string_node(node)) 06162 | { 06163 | return; 06164 | } 06165 | 06166 | node_collection_destructor<expression_node<T> > 06167 | ::delete_nodes(node); 06168 | } 06169 | 06170 | template <typename T> 06171 | inline void destroy_node(expression_node<T>*& node) 06172 | { 06173 | if (0 != node) 06174 | { 06175 | node_collection_destructor<expression_node<T> > 06176 | ::delete_nodes(node); 06177 | } 06178 | } 06179 | 06180 | template <typename Node> 06181 | struct node_depth_base 06182 | { 06183 | typedef Node* node_ptr_t; 06184 | typedef std::pair<node_ptr_t,bool> nb_pair_t; 06185 | 06186 | node_depth_base() 06187 | : depth_set(false) 06188 | , depth(0) 06189 | {} 06190 | 06191 | virtual ~node_depth_base() 06192 | {} 06193 | 06194 | virtual std::size_t node_depth() const { return 1; } 06195 | 06196 | std::size_t compute_node_depth(const Node* const& node) const 06197 | { 06198 | if (!depth_set) 06199 | { 06200 | depth = 1 + (node ? node->node_depth() : 0); 06201 | depth_set = true; 06202 | } 06203 | 06204 | return depth; 06205 | } 06206 | 06207 | std::size_t compute_node_depth(const nb_pair_t& branch) const 06208 | { 06209 | if (!depth_set) 06210 | { 06211 | depth = 1 + (branch.first ? branch.first->node_depth() : 0); 06212 | depth_set = true; 06213 | } 06214 | 06215 | return depth; 06216 | } 06217 | 06218 | template <std::size_t N> 06219 | std::size_t compute_node_depth(const nb_pair_t (&branch)[N]) const 06220 | { 06221 | if (!depth_set) 06222 | { 06223 | depth = 0; 06224 | 06225 | for (std::size_t i = 0; i < N; ++i) 06226 | { 06227 | if (branch[i].first) 06228 | { 06229 | depth = std::max(depth,branch[i].first->node_depth()); 06230 | } 06231 | } 06232 | 06233 | depth += 1; 06234 | depth_set = true; 06235 | } 06236 | 06237 | return depth; 06238 | } 06239 | 06240 | template <typename BranchType> 06241 | std::size_t max_node_depth(const BranchType& n0, const BranchType& n1) const 06242 | { 06243 | return std::max(compute_node_depth(n0), compute_node_depth(n1)); 06244 | } 06245 | 06246 | template <typename BranchType> 06247 | std::size_t max_node_depth(const BranchType& n0, const BranchType& n1, const BranchType& n2) const 06248 | { 06249 | return std::max(compute_node_depth(n0), 06250 | std::max(compute_node_depth(n1), compute_node_depth(n2))); 06251 | } 06252 | 06253 | template <typename BranchType> 06254 | std::size_t max_node_depth(const BranchType& n0, const BranchType& n1, 06255 | const BranchType& n2, const BranchType& n3) const 06256 | { 06257 | return std::max( 06258 | std::max(compute_node_depth(n0), compute_node_depth(n1)), 06259 | std::max(compute_node_depth(n2), compute_node_depth(n3))); 06260 | } 06261 | 06262 | template <typename BranchType> 06263 | std::size_t compute_node_depth(const BranchType& n0, const BranchType& n1) const 06264 | { 06265 | if (!depth_set) 06266 | { 06267 | depth = 1 + max_node_depth(n0, n1); 06268 | depth_set = true; 06269 | } 06270 | 06271 | return depth; 06272 | } 06273 | 06274 | template <typename BranchType> 06275 | std::size_t compute_node_depth(const BranchType& n0, const BranchType& n1, 06276 | const BranchType& n2) const 06277 | { 06278 | if (!depth_set) 06279 | { 06280 | depth = 1 + max_node_depth(n0, n1, n2); 06281 | depth_set = true; 06282 | } 06283 | 06284 | return depth; 06285 | } 06286 | 06287 | template <typename BranchType> 06288 | std::size_t compute_node_depth(const BranchType& n0, const BranchType& n1, 06289 | const BranchType& n2, const BranchType& n3) const 06290 | { 06291 | if (!depth_set) 06292 | { 06293 | depth = 1 + max_node_depth(n0, n1, n2, n3); 06294 | depth_set = true; 06295 | } 06296 | 06297 | return depth; 06298 | } 06299 | 06300 | template <typename Allocator, 06301 | template <typename, typename> class Sequence> 06302 | std::size_t compute_node_depth(const Sequence<node_ptr_t, Allocator>& branch_list) const 06303 | { 06304 | if (!depth_set) 06305 | { 06306 | for (std::size_t i = 0; i < branch_list.size(); ++i) 06307 | { 06308 | if (branch_list[i]) 06309 | { 06310 | depth = std::max(depth, compute_node_depth(branch_list[i])); 06311 | } 06312 | } 06313 | 06314 | depth_set = true; 06315 | } 06316 | 06317 | return depth; 06318 | } 06319 | 06320 | template <typename Allocator, 06321 | template <typename, typename> class Sequence> 06322 | std::size_t compute_node_depth(const Sequence<nb_pair_t,Allocator>& branch_list) const 06323 | { 06324 | if (!depth_set) 06325 | { 06326 | for (std::size_t i = 0; i < branch_list.size(); ++i) 06327 | { 06328 | if (branch_list[i].first) 06329 | { 06330 | depth = std::max(depth, compute_node_depth(branch_list[i].first)); 06331 | } 06332 | } 06333 | 06334 | depth_set = true; 06335 | } 06336 | 06337 | return depth; 06338 | } 06339 | 06340 | mutable bool depth_set; 06341 | mutable std::size_t depth; 06342 | 06343 | template <typename NodeSequence> 06344 | void collect(node_ptr_t const& node, 06345 | const bool deletable, 06346 | NodeSequence& delete_node_list) const 06347 | { 06348 | if ((0 != node) && deletable) 06349 | { 06350 | delete_node_list.push_back(const_cast<node_ptr_t*>(&node)); 06351 | } 06352 | } 06353 | 06354 | template <typename NodeSequence> 06355 | void collect(const nb_pair_t& branch, 06356 | NodeSequence& delete_node_list) const 06357 | { 06358 | collect(branch.first, branch.second, delete_node_list); 06359 | } 06360 | 06361 | template <typename NodeSequence> 06362 | void collect(Node*& node, 06363 | NodeSequence& delete_node_list) const 06364 | { 06365 | collect(node, branch_deletable(node), delete_node_list); 06366 | } 06367 | 06368 | template <std::size_t N, typename NodeSequence> 06369 | void collect(const nb_pair_t(&branch)[N], 06370 | NodeSequence& delete_node_list) const 06371 | { 06372 | for (std::size_t i = 0; i < N; ++i) 06373 | { 06374 | collect(branch[i].first, branch[i].second, delete_node_list); 06375 | } 06376 | } 06377 | 06378 | template <typename Allocator, 06379 | template <typename, typename> class Sequence, 06380 | typename NodeSequence> 06381 | void collect(const Sequence<nb_pair_t, Allocator>& branch, 06382 | NodeSequence& delete_node_list) const 06383 | { 06384 | for (std::size_t i = 0; i < branch.size(); ++i) 06385 | { 06386 | collect(branch[i].first, branch[i].second, delete_node_list); 06387 | } 06388 | } 06389 | 06390 | template <typename Allocator, 06391 | template <typename, typename> class Sequence, 06392 | typename NodeSequence> 06393 | void collect(const Sequence<node_ptr_t, Allocator>& branch_list, 06394 | NodeSequence& delete_node_list) const 06395 | { 06396 | for (std::size_t i = 0; i < branch_list.size(); ++i) 06397 | { 06398 | collect(branch_list[i], branch_deletable(branch_list[i]), delete_node_list); 06399 | } 06400 | } 06401 | 06402 | template <typename Boolean, 06403 | typename AllocatorT, 06404 | typename AllocatorB, 06405 | template <typename, typename> class Sequence, 06406 | typename NodeSequence> 06407 | void collect(const Sequence<node_ptr_t, AllocatorT>& branch_list, 06408 | const Sequence<Boolean, AllocatorB>& branch_deletable_list, 06409 | NodeSequence& delete_node_list) const 06410 | { 06411 | for (std::size_t i = 0; i < branch_list.size(); ++i) 06412 | { 06413 | collect(branch_list[i], branch_deletable_list[i], delete_node_list); 06414 | } 06415 | } 06416 | }; 06417 | 06418 | template <typename Type> 06419 | class vector_holder 06420 | { 06421 | private: 06422 | 06423 | typedef Type value_type; 06424 | typedef value_type* value_ptr; 06425 | typedef const value_ptr const_value_ptr; 06426 | typedef vector_holder<Type> vector_holder_t; 06427 | 06428 | class vector_holder_base 06429 | { 06430 | public: 06431 | 06432 | virtual ~vector_holder_base() 06433 | {} 06434 | 06435 | inline value_ptr operator[](const std::size_t& index) const 06436 | { 06437 | return value_at(index); 06438 | } 06439 | 06440 | inline std::size_t size() const 06441 | { 06442 | return vector_size(); 06443 | } 06444 | 06445 | inline std::size_t base_size() const 06446 | { 06447 | return vector_base_size(); 06448 | } 06449 | 06450 | inline value_ptr data() const 06451 | { 06452 | return value_at(0); 06453 | } 06454 | 06455 | virtual inline bool rebaseable() const 06456 | { 06457 | return false; 06458 | } 06459 | 06460 | virtual void set_ref(value_ptr*) 06461 | {} 06462 | 06463 | virtual void remove_ref(value_ptr*) 06464 | {} 06465 | 06466 | virtual void set_size_ref(std::size_t*) 06467 | {} 06468 | 06469 | virtual void remove_size_ref(std::size_t*) 06470 | {} 06471 | 06472 | virtual vector_view<Type>* rebaseable_instance() 06473 | { 06474 | return reinterpret_cast<vector_view<Type>*>(0); 06475 | } 06476 | 06477 | protected: 06478 | 06479 | virtual value_ptr value_at(const std::size_t&) const = 0; 06480 | virtual std::size_t vector_size() const = 0; 06481 | virtual std::size_t vector_base_size() const = 0; 06482 | }; 06483 | 06484 | class array_vector_impl exprtk_final : public vector_holder_base 06485 | { 06486 | public: 06487 | 06488 | array_vector_impl(const Type* vec, const std::size_t& vec_size) 06489 | : vec_(vec) 06490 | , size_(vec_size) 06491 | {} 06492 | 06493 | protected: 06494 | 06495 | value_ptr value_at(const std::size_t& index) const exprtk_override 06496 | { 06497 | assert(index < size_); 06498 | return const_cast<const_value_ptr>(vec_ + index); 06499 | } 06500 | 06501 | std::size_t vector_size() const exprtk_override 06502 | { 06503 | return size_; 06504 | } 06505 | 06506 | std::size_t vector_base_size() const exprtk_override 06507 | { 06508 | return vector_size(); 06509 | } 06510 | 06511 | private: 06512 | 06513 | array_vector_impl(const array_vector_impl&) exprtk_delete; 06514 | array_vector_impl& operator=(const array_vector_impl&) exprtk_delete; 06515 | 06516 | const Type* vec_; 06517 | const std::size_t size_; 06518 | }; 06519 | 06520 | template <typename Allocator, 06521 | template <typename, typename> class Sequence> 06522 | class sequence_vector_impl exprtk_final : public vector_holder_base 06523 | { 06524 | public: 06525 | 06526 | typedef Sequence<Type,Allocator> sequence_t; 06527 | 06528 | explicit sequence_vector_impl(sequence_t& seq) 06529 | : sequence_(seq) 06530 | {} 06531 | 06532 | protected: 06533 | 06534 | value_ptr value_at(const std::size_t& index) const exprtk_override 06535 | { 06536 | assert(index < sequence_.size()); 06537 | return (&sequence_[index]); 06538 | } 06539 | 06540 | std::size_t vector_size() const exprtk_override 06541 | { 06542 | return sequence_.size(); 06543 | } 06544 | 06545 | std::size_t vector_base_size() const exprtk_override 06546 | { 06547 | return vector_size(); 06548 | } 06549 | 06550 | private: 06551 | 06552 | sequence_vector_impl(const sequence_vector_impl&) exprtk_delete; 06553 | sequence_vector_impl& operator=(const sequence_vector_impl&) exprtk_delete; 06554 | 06555 | sequence_t& sequence_; 06556 | }; 06557 | 06558 | class vector_view_impl exprtk_final : public vector_holder_base 06559 | { 06560 | public: 06561 | 06562 | typedef exprtk::vector_view<Type> vector_view_t; 06563 | 06564 | explicit vector_view_impl(vector_view_t& vec_view) 06565 | : vec_view_(vec_view) 06566 | { 06567 | assert(vec_view_.size() > 0); 06568 | } 06569 | 06570 | void set_ref(value_ptr* ref) exprtk_override 06571 | { 06572 | vec_view_.set_ref(ref); 06573 | } 06574 | 06575 | void remove_ref(value_ptr* ref) exprtk_override 06576 | { 06577 | vec_view_.remove_ref(ref); 06578 | } 06579 | 06580 | bool rebaseable() const exprtk_override 06581 | { 06582 | return true; 06583 | } 06584 | 06585 | vector_view<Type>* rebaseable_instance() exprtk_override 06586 | { 06587 | return &vec_view_; 06588 | } 06589 | 06590 | protected: 06591 | 06592 | value_ptr value_at(const std::size_t& index) const exprtk_override 06593 | { 06594 | assert(index < vec_view_.size()); 06595 | return (&vec_view_[index]); 06596 | } 06597 | 06598 | std::size_t vector_size() const exprtk_override 06599 | { 06600 | return vec_view_.size(); 06601 | } 06602 | 06603 | std::size_t vector_base_size() const exprtk_override 06604 | { 06605 | return vec_view_.base_size(); 06606 | } 06607 | 06608 | private: 06609 | 06610 | vector_view_impl(const vector_view_impl&) exprtk_delete; 06611 | vector_view_impl& operator=(const vector_view_impl&) exprtk_delete; 06612 | 06613 | vector_view_t& vec_view_; 06614 | }; 06615 | 06616 | class resizable_vector_impl exprtk_final : public vector_holder_base 06617 | { 06618 | public: 06619 | 06620 | resizable_vector_impl(vector_holder& vec_view_holder, 06621 | const Type* vec, 06622 | const std::size_t& vec_size) 06623 | : vec_(vec) 06624 | , size_(vec_size) 06625 | , vec_view_holder_(*vec_view_holder.rebaseable_instance()) 06626 | { 06627 | assert(vec_view_holder.rebaseable_instance()); 06628 | assert(size_ <= vector_base_size()); 06629 | } 06630 | 06631 | virtual ~resizable_vector_impl() exprtk_override 06632 | {} 06633 | 06634 | protected: 06635 | 06636 | value_ptr value_at(const std::size_t& index) const exprtk_override 06637 | { 06638 | assert(index < vector_size()); 06639 | return const_cast<const_value_ptr>(vec_ + index); 06640 | } 06641 | 06642 | std::size_t vector_size() const exprtk_override 06643 | { 06644 | return vec_view_holder_.size(); 06645 | } 06646 | 06647 | std::size_t vector_base_size() const exprtk_override 06648 | { 06649 | return vec_view_holder_.base_size(); 06650 | } 06651 | 06652 | bool rebaseable() const exprtk_override 06653 | { 06654 | return true; 06655 | } 06656 | 06657 | virtual vector_view<Type>* rebaseable_instance() exprtk_override 06658 | { 06659 | return &vec_view_holder_; 06660 | } 06661 | 06662 | private: 06663 | 06664 | resizable_vector_impl(const resizable_vector_impl&) exprtk_delete; 06665 | resizable_vector_impl& operator=(const resizable_vector_impl&) exprtk_delete; 06666 | 06667 | const Type* vec_; 06668 | const std::size_t size_; 06669 | vector_view<Type>& vec_view_holder_; 06670 | }; 06671 | 06672 | public: 06673 | 06674 | typedef typename details::vec_data_store<Type> vds_t; 06675 | 06676 | vector_holder(Type* vec, const std::size_t& vec_size) 06677 | : vector_holder_base_(new(buffer)array_vector_impl(vec,vec_size)) 06678 | {} 06679 | 06680 | explicit vector_holder(const vds_t& vds) 06681 | : vector_holder_base_(new(buffer)array_vector_impl(vds.data(),vds.size())) 06682 | {} 06683 | 06684 | template <typename Allocator> 06685 | explicit vector_holder(std::vector<Type,Allocator>& vec) 06686 | : vector_holder_base_(new(buffer)sequence_vector_impl<Allocator,std::vector>(vec)) 06687 | {} 06688 | 06689 | explicit vector_holder(exprtk::vector_view<Type>& vec) 06690 | : vector_holder_base_(new(buffer)vector_view_impl(vec)) 06691 | {} 06692 | 06693 | explicit vector_holder(vector_holder_t& vec_holder, const vds_t& vds) 06694 | : vector_holder_base_(new(buffer)resizable_vector_impl(vec_holder, vds.data(), vds.size())) 06695 | {} 06696 | 06697 | inline value_ptr operator[](const std::size_t& index) const 06698 | { 06699 | return (*vector_holder_base_)[index]; 06700 | } 06701 | 06702 | inline std::size_t size() const 06703 | { 06704 | return vector_holder_base_->size(); 06705 | } 06706 | 06707 | inline std::size_t base_size() const 06708 | { 06709 | return vector_holder_base_->base_size(); 06710 | } 06711 | 06712 | inline value_ptr data() const 06713 | { 06714 | return vector_holder_base_->data(); 06715 | } 06716 | 06717 | void set_ref(value_ptr* ref) 06718 | { 06719 | if (rebaseable()) 06720 | { 06721 | vector_holder_base_->set_ref(ref); 06722 | } 06723 | } 06724 | 06725 | void set_size_ref(std::size_t* ref) 06726 | { 06727 | if (rebaseable()) 06728 | { 06729 | vector_holder_base_->set_size_ref(ref); 06730 | } 06731 | } 06732 | 06733 | void remove_ref(value_ptr* ref) 06734 | { 06735 | if (rebaseable()) 06736 | { 06737 | vector_holder_base_->remove_ref(ref); 06738 | } 06739 | } 06740 | 06741 | void remove_size_ref(std::size_t* ref) 06742 | { 06743 | if (rebaseable()) 06744 | { 06745 | vector_holder_base_->remove_size_ref(ref); 06746 | } 06747 | } 06748 | 06749 | bool rebaseable() const 06750 | { 06751 | return vector_holder_base_->rebaseable(); 06752 | } 06753 | 06754 | vector_view<Type>* rebaseable_instance() 06755 | { 06756 | return vector_holder_base_->rebaseable_instance(); 06757 | } 06758 | 06759 | private: 06760 | 06761 | vector_holder(const vector_holder<Type>&) exprtk_delete; 06762 | vector_holder<Type>& operator=(const vector_holder<Type>&) exprtk_delete; 06763 | 06764 | mutable vector_holder_base* vector_holder_base_; 06765 | uchar_t buffer[64]; 06766 | }; 06767 | 06768 | template <typename T> 06769 | class null_node exprtk_final : public expression_node<T> 06770 | { 06771 | public: 06772 | 06773 | inline T value() const exprtk_override 06774 | { 06775 | return std::numeric_limits<T>::quiet_NaN(); 06776 | } 06777 | 06778 | inline typename expression_node<T>::node_type type() const exprtk_override 06779 | { 06780 | return expression_node<T>::e_null; 06781 | } 06782 | }; 06783 | 06784 | template <typename T, std::size_t N> 06785 | inline void construct_branch_pair(std::pair<expression_node<T>*,bool> (&branch)[N], 06786 | expression_node<T>* b, 06787 | const std::size_t& index) 06788 | { 06789 | if (b && (index < N)) 06790 | { 06791 | branch[index] = std::make_pair(b,branch_deletable(b)); 06792 | } 06793 | } 06794 | 06795 | template <typename T> 06796 | inline void construct_branch_pair(std::pair<expression_node<T>*,bool>& branch, expression_node<T>* b) 06797 | { 06798 | if (b) 06799 | { 06800 | branch = std::make_pair(b,branch_deletable(b)); 06801 | } 06802 | } 06803 | 06804 | template <std::size_t N, typename T> 06805 | inline void init_branches(std::pair<expression_node<T>*,bool> (&branch)[N], 06806 | expression_node<T>* b0, 06807 | expression_node<T>* b1 = reinterpret_cast<expression_node<T>*>(0), 06808 | expression_node<T>* b2 = reinterpret_cast<expression_node<T>*>(0), 06809 | expression_node<T>* b3 = reinterpret_cast<expression_node<T>*>(0), 06810 | expression_node<T>* b4 = reinterpret_cast<expression_node<T>*>(0), 06811 | expression_node<T>* b5 = reinterpret_cast<expression_node<T>*>(0), 06812 | expression_node<T>* b6 = reinterpret_cast<expression_node<T>*>(0), 06813 | expression_node<T>* b7 = reinterpret_cast<expression_node<T>*>(0), 06814 | expression_node<T>* b8 = reinterpret_cast<expression_node<T>*>(0), 06815 | expression_node<T>* b9 = reinterpret_cast<expression_node<T>*>(0)) 06816 | { 06817 | construct_branch_pair(branch, b0, 0); 06818 | construct_branch_pair(branch, b1, 1); 06819 | construct_branch_pair(branch, b2, 2); 06820 | construct_branch_pair(branch, b3, 3); 06821 | construct_branch_pair(branch, b4, 4); 06822 | construct_branch_pair(branch, b5, 5); 06823 | construct_branch_pair(branch, b6, 6); 06824 | construct_branch_pair(branch, b7, 7); 06825 | construct_branch_pair(branch, b8, 8); 06826 | construct_branch_pair(branch, b9, 9); 06827 | } 06828 | 06829 | template <typename T> 06830 | class null_eq_node exprtk_final : public expression_node<T> 06831 | { 06832 | public: 06833 | 06834 | typedef expression_node<T>* expression_ptr; 06835 | typedef std::pair<expression_ptr,bool> branch_t; 06836 | 06837 | explicit null_eq_node(expression_ptr branch, const bool equality = true) 06838 | : equality_(equality) 06839 | { 06840 | construct_branch_pair(branch_, branch); 06841 | assert(valid()); 06842 | } 06843 | 06844 | inline T value() const exprtk_override 06845 | { 06846 | const T v = branch_.first->value(); 06847 | const bool result = details::numeric::is_nan(v); 06848 | 06849 | if (result) 06850 | return equality_ ? T(1) : T(0); 06851 | else 06852 | return equality_ ? T(0) : T(1); 06853 | } 06854 | 06855 | inline typename expression_node<T>::node_type type() const exprtk_override 06856 | { 06857 | return expression_node<T>::e_nulleq; 06858 | } 06859 | 06860 | inline expression_node<T>* branch(const std::size_t&) const exprtk_override 06861 | { 06862 | return branch_.first; 06863 | } 06864 | 06865 | inline bool valid() const exprtk_override 06866 | { 06867 | return branch_.first; 06868 | } 06869 | 06870 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 06871 | { 06872 | expression_node<T>::ndb_t::collect(branch_, node_delete_list); 06873 | } 06874 | 06875 | std::size_t node_depth() const exprtk_override 06876 | { 06877 | return expression_node<T>::ndb_t::compute_node_depth(branch_); 06878 | } 06879 | 06880 | private: 06881 | 06882 | bool equality_; 06883 | branch_t branch_; 06884 | }; 06885 | 06886 | template <typename T> 06887 | class literal_node exprtk_final : public expression_node<T> 06888 | { 06889 | public: 06890 | 06891 | explicit literal_node(const T& v) 06892 | : value_(v) 06893 | {} 06894 | 06895 | inline T value() const exprtk_override 06896 | { 06897 | return value_; 06898 | } 06899 | 06900 | inline typename expression_node<T>::node_type type() const exprtk_override 06901 | { 06902 | return expression_node<T>::e_constant; 06903 | } 06904 | 06905 | inline expression_node<T>* branch(const std::size_t&) const exprtk_override 06906 | { 06907 | return reinterpret_cast<expression_node<T>*>(0); 06908 | } 06909 | 06910 | private: 06911 | 06912 | literal_node(const literal_node<T>&) exprtk_delete; 06913 | literal_node<T>& operator=(const literal_node<T>&) exprtk_delete; 06914 | 06915 | const T value_; 06916 | }; 06917 | 06918 | template <typename T> 06919 | struct range_pack; 06920 | 06921 | template <typename T> 06922 | struct range_data_type; 06923 | 06924 | template <typename T> 06925 | class range_interface 06926 | { 06927 | public: 06928 | 06929 | typedef range_pack<T> range_t; 06930 | 06931 | virtual ~range_interface() 06932 | {} 06933 | 06934 | virtual range_t& range_ref() = 0; 06935 | 06936 | virtual const range_t& range_ref() const = 0; 06937 | }; 06938 | 06939 | #ifndef exprtk_disable_string_capabilities 06940 | template <typename T> 06941 | class string_base_node 06942 | { 06943 | public: 06944 | 06945 | typedef range_data_type<T> range_data_type_t; 06946 | 06947 | virtual ~string_base_node() 06948 | {} 06949 | 06950 | virtual std::string str () const = 0; 06951 | 06952 | virtual char_cptr base() const = 0; 06953 | 06954 | virtual std::size_t size() const = 0; 06955 | }; 06956 | 06957 | template <typename T> 06958 | class string_literal_node exprtk_final 06959 | : public expression_node <T> 06960 | , public string_base_node<T> 06961 | , public range_interface <T> 06962 | { 06963 | public: 06964 | 06965 | typedef range_pack<T> range_t; 06966 | 06967 | explicit string_literal_node(const std::string& v) 06968 | : value_(v) 06969 | { 06970 | rp_.n0_c = std::make_pair<bool,std::size_t>(true, 0); 06971 | rp_.n1_c = std::make_pair<bool,std::size_t>(true, v.size()); 06972 | rp_.cache.first = rp_.n0_c.second; 06973 | rp_.cache.second = rp_.n1_c.second; 06974 | } 06975 | 06976 | inline T value() const exprtk_override 06977 | { 06978 | return std::numeric_limits<T>::quiet_NaN(); 06979 | } 06980 | 06981 | inline typename expression_node<T>::node_type type() const exprtk_override 06982 | { 06983 | return expression_node<T>::e_stringconst; 06984 | } 06985 | 06986 | inline expression_node<T>* branch(const std::size_t&) const exprtk_override 06987 | { 06988 | return reinterpret_cast<expression_node<T>*>(0); 06989 | } 06990 | 06991 | std::string str() const exprtk_override 06992 | { 06993 | return value_; 06994 | } 06995 | 06996 | char_cptr base() const exprtk_override 06997 | { 06998 | return value_.data(); 06999 | } 07000 | 07001 | std::size_t size() const exprtk_override 07002 | { 07003 | return value_.size(); 07004 | } 07005 | 07006 | range_t& range_ref() exprtk_override 07007 | { 07008 | return rp_; 07009 | } 07010 | 07011 | const range_t& range_ref() const exprtk_override 07012 | { 07013 | return rp_; 07014 | } 07015 | 07016 | private: 07017 | 07018 | string_literal_node(const string_literal_node<T>&) exprtk_delete; 07019 | string_literal_node<T>& operator=(const string_literal_node<T>&) exprtk_delete; 07020 | 07021 | const std::string value_; 07022 | range_t rp_; 07023 | }; 07024 | #endif 07025 | 07026 | template <typename T> 07027 | class unary_node : public expression_node<T> 07028 | { 07029 | public: 07030 | 07031 | typedef expression_node<T>* expression_ptr; 07032 | typedef std::pair<expression_ptr,bool> branch_t; 07033 | 07034 | unary_node(const operator_type& opr, expression_ptr branch) 07035 | : operation_(opr) 07036 | { 07037 | construct_branch_pair(branch_,branch); 07038 | assert(valid()); 07039 | } 07040 | 07041 | inline T value() const exprtk_override 07042 | { 07043 | return numeric::process<T> 07044 | (operation_,branch_.first->value()); 07045 | } 07046 | 07047 | inline typename expression_node<T>::node_type type() const exprtk_override 07048 | { 07049 | return expression_node<T>::e_unary; 07050 | } 07051 | 07052 | inline operator_type operation() 07053 | { 07054 | return operation_; 07055 | } 07056 | 07057 | inline expression_node<T>* branch(const std::size_t&) const exprtk_override 07058 | { 07059 | return branch_.first; 07060 | } 07061 | 07062 | inline bool valid() const exprtk_override 07063 | { 07064 | return branch_.first && branch_.first->valid(); 07065 | } 07066 | 07067 | inline void release() 07068 | { 07069 | branch_.second = false; 07070 | } 07071 | 07072 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 07073 | { 07074 | expression_node<T>::ndb_t::collect(branch_, node_delete_list); 07075 | } 07076 | 07077 | std::size_t node_depth() const exprtk_final 07078 | { 07079 | return expression_node<T>::ndb_t::compute_node_depth(branch_); 07080 | } 07081 | 07082 | private: 07083 | 07084 | operator_type operation_; 07085 | branch_t branch_; 07086 | }; 07087 | 07088 | template <typename T> 07089 | class binary_node : public expression_node<T> 07090 | { 07091 | public: 07092 | 07093 | typedef expression_node<T>* expression_ptr; 07094 | typedef std::pair<expression_ptr,bool> branch_t; 07095 | 07096 | binary_node(const operator_type& opr, 07097 | expression_ptr branch0, 07098 | expression_ptr branch1) 07099 | : operation_(opr) 07100 | { 07101 | init_branches<2>(branch_, branch0, branch1); 07102 | assert(valid()); 07103 | } 07104 | 07105 | inline T value() const exprtk_override 07106 | { 07107 | return numeric::process<T> 07108 | ( 07109 | operation_, 07110 | branch_[0].first->value(), 07111 | branch_[1].first->value() 07112 | ); 07113 | } 07114 | 07115 | inline typename expression_node<T>::node_type type() const exprtk_override 07116 | { 07117 | return expression_node<T>::e_binary; 07118 | } 07119 | 07120 | inline operator_type operation() 07121 | { 07122 | return operation_; 07123 | } 07124 | 07125 | inline expression_node<T>* branch(const std::size_t& index = 0) const exprtk_override 07126 | { 07127 | assert(index < 2); 07128 | return branch_[index].first; 07129 | } 07130 | 07131 | inline bool valid() const exprtk_override 07132 | { 07133 | return 07134 | branch_[0].first && branch_[0].first->valid() && 07135 | branch_[1].first && branch_[1].first->valid() ; 07136 | } 07137 | 07138 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 07139 | { 07140 | expression_node<T>::ndb_t::collect(branch_, node_delete_list); 07141 | } 07142 | 07143 | std::size_t node_depth() const exprtk_final 07144 | { 07145 | return expression_node<T>::ndb_t::template compute_node_depth<2>(branch_); 07146 | } 07147 | 07148 | private: 07149 | 07150 | operator_type operation_; 07151 | branch_t branch_[2]; 07152 | }; 07153 | 07154 | template <typename T, typename Operation> 07155 | class binary_ext_node exprtk_final : public expression_node<T> 07156 | { 07157 | public: 07158 | 07159 | typedef expression_node<T>* expression_ptr; 07160 | typedef std::pair<expression_ptr,bool> branch_t; 07161 | 07162 | binary_ext_node(expression_ptr branch0, expression_ptr branch1) 07163 | { 07164 | init_branches<2>(branch_, branch0, branch1); 07165 | assert(valid()); 07166 | } 07167 | 07168 | inline T value() const exprtk_override 07169 | { 07170 | const T arg0 = branch_[0].first->value(); 07171 | const T arg1 = branch_[1].first->value(); 07172 | return Operation::process(arg0,arg1); 07173 | } 07174 | 07175 | inline typename expression_node<T>::node_type type() const exprtk_override 07176 | { 07177 | return expression_node<T>::e_binary_ext; 07178 | } 07179 | 07180 | inline operator_type operation() 07181 | { 07182 | return Operation::operation(); 07183 | } 07184 | 07185 | inline expression_node<T>* branch(const std::size_t& index = 0) const exprtk_override 07186 | { 07187 | assert(index < 2); 07188 | return branch_[index].first; 07189 | } 07190 | 07191 | inline bool valid() const exprtk_override 07192 | { 07193 | return 07194 | branch_[0].first && branch_[0].first->valid() && 07195 | branch_[1].first && branch_[1].first->valid() ; 07196 | } 07197 | 07198 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 07199 | { 07200 | expression_node<T>::ndb_t::collect(branch_, node_delete_list); 07201 | } 07202 | 07203 | std::size_t node_depth() const exprtk_override 07204 | { 07205 | return expression_node<T>::ndb_t::template compute_node_depth<2>(branch_); 07206 | } 07207 | 07208 | protected: 07209 | 07210 | branch_t branch_[2]; 07211 | }; 07212 | 07213 | template <typename T> 07214 | class trinary_node : public expression_node<T> 07215 | { 07216 | public: 07217 | 07218 | typedef expression_node<T>* expression_ptr; 07219 | typedef std::pair<expression_ptr,bool> branch_t; 07220 | 07221 | trinary_node(const operator_type& opr, 07222 | expression_ptr branch0, 07223 | expression_ptr branch1, 07224 | expression_ptr branch2) 07225 | : operation_(opr) 07226 | { 07227 | init_branches<3>(branch_, branch0, branch1, branch2); 07228 | assert(valid()); 07229 | } 07230 | 07231 | inline T value() const exprtk_override 07232 | { 07233 | const T arg0 = branch_[0].first->value(); 07234 | const T arg1 = branch_[1].first->value(); 07235 | const T arg2 = branch_[2].first->value(); 07236 | 07237 | switch (operation_) 07238 | { 07239 | case e_inrange : return (arg1 < arg0) ? T(0) : ((arg1 > arg2) ? T(0) : T(1)); 07240 | 07241 | case e_clamp : return (arg1 < arg0) ? arg0 : (arg1 > arg2 ? arg2 : arg1); 07242 | 07243 | case e_iclamp : if ((arg1 <= arg0) || (arg1 >= arg2)) 07244 | return arg1; 07245 | else 07246 | return ((T(2) * arg1 <= (arg2 + arg0)) ? arg0 : arg2); 07247 | 07248 | default : exprtk_debug(("trinary_node::value() - Error: Invalid operation\n")); 07249 | return std::numeric_limits<T>::quiet_NaN(); 07250 | } 07251 | } 07252 | 07253 | inline typename expression_node<T>::node_type type() const exprtk_override 07254 | { 07255 | return expression_node<T>::e_trinary; 07256 | } 07257 | 07258 | inline bool valid() const exprtk_override 07259 | { 07260 | return 07261 | branch_[0].first && branch_[0].first->valid() && 07262 | branch_[1].first && branch_[1].first->valid() && 07263 | branch_[2].first && branch_[2].first->valid() ; 07264 | } 07265 | 07266 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 07267 | { 07268 | expression_node<T>::ndb_t::collect(branch_, node_delete_list); 07269 | } 07270 | 07271 | std::size_t node_depth() const exprtk_override exprtk_final 07272 | { 07273 | return expression_node<T>::ndb_t::template compute_node_depth<3>(branch_); 07274 | } 07275 | 07276 | protected: 07277 | 07278 | operator_type operation_; 07279 | branch_t branch_[3]; 07280 | }; 07281 | 07282 | template <typename T> 07283 | class quaternary_node : public expression_node<T> 07284 | { 07285 | public: 07286 | 07287 | typedef expression_node<T>* expression_ptr; 07288 | typedef std::pair<expression_ptr,bool> branch_t; 07289 | 07290 | quaternary_node(const operator_type& opr, 07291 | expression_ptr branch0, 07292 | expression_ptr branch1, 07293 | expression_ptr branch2, 07294 | expression_ptr branch3) 07295 | : operation_(opr) 07296 | { 07297 | init_branches<4>(branch_, branch0, branch1, branch2, branch3); 07298 | } 07299 | 07300 | inline T value() const exprtk_override 07301 | { 07302 | return std::numeric_limits<T>::quiet_NaN(); 07303 | } 07304 | 07305 | inline typename expression_node<T>::node_type type() const exprtk_override 07306 | { 07307 | return expression_node<T>::e_quaternary; 07308 | } 07309 | 07310 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 07311 | { 07312 | expression_node<T>::ndb_t::collect(branch_, node_delete_list); 07313 | } 07314 | 07315 | std::size_t node_depth() const exprtk_override exprtk_final 07316 | { 07317 | return expression_node<T>::ndb_t::template compute_node_depth<4>(branch_); 07318 | } 07319 | 07320 | inline bool valid() const exprtk_override 07321 | { 07322 | return 07323 | branch_[0].first && branch_[0].first->valid() && 07324 | branch_[1].first && branch_[1].first->valid() && 07325 | branch_[2].first && branch_[2].first->valid() && 07326 | branch_[3].first && branch_[3].first->valid() ; 07327 | } 07328 | 07329 | protected: 07330 | 07331 | operator_type operation_; 07332 | branch_t branch_[4]; 07333 | }; 07334 | 07335 | template <typename T> 07336 | class conditional_node exprtk_final : public expression_node<T> 07337 | { 07338 | public: 07339 | 07340 | typedef expression_node<T>* expression_ptr; 07341 | typedef std::pair<expression_ptr,bool> branch_t; 07342 | 07343 | conditional_node(expression_ptr condition, 07344 | expression_ptr consequent, 07345 | expression_ptr alternative) 07346 | { 07347 | construct_branch_pair(condition_ , condition ); 07348 | construct_branch_pair(consequent_ , consequent ); 07349 | construct_branch_pair(alternative_, alternative); 07350 | assert(valid()); 07351 | } 07352 | 07353 | inline T value() const exprtk_override 07354 | { 07355 | if (is_true(condition_)) 07356 | return consequent_.first->value(); 07357 | else 07358 | return alternative_.first->value(); 07359 | } 07360 | 07361 | inline typename expression_node<T>::node_type type() const exprtk_override 07362 | { 07363 | return expression_node<T>::e_conditional; 07364 | } 07365 | 07366 | inline bool valid() const exprtk_override 07367 | { 07368 | return 07369 | condition_ .first && condition_ .first->valid() && 07370 | consequent_ .first && consequent_ .first->valid() && 07371 | alternative_.first && alternative_.first->valid() ; 07372 | } 07373 | 07374 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 07375 | { 07376 | expression_node<T>::ndb_t::collect(condition_ , node_delete_list); 07377 | expression_node<T>::ndb_t::collect(consequent_ , node_delete_list); 07378 | expression_node<T>::ndb_t::collect(alternative_ , node_delete_list); 07379 | } 07380 | 07381 | std::size_t node_depth() const exprtk_override 07382 | { 07383 | return expression_node<T>::ndb_t::compute_node_depth 07384 | (condition_, consequent_, alternative_); 07385 | } 07386 | 07387 | private: 07388 | 07389 | branch_t condition_; 07390 | branch_t consequent_; 07391 | branch_t alternative_; 07392 | }; 07393 | 07394 | template <typename T> 07395 | class cons_conditional_node exprtk_final : public expression_node<T> 07396 | { 07397 | public: 07398 | 07399 | // Consequent only conditional statement node 07400 | typedef expression_node<T>* expression_ptr; 07401 | typedef std::pair<expression_ptr,bool> branch_t; 07402 | 07403 | cons_conditional_node(expression_ptr condition, 07404 | expression_ptr consequent) 07405 | { 07406 | construct_branch_pair(condition_ , condition ); 07407 | construct_branch_pair(consequent_, consequent); 07408 | assert(valid()); 07409 | } 07410 | 07411 | inline T value() const exprtk_override 07412 | { 07413 | if (is_true(condition_)) 07414 | return consequent_.first->value(); 07415 | else 07416 | return std::numeric_limits<T>::quiet_NaN(); 07417 | } 07418 | 07419 | inline typename expression_node<T>::node_type type() const exprtk_override 07420 | { 07421 | return expression_node<T>::e_conditional; 07422 | } 07423 | 07424 | inline bool valid() const exprtk_override 07425 | { 07426 | return 07427 | condition_ .first && condition_ .first->valid() && 07428 | consequent_.first && consequent_.first->valid() ; 07429 | } 07430 | 07431 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 07432 | { 07433 | expression_node<T>::ndb_t::collect(condition_ , node_delete_list); 07434 | expression_node<T>::ndb_t::collect(consequent_ , node_delete_list); 07435 | } 07436 | 07437 | std::size_t node_depth() const exprtk_override 07438 | { 07439 | return expression_node<T>::ndb_t:: 07440 | compute_node_depth(condition_, consequent_); 07441 | } 07442 | 07443 | private: 07444 | 07445 | branch_t condition_; 07446 | branch_t consequent_; 07447 | }; 07448 | 07449 | #ifndef exprtk_disable_break_continue 07450 | template <typename T> 07451 | class break_exception 07452 | { 07453 | public: 07454 | 07455 | explicit break_exception(const T& v) 07456 | : value(v) 07457 | {} 07458 | 07459 | T value; 07460 | }; 07461 | 07462 | class continue_exception {}; 07463 | 07464 | template <typename T> 07465 | class break_node exprtk_final : public expression_node<T> 07466 | { 07467 | public: 07468 | 07469 | typedef expression_node<T>* expression_ptr; 07470 | typedef std::pair<expression_ptr,bool> branch_t; 07471 | 07472 | explicit break_node(expression_ptr ret = expression_ptr(0)) 07473 | { 07474 | construct_branch_pair(return_, ret); 07475 | } 07476 | 07477 | inline T value() const exprtk_override 07478 | { 07479 | const T result = return_.first ? 07480 | return_.first->value() : 07481 | std::numeric_limits<T>::quiet_NaN(); 07482 | 07483 | throw break_exception<T>(result); 07484 | 07485 | #if !defined(_MSC_VER) && !defined(__NVCOMPILER) 07486 | return std::numeric_limits<T>::quiet_NaN(); 07487 | #endif 07488 | } 07489 | 07490 | inline typename expression_node<T>::node_type type() const exprtk_override 07491 | { 07492 | return expression_node<T>::e_break; 07493 | } 07494 | 07495 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 07496 | { 07497 | expression_node<T>::ndb_t::collect(return_, node_delete_list); 07498 | } 07499 | 07500 | std::size_t node_depth() const exprtk_override 07501 | { 07502 | return expression_node<T>::ndb_t::compute_node_depth(return_); 07503 | } 07504 | 07505 | private: 07506 | 07507 | branch_t return_; 07508 | }; 07509 | 07510 | template <typename T> 07511 | class continue_node exprtk_final : public expression_node<T> 07512 | { 07513 | public: 07514 | 07515 | inline T value() const exprtk_override 07516 | { 07517 | throw continue_exception(); 07518 | #if !defined(_MSC_VER) && !defined(__NVCOMPILER) 07519 | return std::numeric_limits<T>::quiet_NaN(); 07520 | #endif 07521 | } 07522 | 07523 | inline typename expression_node<T>::node_type type() const exprtk_override 07524 | { 07525 | return expression_node<T>::e_break; 07526 | } 07527 | }; 07528 | #endif 07529 | 07530 | struct loop_runtime_checker 07531 | { 07532 | loop_runtime_checker(loop_runtime_check_ptr loop_runtime_check, 07533 | loop_runtime_check::loop_types lp_typ = loop_runtime_check::e_invalid) 07534 | : iteration_count_(0) 07535 | , loop_runtime_check_(loop_runtime_check) 07536 | , max_loop_iterations_(loop_runtime_check_->max_loop_iterations) 07537 | , loop_type_(lp_typ) 07538 | { 07539 | assert(loop_runtime_check_); 07540 | } 07541 | 07542 | inline void reset(const _uint64_t initial_value = 0) const 07543 | { 07544 | iteration_count_ = initial_value; 07545 | } 07546 | 07547 | inline bool check() const 07548 | { 07549 | assert(loop_runtime_check_); 07550 | 07551 | if ( 07552 | (++iteration_count_ <= max_loop_iterations_) && 07553 | loop_runtime_check_->check() 07554 | ) 07555 | { 07556 | return true; 07557 | } 07558 | 07559 | loop_runtime_check::violation_context ctxt; 07560 | ctxt.loop = loop_type_; 07561 | ctxt.violation = loop_runtime_check::e_iteration_count; 07562 | 07563 | loop_runtime_check_->handle_runtime_violation(ctxt); 07564 | 07565 | return false; 07566 | } 07567 | 07568 | bool valid() const 07569 | { 07570 | return 0 != loop_runtime_check_; 07571 | } 07572 | 07573 | mutable _uint64_t iteration_count_; 07574 | mutable loop_runtime_check_ptr loop_runtime_check_; 07575 | const details::_uint64_t& max_loop_iterations_; 07576 | loop_runtime_check::loop_types loop_type_; 07577 | }; 07578 | 07579 | template <typename T> 07580 | class while_loop_node : public expression_node<T> 07581 | { 07582 | public: 07583 | 07584 | typedef expression_node<T>* expression_ptr; 07585 | typedef std::pair<expression_ptr,bool> branch_t; 07586 | 07587 | while_loop_node(expression_ptr condition, 07588 | expression_ptr loop_body) 07589 | { 07590 | construct_branch_pair(condition_, condition); 07591 | construct_branch_pair(loop_body_, loop_body); 07592 | assert(valid()); 07593 | } 07594 | 07595 | inline T value() const exprtk_override 07596 | { 07597 | T result = T(0); 07598 | 07599 | while (is_true(condition_)) 07600 | { 07601 | result = loop_body_.first->value(); 07602 | } 07603 | 07604 | return result; 07605 | } 07606 | 07607 | inline typename expression_node<T>::node_type type() const exprtk_override 07608 | { 07609 | return expression_node<T>::e_while; 07610 | } 07611 | 07612 | inline bool valid() const exprtk_override 07613 | { 07614 | return 07615 | condition_.first && condition_.first->valid() && 07616 | loop_body_.first && loop_body_.first->valid() ; 07617 | } 07618 | 07619 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 07620 | { 07621 | expression_node<T>::ndb_t::collect(condition_ , node_delete_list); 07622 | expression_node<T>::ndb_t::collect(loop_body_ , node_delete_list); 07623 | } 07624 | 07625 | std::size_t node_depth() const exprtk_override 07626 | { 07627 | return expression_node<T>::ndb_t::compute_node_depth(condition_, loop_body_); 07628 | } 07629 | 07630 | protected: 07631 | 07632 | branch_t condition_; 07633 | branch_t loop_body_; 07634 | }; 07635 | 07636 | template <typename T> 07637 | class while_loop_rtc_node exprtk_final 07638 | : public while_loop_node<T> 07639 | , public loop_runtime_checker 07640 | { 07641 | public: 07642 | 07643 | typedef while_loop_node<T> parent_t; 07644 | typedef expression_node<T>* expression_ptr; 07645 | 07646 | while_loop_rtc_node(expression_ptr condition, 07647 | expression_ptr loop_body, 07648 | loop_runtime_check_ptr loop_rt_chk) 07649 | : parent_t(condition, loop_body) 07650 | , loop_runtime_checker(loop_rt_chk, loop_runtime_check::e_while_loop) 07651 | { 07652 | assert(valid()); 07653 | } 07654 | 07655 | inline T value() const exprtk_override 07656 | { 07657 | 07658 | T result = T(0); 07659 | 07660 | loop_runtime_checker::reset(); 07661 | 07662 | while (is_true(parent_t::condition_) && loop_runtime_checker::check()) 07663 | { 07664 | result = parent_t::loop_body_.first->value(); 07665 | } 07666 | 07667 | return result; 07668 | } 07669 | 07670 | using parent_t::valid; 07671 | 07672 | bool valid() const exprtk_override exprtk_final 07673 | { 07674 | return parent_t::valid() && 07675 | loop_runtime_checker::valid(); 07676 | } 07677 | }; 07678 | 07679 | template <typename T> 07680 | class repeat_until_loop_node : public expression_node<T> 07681 | { 07682 | public: 07683 | 07684 | typedef expression_node<T>* expression_ptr; 07685 | typedef std::pair<expression_ptr,bool> branch_t; 07686 | 07687 | repeat_until_loop_node(expression_ptr condition, 07688 | expression_ptr loop_body) 07689 | { 07690 | construct_branch_pair(condition_, condition); 07691 | construct_branch_pair(loop_body_, loop_body); 07692 | assert(valid()); 07693 | } 07694 | 07695 | inline T value() const exprtk_override 07696 | { 07697 | T result = T(0); 07698 | 07699 | do 07700 | { 07701 | result = loop_body_.first->value(); 07702 | } 07703 | while (is_false(condition_.first)); 07704 | 07705 | return result; 07706 | } 07707 | 07708 | inline typename expression_node<T>::node_type type() const exprtk_override 07709 | { 07710 | return expression_node<T>::e_repeat; 07711 | } 07712 | 07713 | inline bool valid() const exprtk_override 07714 | { 07715 | return 07716 | condition_.first && condition_.first->valid() && 07717 | loop_body_.first && loop_body_.first->valid() ; 07718 | } 07719 | 07720 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 07721 | { 07722 | expression_node<T>::ndb_t::collect(condition_ , node_delete_list); 07723 | expression_node<T>::ndb_t::collect(loop_body_ , node_delete_list); 07724 | } 07725 | 07726 | std::size_t node_depth() const exprtk_override 07727 | { 07728 | return expression_node<T>::ndb_t::compute_node_depth(condition_, loop_body_); 07729 | } 07730 | 07731 | protected: 07732 | 07733 | branch_t condition_; 07734 | branch_t loop_body_; 07735 | }; 07736 | 07737 | template <typename T> 07738 | class repeat_until_loop_rtc_node exprtk_final 07739 | : public repeat_until_loop_node<T> 07740 | , public loop_runtime_checker 07741 | { 07742 | public: 07743 | 07744 | typedef repeat_until_loop_node<T> parent_t; 07745 | typedef expression_node<T>* expression_ptr; 07746 | 07747 | repeat_until_loop_rtc_node(expression_ptr condition, 07748 | expression_ptr loop_body, 07749 | loop_runtime_check_ptr loop_rt_chk) 07750 | : parent_t(condition, loop_body) 07751 | , loop_runtime_checker(loop_rt_chk, loop_runtime_check::e_repeat_until_loop) 07752 | { 07753 | assert(valid()); 07754 | } 07755 | 07756 | inline T value() const exprtk_override 07757 | { 07758 | T result = T(0); 07759 | 07760 | loop_runtime_checker::reset(1); 07761 | 07762 | do 07763 | { 07764 | result = parent_t::loop_body_.first->value(); 07765 | } 07766 | while (is_false(parent_t::condition_.first) && loop_runtime_checker::check()); 07767 | 07768 | return result; 07769 | } 07770 | 07771 | using parent_t::valid; 07772 | 07773 | inline bool valid() const exprtk_override exprtk_final 07774 | { 07775 | return parent_t::valid() && 07776 | loop_runtime_checker::valid(); 07777 | } 07778 | }; 07779 | 07780 | template <typename T> 07781 | class for_loop_node : public expression_node<T> 07782 | { 07783 | public: 07784 | 07785 | typedef expression_node<T>* expression_ptr; 07786 | typedef std::pair<expression_ptr,bool> branch_t; 07787 | 07788 | for_loop_node(expression_ptr initialiser, 07789 | expression_ptr condition, 07790 | expression_ptr incrementor, 07791 | expression_ptr loop_body) 07792 | { 07793 | construct_branch_pair(initialiser_, initialiser); 07794 | construct_branch_pair(condition_ , condition ); 07795 | construct_branch_pair(incrementor_, incrementor); 07796 | construct_branch_pair(loop_body_ , loop_body ); 07797 | assert(valid()); 07798 | } 07799 | 07800 | inline T value() const exprtk_override 07801 | { 07802 | T result = T(0); 07803 | 07804 | if (initialiser_.first) 07805 | initialiser_.first->value(); 07806 | 07807 | if (incrementor_.first) 07808 | { 07809 | while (is_true(condition_)) 07810 | { 07811 | result = loop_body_.first->value(); 07812 | incrementor_.first->value(); 07813 | } 07814 | } 07815 | else 07816 | { 07817 | while (is_true(condition_)) 07818 | { 07819 | result = loop_body_.first->value(); 07820 | } 07821 | } 07822 | 07823 | return result; 07824 | } 07825 | 07826 | inline typename expression_node<T>::node_type type() const exprtk_override 07827 | { 07828 | return expression_node<T>::e_for; 07829 | } 07830 | 07831 | inline bool valid() const exprtk_override 07832 | { 07833 | return condition_.first && loop_body_.first; 07834 | } 07835 | 07836 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 07837 | { 07838 | expression_node<T>::ndb_t::collect(initialiser_ , node_delete_list); 07839 | expression_node<T>::ndb_t::collect(condition_ , node_delete_list); 07840 | expression_node<T>::ndb_t::collect(incrementor_ , node_delete_list); 07841 | expression_node<T>::ndb_t::collect(loop_body_ , node_delete_list); 07842 | } 07843 | 07844 | std::size_t node_depth() const exprtk_override 07845 | { 07846 | return expression_node<T>::ndb_t::compute_node_depth 07847 | (initialiser_, condition_, incrementor_, loop_body_); 07848 | } 07849 | 07850 | protected: 07851 | 07852 | branch_t initialiser_; 07853 | branch_t condition_ ; 07854 | branch_t incrementor_; 07855 | branch_t loop_body_ ; 07856 | }; 07857 | 07858 | template <typename T> 07859 | class for_loop_rtc_node exprtk_final 07860 | : public for_loop_node<T> 07861 | , public loop_runtime_checker 07862 | { 07863 | public: 07864 | 07865 | typedef for_loop_node<T> parent_t; 07866 | typedef expression_node<T>* expression_ptr; 07867 | 07868 | for_loop_rtc_node(expression_ptr initialiser, 07869 | expression_ptr condition, 07870 | expression_ptr incrementor, 07871 | expression_ptr loop_body, 07872 | loop_runtime_check_ptr loop_rt_chk) 07873 | : parent_t(initialiser, condition, incrementor, loop_body) 07874 | , loop_runtime_checker(loop_rt_chk, loop_runtime_check::e_for_loop) 07875 | { 07876 | assert(valid()); 07877 | } 07878 | 07879 | inline T value() const exprtk_override 07880 | { 07881 | T result = T(0); 07882 | 07883 | loop_runtime_checker::reset(); 07884 | 07885 | if (parent_t::initialiser_.first) 07886 | parent_t::initialiser_.first->value(); 07887 | 07888 | if (parent_t::incrementor_.first) 07889 | { 07890 | while (is_true(parent_t::condition_) && loop_runtime_checker::check()) 07891 | { 07892 | result = parent_t::loop_body_.first->value(); 07893 | parent_t::incrementor_.first->value(); 07894 | } 07895 | } 07896 | else 07897 | { 07898 | while (is_true(parent_t::condition_) && loop_runtime_checker::check()) 07899 | { 07900 | result = parent_t::loop_body_.first->value(); 07901 | } 07902 | } 07903 | 07904 | return result; 07905 | } 07906 | 07907 | using parent_t::valid; 07908 | 07909 | inline bool valid() const exprtk_override exprtk_final 07910 | { 07911 | return parent_t::valid() && 07912 | loop_runtime_checker::valid(); 07913 | } 07914 | }; 07915 | 07916 | #ifndef exprtk_disable_break_continue 07917 | template <typename T> 07918 | class while_loop_bc_node : public while_loop_node<T> 07919 | { 07920 | public: 07921 | 07922 | typedef while_loop_node<T> parent_t; 07923 | typedef expression_node<T>* expression_ptr; 07924 | 07925 | while_loop_bc_node(expression_ptr condition, 07926 | expression_ptr loop_body) 07927 | : parent_t(condition, loop_body) 07928 | { 07929 | assert(parent_t::valid()); 07930 | } 07931 | 07932 | inline T value() const exprtk_override 07933 | { 07934 | T result = T(0); 07935 | 07936 | while (is_true(parent_t::condition_)) 07937 | { 07938 | try 07939 | { 07940 | result = parent_t::loop_body_.first->value(); 07941 | } 07942 | catch(const break_exception<T>& e) 07943 | { 07944 | return e.value; 07945 | } 07946 | catch(const continue_exception&) 07947 | {} 07948 | } 07949 | 07950 | return result; 07951 | } 07952 | }; 07953 | 07954 | template <typename T> 07955 | class while_loop_bc_rtc_node exprtk_final 07956 | : public while_loop_bc_node<T> 07957 | , public loop_runtime_checker 07958 | { 07959 | public: 07960 | 07961 | typedef while_loop_bc_node<T> parent_t; 07962 | typedef expression_node<T>* expression_ptr; 07963 | 07964 | while_loop_bc_rtc_node(expression_ptr condition, 07965 | expression_ptr loop_body, 07966 | loop_runtime_check_ptr loop_rt_chk) 07967 | : parent_t(condition, loop_body) 07968 | , loop_runtime_checker(loop_rt_chk, loop_runtime_check::e_while_loop) 07969 | { 07970 | assert(valid()); 07971 | } 07972 | 07973 | inline T value() const exprtk_override 07974 | { 07975 | T result = T(0); 07976 | 07977 | loop_runtime_checker::reset(); 07978 | 07979 | while (is_true(parent_t::condition_) && loop_runtime_checker::check()) 07980 | { 07981 | try 07982 | { 07983 | result = parent_t::loop_body_.first->value(); 07984 | } 07985 | catch(const break_exception<T>& e) 07986 | { 07987 | return e.value; 07988 | } 07989 | catch(const continue_exception&) 07990 | {} 07991 | } 07992 | 07993 | return result; 07994 | } 07995 | 07996 | using parent_t::valid; 07997 | 07998 | inline bool valid() const exprtk_override exprtk_final 07999 | { 08000 | return parent_t::valid() && 08001 | loop_runtime_checker::valid(); 08002 | } 08003 | }; 08004 | 08005 | template <typename T> 08006 | class repeat_until_loop_bc_node : public repeat_until_loop_node<T> 08007 | { 08008 | public: 08009 | 08010 | typedef repeat_until_loop_node<T> parent_t; 08011 | typedef expression_node<T>* expression_ptr; 08012 | 08013 | repeat_until_loop_bc_node(expression_ptr condition, 08014 | expression_ptr loop_body) 08015 | : parent_t(condition, loop_body) 08016 | { 08017 | assert(parent_t::valid()); 08018 | } 08019 | 08020 | inline T value() const exprtk_override 08021 | { 08022 | T result = T(0); 08023 | 08024 | do 08025 | { 08026 | try 08027 | { 08028 | result = parent_t::loop_body_.first->value(); 08029 | } 08030 | catch(const break_exception<T>& e) 08031 | { 08032 | return e.value; 08033 | } 08034 | catch(const continue_exception&) 08035 | {} 08036 | } 08037 | while (is_false(parent_t::condition_.first)); 08038 | 08039 | return result; 08040 | } 08041 | }; 08042 | 08043 | template <typename T> 08044 | class repeat_until_loop_bc_rtc_node exprtk_final 08045 | : public repeat_until_loop_bc_node<T> 08046 | , public loop_runtime_checker 08047 | { 08048 | public: 08049 | 08050 | typedef repeat_until_loop_bc_node<T> parent_t; 08051 | typedef expression_node<T>* expression_ptr; 08052 | 08053 | repeat_until_loop_bc_rtc_node(expression_ptr condition, 08054 | expression_ptr loop_body, 08055 | loop_runtime_check_ptr loop_rt_chk) 08056 | : parent_t(condition, loop_body) 08057 | , loop_runtime_checker(loop_rt_chk, loop_runtime_check::e_repeat_until_loop) 08058 | { 08059 | assert(valid()); 08060 | } 08061 | 08062 | inline T value() const exprtk_override 08063 | { 08064 | T result = T(0); 08065 | 08066 | loop_runtime_checker::reset(); 08067 | 08068 | do 08069 | { 08070 | try 08071 | { 08072 | result = parent_t::loop_body_.first->value(); 08073 | } 08074 | catch(const break_exception<T>& e) 08075 | { 08076 | return e.value; 08077 | } 08078 | catch(const continue_exception&) 08079 | {} 08080 | } 08081 | while (is_false(parent_t::condition_.first) && loop_runtime_checker::check()); 08082 | 08083 | return result; 08084 | } 08085 | 08086 | using parent_t::valid; 08087 | 08088 | inline bool valid() const exprtk_override exprtk_final 08089 | { 08090 | return parent_t::valid() && 08091 | loop_runtime_checker::valid(); 08092 | } 08093 | }; 08094 | 08095 | template <typename T> 08096 | class for_loop_bc_node : public for_loop_node<T> 08097 | { 08098 | public: 08099 | 08100 | typedef for_loop_node<T> parent_t; 08101 | typedef expression_node<T>* expression_ptr; 08102 | 08103 | for_loop_bc_node(expression_ptr initialiser, 08104 | expression_ptr condition, 08105 | expression_ptr incrementor, 08106 | expression_ptr loop_body) 08107 | : parent_t(initialiser, condition, incrementor, loop_body) 08108 | { 08109 | assert(parent_t::valid()); 08110 | } 08111 | 08112 | inline T value() const exprtk_override 08113 | { 08114 | T result = T(0); 08115 | 08116 | if (parent_t::initialiser_.first) 08117 | parent_t::initialiser_.first->value(); 08118 | 08119 | if (parent_t::incrementor_.first) 08120 | { 08121 | while (is_true(parent_t::condition_)) 08122 | { 08123 | try 08124 | { 08125 | result = parent_t::loop_body_.first->value(); 08126 | } 08127 | catch(const break_exception<T>& e) 08128 | { 08129 | return e.value; 08130 | } 08131 | catch(const continue_exception&) 08132 | {} 08133 | 08134 | parent_t::incrementor_.first->value(); 08135 | } 08136 | } 08137 | else 08138 | { 08139 | while (is_true(parent_t::condition_)) 08140 | { 08141 | try 08142 | { 08143 | result = parent_t::loop_body_.first->value(); 08144 | } 08145 | catch(const break_exception<T>& e) 08146 | { 08147 | return e.value; 08148 | } 08149 | catch(const continue_exception&) 08150 | {} 08151 | } 08152 | } 08153 | 08154 | return result; 08155 | } 08156 | }; 08157 | 08158 | template <typename T> 08159 | class for_loop_bc_rtc_node exprtk_final 08160 | : public for_loop_bc_node<T> 08161 | , public loop_runtime_checker 08162 | { 08163 | public: 08164 | 08165 | typedef for_loop_bc_node<T> parent_t; 08166 | typedef expression_node<T>* expression_ptr; 08167 | 08168 | for_loop_bc_rtc_node(expression_ptr initialiser, 08169 | expression_ptr condition, 08170 | expression_ptr incrementor, 08171 | expression_ptr loop_body, 08172 | loop_runtime_check_ptr loop_rt_chk) 08173 | : parent_t(initialiser, condition, incrementor, loop_body) 08174 | , loop_runtime_checker(loop_rt_chk, loop_runtime_check::e_for_loop) 08175 | { 08176 | assert(valid()); 08177 | } 08178 | 08179 | inline T value() const exprtk_override 08180 | { 08181 | T result = T(0); 08182 | 08183 | loop_runtime_checker::reset(); 08184 | 08185 | if (parent_t::initialiser_.first) 08186 | parent_t::initialiser_.first->value(); 08187 | 08188 | if (parent_t::incrementor_.first) 08189 | { 08190 | while (is_true(parent_t::condition_) && loop_runtime_checker::check()) 08191 | { 08192 | try 08193 | { 08194 | result = parent_t::loop_body_.first->value(); 08195 | } 08196 | catch(const break_exception<T>& e) 08197 | { 08198 | return e.value; 08199 | } 08200 | catch(const continue_exception&) 08201 | {} 08202 | 08203 | parent_t::incrementor_.first->value(); 08204 | } 08205 | } 08206 | else 08207 | { 08208 | while (is_true(parent_t::condition_) && loop_runtime_checker::check()) 08209 | { 08210 | try 08211 | { 08212 | result = parent_t::loop_body_.first->value(); 08213 | } 08214 | catch(const break_exception<T>& e) 08215 | { 08216 | return e.value; 08217 | } 08218 | catch(const continue_exception&) 08219 | {} 08220 | } 08221 | } 08222 | 08223 | return result; 08224 | } 08225 | 08226 | using parent_t::valid; 08227 | 08228 | inline bool valid() const exprtk_override exprtk_final 08229 | { 08230 | return parent_t::valid() && 08231 | loop_runtime_checker::valid(); 08232 | } 08233 | }; 08234 | #endif 08235 | 08236 | template <typename T> 08237 | class switch_node : public expression_node<T> 08238 | { 08239 | public: 08240 | 08241 | typedef expression_node<T>* expression_ptr; 08242 | typedef std::pair<expression_ptr,bool> branch_t; 08243 | 08244 | template <typename Allocator, 08245 | template <typename, typename> class Sequence> 08246 | explicit switch_node(const Sequence<expression_ptr,Allocator>& arg_list) 08247 | { 08248 | if (1 != (arg_list.size() & 1)) 08249 | return; 08250 | 08251 | arg_list_.resize(arg_list.size()); 08252 | 08253 | for (std::size_t i = 0; i < arg_list.size(); ++i) 08254 | { 08255 | if (arg_list[i] && arg_list[i]->valid()) 08256 | { 08257 | construct_branch_pair(arg_list_[i], arg_list[i]); 08258 | } 08259 | else 08260 | { 08261 | arg_list_.clear(); 08262 | return; 08263 | } 08264 | } 08265 | 08266 | assert(valid()); 08267 | } 08268 | 08269 | inline T value() const exprtk_override 08270 | { 08271 | const std::size_t upper_bound = (arg_list_.size() - 1); 08272 | 08273 | for (std::size_t i = 0; i < upper_bound; i += 2) 08274 | { 08275 | expression_ptr condition = arg_list_[i ].first; 08276 | expression_ptr consequent = arg_list_[i + 1].first; 08277 | 08278 | if (is_true(condition)) 08279 | { 08280 | return consequent->value(); 08281 | } 08282 | } 08283 | 08284 | return arg_list_[upper_bound].first->value(); 08285 | } 08286 | 08287 | inline typename expression_node<T>::node_type type() const exprtk_override exprtk_final 08288 | { 08289 | return expression_node<T>::e_switch; 08290 | } 08291 | 08292 | inline bool valid() const exprtk_override 08293 | { 08294 | return !arg_list_.empty(); 08295 | } 08296 | 08297 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 08298 | { 08299 | expression_node<T>::ndb_t::collect(arg_list_, node_delete_list); 08300 | } 08301 | 08302 | std::size_t node_depth() const exprtk_override exprtk_final 08303 | { 08304 | return expression_node<T>::ndb_t::compute_node_depth(arg_list_); 08305 | } 08306 | 08307 | protected: 08308 | 08309 | std::vector<branch_t> arg_list_; 08310 | }; 08311 | 08312 | template <typename T, typename Switch_N> 08313 | class switch_n_node exprtk_final : public switch_node<T> 08314 | { 08315 | public: 08316 | 08317 | typedef expression_node<T>* expression_ptr; 08318 | 08319 | template <typename Allocator, 08320 | template <typename, typename> class Sequence> 08321 | explicit switch_n_node(const Sequence<expression_ptr,Allocator>& arg_list) 08322 | : switch_node<T>(arg_list) 08323 | {} 08324 | 08325 | inline T value() const exprtk_override 08326 | { 08327 | return Switch_N::process(switch_node<T>::arg_list_); 08328 | } 08329 | }; 08330 | 08331 | template <typename T> 08332 | class multi_switch_node exprtk_final : public expression_node<T> 08333 | { 08334 | public: 08335 | 08336 | typedef expression_node<T>* expression_ptr; 08337 | typedef std::pair<expression_ptr,bool> branch_t; 08338 | 08339 | template <typename Allocator, 08340 | template <typename, typename> class Sequence> 08341 | explicit multi_switch_node(const Sequence<expression_ptr,Allocator>& arg_list) 08342 | { 08343 | if (0 != (arg_list.size() & 1)) 08344 | return; 08345 | 08346 | arg_list_.resize(arg_list.size()); 08347 | 08348 | for (std::size_t i = 0; i < arg_list.size(); ++i) 08349 | { 08350 | if (arg_list[i] && arg_list[i]->valid()) 08351 | { 08352 | construct_branch_pair(arg_list_[i], arg_list[i]); 08353 | } 08354 | else 08355 | { 08356 | arg_list_.clear(); 08357 | return; 08358 | } 08359 | } 08360 | 08361 | assert(valid()); 08362 | } 08363 | 08364 | inline T value() const exprtk_override 08365 | { 08366 | const std::size_t upper_bound = (arg_list_.size() - 1); 08367 | 08368 | T result = T(0); 08369 | 08370 | for (std::size_t i = 0; i < upper_bound; i += 2) 08371 | { 08372 | expression_ptr condition = arg_list_[i ].first; 08373 | expression_ptr consequent = arg_list_[i + 1].first; 08374 | 08375 | if (is_true(condition)) 08376 | { 08377 | result = consequent->value(); 08378 | } 08379 | } 08380 | 08381 | return result; 08382 | } 08383 | 08384 | inline typename expression_node<T>::node_type type() const exprtk_override 08385 | { 08386 | return expression_node<T>::e_mswitch; 08387 | } 08388 | 08389 | inline bool valid() const exprtk_override 08390 | { 08391 | return !arg_list_.empty() && (0 == (arg_list_.size() % 2)); 08392 | } 08393 | 08394 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 08395 | { 08396 | expression_node<T>::ndb_t::collect(arg_list_, node_delete_list); 08397 | } 08398 | 08399 | std::size_t node_depth() const exprtk_override exprtk_final 08400 | { 08401 | return expression_node<T>::ndb_t::compute_node_depth(arg_list_); 08402 | } 08403 | 08404 | private: 08405 | 08406 | std::vector<branch_t> arg_list_; 08407 | }; 08408 | 08409 | template <typename T> 08410 | class ivariable 08411 | { 08412 | public: 08413 | 08414 | virtual ~ivariable() 08415 | {} 08416 | 08417 | virtual T& ref() = 0; 08418 | virtual const T& ref() const = 0; 08419 | }; 08420 | 08421 | template <typename T> 08422 | class variable_node exprtk_final 08423 | : public expression_node<T> 08424 | , public ivariable <T> 08425 | { 08426 | public: 08427 | 08428 | static T null_value; 08429 | 08430 | explicit variable_node() 08431 | : value_(&null_value) 08432 | {} 08433 | 08434 | explicit variable_node(T& v) 08435 | : value_(&v) 08436 | {} 08437 | 08438 | inline bool operator <(const variable_node<T>& v) const 08439 | { 08440 | return this < (&v); 08441 | } 08442 | 08443 | inline T value() const exprtk_override 08444 | { 08445 | return (*value_); 08446 | } 08447 | 08448 | inline T& ref() exprtk_override 08449 | { 08450 | return (*value_); 08451 | } 08452 | 08453 | inline const T& ref() const exprtk_override 08454 | { 08455 | return (*value_); 08456 | } 08457 | 08458 | inline typename expression_node<T>::node_type type() const exprtk_override 08459 | { 08460 | return expression_node<T>::e_variable; 08461 | } 08462 | 08463 | private: 08464 | 08465 | T* value_; 08466 | }; 08467 | 08468 | template <typename T> 08469 | T variable_node<T>::null_value = T(std::numeric_limits<T>::quiet_NaN()); 08470 | 08471 | template <typename T> 08472 | struct range_pack 08473 | { 08474 | typedef expression_node<T>* expression_node_ptr; 08475 | typedef std::pair<std::size_t,std::size_t> cached_range_t; 08476 | 08477 | range_pack() 08478 | : n0_e (std::make_pair(false,expression_node_ptr(0))) 08479 | , n1_e (std::make_pair(false,expression_node_ptr(0))) 08480 | , n0_c (std::make_pair(false,0)) 08481 | , n1_c (std::make_pair(false,0)) 08482 | , cache(std::make_pair(0,0)) 08483 | {} 08484 | 08485 | void clear() 08486 | { 08487 | n0_e = std::make_pair(false,expression_node_ptr(0)); 08488 | n1_e = std::make_pair(false,expression_node_ptr(0)); 08489 | n0_c = std::make_pair(false,0); 08490 | n1_c = std::make_pair(false,0); 08491 | cache = std::make_pair(0,0); 08492 | } 08493 | 08494 | void free() 08495 | { 08496 | if (n0_e.first && n0_e.second) 08497 | { 08498 | n0_e.first = false; 08499 | 08500 | if ( 08501 | !is_variable_node(n0_e.second) && 08502 | !is_string_node (n0_e.second) 08503 | ) 08504 | { 08505 | destroy_node(n0_e.second); 08506 | } 08507 | } 08508 | 08509 | if (n1_e.first && n1_e.second) 08510 | { 08511 | n1_e.first = false; 08512 | 08513 | if ( 08514 | !is_variable_node(n1_e.second) && 08515 | !is_string_node (n1_e.second) 08516 | ) 08517 | { 08518 | destroy_node(n1_e.second); 08519 | } 08520 | } 08521 | } 08522 | 08523 | bool const_range() const 08524 | { 08525 | return ( n0_c.first && n1_c.first) && 08526 | (!n0_e.first && !n1_e.first); 08527 | } 08528 | 08529 | bool var_range() const 08530 | { 08531 | return ( n0_e.first && n1_e.first) && 08532 | (!n0_c.first && !n1_c.first); 08533 | } 08534 | 08535 | bool operator() (std::size_t& r0, std::size_t& r1, 08536 | const std::size_t& size = std::numeric_limits<std::size_t>::max()) const 08537 | { 08538 | if (n0_c.first) 08539 | r0 = n0_c.second; 08540 | else if (n0_e.first) 08541 | { 08542 | r0 = static_cast<std::size_t>(details::numeric::to_int64(n0_e.second->value())); 08543 | } 08544 | else 08545 | return false; 08546 | 08547 | if (n1_c.first) 08548 | r1 = n1_c.second; 08549 | else if (n1_e.first) 08550 | { 08551 | r1 = static_cast<std::size_t>(details::numeric::to_int64(n1_e.second->value())); 08552 | } 08553 | else 08554 | return false; 08555 | 08556 | if ( 08557 | (std::numeric_limits<std::size_t>::max() != size) && 08558 | (std::numeric_limits<std::size_t>::max() == r1 ) 08559 | ) 08560 | { 08561 | r1 = size; 08562 | } 08563 | 08564 | cache.first = r0; 08565 | cache.second = r1; 08566 | 08567 | #ifndef exprtk_enable_range_runtime_checks 08568 | return (r0 <= r1); 08569 | #else 08570 | return range_runtime_check(r0, r1, size); 08571 | #endif 08572 | } 08573 | 08574 | inline std::size_t const_size() const 08575 | { 08576 | return (n1_c.second - n0_c.second); 08577 | } 08578 | 08579 | inline std::size_t cache_size() const 08580 | { 08581 | return (cache.second - cache.first); 08582 | } 08583 | 08584 | std::pair<bool,expression_node_ptr> n0_e; 08585 | std::pair<bool,expression_node_ptr> n1_e; 08586 | std::pair<bool,std::size_t > n0_c; 08587 | std::pair<bool,std::size_t > n1_c; 08588 | mutable cached_range_t cache; 08589 | 08590 | #ifdef exprtk_enable_range_runtime_checks 08591 | bool range_runtime_check(const std::size_t r0, 08592 | const std::size_t r1, 08593 | const std::size_t size) const 08594 | { 08595 | if (r0 > size) 08596 | { 08597 | throw std::runtime_error("range error: (r0 < 0) || (r0 > size)"); 08598 | #if !defined(_MSC_VER) && !defined(__NVCOMPILER) 08599 | return false; 08600 | #endif 08601 | } 08602 | 08603 | if (r1 > size) 08604 | { 08605 | throw std::runtime_error("range error: (r1 < 0) || (r1 > size)"); 08606 | #if !defined(_MSC_VER) && !defined(__NVCOMPILER) 08607 | return false; 08608 | #endif 08609 | } 08610 | 08611 | return (r0 <= r1); 08612 | } 08613 | #endif 08614 | }; 08615 | 08616 | template <typename T> 08617 | class string_base_node; 08618 | 08619 | template <typename T> 08620 | struct range_data_type 08621 | { 08622 | typedef range_pack<T> range_t; 08623 | typedef string_base_node<T>* strbase_ptr_t; 08624 | 08625 | range_data_type() 08626 | : range(0) 08627 | , data (0) 08628 | , size (0) 08629 | , type_size(0) 08630 | , str_node (0) 08631 | {} 08632 | 08633 | range_t* range; 08634 | void* data; 08635 | std::size_t size; 08636 | std::size_t type_size; 08637 | strbase_ptr_t str_node; 08638 | }; 08639 | 08640 | template <typename T> class vector_node; 08641 | 08642 | template <typename T> 08643 | class vector_interface 08644 | { 08645 | public: 08646 | 08647 | typedef vector_node<T>* vector_node_ptr; 08648 | typedef vec_data_store<T> vds_t; 08649 | 08650 | virtual ~vector_interface() 08651 | {} 08652 | 08653 | virtual std::size_t size () const = 0; 08654 | 08655 | virtual std::size_t base_size() const = 0; 08656 | 08657 | virtual vector_node_ptr vec () const = 0; 08658 | 08659 | virtual vector_node_ptr vec () = 0; 08660 | 08661 | virtual vds_t& vds () = 0; 08662 | 08663 | virtual const vds_t& vds () const = 0; 08664 | 08665 | virtual bool side_effect () const { return false; } 08666 | }; 08667 | 08668 | template <typename T> 08669 | class vector_node exprtk_final 08670 | : public expression_node <T> 08671 | , public vector_interface<T> 08672 | { 08673 | public: 08674 | 08675 | typedef expression_node<T>* expression_ptr; 08676 | typedef vector_holder<T> vector_holder_t; 08677 | typedef vector_node<T>* vector_node_ptr; 08678 | typedef vec_data_store<T> vds_t; 08679 | 08680 | explicit vector_node(vector_holder_t* vh) 08681 | : vector_holder_(vh) 08682 | , vds_((*vector_holder_).size(),(*vector_holder_)[0]) 08683 | { 08684 | vector_holder_->set_ref(&vds_.ref()); 08685 | } 08686 | 08687 | vector_node(const vds_t& vds, vector_holder_t* vh) 08688 | : vector_holder_(vh) 08689 | , vds_(vds) 08690 | {} 08691 | 08692 | ~vector_node() exprtk_override 08693 | { 08694 | assert(valid()); 08695 | vector_holder_->remove_ref(&vds_.ref()); 08696 | } 08697 | 08698 | inline T value() const exprtk_override 08699 | { 08700 | return vds().data()[0]; 08701 | } 08702 | 08703 | vector_node_ptr vec() const exprtk_override 08704 | { 08705 | return const_cast<vector_node_ptr>(this); 08706 | } 08707 | 08708 | vector_node_ptr vec() exprtk_override 08709 | { 08710 | return this; 08711 | } 08712 | 08713 | inline typename expression_node<T>::node_type type() const exprtk_override 08714 | { 08715 | return expression_node<T>::e_vector; 08716 | } 08717 | 08718 | inline bool valid() const exprtk_override 08719 | { 08720 | return vector_holder_; 08721 | } 08722 | 08723 | std::size_t size() const exprtk_override 08724 | { 08725 | return vec_holder().size(); 08726 | } 08727 | 08728 | std::size_t base_size() const exprtk_override 08729 | { 08730 | return vec_holder().base_size(); 08731 | } 08732 | 08733 | vds_t& vds() exprtk_override 08734 | { 08735 | return vds_; 08736 | } 08737 | 08738 | const vds_t& vds() const exprtk_override 08739 | { 08740 | return vds_; 08741 | } 08742 | 08743 | inline vector_holder_t& vec_holder() 08744 | { 08745 | return (*vector_holder_); 08746 | } 08747 | 08748 | inline vector_holder_t& vec_holder() const 08749 | { 08750 | return (*vector_holder_); 08751 | } 08752 | 08753 | private: 08754 | 08755 | vector_holder_t* vector_holder_; 08756 | vds_t vds_; 08757 | }; 08758 | 08759 | template <typename T> 08760 | class vector_size_node exprtk_final 08761 | : public expression_node <T> 08762 | { 08763 | public: 08764 | 08765 | typedef expression_node<T>* expression_ptr; 08766 | typedef vector_holder<T> vector_holder_t; 08767 | 08768 | explicit vector_size_node(vector_holder_t* vh) 08769 | : vector_holder_(vh) 08770 | {} 08771 | 08772 | ~vector_size_node() exprtk_override 08773 | { 08774 | assert(valid()); 08775 | } 08776 | 08777 | inline T value() const exprtk_override 08778 | { 08779 | assert(vector_holder_); 08780 | return static_cast<T>(vector_holder_->size()); 08781 | } 08782 | 08783 | inline typename expression_node<T>::node_type type() const exprtk_override 08784 | { 08785 | return expression_node<T>::e_vecsize; 08786 | } 08787 | 08788 | inline bool valid() const exprtk_override 08789 | { 08790 | return vector_holder_ && vector_holder_->size(); 08791 | } 08792 | 08793 | inline vector_holder_t* vec_holder() 08794 | { 08795 | return vector_holder_; 08796 | } 08797 | 08798 | private: 08799 | 08800 | vector_holder_t* vector_holder_; 08801 | }; 08802 | 08803 | template <typename T> 08804 | class vector_elem_node exprtk_final 08805 | : public expression_node<T> 08806 | , public ivariable <T> 08807 | { 08808 | public: 08809 | 08810 | typedef expression_node<T>* expression_ptr; 08811 | typedef vector_holder<T> vector_holder_t; 08812 | typedef vector_holder_t* vector_holder_ptr; 08813 | typedef std::pair<expression_ptr,bool> branch_t; 08814 | 08815 | vector_elem_node(expression_ptr vec_node, 08816 | expression_ptr index, 08817 | vector_holder_ptr vec_holder) 08818 | : vector_holder_(vec_holder) 08819 | , vector_base_((*vec_holder)[0]) 08820 | { 08821 | construct_branch_pair(vector_node_, vec_node); 08822 | construct_branch_pair(index_ , index ); 08823 | assert(valid()); 08824 | } 08825 | 08826 | inline T value() const exprtk_override 08827 | { 08828 | return *access_vector(); 08829 | } 08830 | 08831 | inline T& ref() exprtk_override 08832 | { 08833 | return *access_vector(); 08834 | } 08835 | 08836 | inline const T& ref() const exprtk_override 08837 | { 08838 | return *access_vector(); 08839 | } 08840 | 08841 | inline typename expression_node<T>::node_type type() const exprtk_override 08842 | { 08843 | return expression_node<T>::e_vecelem; 08844 | } 08845 | 08846 | inline bool valid() const exprtk_override 08847 | { 08848 | return 08849 | vector_holder_ && 08850 | index_.first && 08851 | vector_node_.first && 08852 | index_.first->valid() && 08853 | vector_node_.first->valid(); 08854 | } 08855 | 08856 | inline vector_holder_t& vec_holder() 08857 | { 08858 | return (*vector_holder_); 08859 | } 08860 | 08861 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 08862 | { 08863 | expression_node<T>::ndb_t::collect(vector_node_, node_delete_list); 08864 | expression_node<T>::ndb_t::collect(index_ , node_delete_list); 08865 | } 08866 | 08867 | std::size_t node_depth() const exprtk_override 08868 | { 08869 | return expression_node<T>::ndb_t::compute_node_depth 08870 | (vector_node_, index_); 08871 | } 08872 | 08873 | private: 08874 | 08875 | inline T* access_vector() const 08876 | { 08877 | vector_node_.first->value(); 08878 | return (vector_base_ + details::numeric::to_uint64(index_.first->value())); 08879 | } 08880 | 08881 | vector_holder_ptr vector_holder_; 08882 | T* vector_base_; 08883 | branch_t vector_node_; 08884 | branch_t index_; 08885 | }; 08886 | 08887 | template <typename T> 08888 | class vector_celem_node exprtk_final 08889 | : public expression_node<T> 08890 | , public ivariable <T> 08891 | { 08892 | public: 08893 | 08894 | typedef expression_node<T>* expression_ptr; 08895 | typedef vector_holder<T> vector_holder_t; 08896 | typedef vector_holder_t* vector_holder_ptr; 08897 | typedef std::pair<expression_ptr,bool> branch_t; 08898 | 08899 | vector_celem_node(expression_ptr vec_node, 08900 | const std::size_t index, 08901 | vector_holder_ptr vec_holder) 08902 | : index_(index) 08903 | , vector_holder_(vec_holder) 08904 | , vector_base_((*vec_holder)[0]) 08905 | { 08906 | construct_branch_pair(vector_node_, vec_node); 08907 | assert(valid()); 08908 | } 08909 | 08910 | inline T value() const exprtk_override 08911 | { 08912 | return *access_vector(); 08913 | } 08914 | 08915 | inline T& ref() exprtk_override 08916 | { 08917 | return *access_vector(); 08918 | } 08919 | 08920 | inline const T& ref() const exprtk_override 08921 | { 08922 | return *access_vector(); 08923 | } 08924 | 08925 | inline typename expression_node<T>::node_type type() const exprtk_override 08926 | { 08927 | return expression_node<T>::e_veccelem; 08928 | } 08929 | 08930 | inline bool valid() const exprtk_override 08931 | { 08932 | return 08933 | vector_holder_ && 08934 | vector_node_.first && 08935 | vector_node_.first->valid(); 08936 | } 08937 | 08938 | inline vector_holder_t& vec_holder() 08939 | { 08940 | return (*vector_holder_); 08941 | } 08942 | 08943 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 08944 | { 08945 | expression_node<T>::ndb_t::collect(vector_node_, node_delete_list); 08946 | } 08947 | 08948 | std::size_t node_depth() const exprtk_override 08949 | { 08950 | return expression_node<T>::ndb_t::compute_node_depth(vector_node_); 08951 | } 08952 | 08953 | private: 08954 | 08955 | inline T* access_vector() const 08956 | { 08957 | vector_node_.first->value(); 08958 | return (vector_base_ + index_); 08959 | } 08960 | 08961 | const std::size_t index_; 08962 | vector_holder_ptr vector_holder_; 08963 | T* vector_base_; 08964 | branch_t vector_node_; 08965 | }; 08966 | 08967 | template <typename T> 08968 | class vector_elem_rtc_node exprtk_final 08969 | : public expression_node<T> 08970 | , public ivariable <T> 08971 | { 08972 | public: 08973 | 08974 | typedef expression_node<T>* expression_ptr; 08975 | typedef vector_holder<T> vector_holder_t; 08976 | typedef vector_holder_t* vector_holder_ptr; 08977 | typedef std::pair<expression_ptr,bool> branch_t; 08978 | 08979 | vector_elem_rtc_node(expression_ptr vec_node, 08980 | expression_ptr index, 08981 | vector_holder_ptr vec_holder, 08982 | vector_access_runtime_check_ptr vec_rt_chk) 08983 | : vector_holder_(vec_holder) 08984 | , vector_base_((*vec_holder)[0]) 08985 | , vec_rt_chk_(vec_rt_chk) 08986 | , max_vector_index_(vector_holder_->size() - 1) 08987 | { 08988 | construct_branch_pair(vector_node_, vec_node); 08989 | construct_branch_pair(index_ , index ); 08990 | assert(valid()); 08991 | } 08992 | 08993 | inline T value() const exprtk_override 08994 | { 08995 | return *access_vector(); 08996 | } 08997 | 08998 | inline T& ref() exprtk_override 08999 | { 09000 | return *access_vector(); 09001 | } 09002 | 09003 | inline const T& ref() const exprtk_override 09004 | { 09005 | return *access_vector(); 09006 | } 09007 | 09008 | inline typename expression_node<T>::node_type type() const exprtk_override 09009 | { 09010 | return expression_node<T>::e_vecelemrtc; 09011 | } 09012 | 09013 | inline bool valid() const exprtk_override 09014 | { 09015 | return 09016 | vector_holder_ && 09017 | index_.first && 09018 | vector_node_.first && 09019 | index_.first->valid() && 09020 | vector_node_.first->valid(); 09021 | } 09022 | 09023 | inline vector_holder_t& vec_holder() 09024 | { 09025 | return (*vector_holder_); 09026 | } 09027 | 09028 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 09029 | { 09030 | expression_node<T>::ndb_t::collect(vector_node_, node_delete_list); 09031 | expression_node<T>::ndb_t::collect(index_, node_delete_list); 09032 | } 09033 | 09034 | std::size_t node_depth() const exprtk_override 09035 | { 09036 | return expression_node<T>::ndb_t::compute_node_depth 09037 | (vector_node_, index_); 09038 | } 09039 | 09040 | private: 09041 | 09042 | inline T* access_vector() const 09043 | { 09044 | const _uint64_t index = details::numeric::to_uint64(index_.first->value()); 09045 | vector_node_.first->value(); 09046 | 09047 | if (index <= max_vector_index_) 09048 | { 09049 | return (vector_holder_->data() + index); 09050 | } 09051 | 09052 | assert(vec_rt_chk_); 09053 | 09054 | vector_access_runtime_check::violation_context context; 09055 | context.base_ptr = reinterpret_cast<void*>(vector_base_); 09056 | context.end_ptr = reinterpret_cast<void*>(vector_base_ + vector_holder_->size()); 09057 | context.access_ptr = reinterpret_cast<void*>(vector_base_ + index); 09058 | context.type_size = sizeof(T); 09059 | 09060 | return vec_rt_chk_->handle_runtime_violation(context) ? 09061 | reinterpret_cast<T*>(context.access_ptr) : 09062 | vector_base_ ; 09063 | } 09064 | 09065 | vector_holder_ptr vector_holder_; 09066 | T* vector_base_; 09067 | branch_t vector_node_; 09068 | branch_t index_; 09069 | vector_access_runtime_check_ptr vec_rt_chk_; 09070 | const std::size_t max_vector_index_; 09071 | }; 09072 | 09073 | template <typename T> 09074 | class vector_celem_rtc_node exprtk_final 09075 | : public expression_node<T> 09076 | , public ivariable <T> 09077 | { 09078 | public: 09079 | 09080 | typedef expression_node<T>* expression_ptr; 09081 | typedef vector_holder<T> vector_holder_t; 09082 | typedef vector_holder_t* vector_holder_ptr; 09083 | typedef std::pair<expression_ptr,bool> branch_t; 09084 | 09085 | vector_celem_rtc_node(expression_ptr vec_node, 09086 | const std::size_t index, 09087 | vector_holder_ptr vec_holder, 09088 | vector_access_runtime_check_ptr vec_rt_chk) 09089 | : index_(index) 09090 | , max_vector_index_(vec_holder->size() - 1) 09091 | , vector_holder_(vec_holder) 09092 | , vector_base_((*vec_holder)[0]) 09093 | , vec_rt_chk_(vec_rt_chk) 09094 | { 09095 | construct_branch_pair(vector_node_, vec_node); 09096 | assert(valid()); 09097 | } 09098 | 09099 | inline T value() const exprtk_override 09100 | { 09101 | return *access_vector(); 09102 | } 09103 | 09104 | inline T& ref() exprtk_override 09105 | { 09106 | return *access_vector(); 09107 | } 09108 | 09109 | inline const T& ref() const exprtk_override 09110 | { 09111 | return *access_vector(); 09112 | } 09113 | 09114 | inline typename expression_node<T>::node_type type() const exprtk_override 09115 | { 09116 | return expression_node<T>::e_veccelemrtc; 09117 | } 09118 | 09119 | inline bool valid() const exprtk_override 09120 | { 09121 | return 09122 | vector_holder_ && 09123 | vector_node_.first && 09124 | vector_node_.first->valid(); 09125 | } 09126 | 09127 | inline vector_holder_t& vec_holder() 09128 | { 09129 | return (*vector_holder_); 09130 | } 09131 | 09132 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 09133 | { 09134 | expression_node<T>::ndb_t::collect(vector_node_, node_delete_list); 09135 | } 09136 | 09137 | std::size_t node_depth() const exprtk_override 09138 | { 09139 | return expression_node<T>::ndb_t::compute_node_depth(vector_node_); 09140 | } 09141 | 09142 | private: 09143 | 09144 | inline T* access_vector() const 09145 | { 09146 | vector_node_.first->value(); 09147 | 09148 | if (index_ <= max_vector_index_) 09149 | { 09150 | return (vector_holder_->data() + index_); 09151 | } 09152 | 09153 | assert(vec_rt_chk_); 09154 | 09155 | vector_access_runtime_check::violation_context context; 09156 | context.base_ptr = reinterpret_cast<void*>(vector_base_); 09157 | context.end_ptr = reinterpret_cast<void*>(vector_base_ + vector_holder_->size()); 09158 | context.access_ptr = reinterpret_cast<void*>(vector_base_ + index_); 09159 | context.type_size = sizeof(T); 09160 | 09161 | return vec_rt_chk_->handle_runtime_violation(context) ? 09162 | reinterpret_cast<T*>(context.access_ptr) : 09163 | vector_base_ ; 09164 | } 09165 | 09166 | const std::size_t index_; 09167 | const std::size_t max_vector_index_; 09168 | vector_holder_ptr vector_holder_; 09169 | T* vector_base_; 09170 | branch_t vector_node_; 09171 | vector_access_runtime_check_ptr vec_rt_chk_; 09172 | }; 09173 | 09174 | template <typename T> 09175 | class rebasevector_elem_node exprtk_final 09176 | : public expression_node<T> 09177 | , public ivariable <T> 09178 | { 09179 | public: 09180 | 09181 | typedef expression_node<T>* expression_ptr; 09182 | typedef vector_holder<T> vector_holder_t; 09183 | typedef vector_holder_t* vector_holder_ptr; 09184 | typedef vec_data_store<T> vds_t; 09185 | typedef std::pair<expression_ptr,bool> branch_t; 09186 | 09187 | rebasevector_elem_node(expression_ptr vec_node, 09188 | expression_ptr index, 09189 | vector_holder_ptr vec_holder) 09190 | : vector_holder_(vec_holder) 09191 | { 09192 | construct_branch_pair(vector_node_, vec_node); 09193 | construct_branch_pair(index_ , index ); 09194 | assert(valid()); 09195 | } 09196 | 09197 | inline T value() const exprtk_override 09198 | { 09199 | return *access_vector(); 09200 | } 09201 | 09202 | inline T& ref() exprtk_override 09203 | { 09204 | return *access_vector(); 09205 | } 09206 | 09207 | inline const T& ref() const exprtk_override 09208 | { 09209 | return *access_vector(); 09210 | } 09211 | 09212 | inline typename expression_node<T>::node_type type() const exprtk_override 09213 | { 09214 | return expression_node<T>::e_rbvecelem; 09215 | } 09216 | 09217 | inline bool valid() const exprtk_override 09218 | { 09219 | return 09220 | vector_holder_ && 09221 | index_.first && 09222 | vector_node_.first && 09223 | index_.first->valid() && 09224 | vector_node_.first->valid(); 09225 | } 09226 | 09227 | inline vector_holder_t& vec_holder() 09228 | { 09229 | return (*vector_holder_); 09230 | } 09231 | 09232 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 09233 | { 09234 | expression_node<T>::ndb_t::collect(vector_node_, node_delete_list); 09235 | expression_node<T>::ndb_t::collect(index_, node_delete_list); 09236 | } 09237 | 09238 | std::size_t node_depth() const exprtk_override 09239 | { 09240 | return expression_node<T>::ndb_t::compute_node_depth 09241 | (vector_node_, index_); 09242 | } 09243 | 09244 | private: 09245 | 09246 | inline T* access_vector() const 09247 | { 09248 | vector_node_.first->value(); 09249 | return (vector_holder_->data() + details::numeric::to_uint64(index_.first->value())); 09250 | } 09251 | 09252 | vector_holder_ptr vector_holder_; 09253 | branch_t vector_node_; 09254 | branch_t index_; 09255 | }; 09256 | 09257 | template <typename T> 09258 | class rebasevector_celem_node exprtk_final 09259 | : public expression_node<T> 09260 | , public ivariable <T> 09261 | { 09262 | public: 09263 | 09264 | typedef expression_node<T>* expression_ptr; 09265 | typedef vector_holder<T> vector_holder_t; 09266 | typedef vector_holder_t* vector_holder_ptr; 09267 | typedef std::pair<expression_ptr,bool> branch_t; 09268 | 09269 | rebasevector_celem_node(expression_ptr vec_node, 09270 | const std::size_t index, 09271 | vector_holder_ptr vec_holder) 09272 | : index_(index) 09273 | , vector_holder_(vec_holder) 09274 | { 09275 | construct_branch_pair(vector_node_, vec_node); 09276 | assert(valid()); 09277 | } 09278 | 09279 | inline T value() const exprtk_override 09280 | { 09281 | vector_node_.first->value(); 09282 | return ref(); 09283 | } 09284 | 09285 | inline T& ref() exprtk_override 09286 | { 09287 | return *(vector_holder_->data() + index_); 09288 | } 09289 | 09290 | inline const T& ref() const exprtk_override 09291 | { 09292 | return *(vector_holder_->data() + index_); 09293 | } 09294 | 09295 | inline typename expression_node<T>::node_type type() const exprtk_override 09296 | { 09297 | return expression_node<T>::e_rbveccelem; 09298 | } 09299 | 09300 | inline bool valid() const exprtk_override 09301 | { 09302 | return 09303 | vector_holder_ && 09304 | vector_node_.first && 09305 | vector_node_.first->valid(); 09306 | } 09307 | 09308 | inline vector_holder_t& vec_holder() 09309 | { 09310 | return (*vector_holder_); 09311 | } 09312 | 09313 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 09314 | { 09315 | expression_node<T>::ndb_t::collect(vector_node_, node_delete_list); 09316 | } 09317 | 09318 | std::size_t node_depth() const exprtk_override 09319 | { 09320 | return expression_node<T>::ndb_t::compute_node_depth(vector_node_); 09321 | } 09322 | 09323 | private: 09324 | 09325 | const std::size_t index_; 09326 | vector_holder_ptr vector_holder_; 09327 | branch_t vector_node_; 09328 | }; 09329 | 09330 | template <typename T> 09331 | class rebasevector_elem_rtc_node exprtk_final 09332 | : public expression_node<T> 09333 | , public ivariable <T> 09334 | { 09335 | public: 09336 | 09337 | typedef expression_node<T>* expression_ptr; 09338 | typedef vector_holder<T> vector_holder_t; 09339 | typedef vector_holder_t* vector_holder_ptr; 09340 | typedef std::pair<expression_ptr,bool> branch_t; 09341 | 09342 | rebasevector_elem_rtc_node(expression_ptr vec_node, 09343 | expression_ptr index, 09344 | vector_holder_ptr vec_holder, 09345 | vector_access_runtime_check_ptr vec_rt_chk) 09346 | : vector_holder_(vec_holder) 09347 | , vec_rt_chk_(vec_rt_chk) 09348 | { 09349 | construct_branch_pair(vector_node_, vec_node); 09350 | construct_branch_pair(index_ , index ); 09351 | assert(valid()); 09352 | } 09353 | 09354 | inline T value() const exprtk_override 09355 | { 09356 | return *access_vector(); 09357 | } 09358 | 09359 | inline T& ref() exprtk_override 09360 | { 09361 | return *access_vector(); 09362 | } 09363 | 09364 | inline const T& ref() const exprtk_override 09365 | { 09366 | return *access_vector(); 09367 | } 09368 | 09369 | inline typename expression_node<T>::node_type type() const exprtk_override 09370 | { 09371 | return expression_node<T>::e_rbvecelemrtc; 09372 | } 09373 | 09374 | inline bool valid() const exprtk_override 09375 | { 09376 | return 09377 | vector_holder_ && 09378 | index_.first && 09379 | vector_node_.first && 09380 | index_.first->valid() && 09381 | vector_node_.first->valid(); 09382 | } 09383 | 09384 | inline vector_holder_t& vec_holder() 09385 | { 09386 | return (*vector_holder_); 09387 | } 09388 | 09389 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 09390 | { 09391 | expression_node<T>::ndb_t::collect(vector_node_, node_delete_list); 09392 | expression_node<T>::ndb_t::collect(index_ , node_delete_list); 09393 | } 09394 | 09395 | std::size_t node_depth() const exprtk_override 09396 | { 09397 | return expression_node<T>::ndb_t::compute_node_depth 09398 | (vector_node_, index_); 09399 | } 09400 | 09401 | private: 09402 | 09403 | inline T* access_vector() const 09404 | { 09405 | vector_node_.first->value(); 09406 | const _uint64_t index = details::numeric::to_uint64(index_.first->value()); 09407 | 09408 | if (index <= (vector_holder_->size() - 1)) 09409 | { 09410 | return (vector_holder_->data() + index); 09411 | } 09412 | 09413 | assert(vec_rt_chk_); 09414 | 09415 | vector_access_runtime_check::violation_context context; 09416 | context.base_ptr = reinterpret_cast<void*>(vector_holder_->data()); 09417 | context.end_ptr = reinterpret_cast<void*>(vector_holder_->data() + vector_holder_->size()); 09418 | context.access_ptr = reinterpret_cast<void*>(vector_holder_->data() + index); 09419 | context.type_size = sizeof(T); 09420 | 09421 | return vec_rt_chk_->handle_runtime_violation(context) ? 09422 | reinterpret_cast<T*>(context.access_ptr) : 09423 | vector_holder_->data() ; 09424 | } 09425 | 09426 | vector_holder_ptr vector_holder_; 09427 | branch_t vector_node_; 09428 | branch_t index_; 09429 | vector_access_runtime_check_ptr vec_rt_chk_; 09430 | }; 09431 | 09432 | template <typename T> 09433 | class rebasevector_celem_rtc_node exprtk_final 09434 | : public expression_node<T> 09435 | , public ivariable <T> 09436 | { 09437 | public: 09438 | 09439 | typedef expression_node<T>* expression_ptr; 09440 | typedef vector_holder<T> vector_holder_t; 09441 | typedef vector_holder_t* vector_holder_ptr; 09442 | typedef std::pair<expression_ptr,bool> branch_t; 09443 | 09444 | rebasevector_celem_rtc_node(expression_ptr vec_node, 09445 | const std::size_t index, 09446 | vector_holder_ptr vec_holder, 09447 | vector_access_runtime_check_ptr vec_rt_chk) 09448 | : index_(index) 09449 | , vector_holder_(vec_holder) 09450 | , vector_base_((*vec_holder)[0]) 09451 | , vec_rt_chk_(vec_rt_chk) 09452 | { 09453 | construct_branch_pair(vector_node_, vec_node); 09454 | assert(valid()); 09455 | } 09456 | 09457 | inline T value() const exprtk_override 09458 | { 09459 | return *access_vector(); 09460 | } 09461 | 09462 | inline T& ref() exprtk_override 09463 | { 09464 | return *access_vector(); 09465 | } 09466 | 09467 | inline const T& ref() const exprtk_override 09468 | { 09469 | return *access_vector(); 09470 | } 09471 | 09472 | inline typename expression_node<T>::node_type type() const exprtk_override 09473 | { 09474 | return expression_node<T>::e_rbveccelemrtc; 09475 | } 09476 | 09477 | inline bool valid() const exprtk_override 09478 | { 09479 | return 09480 | vector_holder_ && 09481 | vector_node_.first && 09482 | vector_node_.first->valid(); 09483 | } 09484 | 09485 | inline vector_holder_t& vec_holder() 09486 | { 09487 | return (*vector_holder_); 09488 | } 09489 | 09490 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 09491 | { 09492 | expression_node<T>::ndb_t::collect(vector_node_, node_delete_list); 09493 | } 09494 | 09495 | std::size_t node_depth() const exprtk_override 09496 | { 09497 | return expression_node<T>::ndb_t::compute_node_depth(vector_node_); 09498 | } 09499 | 09500 | private: 09501 | 09502 | inline T* access_vector() const 09503 | { 09504 | vector_node_.first->value(); 09505 | 09506 | if (index_ <= vector_holder_->size() - 1) 09507 | { 09508 | return (vector_holder_->data() + index_); 09509 | } 09510 | 09511 | assert(vec_rt_chk_); 09512 | 09513 | vector_access_runtime_check::violation_context context; 09514 | context.base_ptr = reinterpret_cast<void*>(vector_base_); 09515 | context.end_ptr = reinterpret_cast<void*>(vector_base_ + vector_holder_->size()); 09516 | context.access_ptr = reinterpret_cast<void*>(vector_base_ + index_); 09517 | context.type_size = sizeof(T); 09518 | 09519 | return vec_rt_chk_->handle_runtime_violation(context) ? 09520 | reinterpret_cast<T*>(context.access_ptr) : 09521 | vector_base_ ; 09522 | } 09523 | 09524 | const std::size_t index_; 09525 | vector_holder_ptr vector_holder_; 09526 | T* vector_base_; 09527 | branch_t vector_node_; 09528 | vector_access_runtime_check_ptr vec_rt_chk_; 09529 | }; 09530 | 09531 | template <typename T> 09532 | class vector_initialisation_node exprtk_final : public expression_node<T> 09533 | { 09534 | public: 09535 | 09536 | typedef expression_node<T>* expression_ptr; 09537 | 09538 | vector_initialisation_node(T* vector_base, 09539 | const std::size_t& size, 09540 | const std::vector<expression_ptr>& initialiser_list, 09541 | const bool single_value_initialse) 09542 | : vector_base_(vector_base) 09543 | , initialiser_list_(initialiser_list) 09544 | , size_(size) 09545 | , single_value_initialse_(single_value_initialse) 09546 | , zero_value_initialse_(false) 09547 | , const_nonzero_literal_value_initialse_(false) 09548 | , single_initialiser_value_(T(0)) 09549 | { 09550 | if (single_value_initialse_) 09551 | { 09552 | if (initialiser_list_.empty()) 09553 | zero_value_initialse_ = true; 09554 | else if ( 09555 | (initialiser_list_.size() == 1) && 09556 | details::is_constant_node(initialiser_list_[0]) && 09557 | (T(0) == initialiser_list_[0]->value()) 09558 | ) 09559 | { 09560 | zero_value_initialse_ = true; 09561 | } 09562 | else 09563 | { 09564 | assert(initialiser_list_.size() == 1); 09565 | 09566 | if (details::is_constant_node(initialiser_list_[0])) 09567 | { 09568 | const_nonzero_literal_value_initialse_ = true; 09569 | single_initialiser_value_ = initialiser_list_[0]->value(); 09570 | assert(T(0) != single_initialiser_value_); 09571 | } 09572 | } 09573 | } 09574 | } 09575 | 09576 | inline T value() const exprtk_override 09577 | { 09578 | if (single_value_initialse_) 09579 | { 09580 | if (zero_value_initialse_) 09581 | { 09582 | details::set_zero_value(vector_base_, size_); 09583 | } 09584 | else if (const_nonzero_literal_value_initialse_) 09585 | { 09586 | for (std::size_t i = 0; i < size_; ++i) 09587 | { 09588 | *(vector_base_ + i) = single_initialiser_value_; 09589 | } 09590 | } 09591 | else 09592 | { 09593 | for (std::size_t i = 0; i < size_; ++i) 09594 | { 09595 | *(vector_base_ + i) = initialiser_list_[0]->value(); 09596 | } 09597 | } 09598 | } 09599 | else 09600 | { 09601 | const std::size_t initialiser_list_size = initialiser_list_.size(); 09602 | 09603 | for (std::size_t i = 0; i < initialiser_list_size; ++i) 09604 | { 09605 | *(vector_base_ + i) = initialiser_list_[i]->value(); 09606 | } 09607 | 09608 | if (initialiser_list_size < size_) 09609 | { 09610 | details::set_zero_value( 09611 | vector_base_ + initialiser_list_size, 09612 | (size_ - initialiser_list_size)); 09613 | } 09614 | } 09615 | 09616 | return *(vector_base_); 09617 | } 09618 | 09619 | inline typename expression_node<T>::node_type type() const exprtk_override 09620 | { 09621 | return expression_node<T>::e_vecinit; 09622 | } 09623 | 09624 | inline bool valid() const exprtk_override 09625 | { 09626 | return vector_base_; 09627 | } 09628 | 09629 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 09630 | { 09631 | expression_node<T>::ndb_t::collect(initialiser_list_, node_delete_list); 09632 | } 09633 | 09634 | std::size_t node_depth() const exprtk_override 09635 | { 09636 | return expression_node<T>::ndb_t::compute_node_depth(initialiser_list_); 09637 | } 09638 | 09639 | private: 09640 | 09641 | vector_initialisation_node(const vector_initialisation_node<T>&) exprtk_delete; 09642 | vector_initialisation_node<T>& operator=(const vector_initialisation_node<T>&) exprtk_delete; 09643 | 09644 | mutable T* vector_base_; 09645 | std::vector<expression_ptr> initialiser_list_; 09646 | const std::size_t size_; 09647 | const bool single_value_initialse_; 09648 | bool zero_value_initialse_; 09649 | bool const_nonzero_literal_value_initialse_; 09650 | T single_initialiser_value_; 09651 | }; 09652 | 09653 | template <typename T> 09654 | class vector_init_zero_value_node exprtk_final : public expression_node<T> 09655 | { 09656 | public: 09657 | 09658 | typedef expression_node<T>* expression_ptr; 09659 | 09660 | vector_init_zero_value_node(T* vector_base, 09661 | const std::size_t& size, 09662 | const std::vector<expression_ptr>& initialiser_list) 09663 | : vector_base_(vector_base) 09664 | , size_(size) 09665 | , initialiser_list_(initialiser_list) 09666 | {} 09667 | 09668 | inline T value() const exprtk_override 09669 | { 09670 | details::set_zero_value(vector_base_, size_); 09671 | return *(vector_base_); 09672 | } 09673 | 09674 | inline typename expression_node<T>::node_type type() const exprtk_override 09675 | { 09676 | return expression_node<T>::e_vecinit; 09677 | } 09678 | 09679 | inline bool valid() const exprtk_override 09680 | { 09681 | return vector_base_; 09682 | } 09683 | 09684 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 09685 | { 09686 | expression_node<T>::ndb_t::collect(initialiser_list_, node_delete_list); 09687 | } 09688 | 09689 | std::size_t node_depth() const exprtk_override 09690 | { 09691 | return expression_node<T>::ndb_t::compute_node_depth(initialiser_list_); 09692 | } 09693 | 09694 | private: 09695 | 09696 | vector_init_zero_value_node(const vector_init_zero_value_node<T>&) exprtk_delete; 09697 | vector_init_zero_value_node<T>& operator=(const vector_init_zero_value_node<T>&) exprtk_delete; 09698 | 09699 | mutable T* vector_base_; 09700 | const std::size_t size_; 09701 | std::vector<expression_ptr> initialiser_list_; 09702 | }; 09703 | 09704 | template <typename T> 09705 | class vector_init_single_constvalue_node exprtk_final : public expression_node<T> 09706 | { 09707 | public: 09708 | 09709 | typedef expression_node<T>* expression_ptr; 09710 | 09711 | vector_init_single_constvalue_node(T* vector_base, 09712 | const std::size_t& size, 09713 | const std::vector<expression_ptr>& initialiser_list) 09714 | : vector_base_(vector_base) 09715 | , size_(size) 09716 | , initialiser_list_(initialiser_list) 09717 | { 09718 | single_initialiser_value_ = initialiser_list_[0]->value(); 09719 | assert(valid()); 09720 | } 09721 | 09722 | inline T value() const exprtk_override 09723 | { 09724 | for (std::size_t i = 0; i < size_; ++i) 09725 | { 09726 | *(vector_base_ + i) = single_initialiser_value_; 09727 | } 09728 | 09729 | return *(vector_base_); 09730 | } 09731 | 09732 | inline typename expression_node<T>::node_type type() const exprtk_override 09733 | { 09734 | return expression_node<T>::e_vecinit; 09735 | } 09736 | 09737 | inline bool valid() const exprtk_override 09738 | { 09739 | return vector_base_ && 09740 | (initialiser_list_.size() == 1) && 09741 | (details::is_constant_node(initialiser_list_[0])) && 09742 | (single_initialiser_value_ != T(0)); 09743 | } 09744 | 09745 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 09746 | { 09747 | expression_node<T>::ndb_t::collect(initialiser_list_, node_delete_list); 09748 | } 09749 | 09750 | std::size_t node_depth() const exprtk_override 09751 | { 09752 | return expression_node<T>::ndb_t::compute_node_depth(initialiser_list_); 09753 | } 09754 | 09755 | private: 09756 | 09757 | vector_init_single_constvalue_node(const vector_init_single_constvalue_node<T>&) exprtk_delete; 09758 | vector_init_single_constvalue_node<T>& operator=(const vector_init_single_constvalue_node<T>&) exprtk_delete; 09759 | 09760 | mutable T* vector_base_; 09761 | const std::size_t size_; 09762 | std::vector<expression_ptr> initialiser_list_; 09763 | T single_initialiser_value_; 09764 | }; 09765 | 09766 | template <typename T> 09767 | class vector_init_single_value_node exprtk_final : public expression_node<T> 09768 | { 09769 | public: 09770 | 09771 | typedef expression_node<T>* expression_ptr; 09772 | 09773 | vector_init_single_value_node(T* vector_base, 09774 | const std::size_t& size, 09775 | const std::vector<expression_ptr>& initialiser_list) 09776 | : vector_base_(vector_base) 09777 | , size_(size) 09778 | , initialiser_list_(initialiser_list) 09779 | { 09780 | assert(valid()); 09781 | } 09782 | 09783 | inline T value() const exprtk_override 09784 | { 09785 | expression_node<T>& node = *initialiser_list_[0]; 09786 | 09787 | for (std::size_t i = 0; i < size_; ++i) 09788 | { 09789 | *(vector_base_ + i) = node.value(); 09790 | } 09791 | 09792 | return *(vector_base_); 09793 | } 09794 | 09795 | inline typename expression_node<T>::node_type type() const exprtk_override 09796 | { 09797 | return expression_node<T>::e_vecinit; 09798 | } 09799 | 09800 | inline bool valid() const exprtk_override 09801 | { 09802 | return vector_base_ && 09803 | (initialiser_list_.size() == 1) && 09804 | !details::is_constant_node(initialiser_list_[0]); 09805 | } 09806 | 09807 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 09808 | { 09809 | expression_node<T>::ndb_t::collect(initialiser_list_, node_delete_list); 09810 | } 09811 | 09812 | std::size_t node_depth() const exprtk_override 09813 | { 09814 | return expression_node<T>::ndb_t::compute_node_depth(initialiser_list_); 09815 | } 09816 | 09817 | private: 09818 | 09819 | vector_init_single_value_node(const vector_init_single_value_node<T>&) exprtk_delete; 09820 | vector_init_single_value_node<T>& operator=(const vector_init_single_value_node<T>&) exprtk_delete; 09821 | 09822 | mutable T* vector_base_; 09823 | const std::size_t size_; 09824 | std::vector<expression_ptr> initialiser_list_; 09825 | }; 09826 | 09827 | template <typename T> 09828 | class vector_init_iota_constconst_node exprtk_final : public expression_node<T> 09829 | { 09830 | public: 09831 | 09832 | typedef expression_node<T>* expression_ptr; 09833 | 09834 | vector_init_iota_constconst_node(T* vector_base, 09835 | const std::size_t& size, 09836 | const std::vector<expression_ptr>& initialiser_list) 09837 | : vector_base_(vector_base) 09838 | , size_(size) 09839 | , initialiser_list_(initialiser_list) 09840 | { 09841 | base_value_ = initialiser_list_[0]->value(); 09842 | increment_value_ = initialiser_list_[1]->value(); 09843 | 09844 | assert(valid()); 09845 | } 09846 | 09847 | inline T value() const exprtk_override 09848 | { 09849 | T value = base_value_; 09850 | 09851 | for (std::size_t i = 0; i < size_; ++i, value += increment_value_) 09852 | { 09853 | *(vector_base_ + i) = value; 09854 | } 09855 | 09856 | return *(vector_base_); 09857 | } 09858 | 09859 | inline typename expression_node<T>::node_type type() const exprtk_override 09860 | { 09861 | return expression_node<T>::e_vecinit; 09862 | } 09863 | 09864 | inline bool valid() const exprtk_override 09865 | { 09866 | return vector_base_ && 09867 | (initialiser_list_.size() == 2) && 09868 | (details::is_constant_node(initialiser_list_[0])) && 09869 | (details::is_constant_node(initialiser_list_[1])) ; 09870 | } 09871 | 09872 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 09873 | { 09874 | expression_node<T>::ndb_t::collect(initialiser_list_, node_delete_list); 09875 | } 09876 | 09877 | std::size_t node_depth() const exprtk_override 09878 | { 09879 | return expression_node<T>::ndb_t::compute_node_depth(initialiser_list_); 09880 | } 09881 | 09882 | private: 09883 | 09884 | vector_init_iota_constconst_node(const vector_init_iota_constconst_node<T>&) exprtk_delete; 09885 | vector_init_iota_constconst_node<T>& operator=(const vector_init_iota_constconst_node<T>&) exprtk_delete; 09886 | 09887 | mutable T* vector_base_; 09888 | const std::size_t size_; 09889 | std::vector<expression_ptr> initialiser_list_; 09890 | T base_value_; 09891 | T increment_value_; 09892 | }; 09893 | 09894 | template <typename T> 09895 | class vector_init_iota_constnconst_node exprtk_final : public expression_node<T> 09896 | { 09897 | public: 09898 | 09899 | typedef expression_node<T>* expression_ptr; 09900 | 09901 | vector_init_iota_constnconst_node(T* vector_base, 09902 | const std::size_t& size, 09903 | const std::vector<expression_ptr>& initialiser_list) 09904 | : vector_base_(vector_base) 09905 | , size_(size) 09906 | , initialiser_list_(initialiser_list) 09907 | { 09908 | assert(valid()); 09909 | base_value_ = initialiser_list_[0]->value(); 09910 | } 09911 | 09912 | inline T value() const exprtk_override 09913 | { 09914 | T value = base_value_; 09915 | expression_node<T>& increment = *initialiser_list_[1]; 09916 | 09917 | for (std::size_t i = 0; i < size_; ++i, value += increment.value()) 09918 | { 09919 | *(vector_base_ + i) = value; 09920 | } 09921 | 09922 | return *(vector_base_); 09923 | } 09924 | 09925 | inline typename expression_node<T>::node_type type() const exprtk_override 09926 | { 09927 | return expression_node<T>::e_vecinit; 09928 | } 09929 | 09930 | inline bool valid() const exprtk_override 09931 | { 09932 | return vector_base_ && 09933 | (initialiser_list_.size() == 2) && 09934 | ( details::is_constant_node(initialiser_list_[0])) && 09935 | (!details::is_constant_node(initialiser_list_[1])); 09936 | } 09937 | 09938 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 09939 | { 09940 | expression_node<T>::ndb_t::collect(initialiser_list_, node_delete_list); 09941 | } 09942 | 09943 | std::size_t node_depth() const exprtk_override 09944 | { 09945 | return expression_node<T>::ndb_t::compute_node_depth(initialiser_list_); 09946 | } 09947 | 09948 | private: 09949 | 09950 | vector_init_iota_constnconst_node(const vector_init_iota_constnconst_node<T>&) exprtk_delete; 09951 | vector_init_iota_constnconst_node<T>& operator=(const vector_init_iota_constnconst_node<T>&) exprtk_delete; 09952 | 09953 | mutable T* vector_base_; 09954 | const std::size_t size_; 09955 | std::vector<expression_ptr> initialiser_list_; 09956 | T base_value_; 09957 | }; 09958 | 09959 | template <typename T> 09960 | class vector_init_iota_nconstconst_node exprtk_final : public expression_node<T> 09961 | { 09962 | public: 09963 | 09964 | typedef expression_node<T>* expression_ptr; 09965 | 09966 | vector_init_iota_nconstconst_node(T* vector_base, 09967 | const std::size_t& size, 09968 | const std::vector<expression_ptr>& initialiser_list) 09969 | : vector_base_(vector_base) 09970 | , size_(size) 09971 | , initialiser_list_(initialiser_list) 09972 | { 09973 | assert(valid()); 09974 | } 09975 | 09976 | inline T value() const exprtk_override 09977 | { 09978 | T value = initialiser_list_[0]->value(); 09979 | const T increment = initialiser_list_[1]->value(); 09980 | 09981 | for (std::size_t i = 0; i < size_; ++i, value += increment) 09982 | { 09983 | *(vector_base_ + i) = value; 09984 | } 09985 | 09986 | return *(vector_base_); 09987 | } 09988 | 09989 | inline typename expression_node<T>::node_type type() const exprtk_override 09990 | { 09991 | return expression_node<T>::e_vecinit; 09992 | } 09993 | 09994 | inline bool valid() const exprtk_override 09995 | { 09996 | return vector_base_ && 09997 | (initialiser_list_.size() == 2) && 09998 | (!details::is_constant_node(initialiser_list_[0])) && 09999 | (details::is_constant_node(initialiser_list_[1])); 10000 | } 10001 | 10002 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 10003 | { 10004 | expression_node<T>::ndb_t::collect(initialiser_list_, node_delete_list); 10005 | } 10006 | 10007 | std::size_t node_depth() const exprtk_override 10008 | { 10009 | return expression_node<T>::ndb_t::compute_node_depth(initialiser_list_); 10010 | } 10011 | 10012 | private: 10013 | 10014 | vector_init_iota_nconstconst_node(const vector_init_iota_nconstconst_node<T>&) exprtk_delete; 10015 | vector_init_iota_nconstconst_node<T>& operator=(const vector_init_iota_nconstconst_node<T>&) exprtk_delete; 10016 | 10017 | mutable T* vector_base_; 10018 | const std::size_t size_; 10019 | std::vector<expression_ptr> initialiser_list_; 10020 | }; 10021 | 10022 | template <typename T> 10023 | class vector_init_iota_nconstnconst_node exprtk_final : public expression_node<T> 10024 | { 10025 | public: 10026 | 10027 | typedef expression_node<T>* expression_ptr; 10028 | 10029 | vector_init_iota_nconstnconst_node(T* vector_base, 10030 | const std::size_t& size, 10031 | const std::vector<expression_ptr>& initialiser_list) 10032 | : vector_base_(vector_base) 10033 | , size_(size) 10034 | , initialiser_list_(initialiser_list) 10035 | { 10036 | assert(valid()); 10037 | } 10038 | 10039 | inline T value() const exprtk_override 10040 | { 10041 | T value = initialiser_list_[0]->value(); 10042 | expression_node<T>& increment = *initialiser_list_[1]; 10043 | 10044 | for (std::size_t i = 0; i < size_; ++i, value += increment.value()) 10045 | { 10046 | *(vector_base_ + i) = value; 10047 | } 10048 | 10049 | return *(vector_base_); 10050 | } 10051 | 10052 | inline typename expression_node<T>::node_type type() const exprtk_override 10053 | { 10054 | return expression_node<T>::e_vecinit; 10055 | } 10056 | 10057 | inline bool valid() const exprtk_override 10058 | { 10059 | return vector_base_ && 10060 | (initialiser_list_.size() == 2) && 10061 | (!details::is_constant_node(initialiser_list_[0])) && 10062 | (!details::is_constant_node(initialiser_list_[1])); 10063 | } 10064 | 10065 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 10066 | { 10067 | expression_node<T>::ndb_t::collect(initialiser_list_, node_delete_list); 10068 | } 10069 | 10070 | std::size_t node_depth() const exprtk_override 10071 | { 10072 | return expression_node<T>::ndb_t::compute_node_depth(initialiser_list_); 10073 | } 10074 | 10075 | private: 10076 | 10077 | vector_init_iota_nconstnconst_node(const vector_init_iota_nconstnconst_node<T>&) exprtk_delete; 10078 | vector_init_iota_nconstnconst_node<T>& operator=(const vector_init_iota_nconstnconst_node<T>&) exprtk_delete; 10079 | 10080 | mutable T* vector_base_; 10081 | const std::size_t size_; 10082 | std::vector<expression_ptr> initialiser_list_; 10083 | }; 10084 | 10085 | template <typename T> 10086 | class swap_node exprtk_final : public expression_node<T> 10087 | { 10088 | public: 10089 | 10090 | typedef expression_node<T>* expression_ptr; 10091 | typedef variable_node<T>* variable_node_ptr; 10092 | 10093 | swap_node(variable_node_ptr var0, variable_node_ptr var1) 10094 | : var0_(var0) 10095 | , var1_(var1) 10096 | {} 10097 | 10098 | inline T value() const exprtk_override 10099 | { 10100 | std::swap(var0_->ref(),var1_->ref()); 10101 | return var1_->ref(); 10102 | } 10103 | 10104 | inline typename expression_node<T>::node_type type() const exprtk_override 10105 | { 10106 | return expression_node<T>::e_swap; 10107 | } 10108 | 10109 | private: 10110 | 10111 | variable_node_ptr var0_; 10112 | variable_node_ptr var1_; 10113 | }; 10114 | 10115 | template <typename T> 10116 | class swap_generic_node exprtk_final : public binary_node<T> 10117 | { 10118 | public: 10119 | 10120 | typedef expression_node<T>* expression_ptr; 10121 | typedef ivariable<T>* ivariable_ptr; 10122 | 10123 | swap_generic_node(expression_ptr var0, expression_ptr var1) 10124 | : binary_node<T>(details::e_swap, var0, var1) 10125 | , var0_(dynamic_cast<ivariable_ptr>(var0)) 10126 | , var1_(dynamic_cast<ivariable_ptr>(var1)) 10127 | {} 10128 | 10129 | inline T value() const exprtk_override 10130 | { 10131 | std::swap(var0_->ref(),var1_->ref()); 10132 | return var1_->ref(); 10133 | } 10134 | 10135 | inline typename expression_node<T>::node_type type() const exprtk_override 10136 | { 10137 | return expression_node<T>::e_swap; 10138 | } 10139 | 10140 | private: 10141 | 10142 | ivariable_ptr var0_; 10143 | ivariable_ptr var1_; 10144 | }; 10145 | 10146 | template <typename T> 10147 | class swap_vecvec_node exprtk_final 10148 | : public binary_node <T> 10149 | , public vector_interface<T> 10150 | { 10151 | public: 10152 | 10153 | typedef expression_node<T>* expression_ptr; 10154 | typedef vector_node <T>* vector_node_ptr; 10155 | typedef vec_data_store <T> vds_t; 10156 | 10157 | using binary_node<T>::branch; 10158 | 10159 | swap_vecvec_node(expression_ptr branch0, 10160 | expression_ptr branch1) 10161 | : binary_node<T>(details::e_swap, branch0, branch1) 10162 | , vec0_node_ptr_(0) 10163 | , vec1_node_ptr_(0) 10164 | , initialised_ (false) 10165 | { 10166 | if (is_ivector_node(branch(0))) 10167 | { 10168 | vector_interface<T>* vi = reinterpret_cast<vector_interface<T>*>(0); 10169 | 10170 | if (0 != (vi = dynamic_cast<vector_interface<T>*>(branch(0)))) 10171 | { 10172 | vec0_node_ptr_ = vi->vec(); 10173 | vds() = vi->vds(); 10174 | } 10175 | } 10176 | 10177 | if (is_ivector_node(branch(1))) 10178 | { 10179 | vector_interface<T>* vi = reinterpret_cast<vector_interface<T>*>(0); 10180 | 10181 | if (0 != (vi = dynamic_cast<vector_interface<T>*>(branch(1)))) 10182 | { 10183 | vec1_node_ptr_ = vi->vec(); 10184 | } 10185 | } 10186 | 10187 | if (vec0_node_ptr_ && vec1_node_ptr_) 10188 | { 10189 | initialised_ = size() <= base_size(); 10190 | } 10191 | 10192 | assert(valid()); 10193 | } 10194 | 10195 | inline T value() const exprtk_override 10196 | { 10197 | binary_node<T>::branch(0)->value(); 10198 | binary_node<T>::branch(1)->value(); 10199 | 10200 | T* vec0 = vec0_node_ptr_->vds().data(); 10201 | T* vec1 = vec1_node_ptr_->vds().data(); 10202 | 10203 | assert(size() <= base_size()); 10204 | const std::size_t n = size(); 10205 | 10206 | for (std::size_t i = 0; i < n; ++i) 10207 | { 10208 | std::swap(vec0[i],vec1[i]); 10209 | } 10210 | 10211 | return vec1_node_ptr_->value(); 10212 | } 10213 | 10214 | vector_node_ptr vec() const exprtk_override 10215 | { 10216 | return vec0_node_ptr_; 10217 | } 10218 | 10219 | vector_node_ptr vec() exprtk_override 10220 | { 10221 | return vec0_node_ptr_; 10222 | } 10223 | 10224 | inline typename expression_node<T>::node_type type() const exprtk_override 10225 | { 10226 | return expression_node<T>::e_vecvecswap; 10227 | } 10228 | 10229 | inline bool valid() const exprtk_override 10230 | { 10231 | return initialised_ && binary_node<T>::valid(); 10232 | } 10233 | 10234 | std::size_t size() const exprtk_override 10235 | { 10236 | return std::min( 10237 | vec0_node_ptr_->vec_holder().size(), 10238 | vec1_node_ptr_->vec_holder().size()); 10239 | } 10240 | 10241 | std::size_t base_size() const exprtk_override 10242 | { 10243 | return std::min( 10244 | vec0_node_ptr_->vec_holder().base_size(), 10245 | vec1_node_ptr_->vec_holder().base_size()); 10246 | } 10247 | 10248 | vds_t& vds() exprtk_override 10249 | { 10250 | return vds_; 10251 | } 10252 | 10253 | const vds_t& vds() const exprtk_override 10254 | { 10255 | return vds_; 10256 | } 10257 | 10258 | private: 10259 | 10260 | vector_node<T>* vec0_node_ptr_; 10261 | vector_node<T>* vec1_node_ptr_; 10262 | bool initialised_; 10263 | vds_t vds_; 10264 | }; 10265 | 10266 | #ifndef exprtk_disable_string_capabilities 10267 | template <typename T> 10268 | class stringvar_node exprtk_final 10269 | : public expression_node <T> 10270 | , public string_base_node<T> 10271 | , public range_interface <T> 10272 | { 10273 | public: 10274 | 10275 | typedef typename range_interface<T>::range_t range_t; 10276 | 10277 | static std::string null_value; 10278 | 10279 | explicit stringvar_node() 10280 | : value_(&null_value) 10281 | {} 10282 | 10283 | explicit stringvar_node(std::string& v) 10284 | : value_(&v) 10285 | { 10286 | rp_.n0_c = std::make_pair<bool,std::size_t>(true,0); 10287 | rp_.n1_c = std::make_pair<bool,std::size_t>(true,v.size()); 10288 | rp_.cache.first = rp_.n0_c.second; 10289 | rp_.cache.second = rp_.n1_c.second; 10290 | } 10291 | 10292 | inline bool operator <(const stringvar_node<T>& v) const 10293 | { 10294 | return this < (&v); 10295 | } 10296 | 10297 | inline T value() const exprtk_override 10298 | { 10299 | rp_.n1_c.second = (*value_).size(); 10300 | rp_.cache.second = rp_.n1_c.second; 10301 | 10302 | return std::numeric_limits<T>::quiet_NaN(); 10303 | } 10304 | 10305 | std::string str() const exprtk_override 10306 | { 10307 | return ref(); 10308 | } 10309 | 10310 | char_cptr base() const exprtk_override 10311 | { 10312 | return &(*value_)[0]; 10313 | } 10314 | 10315 | std::size_t size() const exprtk_override 10316 | { 10317 | return ref().size(); 10318 | } 10319 | 10320 | std::string& ref() 10321 | { 10322 | return (*value_); 10323 | } 10324 | 10325 | const std::string& ref() const 10326 | { 10327 | return (*value_); 10328 | } 10329 | 10330 | range_t& range_ref() exprtk_override 10331 | { 10332 | return rp_; 10333 | } 10334 | 10335 | const range_t& range_ref() const exprtk_override 10336 | { 10337 | return rp_; 10338 | } 10339 | 10340 | inline typename expression_node<T>::node_type type() const exprtk_override 10341 | { 10342 | return expression_node<T>::e_stringvar; 10343 | } 10344 | 10345 | void rebase(std::string& s) 10346 | { 10347 | value_ = &s; 10348 | rp_.n0_c = std::make_pair<bool,std::size_t>(true,0); 10349 | rp_.n1_c = std::make_pair<bool,std::size_t>(true,value_->size() - 1); 10350 | rp_.cache.first = rp_.n0_c.second; 10351 | rp_.cache.second = rp_.n1_c.second; 10352 | } 10353 | 10354 | private: 10355 | 10356 | std::string* value_; 10357 | mutable range_t rp_; 10358 | }; 10359 | 10360 | template <typename T> 10361 | std::string stringvar_node<T>::null_value = std::string(""); 10362 | 10363 | template <typename T> 10364 | class string_range_node exprtk_final 10365 | : public expression_node <T> 10366 | , public string_base_node<T> 10367 | , public range_interface <T> 10368 | { 10369 | public: 10370 | 10371 | typedef typename range_interface<T>::range_t range_t; 10372 | 10373 | static std::string null_value; 10374 | 10375 | explicit string_range_node(std::string& v, const range_t& rp) 10376 | : value_(&v) 10377 | , rp_(rp) 10378 | {} 10379 | 10380 | virtual ~string_range_node() 10381 | { 10382 | rp_.free(); 10383 | } 10384 | 10385 | inline bool operator <(const string_range_node<T>& v) const 10386 | { 10387 | return this < (&v); 10388 | } 10389 | 10390 | inline T value() const exprtk_override 10391 | { 10392 | return std::numeric_limits<T>::quiet_NaN(); 10393 | } 10394 | 10395 | inline std::string str() const exprtk_override 10396 | { 10397 | return (*value_); 10398 | } 10399 | 10400 | char_cptr base() const exprtk_override 10401 | { 10402 | return &(*value_)[0]; 10403 | } 10404 | 10405 | std::size_t size() const exprtk_override 10406 | { 10407 | return ref().size(); 10408 | } 10409 | 10410 | inline range_t range() const 10411 | { 10412 | return rp_; 10413 | } 10414 | 10415 | inline std::string& ref() 10416 | { 10417 | return (*value_); 10418 | } 10419 | 10420 | inline const std::string& ref() const 10421 | { 10422 | return (*value_); 10423 | } 10424 | 10425 | inline range_t& range_ref() exprtk_override 10426 | { 10427 | return rp_; 10428 | } 10429 | 10430 | inline const range_t& range_ref() const exprtk_override 10431 | { 10432 | return rp_; 10433 | } 10434 | 10435 | inline typename expression_node<T>::node_type type() const exprtk_override 10436 | { 10437 | return expression_node<T>::e_stringvarrng; 10438 | } 10439 | 10440 | private: 10441 | 10442 | std::string* value_; 10443 | range_t rp_; 10444 | }; 10445 | 10446 | template <typename T> 10447 | std::string string_range_node<T>::null_value = std::string(""); 10448 | 10449 | template <typename T> 10450 | class const_string_range_node exprtk_final 10451 | : public expression_node <T> 10452 | , public string_base_node<T> 10453 | , public range_interface <T> 10454 | { 10455 | public: 10456 | 10457 | typedef typename range_interface<T>::range_t range_t; 10458 | 10459 | explicit const_string_range_node(const std::string& v, const range_t& rp) 10460 | : value_(v) 10461 | , rp_(rp) 10462 | {} 10463 | 10464 | ~const_string_range_node() exprtk_override 10465 | { 10466 | rp_.free(); 10467 | } 10468 | 10469 | inline T value() const exprtk_override 10470 | { 10471 | return std::numeric_limits<T>::quiet_NaN(); 10472 | } 10473 | 10474 | std::string str() const exprtk_override 10475 | { 10476 | return value_; 10477 | } 10478 | 10479 | char_cptr base() const exprtk_override 10480 | { 10481 | return value_.data(); 10482 | } 10483 | 10484 | std::size_t size() const exprtk_override 10485 | { 10486 | return value_.size(); 10487 | } 10488 | 10489 | range_t range() const 10490 | { 10491 | return rp_; 10492 | } 10493 | 10494 | range_t& range_ref() exprtk_override 10495 | { 10496 | return rp_; 10497 | } 10498 | 10499 | const range_t& range_ref() const exprtk_override 10500 | { 10501 | return rp_; 10502 | } 10503 | 10504 | inline typename expression_node<T>::node_type type() const exprtk_override 10505 | { 10506 | return expression_node<T>::e_cstringvarrng; 10507 | } 10508 | 10509 | private: 10510 | 10511 | const_string_range_node(const const_string_range_node<T>&) exprtk_delete; 10512 | const_string_range_node<T>& operator=(const const_string_range_node<T>&) exprtk_delete; 10513 | 10514 | const std::string value_; 10515 | range_t rp_; 10516 | }; 10517 | 10518 | template <typename T> 10519 | class generic_string_range_node exprtk_final 10520 | : public expression_node <T> 10521 | , public string_base_node<T> 10522 | , public range_interface <T> 10523 | { 10524 | public: 10525 | 10526 | typedef expression_node <T>* expression_ptr; 10527 | typedef stringvar_node <T>* strvar_node_ptr; 10528 | typedef string_base_node<T>* str_base_ptr; 10529 | typedef typename range_interface<T>::range_t range_t; 10530 | typedef range_t* range_ptr; 10531 | typedef range_interface<T> irange_t; 10532 | typedef irange_t* irange_ptr; 10533 | typedef std::pair<expression_ptr,bool> branch_t; 10534 | 10535 | generic_string_range_node(expression_ptr str_branch, const range_t& brange) 10536 | : initialised_(false) 10537 | , str_base_ptr_ (0) 10538 | , str_range_ptr_(0) 10539 | , base_range_(brange) 10540 | { 10541 | range_.n0_c = std::make_pair<bool,std::size_t>(true,0); 10542 | range_.n1_c = std::make_pair<bool,std::size_t>(true,0); 10543 | range_.cache.first = range_.n0_c.second; 10544 | range_.cache.second = range_.n1_c.second; 10545 | 10546 | construct_branch_pair(branch_, str_branch); 10547 | 10548 | if (is_generally_string_node(branch_.first)) 10549 | { 10550 | str_base_ptr_ = dynamic_cast<str_base_ptr>(branch_.first); 10551 | 10552 | if (0 == str_base_ptr_) 10553 | return; 10554 | 10555 | str_range_ptr_ = dynamic_cast<irange_ptr>(branch_.first); 10556 | 10557 | if (0 == str_range_ptr_) 10558 | return; 10559 | } 10560 | 10561 | initialised_ = (str_base_ptr_ && str_range_ptr_); 10562 | assert(valid()); 10563 | } 10564 | 10565 | ~generic_string_range_node() exprtk_override 10566 | { 10567 | base_range_.free(); 10568 | } 10569 | 10570 | inline T value() const exprtk_override 10571 | { 10572 | branch_.first->value(); 10573 | 10574 | std::size_t str_r0 = 0; 10575 | std::size_t str_r1 = 0; 10576 | 10577 | std::size_t r0 = 0; 10578 | std::size_t r1 = 0; 10579 | 10580 | const range_t& range = str_range_ptr_->range_ref(); 10581 | 10582 | const std::size_t base_str_size = str_base_ptr_->size(); 10583 | 10584 | if ( 10585 | range (str_r0, str_r1, base_str_size ) && 10586 | base_range_(r0 , r1 , base_str_size - str_r0) 10587 | ) 10588 | { 10589 | const std::size_t size = r1 - r0; 10590 | 10591 | range_.n1_c.second = size; 10592 | range_.cache.second = range_.n1_c.second; 10593 | 10594 | value_.assign(str_base_ptr_->base() + str_r0 + r0, size); 10595 | } 10596 | 10597 | return std::numeric_limits<T>::quiet_NaN(); 10598 | } 10599 | 10600 | std::string str() const exprtk_override 10601 | { 10602 | return value_; 10603 | } 10604 | 10605 | char_cptr base() const exprtk_override 10606 | { 10607 | return &value_[0]; 10608 | } 10609 | 10610 | std::size_t size() const exprtk_override 10611 | { 10612 | return value_.size(); 10613 | } 10614 | 10615 | range_t& range_ref() exprtk_override 10616 | { 10617 | return range_; 10618 | } 10619 | 10620 | const range_t& range_ref() const exprtk_override 10621 | { 10622 | return range_; 10623 | } 10624 | 10625 | inline typename expression_node<T>::node_type type() const exprtk_override 10626 | { 10627 | return expression_node<T>::e_strgenrange; 10628 | } 10629 | 10630 | inline bool valid() const exprtk_override 10631 | { 10632 | return initialised_ && branch_.first; 10633 | } 10634 | 10635 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 10636 | { 10637 | expression_node<T>::ndb_t::collect(branch_, node_delete_list); 10638 | } 10639 | 10640 | std::size_t node_depth() const exprtk_override 10641 | { 10642 | return expression_node<T>::ndb_t::compute_node_depth(branch_); 10643 | } 10644 | 10645 | private: 10646 | 10647 | bool initialised_; 10648 | branch_t branch_; 10649 | str_base_ptr str_base_ptr_; 10650 | irange_ptr str_range_ptr_; 10651 | mutable range_t base_range_; 10652 | mutable range_t range_; 10653 | mutable std::string value_; 10654 | }; 10655 | 10656 | template <typename T> 10657 | class string_concat_node exprtk_final 10658 | : public binary_node <T> 10659 | , public string_base_node<T> 10660 | , public range_interface <T> 10661 | { 10662 | public: 10663 | 10664 | typedef typename range_interface<T>::range_t range_t; 10665 | typedef range_interface<T> irange_t; 10666 | typedef irange_t* irange_ptr; 10667 | typedef range_t* range_ptr; 10668 | typedef expression_node <T>* expression_ptr; 10669 | typedef string_base_node<T>* str_base_ptr; 10670 | 10671 | using binary_node<T>::branch; 10672 | 10673 | string_concat_node(const operator_type& opr, 10674 | expression_ptr branch0, 10675 | expression_ptr branch1) 10676 | : binary_node<T>(opr, branch0, branch1) 10677 | , initialised_(false) 10678 | , str0_base_ptr_ (0) 10679 | , str1_base_ptr_ (0) 10680 | , str0_range_ptr_(0) 10681 | , str1_range_ptr_(0) 10682 | { 10683 | range_.n0_c = std::make_pair<bool,std::size_t>(true,0); 10684 | range_.n1_c = std::make_pair<bool,std::size_t>(true,0); 10685 | 10686 | range_.cache.first = range_.n0_c.second; 10687 | range_.cache.second = range_.n1_c.second; 10688 | 10689 | if (is_generally_string_node(branch(0))) 10690 | { 10691 | str0_base_ptr_ = dynamic_cast<str_base_ptr>(branch(0)); 10692 | 10693 | if (0 == str0_base_ptr_) 10694 | return; 10695 | 10696 | str0_range_ptr_ = dynamic_cast<irange_ptr>(branch(0)); 10697 | 10698 | if (0 == str0_range_ptr_) 10699 | return; 10700 | } 10701 | 10702 | if (is_generally_string_node(branch(1))) 10703 | { 10704 | str1_base_ptr_ = dynamic_cast<str_base_ptr>(branch(1)); 10705 | 10706 | if (0 == str1_base_ptr_) 10707 | return; 10708 | 10709 | str1_range_ptr_ = dynamic_cast<irange_ptr>(branch(1)); 10710 | 10711 | if (0 == str1_range_ptr_) 10712 | return; 10713 | } 10714 | 10715 | initialised_ = str0_base_ptr_ && 10716 | str1_base_ptr_ && 10717 | str0_range_ptr_ && 10718 | str1_range_ptr_ ; 10719 | 10720 | assert(valid()); 10721 | } 10722 | 10723 | inline T value() const exprtk_override 10724 | { 10725 | branch(0)->value(); 10726 | branch(1)->value(); 10727 | 10728 | std::size_t str0_r0 = 0; 10729 | std::size_t str0_r1 = 0; 10730 | 10731 | std::size_t str1_r0 = 0; 10732 | std::size_t str1_r1 = 0; 10733 | 10734 | const range_t& range0 = str0_range_ptr_->range_ref(); 10735 | const range_t& range1 = str1_range_ptr_->range_ref(); 10736 | 10737 | if ( 10738 | range0(str0_r0, str0_r1, str0_base_ptr_->size()) && 10739 | range1(str1_r0, str1_r1, str1_base_ptr_->size()) 10740 | ) 10741 | { 10742 | const std::size_t size0 = (str0_r1 - str0_r0); 10743 | const std::size_t size1 = (str1_r1 - str1_r0); 10744 | 10745 | value_.assign(str0_base_ptr_->base() + str0_r0, size0); 10746 | value_.append(str1_base_ptr_->base() + str1_r0, size1); 10747 | 10748 | range_.n1_c.second = value_.size(); 10749 | range_.cache.second = range_.n1_c.second; 10750 | } 10751 | 10752 | return std::numeric_limits<T>::quiet_NaN(); 10753 | } 10754 | 10755 | std::string str() const exprtk_override 10756 | { 10757 | return value_; 10758 | } 10759 | 10760 | char_cptr base() const exprtk_override 10761 | { 10762 | return &value_[0]; 10763 | } 10764 | 10765 | std::size_t size() const exprtk_override 10766 | { 10767 | return value_.size(); 10768 | } 10769 | 10770 | range_t& range_ref() exprtk_override 10771 | { 10772 | return range_; 10773 | } 10774 | 10775 | const range_t& range_ref() const exprtk_override 10776 | { 10777 | return range_; 10778 | } 10779 | 10780 | inline typename expression_node<T>::node_type type() const exprtk_override 10781 | { 10782 | return expression_node<T>::e_strconcat; 10783 | } 10784 | 10785 | inline bool valid() const exprtk_override 10786 | { 10787 | return initialised_ && binary_node<T>::valid(); 10788 | } 10789 | 10790 | private: 10791 | 10792 | bool initialised_; 10793 | str_base_ptr str0_base_ptr_; 10794 | str_base_ptr str1_base_ptr_; 10795 | irange_ptr str0_range_ptr_; 10796 | irange_ptr str1_range_ptr_; 10797 | mutable range_t range_; 10798 | mutable std::string value_; 10799 | }; 10800 | 10801 | template <typename T> 10802 | class swap_string_node exprtk_final 10803 | : public binary_node <T> 10804 | , public string_base_node<T> 10805 | , public range_interface <T> 10806 | { 10807 | public: 10808 | 10809 | typedef typename range_interface<T>::range_t range_t; 10810 | typedef range_t* range_ptr; 10811 | typedef range_interface<T> irange_t; 10812 | typedef irange_t* irange_ptr; 10813 | typedef expression_node <T>* expression_ptr; 10814 | typedef stringvar_node <T>* strvar_node_ptr; 10815 | typedef string_base_node<T>* str_base_ptr; 10816 | 10817 | using binary_node<T>::branch; 10818 | 10819 | swap_string_node(expression_ptr branch0, expression_ptr branch1) 10820 | : binary_node<T>(details::e_swap, branch0, branch1) 10821 | , initialised_(false) 10822 | , str0_node_ptr_(0) 10823 | , str1_node_ptr_(0) 10824 | { 10825 | if (is_string_node(branch(0))) 10826 | { 10827 | str0_node_ptr_ = static_cast<strvar_node_ptr>(branch(0)); 10828 | } 10829 | 10830 | if (is_string_node(branch(1))) 10831 | { 10832 | str1_node_ptr_ = static_cast<strvar_node_ptr>(branch(1)); 10833 | } 10834 | 10835 | initialised_ = (str0_node_ptr_ && str1_node_ptr_); 10836 | assert(valid()); 10837 | } 10838 | 10839 | inline T value() const exprtk_override 10840 | { 10841 | branch(0)->value(); 10842 | branch(1)->value(); 10843 | 10844 | std::swap(str0_node_ptr_->ref(), str1_node_ptr_->ref()); 10845 | 10846 | return std::numeric_limits<T>::quiet_NaN(); 10847 | } 10848 | 10849 | std::string str() const exprtk_override 10850 | { 10851 | return str0_node_ptr_->str(); 10852 | } 10853 | 10854 | char_cptr base() const exprtk_override 10855 | { 10856 | return str0_node_ptr_->base(); 10857 | } 10858 | 10859 | std::size_t size() const exprtk_override 10860 | { 10861 | return str0_node_ptr_->size(); 10862 | } 10863 | 10864 | range_t& range_ref() exprtk_override 10865 | { 10866 | return str0_node_ptr_->range_ref(); 10867 | } 10868 | 10869 | const range_t& range_ref() const exprtk_override 10870 | { 10871 | return str0_node_ptr_->range_ref(); 10872 | } 10873 | 10874 | inline typename expression_node<T>::node_type type() const exprtk_override 10875 | { 10876 | return expression_node<T>::e_strswap; 10877 | } 10878 | 10879 | inline bool valid() const exprtk_override 10880 | { 10881 | return initialised_ && binary_node<T>::valid(); 10882 | } 10883 | 10884 | private: 10885 | 10886 | bool initialised_; 10887 | strvar_node_ptr str0_node_ptr_; 10888 | strvar_node_ptr str1_node_ptr_; 10889 | }; 10890 | 10891 | template <typename T> 10892 | class swap_genstrings_node exprtk_final : public binary_node<T> 10893 | { 10894 | public: 10895 | 10896 | typedef typename range_interface<T>::range_t range_t; 10897 | typedef range_t* range_ptr; 10898 | typedef range_interface<T> irange_t; 10899 | typedef irange_t* irange_ptr; 10900 | typedef expression_node <T>* expression_ptr; 10901 | typedef string_base_node<T>* str_base_ptr; 10902 | 10903 | using binary_node<T>::branch; 10904 | 10905 | swap_genstrings_node(expression_ptr branch0, 10906 | expression_ptr branch1) 10907 | : binary_node<T>(details::e_default, branch0, branch1) 10908 | , str0_base_ptr_ (0) 10909 | , str1_base_ptr_ (0) 10910 | , str0_range_ptr_(0) 10911 | , str1_range_ptr_(0) 10912 | , initialised_(false) 10913 | { 10914 | if (is_generally_string_node(branch(0))) 10915 | { 10916 | str0_base_ptr_ = dynamic_cast<str_base_ptr>(branch(0)); 10917 | 10918 | if (0 == str0_base_ptr_) 10919 | return; 10920 | 10921 | irange_ptr range = dynamic_cast<irange_ptr>(branch(0)); 10922 | 10923 | if (0 == range) 10924 | return; 10925 | 10926 | str0_range_ptr_ = &(range->range_ref()); 10927 | } 10928 | 10929 | if (is_generally_string_node(branch(1))) 10930 | { 10931 | str1_base_ptr_ = dynamic_cast<str_base_ptr>(branch(1)); 10932 | 10933 | if (0 == str1_base_ptr_) 10934 | return; 10935 | 10936 | irange_ptr range = dynamic_cast<irange_ptr>(branch(1)); 10937 | 10938 | if (0 == range) 10939 | return; 10940 | 10941 | str1_range_ptr_ = &(range->range_ref()); 10942 | } 10943 | 10944 | initialised_ = str0_base_ptr_ && 10945 | str1_base_ptr_ && 10946 | str0_range_ptr_ && 10947 | str1_range_ptr_ ; 10948 | 10949 | assert(valid()); 10950 | } 10951 | 10952 | inline T value() const exprtk_override 10953 | { 10954 | branch(0)->value(); 10955 | branch(1)->value(); 10956 | 10957 | std::size_t str0_r0 = 0; 10958 | std::size_t str0_r1 = 0; 10959 | 10960 | std::size_t str1_r0 = 0; 10961 | std::size_t str1_r1 = 0; 10962 | 10963 | const range_t& range0 = (*str0_range_ptr_); 10964 | const range_t& range1 = (*str1_range_ptr_); 10965 | 10966 | if ( 10967 | range0(str0_r0, str0_r1, str0_base_ptr_->size()) && 10968 | range1(str1_r0, str1_r1, str1_base_ptr_->size()) 10969 | ) 10970 | { 10971 | const std::size_t size0 = range0.cache_size(); 10972 | const std::size_t size1 = range1.cache_size(); 10973 | const std::size_t max_size = std::min(size0,size1); 10974 | 10975 | char_ptr s0 = const_cast<char_ptr>(str0_base_ptr_->base() + str0_r0); 10976 | char_ptr s1 = const_cast<char_ptr>(str1_base_ptr_->base() + str1_r0); 10977 | 10978 | loop_unroll::details lud(max_size); 10979 | char_cptr upper_bound = s0 + lud.upper_bound; 10980 | 10981 | while (s0 < upper_bound) 10982 | { 10983 | #define exprtk_loop(N) \ 10984 | std::swap(s0[N], s1[N]); \ 10985 | 10986 | exprtk_loop( 0) exprtk_loop( 1) 10987 | exprtk_loop( 2) exprtk_loop( 3) 10988 | #ifndef exprtk_disable_superscalar_unroll 10989 | exprtk_loop( 4) exprtk_loop( 5) 10990 | exprtk_loop( 6) exprtk_loop( 7) 10991 | exprtk_loop( 8) exprtk_loop( 9) 10992 | exprtk_loop(10) exprtk_loop(11) 10993 | exprtk_loop(12) exprtk_loop(13) 10994 | exprtk_loop(14) exprtk_loop(15) 10995 | #endif 10996 | 10997 | s0 += lud.batch_size; 10998 | s1 += lud.batch_size; 10999 | } 11000 | 11001 | int i = 0; 11002 | 11003 | switch (lud.remainder) 11004 | { 11005 | #define case_stmt(N) \ 11006 | case N : { std::swap(s0[i], s1[i]); ++i; } \ 11007 | exprtk_fallthrough \ 11008 | 11009 | #ifndef exprtk_disable_superscalar_unroll 11010 | case_stmt(15) case_stmt(14) 11011 | case_stmt(13) case_stmt(12) 11012 | case_stmt(11) case_stmt(10) 11013 | case_stmt( 9) case_stmt( 8) 11014 | case_stmt( 7) case_stmt( 6) 11015 | case_stmt( 5) case_stmt( 4) 11016 | #endif 11017 | case_stmt( 3) case_stmt( 2) 11018 | case_stmt( 1) 11019 | default: break; 11020 | } 11021 | 11022 | #undef exprtk_loop 11023 | #undef case_stmt 11024 | } 11025 | 11026 | return std::numeric_limits<T>::quiet_NaN(); 11027 | } 11028 | 11029 | inline typename expression_node<T>::node_type type() const exprtk_override 11030 | { 11031 | return expression_node<T>::e_strswap; 11032 | } 11033 | 11034 | inline bool valid() const exprtk_override 11035 | { 11036 | return initialised_ && binary_node<T>::valid(); 11037 | } 11038 | 11039 | private: 11040 | 11041 | swap_genstrings_node(const swap_genstrings_node<T>&) exprtk_delete; 11042 | swap_genstrings_node<T>& operator=(const swap_genstrings_node<T>&) exprtk_delete; 11043 | 11044 | str_base_ptr str0_base_ptr_; 11045 | str_base_ptr str1_base_ptr_; 11046 | range_ptr str0_range_ptr_; 11047 | range_ptr str1_range_ptr_; 11048 | bool initialised_; 11049 | }; 11050 | 11051 | template <typename T> 11052 | class stringvar_size_node exprtk_final : public expression_node<T> 11053 | { 11054 | public: 11055 | 11056 | static const std::string null_value; 11057 | 11058 | explicit stringvar_size_node() 11059 | : value_(&null_value) 11060 | {} 11061 | 11062 | explicit stringvar_size_node(std::string& v) 11063 | : value_(&v) 11064 | {} 11065 | 11066 | inline T value() const exprtk_override 11067 | { 11068 | return T((*value_).size()); 11069 | } 11070 | 11071 | inline typename expression_node<T>::node_type type() const exprtk_override 11072 | { 11073 | return expression_node<T>::e_stringvarsize; 11074 | } 11075 | 11076 | private: 11077 | 11078 | const std::string* value_; 11079 | }; 11080 | 11081 | template <typename T> 11082 | const std::string stringvar_size_node<T>::null_value = std::string(""); 11083 | 11084 | template <typename T> 11085 | class string_size_node exprtk_final : public expression_node<T> 11086 | { 11087 | public: 11088 | 11089 | typedef expression_node <T>* expression_ptr; 11090 | typedef string_base_node<T>* str_base_ptr; 11091 | typedef std::pair<expression_ptr,bool> branch_t; 11092 | 11093 | explicit string_size_node(expression_ptr branch) 11094 | : str_base_ptr_(0) 11095 | { 11096 | construct_branch_pair(branch_, branch); 11097 | 11098 | if (is_generally_string_node(branch_.first)) 11099 | { 11100 | str_base_ptr_ = dynamic_cast<str_base_ptr>(branch_.first); 11101 | } 11102 | 11103 | assert(valid()); 11104 | } 11105 | 11106 | inline T value() const exprtk_override 11107 | { 11108 | branch_.first->value(); 11109 | return T(str_base_ptr_->size()); 11110 | } 11111 | 11112 | inline typename expression_node<T>::node_type type() const exprtk_override 11113 | { 11114 | return expression_node<T>::e_stringsize; 11115 | } 11116 | 11117 | inline bool valid() const exprtk_override 11118 | { 11119 | return str_base_ptr_; 11120 | } 11121 | 11122 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 11123 | { 11124 | expression_node<T>::ndb_t::collect(branch_, node_delete_list); 11125 | } 11126 | 11127 | std::size_t node_depth() const exprtk_override 11128 | { 11129 | return expression_node<T>::ndb_t::compute_node_depth(branch_); 11130 | } 11131 | 11132 | private: 11133 | 11134 | branch_t branch_; 11135 | str_base_ptr str_base_ptr_; 11136 | }; 11137 | 11138 | struct asn_assignment 11139 | { 11140 | static inline void execute(std::string& s, char_cptr data, const std::size_t size) 11141 | { s.assign(data,size); } 11142 | }; 11143 | 11144 | struct asn_addassignment 11145 | { 11146 | static inline void execute(std::string& s, char_cptr data, const std::size_t size) 11147 | { s.append(data,size); } 11148 | }; 11149 | 11150 | template <typename T, typename AssignmentProcess = asn_assignment> 11151 | class assignment_string_node exprtk_final 11152 | : public binary_node <T> 11153 | , public string_base_node<T> 11154 | , public range_interface <T> 11155 | { 11156 | public: 11157 | 11158 | typedef typename range_interface<T>::range_t range_t; 11159 | typedef range_t* range_ptr; 11160 | typedef range_interface <T> irange_t; 11161 | typedef irange_t* irange_ptr; 11162 | typedef expression_node <T>* expression_ptr; 11163 | typedef stringvar_node <T>* strvar_node_ptr; 11164 | typedef string_base_node<T>* str_base_ptr; 11165 | 11166 | using binary_node<T>::branch; 11167 | 11168 | assignment_string_node(const operator_type& opr, 11169 | expression_ptr branch0, 11170 | expression_ptr branch1) 11171 | : binary_node<T>(opr, branch0, branch1) 11172 | , initialised_(false) 11173 | , str0_base_ptr_ (0) 11174 | , str1_base_ptr_ (0) 11175 | , str0_node_ptr_ (0) 11176 | , str1_range_ptr_(0) 11177 | { 11178 | if (is_string_node(branch(0))) 11179 | { 11180 | str0_node_ptr_ = static_cast<strvar_node_ptr>(branch(0)); 11181 | str0_base_ptr_ = dynamic_cast<str_base_ptr>(branch(0)); 11182 | } 11183 | 11184 | if (is_generally_string_node(branch(1))) 11185 | { 11186 | str1_base_ptr_ = dynamic_cast<str_base_ptr>(branch(1)); 11187 | 11188 | if (0 == str1_base_ptr_) 11189 | return; 11190 | 11191 | irange_ptr range = dynamic_cast<irange_ptr>(branch(1)); 11192 | 11193 | if (0 == range) 11194 | return; 11195 | 11196 | str1_range_ptr_ = &(range->range_ref()); 11197 | } 11198 | 11199 | initialised_ = str0_base_ptr_ && 11200 | str1_base_ptr_ && 11201 | str0_node_ptr_ && 11202 | str1_range_ptr_ ; 11203 | 11204 | assert(valid()); 11205 | } 11206 | 11207 | inline T value() const exprtk_override 11208 | { 11209 | branch(1)->value(); 11210 | 11211 | std::size_t r0 = 0; 11212 | std::size_t r1 = 0; 11213 | 11214 | const range_t& range = (*str1_range_ptr_); 11215 | 11216 | if (range(r0, r1, str1_base_ptr_->size())) 11217 | { 11218 | AssignmentProcess::execute( 11219 | str0_node_ptr_->ref(), 11220 | str1_base_ptr_->base() + r0, (r1 - r0)); 11221 | 11222 | branch(0)->value(); 11223 | } 11224 | 11225 | return std::numeric_limits<T>::quiet_NaN(); 11226 | } 11227 | 11228 | std::string str() const exprtk_override 11229 | { 11230 | return str0_node_ptr_->str(); 11231 | } 11232 | 11233 | char_cptr base() const exprtk_override 11234 | { 11235 | return str0_node_ptr_->base(); 11236 | } 11237 | 11238 | std::size_t size() const exprtk_override 11239 | { 11240 | return str0_node_ptr_->size(); 11241 | } 11242 | 11243 | range_t& range_ref() exprtk_override 11244 | { 11245 | return str0_node_ptr_->range_ref(); 11246 | } 11247 | 11248 | const range_t& range_ref() const exprtk_override 11249 | { 11250 | return str0_node_ptr_->range_ref(); 11251 | } 11252 | 11253 | inline typename expression_node<T>::node_type type() const exprtk_override 11254 | { 11255 | return expression_node<T>::e_strass; 11256 | } 11257 | 11258 | inline bool valid() const exprtk_override 11259 | { 11260 | return initialised_ && binary_node<T>::valid(); 11261 | } 11262 | 11263 | private: 11264 | 11265 | bool initialised_; 11266 | str_base_ptr str0_base_ptr_; 11267 | str_base_ptr str1_base_ptr_; 11268 | strvar_node_ptr str0_node_ptr_; 11269 | range_ptr str1_range_ptr_; 11270 | }; 11271 | 11272 | template <typename T, typename AssignmentProcess = asn_assignment> 11273 | class assignment_string_range_node exprtk_final 11274 | : public binary_node <T> 11275 | , public string_base_node<T> 11276 | , public range_interface <T> 11277 | { 11278 | public: 11279 | 11280 | typedef typename range_interface<T>::range_t range_t; 11281 | typedef range_t* range_ptr; 11282 | typedef range_interface <T> irange_t; 11283 | typedef irange_t* irange_ptr; 11284 | typedef expression_node <T>* expression_ptr; 11285 | typedef stringvar_node <T>* strvar_node_ptr; 11286 | typedef string_range_node<T>* str_rng_node_ptr; 11287 | typedef string_base_node <T>* str_base_ptr; 11288 | 11289 | using binary_node<T>::branch; 11290 | 11291 | assignment_string_range_node(const operator_type& opr, 11292 | expression_ptr branch0, 11293 | expression_ptr branch1) 11294 | : binary_node<T>(opr, branch0, branch1) 11295 | , initialised_(false) 11296 | , str0_base_ptr_ (0) 11297 | , str1_base_ptr_ (0) 11298 | , str0_rng_node_ptr_(0) 11299 | , str0_range_ptr_ (0) 11300 | , str1_range_ptr_ (0) 11301 | { 11302 | if (is_string_range_node(branch(0))) 11303 | { 11304 | str0_rng_node_ptr_ = static_cast<str_rng_node_ptr>(branch(0)); 11305 | str0_base_ptr_ = dynamic_cast<str_base_ptr>(branch(0)); 11306 | irange_ptr range = dynamic_cast<irange_ptr>(branch(0)); 11307 | 11308 | if (0 == range) 11309 | return; 11310 | 11311 | str0_range_ptr_ = &(range->range_ref()); 11312 | } 11313 | 11314 | if (is_generally_string_node(branch(1))) 11315 | { 11316 | str1_base_ptr_ = dynamic_cast<str_base_ptr>(branch(1)); 11317 | 11318 | if (0 == str1_base_ptr_) 11319 | return; 11320 | 11321 | irange_ptr range = dynamic_cast<irange_ptr>(branch(1)); 11322 | 11323 | if (0 == range) 11324 | return; 11325 | 11326 | str1_range_ptr_ = &(range->range_ref()); 11327 | } 11328 | 11329 | initialised_ = str0_base_ptr_ && 11330 | str1_base_ptr_ && 11331 | str0_rng_node_ptr_ && 11332 | str0_range_ptr_ && 11333 | str1_range_ptr_ ; 11334 | 11335 | assert(valid()); 11336 | } 11337 | 11338 | inline T value() const exprtk_override 11339 | { 11340 | branch(0)->value(); 11341 | branch(1)->value(); 11342 | 11343 | std::size_t s0_r0 = 0; 11344 | std::size_t s0_r1 = 0; 11345 | 11346 | std::size_t s1_r0 = 0; 11347 | std::size_t s1_r1 = 0; 11348 | 11349 | const range_t& range0 = (*str0_range_ptr_); 11350 | const range_t& range1 = (*str1_range_ptr_); 11351 | 11352 | if ( 11353 | range0(s0_r0, s0_r1, str0_base_ptr_->size()) && 11354 | range1(s1_r0, s1_r1, str1_base_ptr_->size()) 11355 | ) 11356 | { 11357 | const std::size_t size = std::min((s0_r1 - s0_r0), (s1_r1 - s1_r0)); 11358 | 11359 | std::copy( 11360 | str1_base_ptr_->base() + s1_r0, 11361 | str1_base_ptr_->base() + s1_r0 + size, 11362 | const_cast<char_ptr>(base() + s0_r0)); 11363 | } 11364 | 11365 | return std::numeric_limits<T>::quiet_NaN(); 11366 | } 11367 | 11368 | std::string str() const exprtk_override 11369 | { 11370 | return str0_base_ptr_->str(); 11371 | } 11372 | 11373 | char_cptr base() const exprtk_override 11374 | { 11375 | return str0_base_ptr_->base(); 11376 | } 11377 | 11378 | std::size_t size() const exprtk_override 11379 | { 11380 | return str0_base_ptr_->size(); 11381 | } 11382 | 11383 | range_t& range_ref() exprtk_override 11384 | { 11385 | return str0_rng_node_ptr_->range_ref(); 11386 | } 11387 | 11388 | const range_t& range_ref() const exprtk_override 11389 | { 11390 | return str0_rng_node_ptr_->range_ref(); 11391 | } 11392 | 11393 | inline typename expression_node<T>::node_type type() const exprtk_override 11394 | { 11395 | return expression_node<T>::e_strass; 11396 | } 11397 | 11398 | inline bool valid() const exprtk_override 11399 | { 11400 | return initialised_ && binary_node<T>::valid(); 11401 | } 11402 | 11403 | private: 11404 | 11405 | bool initialised_; 11406 | str_base_ptr str0_base_ptr_; 11407 | str_base_ptr str1_base_ptr_; 11408 | str_rng_node_ptr str0_rng_node_ptr_; 11409 | range_ptr str0_range_ptr_; 11410 | range_ptr str1_range_ptr_; 11411 | }; 11412 | 11413 | template <typename T> 11414 | class conditional_string_node exprtk_final 11415 | : public trinary_node <T> 11416 | , public string_base_node<T> 11417 | , public range_interface <T> 11418 | { 11419 | public: 11420 | 11421 | typedef typename range_interface<T>::range_t range_t; 11422 | typedef range_t* range_ptr; 11423 | typedef range_interface <T> irange_t; 11424 | typedef irange_t* irange_ptr; 11425 | typedef expression_node <T>* expression_ptr; 11426 | typedef string_base_node<T>* str_base_ptr; 11427 | 11428 | conditional_string_node(expression_ptr condition, 11429 | expression_ptr consequent, 11430 | expression_ptr alternative) 11431 | : trinary_node<T>(details::e_default, consequent, alternative, condition) 11432 | , initialised_(false) 11433 | , str0_base_ptr_ (0) 11434 | , str1_base_ptr_ (0) 11435 | , str0_range_ptr_(0) 11436 | , str1_range_ptr_(0) 11437 | , condition_ (condition ) 11438 | , consequent_ (consequent ) 11439 | , alternative_(alternative) 11440 | { 11441 | range_.n0_c = std::make_pair<bool,std::size_t>(true,0); 11442 | range_.n1_c = std::make_pair<bool,std::size_t>(true,0); 11443 | 11444 | range_.cache.first = range_.n0_c.second; 11445 | range_.cache.second = range_.n1_c.second; 11446 | 11447 | if (is_generally_string_node(trinary_node<T>::branch_[0].first)) 11448 | { 11449 | str0_base_ptr_ = dynamic_cast<str_base_ptr>(trinary_node<T>::branch_[0].first); 11450 | 11451 | if (0 == str0_base_ptr_) 11452 | return; 11453 | 11454 | str0_range_ptr_ = dynamic_cast<irange_ptr>(trinary_node<T>::branch_[0].first); 11455 | 11456 | if (0 == str0_range_ptr_) 11457 | return; 11458 | } 11459 | 11460 | if (is_generally_string_node(trinary_node<T>::branch_[1].first)) 11461 | { 11462 | str1_base_ptr_ = dynamic_cast<str_base_ptr>(trinary_node<T>::branch_[1].first); 11463 | 11464 | if (0 == str1_base_ptr_) 11465 | return; 11466 | 11467 | str1_range_ptr_ = dynamic_cast<irange_ptr>(trinary_node<T>::branch_[1].first); 11468 | 11469 | if (0 == str1_range_ptr_) 11470 | return; 11471 | } 11472 | 11473 | initialised_ = str0_base_ptr_ && 11474 | str1_base_ptr_ && 11475 | str0_range_ptr_ && 11476 | str1_range_ptr_ ; 11477 | 11478 | assert(valid()); 11479 | } 11480 | 11481 | inline T value() const exprtk_override 11482 | { 11483 | std::size_t r0 = 0; 11484 | std::size_t r1 = 0; 11485 | 11486 | if (is_true(condition_)) 11487 | { 11488 | consequent_->value(); 11489 | 11490 | const range_t& range = str0_range_ptr_->range_ref(); 11491 | 11492 | if (range(r0, r1, str0_base_ptr_->size())) 11493 | { 11494 | const std::size_t size = (r1 - r0); 11495 | 11496 | value_.assign(str0_base_ptr_->base() + r0, size); 11497 | 11498 | range_.n1_c.second = value_.size(); 11499 | range_.cache.second = range_.n1_c.second; 11500 | 11501 | return T(1); 11502 | } 11503 | } 11504 | else 11505 | { 11506 | alternative_->value(); 11507 | 11508 | const range_t& range = str1_range_ptr_->range_ref(); 11509 | 11510 | if (range(r0, r1, str1_base_ptr_->size())) 11511 | { 11512 | const std::size_t size = (r1 - r0); 11513 | 11514 | value_.assign(str1_base_ptr_->base() + r0, size); 11515 | 11516 | range_.n1_c.second = value_.size(); 11517 | range_.cache.second = range_.n1_c.second; 11518 | 11519 | return T(0); 11520 | } 11521 | } 11522 | 11523 | return std::numeric_limits<T>::quiet_NaN(); 11524 | } 11525 | 11526 | std::string str() const exprtk_override 11527 | { 11528 | return value_; 11529 | } 11530 | 11531 | char_cptr base() const exprtk_override 11532 | { 11533 | return &value_[0]; 11534 | } 11535 | 11536 | std::size_t size() const exprtk_override 11537 | { 11538 | return value_.size(); 11539 | } 11540 | 11541 | range_t& range_ref() exprtk_override 11542 | { 11543 | return range_; 11544 | } 11545 | 11546 | const range_t& range_ref() const exprtk_override 11547 | { 11548 | return range_; 11549 | } 11550 | 11551 | inline typename expression_node<T>::node_type type() const exprtk_override 11552 | { 11553 | return expression_node<T>::e_strcondition; 11554 | } 11555 | 11556 | inline bool valid() const exprtk_override 11557 | { 11558 | return 11559 | initialised_ && 11560 | condition_ && condition_ ->valid() && 11561 | consequent_ && consequent_ ->valid() && 11562 | alternative_&& alternative_->valid() ; 11563 | } 11564 | 11565 | private: 11566 | 11567 | bool initialised_; 11568 | str_base_ptr str0_base_ptr_; 11569 | str_base_ptr str1_base_ptr_; 11570 | irange_ptr str0_range_ptr_; 11571 | irange_ptr str1_range_ptr_; 11572 | mutable range_t range_; 11573 | mutable std::string value_; 11574 | 11575 | expression_ptr condition_; 11576 | expression_ptr consequent_; 11577 | expression_ptr alternative_; 11578 | }; 11579 | 11580 | template <typename T> 11581 | class cons_conditional_str_node exprtk_final 11582 | : public binary_node <T> 11583 | , public string_base_node<T> 11584 | , public range_interface <T> 11585 | { 11586 | public: 11587 | 11588 | typedef typename range_interface<T>::range_t range_t; 11589 | typedef range_t* range_ptr; 11590 | typedef range_interface <T> irange_t; 11591 | typedef irange_t* irange_ptr; 11592 | typedef expression_node <T>* expression_ptr; 11593 | typedef string_base_node<T>* str_base_ptr; 11594 | 11595 | using binary_node<T>::branch; 11596 | 11597 | cons_conditional_str_node(expression_ptr condition, 11598 | expression_ptr consequent) 11599 | : binary_node<T>(details::e_default, consequent, condition) 11600 | , initialised_(false) 11601 | , str0_base_ptr_ (0) 11602 | , str0_range_ptr_(0) 11603 | , condition_ (condition ) 11604 | , consequent_(consequent) 11605 | { 11606 | range_.n0_c = std::make_pair<bool,std::size_t>(true,0); 11607 | range_.n1_c = std::make_pair<bool,std::size_t>(true,0); 11608 | 11609 | range_.cache.first = range_.n0_c.second; 11610 | range_.cache.second = range_.n1_c.second; 11611 | 11612 | if (is_generally_string_node(branch(0))) 11613 | { 11614 | str0_base_ptr_ = dynamic_cast<str_base_ptr>(branch(0)); 11615 | 11616 | if (0 == str0_base_ptr_) 11617 | return; 11618 | 11619 | str0_range_ptr_ = dynamic_cast<irange_ptr>(branch(0)); 11620 | 11621 | if (0 == str0_range_ptr_) 11622 | return; 11623 | } 11624 | 11625 | initialised_ = str0_base_ptr_ && str0_range_ptr_ ; 11626 | assert(valid()); 11627 | } 11628 | 11629 | inline T value() const exprtk_override 11630 | { 11631 | if (is_true(condition_)) 11632 | { 11633 | consequent_->value(); 11634 | 11635 | const range_t& range = str0_range_ptr_->range_ref(); 11636 | 11637 | std::size_t r0 = 0; 11638 | std::size_t r1 = 0; 11639 | 11640 | if (range(r0, r1, str0_base_ptr_->size())) 11641 | { 11642 | const std::size_t size = (r1 - r0); 11643 | 11644 | value_.assign(str0_base_ptr_->base() + r0, size); 11645 | 11646 | range_.n1_c.second = value_.size(); 11647 | range_.cache.second = range_.n1_c.second; 11648 | 11649 | return T(1); 11650 | } 11651 | } 11652 | 11653 | return std::numeric_limits<T>::quiet_NaN(); 11654 | } 11655 | 11656 | std::string str() const 11657 | { 11658 | return value_; 11659 | } 11660 | 11661 | char_cptr base() const 11662 | { 11663 | return &value_[0]; 11664 | } 11665 | 11666 | std::size_t size() const 11667 | { 11668 | return value_.size(); 11669 | } 11670 | 11671 | range_t& range_ref() 11672 | { 11673 | return range_; 11674 | } 11675 | 11676 | const range_t& range_ref() const 11677 | { 11678 | return range_; 11679 | } 11680 | 11681 | inline typename expression_node<T>::node_type type() const exprtk_override 11682 | { 11683 | return expression_node<T>::e_strccondition; 11684 | } 11685 | 11686 | inline bool valid() const exprtk_override 11687 | { 11688 | return 11689 | initialised_ && 11690 | condition_ && condition_ ->valid() && 11691 | consequent_ && consequent_ ->valid() ; 11692 | } 11693 | 11694 | private: 11695 | 11696 | bool initialised_; 11697 | str_base_ptr str0_base_ptr_; 11698 | irange_ptr str0_range_ptr_; 11699 | mutable range_t range_; 11700 | mutable std::string value_; 11701 | 11702 | expression_ptr condition_; 11703 | expression_ptr consequent_; 11704 | }; 11705 | 11706 | template <typename T, typename VarArgFunction> 11707 | class str_vararg_node exprtk_final 11708 | : public expression_node <T> 11709 | , public string_base_node<T> 11710 | , public range_interface <T> 11711 | { 11712 | public: 11713 | 11714 | typedef typename range_interface<T>::range_t range_t; 11715 | typedef range_t* range_ptr; 11716 | typedef range_interface <T> irange_t; 11717 | typedef irange_t* irange_ptr; 11718 | typedef expression_node <T>* expression_ptr; 11719 | typedef string_base_node<T>* str_base_ptr; 11720 | typedef std::pair<expression_ptr,bool> branch_t; 11721 | 11722 | template <typename Allocator, 11723 | template <typename, typename> class Sequence> 11724 | explicit str_vararg_node(const Sequence<expression_ptr,Allocator>& arg_list) 11725 | : initialised_(false) 11726 | , str_base_ptr_ (0) 11727 | , str_range_ptr_(0) 11728 | { 11729 | construct_branch_pair(final_node_, const_cast<expression_ptr>(arg_list.back())); 11730 | 11731 | if (0 == final_node_.first) 11732 | return; 11733 | else if (!is_generally_string_node(final_node_.first)) 11734 | return; 11735 | 11736 | str_base_ptr_ = dynamic_cast<str_base_ptr>(final_node_.first); 11737 | 11738 | if (0 == str_base_ptr_) 11739 | return; 11740 | 11741 | str_range_ptr_ = dynamic_cast<irange_ptr>(final_node_.first); 11742 | 11743 | if (0 == str_range_ptr_) 11744 | return; 11745 | 11746 | if (arg_list.size() > 1) 11747 | { 11748 | const std::size_t arg_list_size = arg_list.size() - 1; 11749 | 11750 | arg_list_.resize(arg_list_size); 11751 | 11752 | for (std::size_t i = 0; i < arg_list_size; ++i) 11753 | { 11754 | if (arg_list[i] && arg_list[i]->valid()) 11755 | { 11756 | construct_branch_pair(arg_list_[i], arg_list[i]); 11757 | } 11758 | else 11759 | { 11760 | arg_list_.clear(); 11761 | return; 11762 | } 11763 | } 11764 | 11765 | initialised_ = true; 11766 | } 11767 | 11768 | initialised_ &= str_base_ptr_ && str_range_ptr_; 11769 | assert(valid()); 11770 | } 11771 | 11772 | inline T value() const exprtk_override 11773 | { 11774 | if (!arg_list_.empty()) 11775 | { 11776 | VarArgFunction::process(arg_list_); 11777 | } 11778 | 11779 | final_node_.first->value(); 11780 | 11781 | return std::numeric_limits<T>::quiet_NaN(); 11782 | } 11783 | 11784 | std::string str() const exprtk_override 11785 | { 11786 | return str_base_ptr_->str(); 11787 | } 11788 | 11789 | char_cptr base() const exprtk_override 11790 | { 11791 | return str_base_ptr_->base(); 11792 | } 11793 | 11794 | std::size_t size() const exprtk_override 11795 | { 11796 | return str_base_ptr_->size(); 11797 | } 11798 | 11799 | range_t& range_ref() exprtk_override 11800 | { 11801 | return str_range_ptr_->range_ref(); 11802 | } 11803 | 11804 | const range_t& range_ref() const exprtk_override 11805 | { 11806 | return str_range_ptr_->range_ref(); 11807 | } 11808 | 11809 | inline typename expression_node<T>::node_type type() const exprtk_override 11810 | { 11811 | return expression_node<T>::e_stringvararg; 11812 | } 11813 | 11814 | inline bool valid() const exprtk_override 11815 | { 11816 | return 11817 | initialised_ && 11818 | final_node_.first && final_node_.first->valid(); 11819 | } 11820 | 11821 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 11822 | { 11823 | expression_node<T>::ndb_t::collect(final_node_ , node_delete_list); 11824 | expression_node<T>::ndb_t::collect(arg_list_ , node_delete_list); 11825 | } 11826 | 11827 | std::size_t node_depth() const exprtk_override 11828 | { 11829 | return std::max( 11830 | expression_node<T>::ndb_t::compute_node_depth(final_node_), 11831 | expression_node<T>::ndb_t::compute_node_depth(arg_list_ )); 11832 | } 11833 | 11834 | private: 11835 | 11836 | bool initialised_; 11837 | branch_t final_node_; 11838 | str_base_ptr str_base_ptr_; 11839 | irange_ptr str_range_ptr_; 11840 | std::vector<branch_t> arg_list_; 11841 | }; 11842 | #endif 11843 | 11844 | template <typename T> 11845 | class assert_node exprtk_final : public expression_node<T> 11846 | { 11847 | public: 11848 | 11849 | typedef expression_node<T>* expression_ptr; 11850 | typedef std::pair<expression_ptr,bool> branch_t; 11851 | typedef string_base_node<T>* str_base_ptr; 11852 | typedef assert_check::assert_context assert_context_t; 11853 | 11854 | assert_node(expression_ptr assert_condition_node, 11855 | expression_ptr assert_message_node, 11856 | assert_check_ptr assert_check, 11857 | const assert_context_t& context) 11858 | : assert_message_str_base_(0) 11859 | , assert_check_(assert_check) 11860 | , context_(context) 11861 | { 11862 | construct_branch_pair(assert_condition_node_, assert_condition_node); 11863 | construct_branch_pair(assert_message_node_ , assert_message_node ); 11864 | 11865 | #ifndef exprtk_disable_string_capabilities 11866 | if ( 11867 | assert_message_node_.first && 11868 | details::is_generally_string_node(assert_message_node_.first) 11869 | ) 11870 | { 11871 | assert_message_str_base_ = dynamic_cast<str_base_ptr>(assert_message_node_.first); 11872 | } 11873 | #endif 11874 | 11875 | assert(valid()); 11876 | } 11877 | 11878 | inline T value() const exprtk_override 11879 | { 11880 | if (details::is_true(assert_condition_node_.first->value())) 11881 | { 11882 | return T(1); 11883 | } 11884 | 11885 | #ifndef exprtk_disable_string_capabilities 11886 | if (assert_message_node_.first) 11887 | { 11888 | assert_message_node_.first->value(); 11889 | assert(assert_message_str_base_); 11890 | context_.message = assert_message_str_base_->str(); 11891 | } 11892 | #endif 11893 | 11894 | assert_check_->handle_assert(context_); 11895 | return T(0); 11896 | } 11897 | 11898 | inline typename expression_node<T>::node_type type() const exprtk_override 11899 | { 11900 | return expression_node<T>::e_assert; 11901 | } 11902 | 11903 | inline bool valid() const exprtk_override 11904 | { 11905 | return ( 11906 | assert_check_ && 11907 | assert_condition_node_.first && 11908 | assert_condition_node_.first->valid() 11909 | ) && 11910 | ( 11911 | (0 == assert_message_node_.first) || 11912 | ( 11913 | assert_message_node_.first && 11914 | assert_message_str_base_ && 11915 | assert_message_node_.first->valid() && 11916 | details::is_generally_string_node(assert_message_node_.first) 11917 | ) 11918 | ); 11919 | } 11920 | 11921 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 11922 | { 11923 | expression_node<T>::ndb_t::collect(assert_condition_node_, node_delete_list); 11924 | expression_node<T>::ndb_t::collect(assert_message_node_ , node_delete_list); 11925 | } 11926 | 11927 | std::size_t node_depth() const exprtk_override 11928 | { 11929 | return expression_node<T>::ndb_t::compute_node_depth 11930 | (assert_condition_node_, assert_message_node_); 11931 | } 11932 | 11933 | private: 11934 | 11935 | branch_t assert_condition_node_; 11936 | branch_t assert_message_node_; 11937 | str_base_ptr assert_message_str_base_; 11938 | assert_check_ptr assert_check_; 11939 | mutable assert_context_t context_; 11940 | }; 11941 | 11942 | template <typename T, std::size_t N> 11943 | inline T axn(const T a, const T x) 11944 | { 11945 | // a*x^n 11946 | return a * exprtk::details::numeric::fast_exp<T,N>::result(x); 11947 | } 11948 | 11949 | template <typename T, std::size_t N> 11950 | inline T axnb(const T a, const T x, const T b) 11951 | { 11952 | // a*x^n+b 11953 | return a * exprtk::details::numeric::fast_exp<T,N>::result(x) + b; 11954 | } 11955 | 11956 | template <typename T> 11957 | struct sf_base 11958 | { 11959 | typedef typename details::functor_t<T>::Type Type; 11960 | typedef typename details::functor_t<T> functor_t; 11961 | typedef typename functor_t::qfunc_t quaternary_functor_t; 11962 | typedef typename functor_t::tfunc_t trinary_functor_t; 11963 | typedef typename functor_t::bfunc_t binary_functor_t; 11964 | typedef typename functor_t::ufunc_t unary_functor_t; 11965 | }; 11966 | 11967 | #define define_sfop3(NN, OP0, OP1) \ 11968 | template <typename T> \ 11969 | struct sf##NN##_op : public sf_base<T> \ 11970 | { \ 11971 | typedef typename sf_base<T>::Type const Type; \ 11972 | static inline T process(Type x, Type y, Type z) \ 11973 | { \ 11974 | return (OP0); \ 11975 | } \ 11976 | static inline std::string id() \ 11977 | { \ 11978 | return (OP1); \ 11979 | } \ 11980 | }; \ 11981 | 11982 | define_sfop3(00,(x + y) / z ,"(t+t)/t") 11983 | define_sfop3(01,(x + y) * z ,"(t+t)*t") 11984 | define_sfop3(02,(x + y) - z ,"(t+t)-t") 11985 | define_sfop3(03,(x + y) + z ,"(t+t)+t") 11986 | define_sfop3(04,(x - y) + z ,"(t-t)+t") 11987 | define_sfop3(05,(x - y) / z ,"(t-t)/t") 11988 | define_sfop3(06,(x - y) * z ,"(t-t)*t") 11989 | define_sfop3(07,(x * y) + z ,"(t*t)+t") 11990 | define_sfop3(08,(x * y) - z ,"(t*t)-t") 11991 | define_sfop3(09,(x * y) / z ,"(t*t)/t") 11992 | define_sfop3(10,(x * y) * z ,"(t*t)*t") 11993 | define_sfop3(11,(x / y) + z ,"(t/t)+t") 11994 | define_sfop3(12,(x / y) - z ,"(t/t)-t") 11995 | define_sfop3(13,(x / y) / z ,"(t/t)/t") 11996 | define_sfop3(14,(x / y) * z ,"(t/t)*t") 11997 | define_sfop3(15,x / (y + z) ,"t/(t+t)") 11998 | define_sfop3(16,x / (y - z) ,"t/(t-t)") 11999 | define_sfop3(17,x / (y * z) ,"t/(t*t)") 12000 | define_sfop3(18,x / (y / z) ,"t/(t/t)") 12001 | define_sfop3(19,x * (y + z) ,"t*(t+t)") 12002 | define_sfop3(20,x * (y - z) ,"t*(t-t)") 12003 | define_sfop3(21,x * (y * z) ,"t*(t*t)") 12004 | define_sfop3(22,x * (y / z) ,"t*(t/t)") 12005 | define_sfop3(23,x - (y + z) ,"t-(t+t)") 12006 | define_sfop3(24,x - (y - z) ,"t-(t-t)") 12007 | define_sfop3(25,x - (y / z) ,"t-(t/t)") 12008 | define_sfop3(26,x - (y * z) ,"t-(t*t)") 12009 | define_sfop3(27,x + (y * z) ,"t+(t*t)") 12010 | define_sfop3(28,x + (y / z) ,"t+(t/t)") 12011 | define_sfop3(29,x + (y + z) ,"t+(t+t)") 12012 | define_sfop3(30,x + (y - z) ,"t+(t-t)") 12013 | define_sfop3(31,(axnb<T,2>(x,y,z))," ") 12014 | define_sfop3(32,(axnb<T,3>(x,y,z))," ") 12015 | define_sfop3(33,(axnb<T,4>(x,y,z))," ") 12016 | define_sfop3(34,(axnb<T,5>(x,y,z))," ") 12017 | define_sfop3(35,(axnb<T,6>(x,y,z))," ") 12018 | define_sfop3(36,(axnb<T,7>(x,y,z))," ") 12019 | define_sfop3(37,(axnb<T,8>(x,y,z))," ") 12020 | define_sfop3(38,(axnb<T,9>(x,y,z))," ") 12021 | define_sfop3(39,x * numeric::log(y) + z,"") 12022 | define_sfop3(40,x * numeric::log(y) - z,"") 12023 | define_sfop3(41,x * numeric::log10(y) + z,"") 12024 | define_sfop3(42,x * numeric::log10(y) - z,"") 12025 | define_sfop3(43,x * numeric::sin(y) + z ,"") 12026 | define_sfop3(44,x * numeric::sin(y) - z ,"") 12027 | define_sfop3(45,x * numeric::cos(y) + z ,"") 12028 | define_sfop3(46,x * numeric::cos(y) - z ,"") 12029 | define_sfop3(47,details::is_true(x) ? y : z,"") 12030 | 12031 | #define define_sfop4(NN, OP0, OP1) \ 12032 | template <typename T> \ 12033 | struct sf##NN##_op : public sf_base<T> \ 12034 | { \ 12035 | typedef typename sf_base<T>::Type const Type; \ 12036 | static inline T process(Type x, Type y, Type z, Type w) \ 12037 | { \ 12038 | return (OP0); \ 12039 | } \ 12040 | static inline std::string id() \ 12041 | { \ 12042 | return (OP1); \ 12043 | } \ 12044 | }; \ 12045 | 12046 | define_sfop4(48,(x + ((y + z) / w)),"t+((t+t)/t)") 12047 | define_sfop4(49,(x + ((y + z) * w)),"t+((t+t)*t)") 12048 | define_sfop4(50,(x + ((y - z) / w)),"t+((t-t)/t)") 12049 | define_sfop4(51,(x + ((y - z) * w)),"t+((t-t)*t)") 12050 | define_sfop4(52,(x + ((y * z) / w)),"t+((t*t)/t)") 12051 | define_sfop4(53,(x + ((y * z) * w)),"t+((t*t)*t)") 12052 | define_sfop4(54,(x + ((y / z) + w)),"t+((t/t)+t)") 12053 | define_sfop4(55,(x + ((y / z) / w)),"t+((t/t)/t)") 12054 | define_sfop4(56,(x + ((y / z) * w)),"t+((t/t)*t)") 12055 | define_sfop4(57,(x - ((y + z) / w)),"t-((t+t)/t)") 12056 | define_sfop4(58,(x - ((y + z) * w)),"t-((t+t)*t)") 12057 | define_sfop4(59,(x - ((y - z) / w)),"t-((t-t)/t)") 12058 | define_sfop4(60,(x - ((y - z) * w)),"t-((t-t)*t)") 12059 | define_sfop4(61,(x - ((y * z) / w)),"t-((t*t)/t)") 12060 | define_sfop4(62,(x - ((y * z) * w)),"t-((t*t)*t)") 12061 | define_sfop4(63,(x - ((y / z) / w)),"t-((t/t)/t)") 12062 | define_sfop4(64,(x - ((y / z) * w)),"t-((t/t)*t)") 12063 | define_sfop4(65,(((x + y) * z) - w),"((t+t)*t)-t") 12064 | define_sfop4(66,(((x - y) * z) - w),"((t-t)*t)-t") 12065 | define_sfop4(67,(((x * y) * z) - w),"((t*t)*t)-t") 12066 | define_sfop4(68,(((x / y) * z) - w),"((t/t)*t)-t") 12067 | define_sfop4(69,(((x + y) / z) - w),"((t+t)/t)-t") 12068 | define_sfop4(70,(((x - y) / z) - w),"((t-t)/t)-t") 12069 | define_sfop4(71,(((x * y) / z) - w),"((t*t)/t)-t") 12070 | define_sfop4(72,(((x / y) / z) - w),"((t/t)/t)-t") 12071 | define_sfop4(73,((x * y) + (z * w)),"(t*t)+(t*t)") 12072 | define_sfop4(74,((x * y) - (z * w)),"(t*t)-(t*t)") 12073 | define_sfop4(75,((x * y) + (z / w)),"(t*t)+(t/t)") 12074 | define_sfop4(76,((x * y) - (z / w)),"(t*t)-(t/t)") 12075 | define_sfop4(77,((x / y) + (z / w)),"(t/t)+(t/t)") 12076 | define_sfop4(78,((x / y) - (z / w)),"(t/t)-(t/t)") 12077 | define_sfop4(79,((x / y) - (z * w)),"(t/t)-(t*t)") 12078 | define_sfop4(80,(x / (y + (z * w))),"t/(t+(t*t))") 12079 | define_sfop4(81,(x / (y - (z * w))),"t/(t-(t*t))") 12080 | define_sfop4(82,(x * (y + (z * w))),"t*(t+(t*t))") 12081 | define_sfop4(83,(x * (y - (z * w))),"t*(t-(t*t))") 12082 | 12083 | define_sfop4(84,(axn<T,2>(x,y) + axn<T,2>(z,w)),"") 12084 | define_sfop4(85,(axn<T,3>(x,y) + axn<T,3>(z,w)),"") 12085 | define_sfop4(86,(axn<T,4>(x,y) + axn<T,4>(z,w)),"") 12086 | define_sfop4(87,(axn<T,5>(x,y) + axn<T,5>(z,w)),"") 12087 | define_sfop4(88,(axn<T,6>(x,y) + axn<T,6>(z,w)),"") 12088 | define_sfop4(89,(axn<T,7>(x,y) + axn<T,7>(z,w)),"") 12089 | define_sfop4(90,(axn<T,8>(x,y) + axn<T,8>(z,w)),"") 12090 | define_sfop4(91,(axn<T,9>(x,y) + axn<T,9>(z,w)),"") 12091 | define_sfop4(92,((details::is_true(x) && details::is_true(y)) ? z : w),"") 12092 | define_sfop4(93,((details::is_true(x) || details::is_true(y)) ? z : w),"") 12093 | define_sfop4(94,((x < y) ? z : w),"") 12094 | define_sfop4(95,((x <= y) ? z : w),"") 12095 | define_sfop4(96,((x > y) ? z : w),"") 12096 | define_sfop4(97,((x >= y) ? z : w),"") 12097 | define_sfop4(98,(details::is_true(numeric::equal(x,y)) ? z : w),"") 12098 | define_sfop4(99,(x * numeric::sin(y) + z * numeric::cos(w)),"") 12099 | 12100 | define_sfop4(ext00,((x + y) - (z * w)),"(t+t)-(t*t)") 12101 | define_sfop4(ext01,((x + y) - (z / w)),"(t+t)-(t/t)") 12102 | define_sfop4(ext02,((x + y) + (z * w)),"(t+t)+(t*t)") 12103 | define_sfop4(ext03,((x + y) + (z / w)),"(t+t)+(t/t)") 12104 | define_sfop4(ext04,((x - y) + (z * w)),"(t-t)+(t*t)") 12105 | define_sfop4(ext05,((x - y) + (z / w)),"(t-t)+(t/t)") 12106 | define_sfop4(ext06,((x - y) - (z * w)),"(t-t)-(t*t)") 12107 | define_sfop4(ext07,((x - y) - (z / w)),"(t-t)-(t/t)") 12108 | define_sfop4(ext08,((x + y) - (z - w)),"(t+t)-(t-t)") 12109 | define_sfop4(ext09,((x + y) + (z - w)),"(t+t)+(t-t)") 12110 | define_sfop4(ext10,((x + y) + (z + w)),"(t+t)+(t+t)") 12111 | define_sfop4(ext11,((x + y) * (z - w)),"(t+t)*(t-t)") 12112 | define_sfop4(ext12,((x + y) / (z - w)),"(t+t)/(t-t)") 12113 | define_sfop4(ext13,((x - y) - (z + w)),"(t-t)-(t+t)") 12114 | define_sfop4(ext14,((x - y) + (z + w)),"(t-t)+(t+t)") 12115 | define_sfop4(ext15,((x - y) * (z + w)),"(t-t)*(t+t)") 12116 | define_sfop4(ext16,((x - y) / (z + w)),"(t-t)/(t+t)") 12117 | define_sfop4(ext17,((x * y) - (z + w)),"(t*t)-(t+t)") 12118 | define_sfop4(ext18,((x / y) - (z + w)),"(t/t)-(t+t)") 12119 | define_sfop4(ext19,((x * y) + (z + w)),"(t*t)+(t+t)") 12120 | define_sfop4(ext20,((x / y) + (z + w)),"(t/t)+(t+t)") 12121 | define_sfop4(ext21,((x * y) + (z - w)),"(t*t)+(t-t)") 12122 | define_sfop4(ext22,((x / y) + (z - w)),"(t/t)+(t-t)") 12123 | define_sfop4(ext23,((x * y) - (z - w)),"(t*t)-(t-t)") 12124 | define_sfop4(ext24,((x / y) - (z - w)),"(t/t)-(t-t)") 12125 | define_sfop4(ext25,((x + y) * (z * w)),"(t+t)*(t*t)") 12126 | define_sfop4(ext26,((x + y) * (z / w)),"(t+t)*(t/t)") 12127 | define_sfop4(ext27,((x + y) / (z * w)),"(t+t)/(t*t)") 12128 | define_sfop4(ext28,((x + y) / (z / w)),"(t+t)/(t/t)") 12129 | define_sfop4(ext29,((x - y) / (z * w)),"(t-t)/(t*t)") 12130 | define_sfop4(ext30,((x - y) / (z / w)),"(t-t)/(t/t)") 12131 | define_sfop4(ext31,((x - y) * (z * w)),"(t-t)*(t*t)") 12132 | define_sfop4(ext32,((x - y) * (z / w)),"(t-t)*(t/t)") 12133 | define_sfop4(ext33,((x * y) * (z + w)),"(t*t)*(t+t)") 12134 | define_sfop4(ext34,((x / y) * (z + w)),"(t/t)*(t+t)") 12135 | define_sfop4(ext35,((x * y) / (z + w)),"(t*t)/(t+t)") 12136 | define_sfop4(ext36,((x / y) / (z + w)),"(t/t)/(t+t)") 12137 | define_sfop4(ext37,((x * y) / (z - w)),"(t*t)/(t-t)") 12138 | define_sfop4(ext38,((x / y) / (z - w)),"(t/t)/(t-t)") 12139 | define_sfop4(ext39,((x * y) * (z - w)),"(t*t)*(t-t)") 12140 | define_sfop4(ext40,((x * y) / (z * w)),"(t*t)/(t*t)") 12141 | define_sfop4(ext41,((x / y) * (z / w)),"(t/t)*(t/t)") 12142 | define_sfop4(ext42,((x / y) * (z - w)),"(t/t)*(t-t)") 12143 | define_sfop4(ext43,((x * y) * (z * w)),"(t*t)*(t*t)") 12144 | define_sfop4(ext44,(x + (y * (z / w))),"t+(t*(t/t))") 12145 | define_sfop4(ext45,(x - (y * (z / w))),"t-(t*(t/t))") 12146 | define_sfop4(ext46,(x + (y / (z * w))),"t+(t/(t*t))") 12147 | define_sfop4(ext47,(x - (y / (z * w))),"t-(t/(t*t))") 12148 | define_sfop4(ext48,(((x - y) - z) * w),"((t-t)-t)*t") 12149 | define_sfop4(ext49,(((x - y) - z) / w),"((t-t)-t)/t") 12150 | define_sfop4(ext50,(((x - y) + z) * w),"((t-t)+t)*t") 12151 | define_sfop4(ext51,(((x - y) + z) / w),"((t-t)+t)/t") 12152 | define_sfop4(ext52,((x + (y - z)) * w),"(t+(t-t))*t") 12153 | define_sfop4(ext53,((x + (y - z)) / w),"(t+(t-t))/t") 12154 | define_sfop4(ext54,((x + y) / (z + w)),"(t+t)/(t+t)") 12155 | define_sfop4(ext55,((x - y) / (z - w)),"(t-t)/(t-t)") 12156 | define_sfop4(ext56,((x + y) * (z + w)),"(t+t)*(t+t)") 12157 | define_sfop4(ext57,((x - y) * (z - w)),"(t-t)*(t-t)") 12158 | define_sfop4(ext58,((x - y) + (z - w)),"(t-t)+(t-t)") 12159 | define_sfop4(ext59,((x - y) - (z - w)),"(t-t)-(t-t)") 12160 | define_sfop4(ext60,((x / y) + (z * w)),"(t/t)+(t*t)") 12161 | define_sfop4(ext61,(((x * y) * z) / w),"((t*t)*t)/t") 12162 | 12163 | #undef define_sfop3 12164 | #undef define_sfop4 12165 | 12166 | template <typename T, typename SpecialFunction> 12167 | class sf3_node exprtk_final : public trinary_node<T> 12168 | { 12169 | public: 12170 | 12171 | typedef expression_node<T>* expression_ptr; 12172 | 12173 | sf3_node(const operator_type& opr, 12174 | expression_ptr branch0, 12175 | expression_ptr branch1, 12176 | expression_ptr branch2) 12177 | : trinary_node<T>(opr, branch0, branch1, branch2) 12178 | {} 12179 | 12180 | inline T value() const exprtk_override 12181 | { 12182 | const T x = trinary_node<T>::branch_[0].first->value(); 12183 | const T y = trinary_node<T>::branch_[1].first->value(); 12184 | const T z = trinary_node<T>::branch_[2].first->value(); 12185 | 12186 | return SpecialFunction::process(x, y, z); 12187 | } 12188 | }; 12189 | 12190 | template <typename T, typename SpecialFunction> 12191 | class sf4_node exprtk_final : public quaternary_node<T> 12192 | { 12193 | public: 12194 | 12195 | typedef expression_node<T>* expression_ptr; 12196 | 12197 | sf4_node(const operator_type& opr, 12198 | expression_ptr branch0, 12199 | expression_ptr branch1, 12200 | expression_ptr branch2, 12201 | expression_ptr branch3) 12202 | : quaternary_node<T>(opr, branch0, branch1, branch2, branch3) 12203 | {} 12204 | 12205 | inline T value() const exprtk_override 12206 | { 12207 | const T x = quaternary_node<T>::branch_[0].first->value(); 12208 | const T y = quaternary_node<T>::branch_[1].first->value(); 12209 | const T z = quaternary_node<T>::branch_[2].first->value(); 12210 | const T w = quaternary_node<T>::branch_[3].first->value(); 12211 | 12212 | return SpecialFunction::process(x, y, z, w); 12213 | } 12214 | }; 12215 | 12216 | template <typename T, typename SpecialFunction> 12217 | class sf3_var_node exprtk_final : public expression_node<T> 12218 | { 12219 | public: 12220 | 12221 | typedef expression_node<T>* expression_ptr; 12222 | 12223 | sf3_var_node(const T& v0, const T& v1, const T& v2) 12224 | : v0_(v0) 12225 | , v1_(v1) 12226 | , v2_(v2) 12227 | {} 12228 | 12229 | inline T value() const exprtk_override 12230 | { 12231 | return SpecialFunction::process(v0_, v1_, v2_); 12232 | } 12233 | 12234 | inline typename expression_node<T>::node_type type() const exprtk_override 12235 | { 12236 | return expression_node<T>::e_trinary; 12237 | } 12238 | 12239 | private: 12240 | 12241 | sf3_var_node(const sf3_var_node<T,SpecialFunction>&) exprtk_delete; 12242 | sf3_var_node<T,SpecialFunction>& operator=(const sf3_var_node<T,SpecialFunction>&) exprtk_delete; 12243 | 12244 | const T& v0_; 12245 | const T& v1_; 12246 | const T& v2_; 12247 | }; 12248 | 12249 | template <typename T, typename SpecialFunction> 12250 | class sf4_var_node exprtk_final : public expression_node<T> 12251 | { 12252 | public: 12253 | 12254 | typedef expression_node<T>* expression_ptr; 12255 | 12256 | sf4_var_node(const T& v0, const T& v1, const T& v2, const T& v3) 12257 | : v0_(v0) 12258 | , v1_(v1) 12259 | , v2_(v2) 12260 | , v3_(v3) 12261 | {} 12262 | 12263 | inline T value() const exprtk_override 12264 | { 12265 | return SpecialFunction::process(v0_, v1_, v2_, v3_); 12266 | } 12267 | 12268 | inline typename expression_node<T>::node_type type() const exprtk_override 12269 | { 12270 | return expression_node<T>::e_trinary; 12271 | } 12272 | 12273 | private: 12274 | 12275 | sf4_var_node(const sf4_var_node<T,SpecialFunction>&) exprtk_delete; 12276 | sf4_var_node<T,SpecialFunction>& operator=(const sf4_var_node<T,SpecialFunction>&) exprtk_delete; 12277 | 12278 | const T& v0_; 12279 | const T& v1_; 12280 | const T& v2_; 12281 | const T& v3_; 12282 | }; 12283 | 12284 | template <typename T, typename VarArgFunction> 12285 | class vararg_node exprtk_final : public expression_node<T> 12286 | { 12287 | public: 12288 | 12289 | typedef expression_node<T>* expression_ptr; 12290 | typedef std::pair<expression_ptr,bool> branch_t; 12291 | 12292 | template <typename Allocator, 12293 | template <typename, typename> class Sequence> 12294 | explicit vararg_node(const Sequence<expression_ptr,Allocator>& arg_list) 12295 | : initialised_(false) 12296 | { 12297 | arg_list_.resize(arg_list.size()); 12298 | 12299 | for (std::size_t i = 0; i < arg_list.size(); ++i) 12300 | { 12301 | if (arg_list[i] && arg_list[i]->valid()) 12302 | { 12303 | construct_branch_pair(arg_list_[i],arg_list[i]); 12304 | } 12305 | else 12306 | { 12307 | arg_list_.clear(); 12308 | return; 12309 | } 12310 | } 12311 | 12312 | initialised_ = (arg_list_.size() == arg_list.size()); 12313 | assert(valid()); 12314 | } 12315 | 12316 | inline T value() const exprtk_override 12317 | { 12318 | return VarArgFunction::process(arg_list_); 12319 | } 12320 | 12321 | inline typename expression_node<T>::node_type type() const exprtk_override 12322 | { 12323 | return expression_node<T>::e_vararg; 12324 | } 12325 | 12326 | inline bool valid() const exprtk_override 12327 | { 12328 | return initialised_; 12329 | } 12330 | 12331 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 12332 | { 12333 | expression_node<T>::ndb_t::collect(arg_list_, node_delete_list); 12334 | } 12335 | 12336 | std::size_t node_depth() const exprtk_override 12337 | { 12338 | return expression_node<T>::ndb_t::compute_node_depth(arg_list_); 12339 | } 12340 | 12341 | std::size_t size() const 12342 | { 12343 | return arg_list_.size(); 12344 | } 12345 | 12346 | expression_ptr operator[](const std::size_t& index) const 12347 | { 12348 | return arg_list_[index].first; 12349 | } 12350 | 12351 | private: 12352 | 12353 | std::vector<branch_t> arg_list_; 12354 | bool initialised_; 12355 | }; 12356 | 12357 | template <typename T, typename VarArgFunction> 12358 | class vararg_varnode exprtk_final : public expression_node<T> 12359 | { 12360 | public: 12361 | 12362 | typedef expression_node<T>* expression_ptr; 12363 | 12364 | template <typename Allocator, 12365 | template <typename, typename> class Sequence> 12366 | explicit vararg_varnode(const Sequence<expression_ptr,Allocator>& arg_list) 12367 | : initialised_(false) 12368 | { 12369 | arg_list_.resize(arg_list.size()); 12370 | 12371 | for (std::size_t i = 0; i < arg_list.size(); ++i) 12372 | { 12373 | if (arg_list[i] && arg_list[i]->valid() && is_variable_node(arg_list[i])) 12374 | { 12375 | variable_node<T>* var_node_ptr = static_cast<variable_node<T>*>(arg_list[i]); 12376 | arg_list_[i] = (&var_node_ptr->ref()); 12377 | } 12378 | else 12379 | { 12380 | arg_list_.clear(); 12381 | return; 12382 | } 12383 | } 12384 | 12385 | initialised_ = (arg_list.size() == arg_list_.size()); 12386 | assert(valid()); 12387 | } 12388 | 12389 | inline T value() const exprtk_override 12390 | { 12391 | return VarArgFunction::process(arg_list_); 12392 | } 12393 | 12394 | inline typename expression_node<T>::node_type type() const exprtk_override 12395 | { 12396 | return expression_node<T>::e_vararg; 12397 | } 12398 | 12399 | inline bool valid() const exprtk_override 12400 | { 12401 | return initialised_; 12402 | } 12403 | 12404 | private: 12405 | 12406 | std::vector<const T*> arg_list_; 12407 | bool initialised_; 12408 | }; 12409 | 12410 | template <typename T, typename VecFunction> 12411 | class vectorize_node exprtk_final : public expression_node<T> 12412 | { 12413 | public: 12414 | 12415 | typedef expression_node<T>* expression_ptr; 12416 | typedef std::pair<expression_ptr,bool> branch_t; 12417 | 12418 | explicit vectorize_node(const expression_ptr v) 12419 | : ivec_ptr_(0) 12420 | { 12421 | construct_branch_pair(v_, v); 12422 | 12423 | if (is_ivector_node(v_.first)) 12424 | { 12425 | ivec_ptr_ = dynamic_cast<vector_interface<T>*>(v_.first); 12426 | } 12427 | } 12428 | 12429 | inline T value() const exprtk_override 12430 | { 12431 | v_.first->value(); 12432 | return VecFunction::process(ivec_ptr_); 12433 | } 12434 | 12435 | inline typename expression_node<T>::node_type type() const exprtk_override 12436 | { 12437 | return expression_node<T>::e_vecfunc; 12438 | } 12439 | 12440 | inline bool valid() const exprtk_override 12441 | { 12442 | return ivec_ptr_ && v_.first && v_.first->valid(); 12443 | } 12444 | 12445 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 12446 | { 12447 | expression_node<T>::ndb_t::collect(v_, node_delete_list); 12448 | } 12449 | 12450 | std::size_t node_depth() const exprtk_override 12451 | { 12452 | return expression_node<T>::ndb_t::compute_node_depth(v_); 12453 | } 12454 | 12455 | private: 12456 | 12457 | vector_interface<T>* ivec_ptr_; 12458 | branch_t v_; 12459 | }; 12460 | 12461 | template <typename T> 12462 | class assignment_node exprtk_final : public binary_node<T> 12463 | { 12464 | public: 12465 | 12466 | typedef expression_node<T>* expression_ptr; 12467 | using binary_node<T>::branch; 12468 | 12469 | assignment_node(const operator_type& opr, 12470 | expression_ptr branch0, 12471 | expression_ptr branch1) 12472 | : binary_node<T>(opr, branch0, branch1) 12473 | , var_node_ptr_(0) 12474 | { 12475 | if (is_variable_node(branch(0))) 12476 | { 12477 | var_node_ptr_ = static_cast<variable_node<T>*>(branch(0)); 12478 | } 12479 | } 12480 | 12481 | inline T value() const exprtk_override 12482 | { 12483 | T& result = var_node_ptr_->ref(); 12484 | result = branch(1)->value(); 12485 | 12486 | return result; 12487 | } 12488 | 12489 | inline bool valid() const exprtk_override 12490 | { 12491 | return var_node_ptr_ && binary_node<T>::valid(); 12492 | } 12493 | 12494 | private: 12495 | 12496 | variable_node<T>* var_node_ptr_; 12497 | }; 12498 | 12499 | template <typename T> 12500 | class assignment_vec_elem_node exprtk_final : public binary_node<T> 12501 | { 12502 | public: 12503 | 12504 | typedef expression_node<T>* expression_ptr; 12505 | using binary_node<T>::branch; 12506 | 12507 | assignment_vec_elem_node(const operator_type& opr, 12508 | expression_ptr branch0, 12509 | expression_ptr branch1) 12510 | : binary_node<T>(opr, branch0, branch1) 12511 | , vec_node_ptr_(0) 12512 | { 12513 | if (is_vector_elem_node(branch(0))) 12514 | { 12515 | vec_node_ptr_ = static_cast<vector_elem_node<T>*>(branch(0)); 12516 | } 12517 | 12518 | assert(valid()); 12519 | } 12520 | 12521 | inline T value() const exprtk_override 12522 | { 12523 | T& result = vec_node_ptr_->ref(); 12524 | result = branch(1)->value(); 12525 | 12526 | return result; 12527 | } 12528 | 12529 | inline bool valid() const exprtk_override 12530 | { 12531 | return vec_node_ptr_ && binary_node<T>::valid(); 12532 | } 12533 | 12534 | private: 12535 | 12536 | vector_elem_node<T>* vec_node_ptr_; 12537 | }; 12538 | 12539 | template <typename T> 12540 | class assignment_vec_elem_rtc_node exprtk_final : public binary_node<T> 12541 | { 12542 | public: 12543 | 12544 | typedef expression_node<T>* expression_ptr; 12545 | using binary_node<T>::branch; 12546 | 12547 | assignment_vec_elem_rtc_node(const operator_type& opr, 12548 | expression_ptr branch0, 12549 | expression_ptr branch1) 12550 | : binary_node<T>(opr, branch0, branch1) 12551 | , vec_node_ptr_(0) 12552 | { 12553 | if (is_vector_elem_rtc_node(branch(0))) 12554 | { 12555 | vec_node_ptr_ = static_cast<vector_elem_rtc_node<T>*>(branch(0)); 12556 | } 12557 | 12558 | assert(valid()); 12559 | } 12560 | 12561 | inline T value() const exprtk_override 12562 | { 12563 | T& result = vec_node_ptr_->ref(); 12564 | result = branch(1)->value(); 12565 | 12566 | return result; 12567 | } 12568 | 12569 | inline bool valid() const exprtk_override 12570 | { 12571 | return vec_node_ptr_ && binary_node<T>::valid(); 12572 | } 12573 | 12574 | private: 12575 | 12576 | vector_elem_rtc_node<T>* vec_node_ptr_; 12577 | }; 12578 | 12579 | template <typename T> 12580 | class assignment_rebasevec_elem_node exprtk_final : public binary_node<T> 12581 | { 12582 | public: 12583 | 12584 | typedef expression_node<T>* expression_ptr; 12585 | using expression_node<T>::branch; 12586 | 12587 | assignment_rebasevec_elem_node(const operator_type& opr, 12588 | expression_ptr branch0, 12589 | expression_ptr branch1) 12590 | : binary_node<T>(opr, branch0, branch1) 12591 | , rbvec_node_ptr_(0) 12592 | { 12593 | if (is_rebasevector_elem_node(branch(0))) 12594 | { 12595 | rbvec_node_ptr_ = static_cast<rebasevector_elem_node<T>*>(branch(0)); 12596 | } 12597 | 12598 | assert(valid()); 12599 | } 12600 | 12601 | inline T value() const exprtk_override 12602 | { 12603 | T& result = rbvec_node_ptr_->ref(); 12604 | result = branch(1)->value(); 12605 | 12606 | return result; 12607 | } 12608 | 12609 | inline bool valid() const exprtk_override 12610 | { 12611 | return rbvec_node_ptr_ && binary_node<T>::valid(); 12612 | } 12613 | 12614 | private: 12615 | 12616 | rebasevector_elem_node<T>* rbvec_node_ptr_; 12617 | }; 12618 | 12619 | template <typename T> 12620 | class assignment_rebasevec_elem_rtc_node exprtk_final : public binary_node<T> 12621 | { 12622 | public: 12623 | 12624 | typedef expression_node<T>* expression_ptr; 12625 | using expression_node<T>::branch; 12626 | 12627 | assignment_rebasevec_elem_rtc_node(const operator_type& opr, 12628 | expression_ptr branch0, 12629 | expression_ptr branch1) 12630 | : binary_node<T>(opr, branch0, branch1) 12631 | , rbvec_node_ptr_(0) 12632 | { 12633 | if (is_rebasevector_elem_rtc_node(branch(0))) 12634 | { 12635 | rbvec_node_ptr_ = static_cast<rebasevector_elem_rtc_node<T>*>(branch(0)); 12636 | } 12637 | 12638 | assert(valid()); 12639 | } 12640 | 12641 | inline T value() const exprtk_override 12642 | { 12643 | T& result = rbvec_node_ptr_->ref(); 12644 | result = branch(1)->value(); 12645 | 12646 | return result; 12647 | } 12648 | 12649 | inline bool valid() const exprtk_override 12650 | { 12651 | return rbvec_node_ptr_ && binary_node<T>::valid(); 12652 | } 12653 | 12654 | private: 12655 | 12656 | rebasevector_elem_rtc_node<T>* rbvec_node_ptr_; 12657 | }; 12658 | 12659 | template <typename T> 12660 | class assignment_rebasevec_celem_node exprtk_final : public binary_node<T> 12661 | { 12662 | public: 12663 | 12664 | typedef expression_node<T>* expression_ptr; 12665 | using binary_node<T>::branch; 12666 | 12667 | assignment_rebasevec_celem_node(const operator_type& opr, 12668 | expression_ptr branch0, 12669 | expression_ptr branch1) 12670 | : binary_node<T>(opr, branch0, branch1) 12671 | , rbvec_node_ptr_(0) 12672 | { 12673 | if (is_rebasevector_celem_node(branch(0))) 12674 | { 12675 | rbvec_node_ptr_ = static_cast<rebasevector_celem_node<T>*>(branch(0)); 12676 | } 12677 | 12678 | assert(valid()); 12679 | } 12680 | 12681 | inline T value() const exprtk_override 12682 | { 12683 | T& result = rbvec_node_ptr_->ref(); 12684 | result = branch(1)->value(); 12685 | 12686 | return result; 12687 | } 12688 | 12689 | inline bool valid() const exprtk_override 12690 | { 12691 | return rbvec_node_ptr_ && binary_node<T>::valid(); 12692 | } 12693 | 12694 | private: 12695 | 12696 | rebasevector_celem_node<T>* rbvec_node_ptr_; 12697 | }; 12698 | 12699 | template <typename T> 12700 | class assignment_vec_node exprtk_final 12701 | : public binary_node <T> 12702 | , public vector_interface<T> 12703 | { 12704 | public: 12705 | 12706 | typedef expression_node<T>* expression_ptr; 12707 | typedef vector_node<T>* vector_node_ptr; 12708 | typedef vec_data_store<T> vds_t; 12709 | 12710 | using binary_node<T>::branch; 12711 | 12712 | assignment_vec_node(const operator_type& opr, 12713 | expression_ptr branch0, 12714 | expression_ptr branch1) 12715 | : binary_node<T>(opr, branch0, branch1) 12716 | , vec_node_ptr_(0) 12717 | { 12718 | if (is_vector_node(branch(0))) 12719 | { 12720 | vec_node_ptr_ = static_cast<vector_node<T>*>(branch(0)); 12721 | vds() = vec_node_ptr_->vds(); 12722 | } 12723 | 12724 | assert(valid()); 12725 | } 12726 | 12727 | inline T value() const exprtk_override 12728 | { 12729 | const T v = branch(1)->value(); 12730 | 12731 | T* vec = vds().data(); 12732 | 12733 | loop_unroll::details lud(size()); 12734 | const T* upper_bound = vec + lud.upper_bound; 12735 | 12736 | while (vec < upper_bound) 12737 | { 12738 | #define exprtk_loop(N) \ 12739 | vec[N] = v; \ 12740 | 12741 | exprtk_loop( 0) exprtk_loop( 1) 12742 | exprtk_loop( 2) exprtk_loop( 3) 12743 | #ifndef exprtk_disable_superscalar_unroll 12744 | exprtk_loop( 4) exprtk_loop( 5) 12745 | exprtk_loop( 6) exprtk_loop( 7) 12746 | exprtk_loop( 8) exprtk_loop( 9) 12747 | exprtk_loop(10) exprtk_loop(11) 12748 | exprtk_loop(12) exprtk_loop(13) 12749 | exprtk_loop(14) exprtk_loop(15) 12750 | #endif 12751 | 12752 | vec += lud.batch_size; 12753 | } 12754 | 12755 | switch (lud.remainder) 12756 | { 12757 | #define case_stmt(N) \ 12758 | case N : *vec++ = v; \ 12759 | exprtk_fallthrough \ 12760 | 12761 | #ifndef exprtk_disable_superscalar_unroll 12762 | case_stmt(15) case_stmt(14) 12763 | case_stmt(13) case_stmt(12) 12764 | case_stmt(11) case_stmt(10) 12765 | case_stmt( 9) case_stmt( 8) 12766 | case_stmt( 7) case_stmt( 6) 12767 | case_stmt( 5) case_stmt( 4) 12768 | #endif 12769 | case_stmt( 3) case_stmt( 2) 12770 | case 1 : *vec++ = v; 12771 | } 12772 | 12773 | #undef exprtk_loop 12774 | #undef case_stmt 12775 | 12776 | return vec_node_ptr_->value(); 12777 | } 12778 | 12779 | vector_node_ptr vec() const exprtk_override 12780 | { 12781 | return vec_node_ptr_; 12782 | } 12783 | 12784 | vector_node_ptr vec() exprtk_override 12785 | { 12786 | return vec_node_ptr_; 12787 | } 12788 | 12789 | inline typename expression_node<T>::node_type type() const exprtk_override 12790 | { 12791 | return expression_node<T>::e_vecvalass; 12792 | } 12793 | 12794 | inline bool valid() const exprtk_override 12795 | { 12796 | return 12797 | vec_node_ptr_ && 12798 | (vds().size() <= vec_node_ptr_->vec_holder().base_size()) && 12799 | binary_node<T>::valid(); 12800 | } 12801 | 12802 | std::size_t size() const exprtk_override 12803 | { 12804 | return vec_node_ptr_->vec_holder().size(); 12805 | } 12806 | 12807 | std::size_t base_size() const exprtk_override 12808 | { 12809 | return vec_node_ptr_->vec_holder().base_size(); 12810 | } 12811 | 12812 | vds_t& vds() exprtk_override 12813 | { 12814 | return vds_; 12815 | } 12816 | 12817 | const vds_t& vds() const exprtk_override 12818 | { 12819 | return vds_; 12820 | } 12821 | 12822 | private: 12823 | 12824 | vector_node<T>* vec_node_ptr_; 12825 | vds_t vds_; 12826 | }; 12827 | 12828 | template <typename T> 12829 | class assignment_vecvec_node exprtk_final 12830 | : public binary_node <T> 12831 | , public vector_interface<T> 12832 | { 12833 | public: 12834 | 12835 | typedef expression_node<T>* expression_ptr; 12836 | typedef vector_node<T>* vector_node_ptr; 12837 | typedef vec_data_store<T> vds_t; 12838 | 12839 | using binary_node<T>::branch; 12840 | 12841 | assignment_vecvec_node(const operator_type& opr, 12842 | expression_ptr branch0, 12843 | expression_ptr branch1) 12844 | : binary_node<T>(opr, branch0, branch1) 12845 | , vec0_node_ptr_(0) 12846 | , vec1_node_ptr_(0) 12847 | , initialised_(false) 12848 | , src_is_ivec_(false) 12849 | { 12850 | if (is_vector_node(branch(0))) 12851 | { 12852 | vec0_node_ptr_ = static_cast<vector_node<T>*>(branch(0)); 12853 | vds() = vec0_node_ptr_->vds(); 12854 | } 12855 | 12856 | if (is_vector_node(branch(1))) 12857 | { 12858 | vec1_node_ptr_ = static_cast<vector_node<T>*>(branch(1)); 12859 | vds_t::match_sizes(vds(),vec1_node_ptr_->vds()); 12860 | } 12861 | else if (is_ivector_node(branch(1))) 12862 | { 12863 | vector_interface<T>* vi = reinterpret_cast<vector_interface<T>*>(0); 12864 | 12865 | if (0 != (vi = dynamic_cast<vector_interface<T>*>(branch(1)))) 12866 | { 12867 | vec1_node_ptr_ = vi->vec(); 12868 | 12869 | if (!vi->side_effect()) 12870 | { 12871 | vi->vds() = vds(); 12872 | src_is_ivec_ = true; 12873 | } 12874 | else 12875 | vds_t::match_sizes(vds(),vi->vds()); 12876 | } 12877 | } 12878 | 12879 | initialised_ = 12880 | vec0_node_ptr_ && 12881 | vec1_node_ptr_ && 12882 | (size() <= base_size()) && 12883 | (vds_.size() <= base_size()) && 12884 | binary_node<T>::valid(); 12885 | 12886 | assert(valid()); 12887 | } 12888 | 12889 | inline T value() const exprtk_override 12890 | { 12891 | branch(1)->value(); 12892 | 12893 | if (src_is_ivec_) 12894 | return vec0_node_ptr_->value(); 12895 | 12896 | T* vec0 = vec0_node_ptr_->vds().data(); 12897 | T* vec1 = vec1_node_ptr_->vds().data(); 12898 | 12899 | loop_unroll::details lud(size()); 12900 | const T* upper_bound = vec0 + lud.upper_bound; 12901 | 12902 | while (vec0 < upper_bound) 12903 | { 12904 | #define exprtk_loop(N) \ 12905 | vec0[N] = vec1[N]; \ 12906 | 12907 | exprtk_loop( 0) exprtk_loop( 1) 12908 | exprtk_loop( 2) exprtk_loop( 3) 12909 | #ifndef exprtk_disable_superscalar_unroll 12910 | exprtk_loop( 4) exprtk_loop( 5) 12911 | exprtk_loop( 6) exprtk_loop( 7) 12912 | exprtk_loop( 8) exprtk_loop( 9) 12913 | exprtk_loop(10) exprtk_loop(11) 12914 | exprtk_loop(12) exprtk_loop(13) 12915 | exprtk_loop(14) exprtk_loop(15) 12916 | #endif 12917 | 12918 | vec0 += lud.batch_size; 12919 | vec1 += lud.batch_size; 12920 | } 12921 | 12922 | switch (lud.remainder) 12923 | { 12924 | #define case_stmt(N,fall_through) \ 12925 | case N : *vec0++ = *vec1++; \ 12926 | fall_through \ 12927 | 12928 | #ifndef exprtk_disable_superscalar_unroll 12929 | case_stmt(15, exprtk_fallthrough) case_stmt(14, exprtk_fallthrough) 12930 | case_stmt(13, exprtk_fallthrough) case_stmt(12, exprtk_fallthrough) 12931 | case_stmt(11, exprtk_fallthrough) case_stmt(10, exprtk_fallthrough) 12932 | case_stmt( 9, exprtk_fallthrough) case_stmt( 8, exprtk_fallthrough) 12933 | case_stmt( 7, exprtk_fallthrough) case_stmt( 6, exprtk_fallthrough) 12934 | case_stmt( 5, exprtk_fallthrough) case_stmt( 4, exprtk_fallthrough) 12935 | #endif 12936 | case_stmt( 3, exprtk_fallthrough) case_stmt( 2, exprtk_fallthrough) 12937 | case_stmt( 1, (void)0;) 12938 | } 12939 | 12940 | #undef exprtk_loop 12941 | #undef case_stmt 12942 | 12943 | return vec0_node_ptr_->value(); 12944 | } 12945 | 12946 | vector_node_ptr vec() exprtk_override 12947 | { 12948 | return vec0_node_ptr_; 12949 | } 12950 | 12951 | vector_node_ptr vec() const exprtk_override 12952 | { 12953 | return vec0_node_ptr_; 12954 | } 12955 | 12956 | inline typename expression_node<T>::node_type type() const exprtk_override 12957 | { 12958 | return expression_node<T>::e_vecvecass; 12959 | } 12960 | 12961 | inline bool valid() const exprtk_override 12962 | { 12963 | return initialised_; 12964 | } 12965 | 12966 | std::size_t size() const exprtk_override 12967 | { 12968 | return std::min( 12969 | vec0_node_ptr_->vec_holder().size(), 12970 | vec1_node_ptr_->vec_holder().size()); 12971 | } 12972 | 12973 | std::size_t base_size() const exprtk_override 12974 | { 12975 | return std::min( 12976 | vec0_node_ptr_->vec_holder().base_size(), 12977 | vec1_node_ptr_->vec_holder().base_size()); 12978 | } 12979 | 12980 | vds_t& vds() exprtk_override 12981 | { 12982 | return vds_; 12983 | } 12984 | 12985 | const vds_t& vds() const exprtk_override 12986 | { 12987 | return vds_; 12988 | } 12989 | 12990 | private: 12991 | 12992 | vector_node<T>* vec0_node_ptr_; 12993 | vector_node<T>* vec1_node_ptr_; 12994 | bool initialised_; 12995 | bool src_is_ivec_; 12996 | vds_t vds_; 12997 | }; 12998 | 12999 | template <typename T, typename Operation> 13000 | class assignment_op_node exprtk_final : public binary_node<T> 13001 | { 13002 | public: 13003 | 13004 | typedef expression_node<T>* expression_ptr; 13005 | using binary_node<T>::branch; 13006 | 13007 | assignment_op_node(const operator_type& opr, 13008 | expression_ptr branch0, 13009 | expression_ptr branch1) 13010 | : binary_node<T>(opr, branch0, branch1) 13011 | , var_node_ptr_(0) 13012 | { 13013 | if (is_variable_node(branch(0))) 13014 | { 13015 | var_node_ptr_ = static_cast<variable_node<T>*>(branch(0)); 13016 | } 13017 | 13018 | assert(valid()); 13019 | } 13020 | 13021 | inline T value() const exprtk_override 13022 | { 13023 | T& v = var_node_ptr_->ref(); 13024 | v = Operation::process(v,branch(1)->value()); 13025 | 13026 | return v; 13027 | } 13028 | 13029 | inline bool valid() const exprtk_override 13030 | { 13031 | return var_node_ptr_ && binary_node<T>::valid(); 13032 | } 13033 | 13034 | private: 13035 | 13036 | variable_node<T>* var_node_ptr_; 13037 | }; 13038 | 13039 | template <typename T, typename Operation> 13040 | class assignment_vec_elem_op_node exprtk_final : public binary_node<T> 13041 | { 13042 | public: 13043 | 13044 | typedef expression_node<T>* expression_ptr; 13045 | using binary_node<T>::branch; 13046 | 13047 | assignment_vec_elem_op_node(const operator_type& opr, 13048 | expression_ptr branch0, 13049 | expression_ptr branch1) 13050 | : binary_node<T>(opr, branch0, branch1) 13051 | , vec_node_ptr_(0) 13052 | { 13053 | if (is_vector_elem_node(branch(0))) 13054 | { 13055 | vec_node_ptr_ = static_cast<vector_elem_node<T>*>(branch(0)); 13056 | } 13057 | 13058 | assert(valid()); 13059 | } 13060 | 13061 | inline T value() const exprtk_override 13062 | { 13063 | T& v = vec_node_ptr_->ref(); 13064 | v = Operation::process(v,branch(1)->value()); 13065 | 13066 | return v; 13067 | } 13068 | 13069 | inline bool valid() const exprtk_override 13070 | { 13071 | return vec_node_ptr_ && binary_node<T>::valid(); 13072 | } 13073 | 13074 | private: 13075 | 13076 | vector_elem_node<T>* vec_node_ptr_; 13077 | }; 13078 | 13079 | template <typename T, typename Operation> 13080 | class assignment_vec_elem_op_rtc_node exprtk_final : public binary_node<T> 13081 | { 13082 | public: 13083 | 13084 | typedef expression_node<T>* expression_ptr; 13085 | using binary_node<T>::branch; 13086 | 13087 | assignment_vec_elem_op_rtc_node(const operator_type& opr, 13088 | expression_ptr branch0, 13089 | expression_ptr branch1) 13090 | : binary_node<T>(opr, branch0, branch1) 13091 | , vec_node_ptr_(0) 13092 | { 13093 | if (is_vector_elem_rtc_node(branch(0))) 13094 | { 13095 | vec_node_ptr_ = static_cast<vector_elem_rtc_node<T>*>(branch(0)); 13096 | } 13097 | 13098 | assert(valid()); 13099 | } 13100 | 13101 | inline T value() const exprtk_override 13102 | { 13103 | T& v = vec_node_ptr_->ref(); 13104 | v = Operation::process(v,branch(1)->value()); 13105 | 13106 | return v; 13107 | } 13108 | 13109 | inline bool valid() const exprtk_override 13110 | { 13111 | return vec_node_ptr_ && binary_node<T>::valid(); 13112 | } 13113 | 13114 | private: 13115 | 13116 | vector_elem_rtc_node<T>* vec_node_ptr_; 13117 | }; 13118 | 13119 | template <typename T, typename Operation> 13120 | class assignment_vec_celem_op_rtc_node exprtk_final : public binary_node<T> 13121 | { 13122 | public: 13123 | 13124 | typedef expression_node<T>* expression_ptr; 13125 | using binary_node<T>::branch; 13126 | 13127 | assignment_vec_celem_op_rtc_node(const operator_type& opr, 13128 | expression_ptr branch0, 13129 | expression_ptr branch1) 13130 | : binary_node<T>(opr, branch0, branch1) 13131 | , vec_node_ptr_(0) 13132 | { 13133 | if (is_vector_celem_rtc_node(branch(0))) 13134 | { 13135 | vec_node_ptr_ = static_cast<vector_celem_rtc_node<T>*>(branch(0)); 13136 | } 13137 | 13138 | assert(valid()); 13139 | } 13140 | 13141 | inline T value() const exprtk_override 13142 | { 13143 | T& v = vec_node_ptr_->ref(); 13144 | v = Operation::process(v,branch(1)->value()); 13145 | 13146 | return v; 13147 | } 13148 | 13149 | inline bool valid() const exprtk_override 13150 | { 13151 | return vec_node_ptr_ && binary_node<T>::valid(); 13152 | } 13153 | 13154 | private: 13155 | 13156 | vector_celem_rtc_node<T>* vec_node_ptr_; 13157 | }; 13158 | 13159 | template <typename T, typename Operation> 13160 | class assignment_rebasevec_elem_op_node exprtk_final : public binary_node<T> 13161 | { 13162 | public: 13163 | 13164 | typedef expression_node<T>* expression_ptr; 13165 | using binary_node<T>::branch; 13166 | 13167 | assignment_rebasevec_elem_op_node(const operator_type& opr, 13168 | expression_ptr branch0, 13169 | expression_ptr branch1) 13170 | : binary_node<T>(opr, branch0, branch1) 13171 | , rbvec_node_ptr_(0) 13172 | { 13173 | if (is_rebasevector_elem_node(branch(0))) 13174 | { 13175 | rbvec_node_ptr_ = static_cast<rebasevector_elem_node<T>*>(branch(0)); 13176 | } 13177 | 13178 | assert(valid()); 13179 | } 13180 | 13181 | inline T value() const exprtk_override 13182 | { 13183 | T& v = rbvec_node_ptr_->ref(); 13184 | v = Operation::process(v,branch(1)->value()); 13185 | 13186 | return v; 13187 | } 13188 | 13189 | inline bool valid() const exprtk_override 13190 | { 13191 | return rbvec_node_ptr_ && binary_node<T>::valid(); 13192 | } 13193 | 13194 | private: 13195 | 13196 | rebasevector_elem_node<T>* rbvec_node_ptr_; 13197 | }; 13198 | 13199 | template <typename T, typename Operation> 13200 | class assignment_rebasevec_celem_op_node exprtk_final : public binary_node<T> 13201 | { 13202 | public: 13203 | 13204 | typedef expression_node<T>* expression_ptr; 13205 | using binary_node<T>::branch; 13206 | 13207 | assignment_rebasevec_celem_op_node(const operator_type& opr, 13208 | expression_ptr branch0, 13209 | expression_ptr branch1) 13210 | : binary_node<T>(opr, branch0, branch1) 13211 | , rbvec_node_ptr_(0) 13212 | { 13213 | if (is_rebasevector_celem_node(branch(0))) 13214 | { 13215 | rbvec_node_ptr_ = static_cast<rebasevector_celem_node<T>*>(branch(0)); 13216 | } 13217 | 13218 | assert(valid()); 13219 | } 13220 | 13221 | inline T value() const exprtk_override 13222 | { 13223 | T& v = rbvec_node_ptr_->ref(); 13224 | v = Operation::process(v,branch(1)->value()); 13225 | 13226 | return v; 13227 | } 13228 | 13229 | inline bool valid() const exprtk_override 13230 | { 13231 | return rbvec_node_ptr_ && binary_node<T>::valid(); 13232 | } 13233 | 13234 | private: 13235 | 13236 | rebasevector_celem_node<T>* rbvec_node_ptr_; 13237 | }; 13238 | 13239 | template <typename T, typename Operation> 13240 | class assignment_rebasevec_elem_op_rtc_node exprtk_final : public binary_node<T> 13241 | { 13242 | public: 13243 | 13244 | typedef expression_node<T>* expression_ptr; 13245 | using binary_node<T>::branch; 13246 | 13247 | assignment_rebasevec_elem_op_rtc_node(const operator_type& opr, 13248 | expression_ptr branch0, 13249 | expression_ptr branch1) 13250 | : binary_node<T>(opr, branch0, branch1) 13251 | , rbvec_node_ptr_(0) 13252 | { 13253 | if (is_rebasevector_elem_rtc_node(branch(0))) 13254 | { 13255 | rbvec_node_ptr_ = static_cast<rebasevector_elem_rtc_node<T>*>(branch(0)); 13256 | } 13257 | 13258 | assert(valid()); 13259 | } 13260 | 13261 | inline T value() const exprtk_override 13262 | { 13263 | T& v = rbvec_node_ptr_->ref(); 13264 | v = Operation::process(v,branch(1)->value()); 13265 | 13266 | return v; 13267 | } 13268 | 13269 | inline bool valid() const exprtk_override 13270 | { 13271 | return rbvec_node_ptr_ && binary_node<T>::valid(); 13272 | } 13273 | 13274 | private: 13275 | 13276 | rebasevector_elem_rtc_node<T>* rbvec_node_ptr_; 13277 | }; 13278 | 13279 | template <typename T, typename Operation> 13280 | class assignment_rebasevec_celem_op_rtc_node exprtk_final : public binary_node<T> 13281 | { 13282 | public: 13283 | 13284 | typedef expression_node<T>* expression_ptr; 13285 | using binary_node<T>::branch; 13286 | 13287 | assignment_rebasevec_celem_op_rtc_node(const operator_type& opr, 13288 | expression_ptr branch0, 13289 | expression_ptr branch1) 13290 | : binary_node<T>(opr, branch0, branch1) 13291 | , rbvec_node_ptr_(0) 13292 | { 13293 | if (is_rebasevector_celem_rtc_node(branch(0))) 13294 | { 13295 | rbvec_node_ptr_ = static_cast<rebasevector_celem_rtc_node<T>*>(branch(0)); 13296 | } 13297 | 13298 | assert(valid()); 13299 | } 13300 | 13301 | inline T value() const exprtk_override 13302 | { 13303 | T& v = rbvec_node_ptr_->ref(); 13304 | v = Operation::process(v,branch(1)->value()); 13305 | 13306 | return v; 13307 | } 13308 | 13309 | inline bool valid() const exprtk_override 13310 | { 13311 | return rbvec_node_ptr_ && binary_node<T>::valid(); 13312 | } 13313 | 13314 | private: 13315 | 13316 | rebasevector_celem_rtc_node<T>* rbvec_node_ptr_; 13317 | }; 13318 | 13319 | template <typename T, typename Operation> 13320 | class assignment_vec_op_node exprtk_final 13321 | : public binary_node <T> 13322 | , public vector_interface<T> 13323 | { 13324 | public: 13325 | 13326 | typedef expression_node<T>* expression_ptr; 13327 | typedef vector_node<T>* vector_node_ptr; 13328 | typedef vec_data_store<T> vds_t; 13329 | 13330 | using binary_node<T>::branch; 13331 | 13332 | assignment_vec_op_node(const operator_type& opr, 13333 | expression_ptr branch0, 13334 | expression_ptr branch1) 13335 | : binary_node<T>(opr, branch0, branch1) 13336 | , vec_node_ptr_(0) 13337 | { 13338 | if (is_vector_node(branch(0))) 13339 | { 13340 | vec_node_ptr_ = static_cast<vector_node<T>*>(branch(0)); 13341 | vds() = vec_node_ptr_->vds(); 13342 | } 13343 | 13344 | assert(valid()); 13345 | } 13346 | 13347 | inline T value() const exprtk_override 13348 | { 13349 | const T v = branch(1)->value(); 13350 | 13351 | T* vec = vds().data(); 13352 | 13353 | loop_unroll::details lud(size()); 13354 | const T* upper_bound = vec + lud.upper_bound; 13355 | 13356 | while (vec < upper_bound) 13357 | { 13358 | #define exprtk_loop(N) \ 13359 | Operation::assign(vec[N],v); \ 13360 | 13361 | exprtk_loop( 0) exprtk_loop( 1) 13362 | exprtk_loop( 2) exprtk_loop( 3) 13363 | #ifndef exprtk_disable_superscalar_unroll 13364 | exprtk_loop( 4) exprtk_loop( 5) 13365 | exprtk_loop( 6) exprtk_loop( 7) 13366 | exprtk_loop( 8) exprtk_loop( 9) 13367 | exprtk_loop(10) exprtk_loop(11) 13368 | exprtk_loop(12) exprtk_loop(13) 13369 | exprtk_loop(14) exprtk_loop(15) 13370 | #endif 13371 | 13372 | vec += lud.batch_size; 13373 | } 13374 | 13375 | switch (lud.remainder) 13376 | { 13377 | #define case_stmt(N,fall_through) \ 13378 | case N : Operation::assign(*vec++,v); \ 13379 | fall_through \ 13380 | 13381 | #ifndef exprtk_disable_superscalar_unroll 13382 | case_stmt(15, exprtk_fallthrough) case_stmt(14, exprtk_fallthrough) 13383 | case_stmt(13, exprtk_fallthrough) case_stmt(12, exprtk_fallthrough) 13384 | case_stmt(11, exprtk_fallthrough) case_stmt(10, exprtk_fallthrough) 13385 | case_stmt( 9, exprtk_fallthrough) case_stmt( 8, exprtk_fallthrough) 13386 | case_stmt( 7, exprtk_fallthrough) case_stmt( 6, exprtk_fallthrough) 13387 | case_stmt( 5, exprtk_fallthrough) case_stmt( 4, exprtk_fallthrough) 13388 | #endif 13389 | case_stmt( 3, exprtk_fallthrough) case_stmt( 2, exprtk_fallthrough) 13390 | case_stmt( 1, (void)0;) 13391 | } 13392 | 13393 | #undef exprtk_loop 13394 | #undef case_stmt 13395 | 13396 | return vec_node_ptr_->value(); 13397 | } 13398 | 13399 | vector_node_ptr vec() const exprtk_override 13400 | { 13401 | return vec_node_ptr_; 13402 | } 13403 | 13404 | vector_node_ptr vec() exprtk_override 13405 | { 13406 | return vec_node_ptr_; 13407 | } 13408 | 13409 | inline typename expression_node<T>::node_type type() const exprtk_override 13410 | { 13411 | return expression_node<T>::e_vecopvalass; 13412 | } 13413 | 13414 | inline bool valid() const exprtk_override 13415 | { 13416 | return 13417 | vec_node_ptr_ && 13418 | (size() <= base_size()) && 13419 | binary_node<T>::valid() ; 13420 | } 13421 | 13422 | std::size_t size() const exprtk_override 13423 | { 13424 | return vec_node_ptr_->vec_holder().size(); 13425 | } 13426 | 13427 | std::size_t base_size() const exprtk_override 13428 | { 13429 | return vec_node_ptr_->vec_holder().base_size(); 13430 | } 13431 | 13432 | vds_t& vds() exprtk_override 13433 | { 13434 | return vds_; 13435 | } 13436 | 13437 | const vds_t& vds() const exprtk_override 13438 | { 13439 | return vds_; 13440 | } 13441 | 13442 | bool side_effect() const exprtk_override 13443 | { 13444 | return true; 13445 | } 13446 | 13447 | private: 13448 | 13449 | vector_node<T>* vec_node_ptr_; 13450 | vds_t vds_; 13451 | }; 13452 | 13453 | template <typename T, typename Operation> 13454 | class assignment_vecvec_op_node exprtk_final 13455 | : public binary_node <T> 13456 | , public vector_interface<T> 13457 | { 13458 | public: 13459 | 13460 | typedef expression_node<T>* expression_ptr; 13461 | typedef vector_node<T>* vector_node_ptr; 13462 | typedef vec_data_store<T> vds_t; 13463 | 13464 | using binary_node<T>::branch; 13465 | 13466 | assignment_vecvec_op_node(const operator_type& opr, 13467 | expression_ptr branch0, 13468 | expression_ptr branch1) 13469 | : binary_node<T>(opr, branch0, branch1) 13470 | , vec0_node_ptr_(0) 13471 | , vec1_node_ptr_(0) 13472 | , initialised_(false) 13473 | { 13474 | if (is_vector_node(branch(0))) 13475 | { 13476 | vec0_node_ptr_ = static_cast<vector_node<T>*>(branch(0)); 13477 | vds() = vec0_node_ptr_->vds(); 13478 | } 13479 | 13480 | if (is_vector_node(branch(1))) 13481 | { 13482 | vec1_node_ptr_ = static_cast<vector_node<T>*>(branch(1)); 13483 | vec1_node_ptr_->vds() = vds(); 13484 | } 13485 | else if (is_ivector_node(branch(1))) 13486 | { 13487 | vector_interface<T>* vi = reinterpret_cast<vector_interface<T>*>(0); 13488 | 13489 | if (0 != (vi = dynamic_cast<vector_interface<T>*>(branch(1)))) 13490 | { 13491 | vec1_node_ptr_ = vi->vec(); 13492 | vec1_node_ptr_->vds() = vi->vds(); 13493 | } 13494 | else 13495 | vds_t::match_sizes(vds(),vec1_node_ptr_->vds()); 13496 | } 13497 | 13498 | initialised_ = 13499 | vec0_node_ptr_ && 13500 | vec1_node_ptr_ && 13501 | (size() <= base_size()) && 13502 | binary_node<T>::valid(); 13503 | 13504 | assert(valid()); 13505 | } 13506 | 13507 | inline T value() const exprtk_override 13508 | { 13509 | branch(0)->value(); 13510 | branch(1)->value(); 13511 | 13512 | T* vec0 = vec0_node_ptr_->vds().data(); 13513 | const T* vec1 = vec1_node_ptr_->vds().data(); 13514 | 13515 | loop_unroll::details lud(size()); 13516 | const T* upper_bound = vec0 + lud.upper_bound; 13517 | 13518 | while (vec0 < upper_bound) 13519 | { 13520 | #define exprtk_loop(N) \ 13521 | vec0[N] = Operation::process(vec0[N], vec1[N]); \ 13522 | 13523 | exprtk_loop( 0) exprtk_loop( 1) 13524 | exprtk_loop( 2) exprtk_loop( 3) 13525 | #ifndef exprtk_disable_superscalar_unroll 13526 | exprtk_loop( 4) exprtk_loop( 5) 13527 | exprtk_loop( 6) exprtk_loop( 7) 13528 | exprtk_loop( 8) exprtk_loop( 9) 13529 | exprtk_loop(10) exprtk_loop(11) 13530 | exprtk_loop(12) exprtk_loop(13) 13531 | exprtk_loop(14) exprtk_loop(15) 13532 | #endif 13533 | 13534 | vec0 += lud.batch_size; 13535 | vec1 += lud.batch_size; 13536 | } 13537 | 13538 | int i = 0; 13539 | 13540 | switch (lud.remainder) 13541 | { 13542 | #define case_stmt(N,fall_through) \ 13543 | case N : { vec0[i] = Operation::process(vec0[i], vec1[i]); ++i; } \ 13544 | fall_through \ 13545 | 13546 | #ifndef exprtk_disable_superscalar_unroll 13547 | case_stmt(15, exprtk_fallthrough) case_stmt(14, exprtk_fallthrough) 13548 | case_stmt(13, exprtk_fallthrough) case_stmt(12, exprtk_fallthrough) 13549 | case_stmt(11, exprtk_fallthrough) case_stmt(10, exprtk_fallthrough) 13550 | case_stmt( 9, exprtk_fallthrough) case_stmt( 8, exprtk_fallthrough) 13551 | case_stmt( 7, exprtk_fallthrough) case_stmt( 6, exprtk_fallthrough) 13552 | case_stmt( 5, exprtk_fallthrough) case_stmt( 4, exprtk_fallthrough) 13553 | #endif 13554 | case_stmt( 3, exprtk_fallthrough) case_stmt( 2, exprtk_fallthrough) 13555 | case_stmt( 1, (void)0;) 13556 | } 13557 | 13558 | #undef exprtk_loop 13559 | #undef case_stmt 13560 | 13561 | return vec0_node_ptr_->value(); 13562 | } 13563 | 13564 | vector_node_ptr vec() const exprtk_override 13565 | { 13566 | return vec0_node_ptr_; 13567 | } 13568 | 13569 | vector_node_ptr vec() exprtk_override 13570 | { 13571 | return vec0_node_ptr_; 13572 | } 13573 | 13574 | inline typename expression_node<T>::node_type type() const exprtk_override 13575 | { 13576 | return expression_node<T>::e_vecopvecass; 13577 | } 13578 | 13579 | inline bool valid() const exprtk_override 13580 | { 13581 | return initialised_; 13582 | } 13583 | 13584 | std::size_t size() const exprtk_override 13585 | { 13586 | return std::min( 13587 | vec0_node_ptr_->vec_holder().size(), 13588 | vec1_node_ptr_->vec_holder().size()); 13589 | } 13590 | 13591 | std::size_t base_size() const exprtk_override 13592 | { 13593 | return std::min( 13594 | vec0_node_ptr_->vec_holder().base_size(), 13595 | vec1_node_ptr_->vec_holder().base_size()); 13596 | } 13597 | 13598 | vds_t& vds() exprtk_override 13599 | { 13600 | return vds_; 13601 | } 13602 | 13603 | const vds_t& vds() const exprtk_override 13604 | { 13605 | return vds_; 13606 | } 13607 | 13608 | bool side_effect() const exprtk_override 13609 | { 13610 | return true; 13611 | } 13612 | 13613 | private: 13614 | 13615 | vector_node<T>* vec0_node_ptr_; 13616 | vector_node<T>* vec1_node_ptr_; 13617 | bool initialised_; 13618 | vds_t vds_; 13619 | }; 13620 | 13621 | template <typename T> 13622 | struct memory_context_t 13623 | { 13624 | typedef vector_node<T>* vector_node_ptr; 13625 | typedef vector_holder<T> vector_holder_t; 13626 | typedef vector_holder_t* vector_holder_ptr; 13627 | 13628 | memory_context_t() 13629 | : temp_(0) 13630 | , temp_vec_node_(0) 13631 | {} 13632 | 13633 | void clear() 13634 | { 13635 | delete temp_vec_node_; 13636 | delete temp_; 13637 | } 13638 | 13639 | vector_holder_ptr temp_; 13640 | vector_node_ptr temp_vec_node_; 13641 | }; 13642 | 13643 | template <typename T> 13644 | inline memory_context_t<T> make_memory_context(vector_holder<T>& vec_holder, 13645 | vec_data_store<T>& vds) 13646 | { 13647 | memory_context_t<T> result_ctxt; 13648 | 13649 | result_ctxt.temp_ = (vec_holder.rebaseable()) ? 13650 | new vector_holder<T>(vec_holder,vds) : 13651 | new vector_holder<T>(vds) ; 13652 | 13653 | result_ctxt.temp_vec_node_ = new vector_node<T>(vds,result_ctxt.temp_); 13654 | 13655 | return result_ctxt; 13656 | } 13657 | 13658 | template <typename T> 13659 | inline memory_context_t<T> make_memory_context(vector_holder<T>& vec_holder0, 13660 | vector_holder<T>& vec_holder1, 13661 | vec_data_store<T>& vds) 13662 | { 13663 | memory_context_t<T> result_ctxt; 13664 | 13665 | if (!vec_holder0.rebaseable() && !vec_holder1.rebaseable()) 13666 | result_ctxt.temp_ = new vector_holder<T>(vds); 13667 | else if (vec_holder0.rebaseable() && !vec_holder1.rebaseable()) 13668 | result_ctxt.temp_ = new vector_holder<T>(vec_holder0,vds); 13669 | else if (!vec_holder0.rebaseable() && vec_holder1.rebaseable()) 13670 | result_ctxt.temp_ = new vector_holder<T>(vec_holder1,vds); 13671 | else 13672 | { 13673 | result_ctxt.temp_ = (vec_holder0.base_size() >= vec_holder1.base_size()) ? 13674 | new vector_holder<T>(vec_holder0, vds) : 13675 | new vector_holder<T>(vec_holder1, vds) ; 13676 | } 13677 | 13678 | result_ctxt.temp_vec_node_ = new vector_node<T>(vds,result_ctxt.temp_); 13679 | 13680 | return result_ctxt; 13681 | } 13682 | 13683 | template <typename T, typename Operation> 13684 | class vec_binop_vecvec_node exprtk_final 13685 | : public binary_node <T> 13686 | , public vector_interface<T> 13687 | { 13688 | public: 13689 | 13690 | typedef expression_node<T>* expression_ptr; 13691 | typedef vector_node<T>* vector_node_ptr; 13692 | typedef vector_holder<T> vector_holder_t; 13693 | typedef vector_holder_t* vector_holder_ptr; 13694 | typedef vec_data_store<T> vds_t; 13695 | typedef memory_context_t<T> memory_context; 13696 | 13697 | using binary_node<T>::branch; 13698 | 13699 | vec_binop_vecvec_node(const operator_type& opr, 13700 | expression_ptr branch0, 13701 | expression_ptr branch1) 13702 | : binary_node<T>(opr, branch0, branch1) 13703 | , vec0_node_ptr_(0) 13704 | , vec1_node_ptr_(0) 13705 | , initialised_(false) 13706 | { 13707 | bool v0_is_ivec = false; 13708 | bool v1_is_ivec = false; 13709 | 13710 | if (is_vector_node(branch(0))) 13711 | { 13712 | vec0_node_ptr_ = static_cast<vector_node_ptr>(branch(0)); 13713 | } 13714 | else if (is_ivector_node(branch(0))) 13715 | { 13716 | vector_interface<T>* vi = reinterpret_cast<vector_interface<T>*>(0); 13717 | 13718 | if (0 != (vi = dynamic_cast<vector_interface<T>*>(branch(0)))) 13719 | { 13720 | vec0_node_ptr_ = vi->vec(); 13721 | v0_is_ivec = true; 13722 | } 13723 | } 13724 | 13725 | if (is_vector_node(branch(1))) 13726 | { 13727 | vec1_node_ptr_ = static_cast<vector_node_ptr>(branch(1)); 13728 | } 13729 | else if (is_ivector_node(branch(1))) 13730 | { 13731 | vector_interface<T>* vi = reinterpret_cast<vector_interface<T>*>(0); 13732 | 13733 | if (0 != (vi = dynamic_cast<vector_interface<T>*>(branch(1)))) 13734 | { 13735 | vec1_node_ptr_ = vi->vec(); 13736 | v1_is_ivec = true; 13737 | } 13738 | } 13739 | 13740 | if (vec0_node_ptr_ && vec1_node_ptr_) 13741 | { 13742 | vector_holder<T>& vec0 = vec0_node_ptr_->vec_holder(); 13743 | vector_holder<T>& vec1 = vec1_node_ptr_->vec_holder(); 13744 | 13745 | if (v0_is_ivec && (vec0.base_size() <= vec1.base_size())) 13746 | { 13747 | vds_ = vds_t(vec0_node_ptr_->vds()); 13748 | } 13749 | else if (v1_is_ivec && (vec1.base_size() <= vec0.base_size())) 13750 | { 13751 | vds_ = vds_t(vec1_node_ptr_->vds()); 13752 | } 13753 | else 13754 | { 13755 | vds_ = vds_t(std::min(vec0.base_size(),vec1.base_size())); 13756 | } 13757 | 13758 | memory_context_ = make_memory_context(vec0, vec1, vds()); 13759 | 13760 | initialised_ = 13761 | (size() <= base_size()) && 13762 | binary_node<T>::valid(); 13763 | } 13764 | 13765 | assert(valid()); 13766 | } 13767 | 13768 | ~vec_binop_vecvec_node() 13769 | { 13770 | memory_context_.clear(); 13771 | } 13772 | 13773 | inline T value() const exprtk_override 13774 | { 13775 | branch(0)->value(); 13776 | branch(1)->value(); 13777 | 13778 | const T* vec0 = vec0_node_ptr_->vds().data(); 13779 | const T* vec1 = vec1_node_ptr_->vds().data(); 13780 | T* vec2 = vds().data(); 13781 | 13782 | loop_unroll::details lud(size()); 13783 | const T* upper_bound = vec2 + lud.upper_bound; 13784 | 13785 | while (vec2 < upper_bound) 13786 | { 13787 | #define exprtk_loop(N) \ 13788 | vec2[N] = Operation::process(vec0[N], vec1[N]); \ 13789 | 13790 | exprtk_loop( 0) exprtk_loop( 1) 13791 | exprtk_loop( 2) exprtk_loop( 3) 13792 | #ifndef exprtk_disable_superscalar_unroll 13793 | exprtk_loop( 4) exprtk_loop( 5) 13794 | exprtk_loop( 6) exprtk_loop( 7) 13795 | exprtk_loop( 8) exprtk_loop( 9) 13796 | exprtk_loop(10) exprtk_loop(11) 13797 | exprtk_loop(12) exprtk_loop(13) 13798 | exprtk_loop(14) exprtk_loop(15) 13799 | #endif 13800 | 13801 | vec0 += lud.batch_size; 13802 | vec1 += lud.batch_size; 13803 | vec2 += lud.batch_size; 13804 | } 13805 | 13806 | int i = 0; 13807 | 13808 | switch (lud.remainder) 13809 | { 13810 | #define case_stmt(N) \ 13811 | case N : { vec2[i] = Operation::process(vec0[i], vec1[i]); ++i; } \ 13812 | exprtk_fallthrough \ 13813 | 13814 | #ifndef exprtk_disable_superscalar_unroll 13815 | case_stmt(15) case_stmt(14) 13816 | case_stmt(13) case_stmt(12) 13817 | case_stmt(11) case_stmt(10) 13818 | case_stmt( 9) case_stmt( 8) 13819 | case_stmt( 7) case_stmt( 6) 13820 | case_stmt( 5) case_stmt( 4) 13821 | #endif 13822 | case_stmt( 3) case_stmt( 2) 13823 | case_stmt( 1) 13824 | default: break; 13825 | } 13826 | 13827 | #undef exprtk_loop 13828 | #undef case_stmt 13829 | 13830 | return (vds().data())[0]; 13831 | } 13832 | 13833 | vector_node_ptr vec() const exprtk_override 13834 | { 13835 | return memory_context_.temp_vec_node_; 13836 | } 13837 | 13838 | vector_node_ptr vec() exprtk_override 13839 | { 13840 | return memory_context_.temp_vec_node_; 13841 | } 13842 | 13843 | inline typename expression_node<T>::node_type type() const exprtk_override 13844 | { 13845 | return expression_node<T>::e_vecvecarith; 13846 | } 13847 | 13848 | inline bool valid() const exprtk_override 13849 | { 13850 | return initialised_; 13851 | } 13852 | 13853 | std::size_t size() const exprtk_override 13854 | { 13855 | return std::min( 13856 | vec0_node_ptr_->vec_holder().size(), 13857 | vec1_node_ptr_->vec_holder().size()); 13858 | } 13859 | 13860 | std::size_t base_size() const exprtk_override 13861 | { 13862 | return std::min( 13863 | vec0_node_ptr_->vec_holder().base_size(), 13864 | vec1_node_ptr_->vec_holder().base_size()); 13865 | } 13866 | 13867 | vds_t& vds() exprtk_override 13868 | { 13869 | return vds_; 13870 | } 13871 | 13872 | const vds_t& vds() const exprtk_override 13873 | { 13874 | return vds_; 13875 | } 13876 | 13877 | private: 13878 | 13879 | vector_node_ptr vec0_node_ptr_; 13880 | vector_node_ptr vec1_node_ptr_; 13881 | bool initialised_; 13882 | vds_t vds_; 13883 | memory_context memory_context_; 13884 | }; 13885 | 13886 | template <typename T, typename Operation> 13887 | class vec_binop_vecval_node exprtk_final 13888 | : public binary_node <T> 13889 | , public vector_interface<T> 13890 | { 13891 | public: 13892 | 13893 | typedef expression_node<T>* expression_ptr; 13894 | typedef vector_node<T>* vector_node_ptr; 13895 | typedef vector_holder<T> vector_holder_t; 13896 | typedef vector_holder_t* vector_holder_ptr; 13897 | typedef vec_data_store<T> vds_t; 13898 | typedef memory_context_t<T> memory_context; 13899 | 13900 | using binary_node<T>::branch; 13901 | 13902 | vec_binop_vecval_node(const operator_type& opr, 13903 | expression_ptr branch0, 13904 | expression_ptr branch1) 13905 | : binary_node<T>(opr, branch0, branch1) 13906 | , vec0_node_ptr_(0) 13907 | { 13908 | bool v0_is_ivec = false; 13909 | 13910 | if (is_vector_node(branch(0))) 13911 | { 13912 | vec0_node_ptr_ = static_cast<vector_node_ptr>(branch(0)); 13913 | } 13914 | else if (is_ivector_node(branch(0))) 13915 | { 13916 | vector_interface<T>* vi = reinterpret_cast<vector_interface<T>*>(0); 13917 | 13918 | if (0 != (vi = dynamic_cast<vector_interface<T>*>(branch(0)))) 13919 | { 13920 | vec0_node_ptr_ = vi->vec(); 13921 | v0_is_ivec = true; 13922 | } 13923 | } 13924 | 13925 | if (vec0_node_ptr_) 13926 | { 13927 | if (v0_is_ivec) 13928 | vds() = vec0_node_ptr_->vds(); 13929 | else 13930 | vds() = vds_t(vec0_node_ptr_->base_size()); 13931 | 13932 | memory_context_ = make_memory_context(vec0_node_ptr_->vec_holder(), vds()); 13933 | } 13934 | 13935 | assert(valid()); 13936 | } 13937 | 13938 | ~vec_binop_vecval_node() 13939 | { 13940 | memory_context_.clear(); 13941 | } 13942 | 13943 | inline T value() const exprtk_override 13944 | { 13945 | branch(0)->value(); 13946 | const T v = branch(1)->value(); 13947 | 13948 | const T* vec0 = vec0_node_ptr_->vds().data(); 13949 | T* vec1 = vds().data(); 13950 | 13951 | loop_unroll::details lud(size()); 13952 | const T* upper_bound = vec0 + lud.upper_bound; 13953 | 13954 | while (vec0 < upper_bound) 13955 | { 13956 | #define exprtk_loop(N) \ 13957 | vec1[N] = Operation::process(vec0[N], v); \ 13958 | 13959 | exprtk_loop( 0) exprtk_loop( 1) 13960 | exprtk_loop( 2) exprtk_loop( 3) 13961 | #ifndef exprtk_disable_superscalar_unroll 13962 | exprtk_loop( 4) exprtk_loop( 5) 13963 | exprtk_loop( 6) exprtk_loop( 7) 13964 | exprtk_loop( 8) exprtk_loop( 9) 13965 | exprtk_loop(10) exprtk_loop(11) 13966 | exprtk_loop(12) exprtk_loop(13) 13967 | exprtk_loop(14) exprtk_loop(15) 13968 | #endif 13969 | 13970 | vec0 += lud.batch_size; 13971 | vec1 += lud.batch_size; 13972 | } 13973 | 13974 | int i = 0; 13975 | 13976 | switch (lud.remainder) 13977 | { 13978 | #define case_stmt(N,fall_through) \ 13979 | case N : { vec1[i] = Operation::process(vec0[i], v); ++i; } \ 13980 | fall_through \ 13981 | 13982 | #ifndef exprtk_disable_superscalar_unroll 13983 | case_stmt(15, exprtk_fallthrough) case_stmt(14, exprtk_fallthrough) 13984 | case_stmt(13, exprtk_fallthrough) case_stmt(12, exprtk_fallthrough) 13985 | case_stmt(11, exprtk_fallthrough) case_stmt(10, exprtk_fallthrough) 13986 | case_stmt( 9, exprtk_fallthrough) case_stmt( 8, exprtk_fallthrough) 13987 | case_stmt( 7, exprtk_fallthrough) case_stmt( 6, exprtk_fallthrough) 13988 | case_stmt( 5, exprtk_fallthrough) case_stmt( 4, exprtk_fallthrough) 13989 | #endif 13990 | case_stmt( 3, exprtk_fallthrough) case_stmt( 2, exprtk_fallthrough) 13991 | case_stmt( 1, (void)0;) 13992 | } 13993 | 13994 | #undef exprtk_loop 13995 | #undef case_stmt 13996 | 13997 | return (vds().data())[0]; 13998 | } 13999 | 14000 | vector_node_ptr vec() const exprtk_override 14001 | { 14002 | return memory_context_.temp_vec_node_; 14003 | } 14004 | 14005 | vector_node_ptr vec() exprtk_override 14006 | { 14007 | return memory_context_.temp_vec_node_; 14008 | } 14009 | 14010 | inline typename expression_node<T>::node_type type() const exprtk_override 14011 | { 14012 | return expression_node<T>::e_vecvalarith; 14013 | } 14014 | 14015 | inline bool valid() const exprtk_override 14016 | { 14017 | return 14018 | vec0_node_ptr_ && 14019 | (size() <= base_size()) && 14020 | binary_node<T>::valid(); 14021 | } 14022 | 14023 | std::size_t size() const exprtk_override 14024 | { 14025 | return vec0_node_ptr_->size(); 14026 | } 14027 | 14028 | std::size_t base_size() const exprtk_override 14029 | { 14030 | return vec0_node_ptr_->vec_holder().base_size(); 14031 | } 14032 | 14033 | vds_t& vds() exprtk_override 14034 | { 14035 | return vds_; 14036 | } 14037 | 14038 | const vds_t& vds() const exprtk_override 14039 | { 14040 | return vds_; 14041 | } 14042 | 14043 | private: 14044 | 14045 | vector_node_ptr vec0_node_ptr_; 14046 | vds_t vds_; 14047 | memory_context memory_context_; 14048 | }; 14049 | 14050 | template <typename T, typename Operation> 14051 | class vec_binop_valvec_node exprtk_final 14052 | : public binary_node <T> 14053 | , public vector_interface<T> 14054 | { 14055 | public: 14056 | 14057 | typedef expression_node<T>* expression_ptr; 14058 | typedef vector_node<T>* vector_node_ptr; 14059 | typedef vector_holder<T> vector_holder_t; 14060 | typedef vector_holder_t* vector_holder_ptr; 14061 | typedef vec_data_store<T> vds_t; 14062 | typedef memory_context_t<T> memory_context; 14063 | 14064 | using binary_node<T>::branch; 14065 | 14066 | vec_binop_valvec_node(const operator_type& opr, 14067 | expression_ptr branch0, 14068 | expression_ptr branch1) 14069 | : binary_node<T>(opr, branch0, branch1) 14070 | , vec1_node_ptr_(0) 14071 | { 14072 | bool v1_is_ivec = false; 14073 | 14074 | if (is_vector_node(branch(1))) 14075 | { 14076 | vec1_node_ptr_ = static_cast<vector_node_ptr>(branch(1)); 14077 | } 14078 | else if (is_ivector_node(branch(1))) 14079 | { 14080 | vector_interface<T>* vi = reinterpret_cast<vector_interface<T>*>(0); 14081 | 14082 | if (0 != (vi = dynamic_cast<vector_interface<T>*>(branch(1)))) 14083 | { 14084 | vec1_node_ptr_ = vi->vec(); 14085 | v1_is_ivec = true; 14086 | } 14087 | } 14088 | 14089 | if (vec1_node_ptr_) 14090 | { 14091 | if (v1_is_ivec) 14092 | vds() = vec1_node_ptr_->vds(); 14093 | else 14094 | vds() = vds_t(vec1_node_ptr_->base_size()); 14095 | 14096 | memory_context_ = make_memory_context(vec1_node_ptr_->vec_holder(), vds()); 14097 | } 14098 | 14099 | assert(valid()); 14100 | } 14101 | 14102 | ~vec_binop_valvec_node() 14103 | { 14104 | memory_context_.clear(); 14105 | } 14106 | 14107 | inline T value() const exprtk_override 14108 | { 14109 | const T v = branch(0)->value(); 14110 | branch(1)->value(); 14111 | 14112 | T* vec0 = vds().data(); 14113 | const T* vec1 = vec1_node_ptr_->vds().data(); 14114 | 14115 | loop_unroll::details lud(size()); 14116 | const T* upper_bound = vec0 + lud.upper_bound; 14117 | 14118 | while (vec0 < upper_bound) 14119 | { 14120 | #define exprtk_loop(N) \ 14121 | vec0[N] = Operation::process(v, vec1[N]); \ 14122 | 14123 | exprtk_loop( 0) exprtk_loop( 1) 14124 | exprtk_loop( 2) exprtk_loop( 3) 14125 | #ifndef exprtk_disable_superscalar_unroll 14126 | exprtk_loop( 4) exprtk_loop( 5) 14127 | exprtk_loop( 6) exprtk_loop( 7) 14128 | exprtk_loop( 8) exprtk_loop( 9) 14129 | exprtk_loop(10) exprtk_loop(11) 14130 | exprtk_loop(12) exprtk_loop(13) 14131 | exprtk_loop(14) exprtk_loop(15) 14132 | #endif 14133 | 14134 | vec0 += lud.batch_size; 14135 | vec1 += lud.batch_size; 14136 | } 14137 | 14138 | int i = 0; 14139 | 14140 | switch (lud.remainder) 14141 | { 14142 | #define case_stmt(N,fall_through) \ 14143 | case N : { vec0[i] = Operation::process(v, vec1[i]); ++i; } \ 14144 | fall_through \ 14145 | 14146 | #ifndef exprtk_disable_superscalar_unroll 14147 | case_stmt(15, exprtk_fallthrough) case_stmt(14, exprtk_fallthrough) 14148 | case_stmt(13, exprtk_fallthrough) case_stmt(12, exprtk_fallthrough) 14149 | case_stmt(11, exprtk_fallthrough) case_stmt(10, exprtk_fallthrough) 14150 | case_stmt( 9, exprtk_fallthrough) case_stmt( 8, exprtk_fallthrough) 14151 | case_stmt( 7, exprtk_fallthrough) case_stmt( 6, exprtk_fallthrough) 14152 | case_stmt( 5, exprtk_fallthrough) case_stmt( 4, exprtk_fallthrough) 14153 | #endif 14154 | case_stmt( 3, exprtk_fallthrough) case_stmt( 2, exprtk_fallthrough) 14155 | case_stmt( 1, (void)0;) 14156 | } 14157 | 14158 | #undef exprtk_loop 14159 | #undef case_stmt 14160 | 14161 | return (vds().data())[0]; 14162 | } 14163 | 14164 | vector_node_ptr vec() const exprtk_override 14165 | { 14166 | return memory_context_.temp_vec_node_; 14167 | } 14168 | 14169 | vector_node_ptr vec() exprtk_override 14170 | { 14171 | return memory_context_.temp_vec_node_; 14172 | } 14173 | 14174 | inline typename expression_node<T>::node_type type() const exprtk_override 14175 | { 14176 | return expression_node<T>::e_vecvalarith; 14177 | } 14178 | 14179 | inline bool valid() const exprtk_override 14180 | { 14181 | return 14182 | vec1_node_ptr_ && 14183 | (size() <= base_size()) && 14184 | (vds_.size() <= base_size()) && 14185 | binary_node<T>::valid(); 14186 | } 14187 | 14188 | std::size_t size() const exprtk_override 14189 | { 14190 | return vec1_node_ptr_->vec_holder().size(); 14191 | } 14192 | 14193 | std::size_t base_size() const exprtk_override 14194 | { 14195 | return vec1_node_ptr_->vec_holder().base_size(); 14196 | } 14197 | 14198 | vds_t& vds() exprtk_override 14199 | { 14200 | return vds_; 14201 | } 14202 | 14203 | const vds_t& vds() const exprtk_override 14204 | { 14205 | return vds_; 14206 | } 14207 | 14208 | private: 14209 | 14210 | vector_node_ptr vec1_node_ptr_; 14211 | vds_t vds_; 14212 | memory_context memory_context_; 14213 | }; 14214 | 14215 | template <typename T, typename Operation> 14216 | class unary_vector_node exprtk_final 14217 | : public unary_node <T> 14218 | , public vector_interface<T> 14219 | { 14220 | public: 14221 | 14222 | typedef expression_node<T>* expression_ptr; 14223 | typedef vector_node<T>* vector_node_ptr; 14224 | typedef vector_holder<T> vector_holder_t; 14225 | typedef vector_holder_t* vector_holder_ptr; 14226 | typedef vec_data_store<T> vds_t; 14227 | typedef memory_context_t<T> memory_context; 14228 | 14229 | using expression_node<T>::branch; 14230 | 14231 | unary_vector_node(const operator_type& opr, expression_ptr branch0) 14232 | : unary_node<T>(opr, branch0) 14233 | , vec0_node_ptr_(0) 14234 | { 14235 | bool vec0_is_ivec = false; 14236 | 14237 | if (is_vector_node(branch(0))) 14238 | { 14239 | vec0_node_ptr_ = static_cast<vector_node_ptr>(branch(0)); 14240 | } 14241 | else if (is_ivector_node(branch(0))) 14242 | { 14243 | vector_interface<T>* vi = reinterpret_cast<vector_interface<T>*>(0); 14244 | 14245 | if (0 != (vi = dynamic_cast<vector_interface<T>*>(branch(0)))) 14246 | { 14247 | vec0_node_ptr_ = vi->vec(); 14248 | vec0_is_ivec = true; 14249 | } 14250 | } 14251 | 14252 | if (vec0_node_ptr_) 14253 | { 14254 | if (vec0_is_ivec) 14255 | vds_ = vec0_node_ptr_->vds(); 14256 | else 14257 | vds_ = vds_t(vec0_node_ptr_->base_size()); 14258 | 14259 | memory_context_ = make_memory_context(vec0_node_ptr_->vec_holder(), vds()); 14260 | } 14261 | 14262 | assert(valid()); 14263 | } 14264 | 14265 | ~unary_vector_node() 14266 | { 14267 | memory_context_.clear(); 14268 | } 14269 | 14270 | inline T value() const exprtk_override 14271 | { 14272 | branch()->value(); 14273 | 14274 | const T* vec0 = vec0_node_ptr_->vds().data(); 14275 | T* vec1 = vds().data(); 14276 | 14277 | loop_unroll::details lud(size()); 14278 | const T* upper_bound = vec0 + lud.upper_bound; 14279 | 14280 | while (vec0 < upper_bound) 14281 | { 14282 | #define exprtk_loop(N) \ 14283 | vec1[N] = Operation::process(vec0[N]); \ 14284 | 14285 | exprtk_loop( 0) exprtk_loop( 1) 14286 | exprtk_loop( 2) exprtk_loop( 3) 14287 | #ifndef exprtk_disable_superscalar_unroll 14288 | exprtk_loop( 4) exprtk_loop( 5) 14289 | exprtk_loop( 6) exprtk_loop( 7) 14290 | exprtk_loop( 8) exprtk_loop( 9) 14291 | exprtk_loop(10) exprtk_loop(11) 14292 | exprtk_loop(12) exprtk_loop(13) 14293 | exprtk_loop(14) exprtk_loop(15) 14294 | #endif 14295 | 14296 | vec0 += lud.batch_size; 14297 | vec1 += lud.batch_size; 14298 | } 14299 | 14300 | int i = 0; 14301 | 14302 | switch (lud.remainder) 14303 | { 14304 | #define case_stmt(N) \ 14305 | case N : { vec1[i] = Operation::process(vec0[i]); ++i; } \ 14306 | exprtk_fallthrough \ 14307 | 14308 | #ifndef exprtk_disable_superscalar_unroll 14309 | case_stmt(15) case_stmt(14) 14310 | case_stmt(13) case_stmt(12) 14311 | case_stmt(11) case_stmt(10) 14312 | case_stmt( 9) case_stmt( 8) 14313 | case_stmt( 7) case_stmt( 6) 14314 | case_stmt( 5) case_stmt( 4) 14315 | #endif 14316 | case_stmt( 3) case_stmt( 2) 14317 | case_stmt( 1) 14318 | default: break; 14319 | } 14320 | 14321 | #undef exprtk_loop 14322 | #undef case_stmt 14323 | 14324 | return (vds().data())[0]; 14325 | } 14326 | 14327 | vector_node_ptr vec() const exprtk_override 14328 | { 14329 | return memory_context_.temp_vec_node_; 14330 | } 14331 | 14332 | vector_node_ptr vec() exprtk_override 14333 | { 14334 | return memory_context_.temp_vec_node_; 14335 | } 14336 | 14337 | inline typename expression_node<T>::node_type type() const exprtk_override 14338 | { 14339 | return expression_node<T>::e_vecunaryop; 14340 | } 14341 | 14342 | inline bool valid() const exprtk_override 14343 | { 14344 | return vec0_node_ptr_ && unary_node<T>::valid(); 14345 | } 14346 | 14347 | std::size_t size() const exprtk_override 14348 | { 14349 | return vec0_node_ptr_->vec_holder().size(); 14350 | } 14351 | 14352 | std::size_t base_size() const exprtk_override 14353 | { 14354 | return vec0_node_ptr_->vec_holder().base_size(); 14355 | } 14356 | 14357 | vds_t& vds() exprtk_override 14358 | { 14359 | return vds_; 14360 | } 14361 | 14362 | const vds_t& vds() const exprtk_override 14363 | { 14364 | return vds_; 14365 | } 14366 | 14367 | private: 14368 | 14369 | vector_node_ptr vec0_node_ptr_; 14370 | vds_t vds_; 14371 | memory_context memory_context_; 14372 | }; 14373 | 14374 | template <typename T> 14375 | class conditional_vector_node exprtk_final 14376 | : public expression_node <T> 14377 | , public vector_interface<T> 14378 | { 14379 | public: 14380 | 14381 | typedef expression_node <T>* expression_ptr; 14382 | typedef vector_interface<T>* vec_interface_ptr; 14383 | typedef vector_node <T>* vector_node_ptr; 14384 | typedef vector_holder <T> vector_holder_t; 14385 | typedef vector_holder_t* vector_holder_ptr; 14386 | typedef vec_data_store <T> vds_t; 14387 | typedef memory_context_t<T> memory_context; 14388 | typedef std::pair<expression_ptr,bool> branch_t; 14389 | 14390 | conditional_vector_node(expression_ptr condition, 14391 | expression_ptr consequent, 14392 | expression_ptr alternative) 14393 | : consequent_node_ptr_ (0) 14394 | , alternative_node_ptr_(0) 14395 | , temp_vec_node_ (0) 14396 | , temp_ (0) 14397 | , result_vec_size_ (0) 14398 | , initialised_ (false) 14399 | { 14400 | construct_branch_pair(condition_ , condition ); 14401 | construct_branch_pair(consequent_ , consequent ); 14402 | construct_branch_pair(alternative_, alternative); 14403 | 14404 | if (details::is_ivector_node(consequent_.first)) 14405 | { 14406 | vec_interface_ptr ivec_ptr = dynamic_cast<vec_interface_ptr>(consequent_.first); 14407 | 14408 | if (0 != ivec_ptr) 14409 | { 14410 | consequent_node_ptr_ = ivec_ptr->vec(); 14411 | } 14412 | } 14413 | 14414 | if (details::is_ivector_node(alternative_.first)) 14415 | { 14416 | vec_interface_ptr ivec_ptr = dynamic_cast<vec_interface_ptr>(alternative_.first); 14417 | 14418 | if (0 != ivec_ptr) 14419 | { 14420 | alternative_node_ptr_ = ivec_ptr->vec(); 14421 | } 14422 | } 14423 | 14424 | if (consequent_node_ptr_ && alternative_node_ptr_) 14425 | { 14426 | const std::size_t vec_size = 14427 | std::max(consequent_node_ptr_ ->vec_holder().base_size(), 14428 | alternative_node_ptr_->vec_holder().base_size()); 14429 | 14430 | vds_ = vds_t(vec_size); 14431 | memory_context_ = make_memory_context( 14432 | consequent_node_ptr_ ->vec_holder(), 14433 | alternative_node_ptr_->vec_holder(), 14434 | vds()); 14435 | 14436 | initialised_ = (vec_size > 0); 14437 | } 14438 | 14439 | assert(initialised_); 14440 | } 14441 | 14442 | ~conditional_vector_node() 14443 | { 14444 | memory_context_.clear(); 14445 | } 14446 | 14447 | inline T value() const exprtk_override 14448 | { 14449 | T result = T(0); 14450 | T* source_vector = 0; 14451 | T* result_vector = vds().data(); 14452 | 14453 | if (is_true(condition_)) 14454 | { 14455 | result = consequent_.first->value(); 14456 | source_vector = consequent_node_ptr_->vds().data(); 14457 | result_vec_size_ = consequent_node_ptr_->size(); 14458 | } 14459 | else 14460 | { 14461 | result = alternative_.first->value(); 14462 | source_vector = alternative_node_ptr_->vds().data(); 14463 | result_vec_size_ = alternative_node_ptr_->size(); 14464 | } 14465 | 14466 | for (std::size_t i = 0; i < result_vec_size_; ++i) 14467 | { 14468 | result_vector[i] = source_vector[i]; 14469 | } 14470 | 14471 | return result; 14472 | } 14473 | 14474 | vector_node_ptr vec() const exprtk_override 14475 | { 14476 | return memory_context_.temp_vec_node_; 14477 | } 14478 | 14479 | vector_node_ptr vec() exprtk_override 14480 | { 14481 | return memory_context_.temp_vec_node_; 14482 | } 14483 | 14484 | inline typename expression_node<T>::node_type type() const exprtk_override 14485 | { 14486 | return expression_node<T>::e_vecondition; 14487 | } 14488 | 14489 | inline bool valid() const exprtk_override 14490 | { 14491 | return 14492 | initialised_ && 14493 | condition_ .first && condition_ .first->valid() && 14494 | consequent_ .first && consequent_ .first->valid() && 14495 | alternative_.first && alternative_.first->valid() && 14496 | size() <= base_size(); 14497 | } 14498 | 14499 | std::size_t size() const exprtk_override 14500 | { 14501 | return result_vec_size_; 14502 | } 14503 | 14504 | std::size_t base_size() const exprtk_override 14505 | { 14506 | return std::min( 14507 | consequent_node_ptr_ ->vec_holder().base_size(), 14508 | alternative_node_ptr_->vec_holder().base_size()); 14509 | } 14510 | 14511 | vds_t& vds() exprtk_override 14512 | { 14513 | return vds_; 14514 | } 14515 | 14516 | const vds_t& vds() const exprtk_override 14517 | { 14518 | return vds_; 14519 | } 14520 | 14521 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 14522 | { 14523 | expression_node<T>::ndb_t::collect(condition_ , node_delete_list); 14524 | expression_node<T>::ndb_t::collect(consequent_ , node_delete_list); 14525 | expression_node<T>::ndb_t::collect(alternative_ , node_delete_list); 14526 | } 14527 | 14528 | std::size_t node_depth() const exprtk_override 14529 | { 14530 | return expression_node<T>::ndb_t::compute_node_depth 14531 | (condition_, consequent_, alternative_); 14532 | } 14533 | 14534 | private: 14535 | 14536 | branch_t condition_; 14537 | branch_t consequent_; 14538 | branch_t alternative_; 14539 | vector_node_ptr consequent_node_ptr_; 14540 | vector_node_ptr alternative_node_ptr_; 14541 | vector_node_ptr temp_vec_node_; 14542 | vector_holder_ptr temp_; 14543 | vds_t vds_; 14544 | mutable std::size_t result_vec_size_; 14545 | bool initialised_; 14546 | memory_context memory_context_; 14547 | }; 14548 | 14549 | template <typename T> 14550 | class scand_node exprtk_final : public binary_node<T> 14551 | { 14552 | public: 14553 | 14554 | typedef expression_node<T>* expression_ptr; 14555 | using binary_node<T>::branch; 14556 | 14557 | scand_node(const operator_type& opr, 14558 | expression_ptr branch0, 14559 | expression_ptr branch1) 14560 | : binary_node<T>(opr, branch0, branch1) 14561 | { 14562 | assert(binary_node<T>::valid()); 14563 | } 14564 | 14565 | inline T value() const exprtk_override 14566 | { 14567 | return ( 14568 | std::not_equal_to<T>() 14569 | (T(0),branch(0)->value()) && 14570 | std::not_equal_to<T>() 14571 | (T(0),branch(1)->value()) 14572 | ) ? T(1) : T(0); 14573 | } 14574 | }; 14575 | 14576 | template <typename T> 14577 | class scor_node exprtk_final : public binary_node<T> 14578 | { 14579 | public: 14580 | 14581 | typedef expression_node<T>* expression_ptr; 14582 | using binary_node<T>::branch; 14583 | 14584 | scor_node(const operator_type& opr, 14585 | expression_ptr branch0, 14586 | expression_ptr branch1) 14587 | : binary_node<T>(opr, branch0, branch1) 14588 | { 14589 | assert(binary_node<T>::valid()); 14590 | } 14591 | 14592 | inline T value() const exprtk_override 14593 | { 14594 | return ( 14595 | std::not_equal_to<T>() 14596 | (T(0),branch(0)->value()) || 14597 | std::not_equal_to<T>() 14598 | (T(0),branch(1)->value()) 14599 | ) ? T(1) : T(0); 14600 | } 14601 | }; 14602 | 14603 | template <typename T, typename IFunction, std::size_t N> 14604 | class function_N_node exprtk_final : public expression_node<T> 14605 | { 14606 | public: 14607 | 14608 | // Function of N parameters. 14609 | typedef expression_node<T>* expression_ptr; 14610 | typedef std::pair<expression_ptr,bool> branch_t; 14611 | typedef IFunction ifunction; 14612 | 14613 | explicit function_N_node(ifunction* func) 14614 | : function_((N == func->param_count) ? func : reinterpret_cast<ifunction*>(0)) 14615 | , parameter_count_(func->param_count) 14616 | , initialised_(false) 14617 | {} 14618 | 14619 | template <std::size_t NumBranches> 14620 | bool init_branches(expression_ptr (&b)[NumBranches]) 14621 | { 14622 | // Needed for incompetent and broken msvc compiler versions 14623 | #ifdef _MSC_VER 14624 | #pragma warning(push) 14625 | #pragma warning(disable: 4127) 14626 | #endif 14627 | 14628 | if (N != NumBranches) 14629 | { 14630 | return false; 14631 | } 14632 | 14633 | for (std::size_t i = 0; i < NumBranches; ++i) 14634 | { 14635 | if (b[i] && b[i]->valid()) 14636 | branch_[i] = std::make_pair(b[i],branch_deletable(b[i])); 14637 | else 14638 | return false; 14639 | } 14640 | 14641 | initialised_ = function_; 14642 | assert(valid()); 14643 | return initialised_; 14644 | 14645 | #ifdef _MSC_VER 14646 | #pragma warning(pop) 14647 | #endif 14648 | } 14649 | 14650 | inline bool operator <(const function_N_node<T,IFunction,N>& fn) const 14651 | { 14652 | return this < (&fn); 14653 | } 14654 | 14655 | inline T value() const exprtk_override 14656 | { 14657 | // Needed for incompetent and broken msvc compiler versions 14658 | #ifdef _MSC_VER 14659 | #pragma warning(push) 14660 | #pragma warning(disable: 4127) 14661 | #endif 14662 | 14663 | T v[N]; 14664 | evaluate_branches<T,N>::execute(v,branch_); 14665 | return invoke<T,N>::execute(*function_,v); 14666 | 14667 | #ifdef _MSC_VER 14668 | #pragma warning(pop) 14669 | #endif 14670 | } 14671 | 14672 | inline typename expression_node<T>::node_type type() const exprtk_override 14673 | { 14674 | return expression_node<T>::e_function; 14675 | } 14676 | 14677 | inline bool valid() const exprtk_override 14678 | { 14679 | return initialised_; 14680 | } 14681 | 14682 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 14683 | { 14684 | expression_node<T>::ndb_t::collect(branch_, node_delete_list); 14685 | } 14686 | 14687 | std::size_t node_depth() const exprtk_override 14688 | { 14689 | return expression_node<T>::ndb_t::template compute_node_depth<N>(branch_); 14690 | } 14691 | 14692 | template <typename T_, std::size_t BranchCount> 14693 | struct evaluate_branches 14694 | { 14695 | static inline void execute(T_ (&v)[BranchCount], const branch_t (&b)[BranchCount]) 14696 | { 14697 | for (std::size_t i = 0; i < BranchCount; ++i) 14698 | { 14699 | v[i] = b[i].first->value(); 14700 | } 14701 | } 14702 | }; 14703 | 14704 | template <typename T_> 14705 | struct evaluate_branches <T_,6> 14706 | { 14707 | static inline void execute(T_ (&v)[6], const branch_t (&b)[6]) 14708 | { 14709 | v[0] = b[0].first->value(); 14710 | v[1] = b[1].first->value(); 14711 | v[2] = b[2].first->value(); 14712 | v[3] = b[3].first->value(); 14713 | v[4] = b[4].first->value(); 14714 | v[5] = b[5].first->value(); 14715 | } 14716 | }; 14717 | 14718 | template <typename T_> 14719 | struct evaluate_branches <T_,5> 14720 | { 14721 | static inline void execute(T_ (&v)[5], const branch_t (&b)[5]) 14722 | { 14723 | v[0] = b[0].first->value(); 14724 | v[1] = b[1].first->value(); 14725 | v[2] = b[2].first->value(); 14726 | v[3] = b[3].first->value(); 14727 | v[4] = b[4].first->value(); 14728 | } 14729 | }; 14730 | 14731 | template <typename T_> 14732 | struct evaluate_branches <T_,4> 14733 | { 14734 | static inline void execute(T_ (&v)[4], const branch_t (&b)[4]) 14735 | { 14736 | v[0] = b[0].first->value(); 14737 | v[1] = b[1].first->value(); 14738 | v[2] = b[2].first->value(); 14739 | v[3] = b[3].first->value(); 14740 | } 14741 | }; 14742 | 14743 | template <typename T_> 14744 | struct evaluate_branches <T_,3> 14745 | { 14746 | static inline void execute(T_ (&v)[3], const branch_t (&b)[3]) 14747 | { 14748 | v[0] = b[0].first->value(); 14749 | v[1] = b[1].first->value(); 14750 | v[2] = b[2].first->value(); 14751 | } 14752 | }; 14753 | 14754 | template <typename T_> 14755 | struct evaluate_branches <T_,2> 14756 | { 14757 | static inline void execute(T_ (&v)[2], const branch_t (&b)[2]) 14758 | { 14759 | v[0] = b[0].first->value(); 14760 | v[1] = b[1].first->value(); 14761 | } 14762 | }; 14763 | 14764 | template <typename T_> 14765 | struct evaluate_branches <T_,1> 14766 | { 14767 | static inline void execute(T_ (&v)[1], const branch_t (&b)[1]) 14768 | { 14769 | v[0] = b[0].first->value(); 14770 | } 14771 | }; 14772 | 14773 | template <typename T_, std::size_t ParamCount> 14774 | struct invoke { static inline T execute(ifunction&, branch_t (&)[ParamCount]) { return std::numeric_limits<T_>::quiet_NaN(); } }; 14775 | 14776 | template <typename T_> 14777 | struct invoke<T_,20> 14778 | { 14779 | static inline T_ execute(ifunction& f, T_ (&v)[20]) 14780 | { return f(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9],v[10],v[11],v[12],v[13],v[14],v[15],v[16],v[17],v[18],v[19]); } 14781 | }; 14782 | 14783 | template <typename T_> 14784 | struct invoke<T_,19> 14785 | { 14786 | static inline T_ execute(ifunction& f, T_ (&v)[19]) 14787 | { return f(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9],v[10],v[11],v[12],v[13],v[14],v[15],v[16],v[17],v[18]); } 14788 | }; 14789 | 14790 | template <typename T_> 14791 | struct invoke<T_,18> 14792 | { 14793 | static inline T_ execute(ifunction& f, T_ (&v)[18]) 14794 | { return f(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11], v[12], v[13], v[14], v[15], v[16], v[17]); } 14795 | }; 14796 | 14797 | template <typename T_> 14798 | struct invoke<T_,17> 14799 | { 14800 | static inline T_ execute(ifunction& f, T_ (&v)[17]) 14801 | { return f(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11], v[12], v[13], v[14], v[15], v[16]); } 14802 | }; 14803 | 14804 | template <typename T_> 14805 | struct invoke<T_,16> 14806 | { 14807 | static inline T_ execute(ifunction& f, T_ (&v)[16]) 14808 | { return f(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11], v[12], v[13], v[14], v[15]); } 14809 | }; 14810 | 14811 | template <typename T_> 14812 | struct invoke<T_,15> 14813 | { 14814 | static inline T_ execute(ifunction& f, T_ (&v)[15]) 14815 | { return f(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11], v[12], v[13], v[14]); } 14816 | }; 14817 | 14818 | template <typename T_> 14819 | struct invoke<T_,14> 14820 | { 14821 | static inline T_ execute(ifunction& f, T_ (&v)[14]) 14822 | { return f(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11], v[12], v[13]); } 14823 | }; 14824 | 14825 | template <typename T_> 14826 | struct invoke<T_,13> 14827 | { 14828 | static inline T_ execute(ifunction& f, T_ (&v)[13]) 14829 | { return f(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11], v[12]); } 14830 | }; 14831 | 14832 | template <typename T_> 14833 | struct invoke<T_,12> 14834 | { 14835 | static inline T_ execute(ifunction& f, T_ (&v)[12]) 14836 | { return f(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11]); } 14837 | }; 14838 | 14839 | template <typename T_> 14840 | struct invoke<T_,11> 14841 | { 14842 | static inline T_ execute(ifunction& f, T_ (&v)[11]) 14843 | { return f(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10]); } 14844 | }; 14845 | 14846 | template <typename T_> 14847 | struct invoke<T_,10> 14848 | { 14849 | static inline T_ execute(ifunction& f, T_ (&v)[10]) 14850 | { return f(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9]); } 14851 | }; 14852 | 14853 | template <typename T_> 14854 | struct invoke<T_,9> 14855 | { 14856 | static inline T_ execute(ifunction& f, T_ (&v)[9]) 14857 | { return f(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8]); } 14858 | }; 14859 | 14860 | template <typename T_> 14861 | struct invoke<T_,8> 14862 | { 14863 | static inline T_ execute(ifunction& f, T_ (&v)[8]) 14864 | { return f(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]); } 14865 | }; 14866 | 14867 | template <typename T_> 14868 | struct invoke<T_,7> 14869 | { 14870 | static inline T_ execute(ifunction& f, T_ (&v)[7]) 14871 | { return f(v[0], v[1], v[2], v[3], v[4], v[5], v[6]); } 14872 | }; 14873 | 14874 | template <typename T_> 14875 | struct invoke<T_,6> 14876 | { 14877 | static inline T_ execute(ifunction& f, T_ (&v)[6]) 14878 | { return f(v[0], v[1], v[2], v[3], v[4], v[5]); } 14879 | }; 14880 | 14881 | template <typename T_> 14882 | struct invoke<T_,5> 14883 | { 14884 | static inline T_ execute(ifunction& f, T_ (&v)[5]) 14885 | { return f(v[0], v[1], v[2], v[3], v[4]); } 14886 | }; 14887 | 14888 | template <typename T_> 14889 | struct invoke<T_,4> 14890 | { 14891 | static inline T_ execute(ifunction& f, T_ (&v)[4]) 14892 | { return f(v[0], v[1], v[2], v[3]); } 14893 | }; 14894 | 14895 | template <typename T_> 14896 | struct invoke<T_,3> 14897 | { 14898 | static inline T_ execute(ifunction& f, T_ (&v)[3]) 14899 | { return f(v[0], v[1], v[2]); } 14900 | }; 14901 | 14902 | template <typename T_> 14903 | struct invoke<T_,2> 14904 | { 14905 | static inline T_ execute(ifunction& f, T_ (&v)[2]) 14906 | { return f(v[0], v[1]); } 14907 | }; 14908 | 14909 | template <typename T_> 14910 | struct invoke<T_,1> 14911 | { 14912 | static inline T_ execute(ifunction& f, T_ (&v)[1]) 14913 | { return f(v[0]); } 14914 | }; 14915 | 14916 | private: 14917 | 14918 | ifunction* function_; 14919 | std::size_t parameter_count_; 14920 | branch_t branch_[N]; 14921 | bool initialised_; 14922 | }; 14923 | 14924 | template <typename T, typename IFunction> 14925 | class function_N_node<T,IFunction,0> exprtk_final : public expression_node<T> 14926 | { 14927 | public: 14928 | 14929 | typedef expression_node<T>* expression_ptr; 14930 | typedef IFunction ifunction; 14931 | 14932 | explicit function_N_node(ifunction* func) 14933 | : function_((0 == func->param_count) ? func : reinterpret_cast<ifunction*>(0)) 14934 | { 14935 | assert(valid()); 14936 | } 14937 | 14938 | inline bool operator <(const function_N_node<T,IFunction,0>& fn) const 14939 | { 14940 | return this < (&fn); 14941 | } 14942 | 14943 | inline T value() const exprtk_override 14944 | { 14945 | return (*function_)(); 14946 | } 14947 | 14948 | inline typename expression_node<T>::node_type type() const exprtk_override 14949 | { 14950 | return expression_node<T>::e_function; 14951 | } 14952 | 14953 | inline bool valid() const exprtk_override 14954 | { 14955 | return function_; 14956 | } 14957 | 14958 | private: 14959 | 14960 | ifunction* function_; 14961 | }; 14962 | 14963 | template <typename T, typename VarArgFunction> 14964 | class vararg_function_node exprtk_final : public expression_node<T> 14965 | { 14966 | public: 14967 | 14968 | typedef expression_node<T>* expression_ptr; 14969 | 14970 | vararg_function_node(VarArgFunction* func, 14971 | const std::vector<expression_ptr>& arg_list) 14972 | : function_(func) 14973 | , arg_list_(arg_list) 14974 | { 14975 | value_list_.resize(arg_list.size(),std::numeric_limits<T>::quiet_NaN()); 14976 | assert(valid()); 14977 | } 14978 | 14979 | inline bool operator <(const vararg_function_node<T,VarArgFunction>& fn) const 14980 | { 14981 | return this < (&fn); 14982 | } 14983 | 14984 | inline T value() const exprtk_override 14985 | { 14986 | populate_value_list(); 14987 | return (*function_)(value_list_); 14988 | } 14989 | 14990 | inline typename expression_node<T>::node_type type() const exprtk_override 14991 | { 14992 | return expression_node<T>::e_vafunction; 14993 | } 14994 | 14995 | inline bool valid() const exprtk_override 14996 | { 14997 | return function_; 14998 | } 14999 | 15000 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 15001 | { 15002 | for (std::size_t i = 0; i < arg_list_.size(); ++i) 15003 | { 15004 | if (arg_list_[i] && !details::is_variable_node(arg_list_[i])) 15005 | { 15006 | node_delete_list.push_back(&arg_list_[i]); 15007 | } 15008 | } 15009 | } 15010 | 15011 | std::size_t node_depth() const exprtk_override 15012 | { 15013 | return expression_node<T>::ndb_t::compute_node_depth(arg_list_); 15014 | } 15015 | 15016 | private: 15017 | 15018 | inline void populate_value_list() const 15019 | { 15020 | for (std::size_t i = 0; i < arg_list_.size(); ++i) 15021 | { 15022 | value_list_[i] = arg_list_[i]->value(); 15023 | } 15024 | } 15025 | 15026 | VarArgFunction* function_; 15027 | std::vector<expression_ptr> arg_list_; 15028 | mutable std::vector<T> value_list_; 15029 | }; 15030 | 15031 | template <typename T, typename GenericFunction> 15032 | class generic_function_node : public expression_node<T> 15033 | { 15034 | public: 15035 | 15036 | typedef type_store<T> type_store_t; 15037 | typedef expression_node<T>* expression_ptr; 15038 | typedef variable_node<T> variable_node_t; 15039 | typedef vector_node<T> vector_node_t; 15040 | typedef variable_node_t* variable_node_ptr_t; 15041 | typedef vector_node_t* vector_node_ptr_t; 15042 | typedef range_interface<T> range_interface_t; 15043 | typedef range_data_type<T> range_data_type_t; 15044 | typedef typename range_interface<T>::range_t range_t; 15045 | 15046 | typedef std::pair<expression_ptr,bool> branch_t; 15047 | typedef vector_holder<T>* vh_t; 15048 | typedef vector_view<T>* vecview_t; 15049 | 15050 | typedef std::vector<T> tmp_vs_t; 15051 | typedef std::vector<type_store_t> typestore_list_t; 15052 | typedef std::vector<range_data_type_t> range_list_t; 15053 | 15054 | explicit generic_function_node(const std::vector<expression_ptr>& arg_list, 15055 | GenericFunction* func = reinterpret_cast<GenericFunction*>(0)) 15056 | : function_(func) 15057 | , arg_list_(arg_list) 15058 | {} 15059 | 15060 | virtual ~generic_function_node() 15061 | { 15062 | for (std::size_t i = 0; i < vv_list_.size(); ++i) 15063 | { 15064 | vecview_t& vv = vv_list_[i]; 15065 | if (vv) 15066 | { 15067 | if (typestore_list_[i].vec_data) 15068 | { 15069 | vv->remove_ref(&typestore_list_[i].vec_data); 15070 | } 15071 | 15072 | vv->remove_size_ref(&typestore_list_[i].size); 15073 | typestore_list_[i].vec_data = 0; 15074 | } 15075 | } 15076 | } 15077 | 15078 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 15079 | { 15080 | expression_node<T>::ndb_t::collect(branch_, node_delete_list); 15081 | } 15082 | 15083 | std::size_t node_depth() const exprtk_override exprtk_final 15084 | { 15085 | return expression_node<T>::ndb_t::compute_node_depth(branch_); 15086 | } 15087 | 15088 | virtual bool init_branches() 15089 | { 15090 | expr_as_vec1_store_.resize(arg_list_.size(), T(0) ); 15091 | typestore_list_ .resize(arg_list_.size(), type_store_t() ); 15092 | range_list_ .resize(arg_list_.size(), range_data_type_t()); 15093 | branch_ .resize(arg_list_.size(), branch_t(reinterpret_cast<expression_ptr>(0),false)); 15094 | vv_list_ .resize(arg_list_.size(), vecview_t(0)); 15095 | 15096 | for (std::size_t i = 0; i < arg_list_.size(); ++i) 15097 | { 15098 | type_store_t& ts = typestore_list_[i]; 15099 | 15100 | if (0 == arg_list_[i]) 15101 | return false; 15102 | else if (is_ivector_node(arg_list_[i])) 15103 | { 15104 | vector_interface<T>* vi = reinterpret_cast<vector_interface<T>*>(0); 15105 | 15106 | if (0 == (vi = dynamic_cast<vector_interface<T>*>(arg_list_[i]))) 15107 | return false; 15108 | 15109 | ts.size = vi->size(); 15110 | ts.data = vi->vds().data(); 15111 | ts.type = type_store_t::e_vector; 15112 | ts.ivec = vi; 15113 | 15114 | if ( 15115 | vi->vec()->vec_holder().rebaseable() && 15116 | vi->vec()->vec_holder().rebaseable_instance() 15117 | ) 15118 | { 15119 | vv_list_[i] = vi->vec()->vec_holder().rebaseable_instance(); 15120 | vv_list_[i]->set_size_ref(&ts.size); 15121 | 15122 | if (!amalgamated_vecop(arg_list_[i])) 15123 | { 15124 | vv_list_[i]->set_ref(&ts.vec_data); 15125 | } 15126 | } 15127 | } 15128 | #ifndef exprtk_disable_string_capabilities 15129 | else if (is_generally_string_node(arg_list_[i])) 15130 | { 15131 | string_base_node<T>* sbn = reinterpret_cast<string_base_node<T>*>(0); 15132 | 15133 | if (0 == (sbn = dynamic_cast<string_base_node<T>*>(arg_list_[i]))) 15134 | return false; 15135 | 15136 | ts.size = sbn->size(); 15137 | ts.data = reinterpret_cast<void*>(const_cast<char_ptr>(sbn->base())); 15138 | ts.type = type_store_t::e_string; 15139 | 15140 | range_list_[i].data = ts.data; 15141 | range_list_[i].size = ts.size; 15142 | range_list_[i].type_size = sizeof(char); 15143 | range_list_[i].str_node = sbn; 15144 | 15145 | range_interface_t* ri = reinterpret_cast<range_interface_t*>(0); 15146 | 15147 | if (0 == (ri = dynamic_cast<range_interface_t*>(arg_list_[i]))) 15148 | return false; 15149 | 15150 | const range_t& rp = ri->range_ref(); 15151 | 15152 | if ( 15153 | rp.const_range() && 15154 | is_const_string_range_node(arg_list_[i]) 15155 | ) 15156 | { 15157 | ts.size = rp.const_size(); 15158 | ts.data = static_cast<char_ptr>(ts.data) + rp.n0_c.second; 15159 | range_list_[i].range = reinterpret_cast<range_t*>(0); 15160 | } 15161 | else 15162 | { 15163 | range_list_[i].range = &(ri->range_ref()); 15164 | range_param_list_.push_back(i); 15165 | } 15166 | } 15167 | #endif 15168 | else if (is_variable_node(arg_list_[i])) 15169 | { 15170 | variable_node_ptr_t var = variable_node_ptr_t(0); 15171 | 15172 | if (0 == (var = dynamic_cast<variable_node_ptr_t>(arg_list_[i]))) 15173 | return false; 15174 | 15175 | ts.size = 1; 15176 | ts.data = &var->ref(); 15177 | ts.type = type_store_t::e_scalar; 15178 | } 15179 | else 15180 | { 15181 | ts.size = 1; 15182 | ts.data = reinterpret_cast<void*>(&expr_as_vec1_store_[i]); 15183 | ts.type = type_store_t::e_scalar; 15184 | } 15185 | 15186 | branch_[i] = std::make_pair(arg_list_[i],branch_deletable(arg_list_[i])); 15187 | } 15188 | 15189 | return true; 15190 | } 15191 | 15192 | inline bool operator <(const generic_function_node<T,GenericFunction>& fn) const 15193 | { 15194 | return this < (&fn); 15195 | } 15196 | 15197 | inline T value() const exprtk_override 15198 | { 15199 | if (populate_value_list()) 15200 | { 15201 | typedef typename GenericFunction::parameter_list_t parameter_list_t; 15202 | 15203 | return (*function_)(parameter_list_t(typestore_list_)); 15204 | } 15205 | 15206 | return std::numeric_limits<T>::quiet_NaN(); 15207 | } 15208 | 15209 | inline typename expression_node<T>::node_type type() const exprtk_override 15210 | { 15211 | return expression_node<T>::e_genfunction; 15212 | } 15213 | 15214 | inline bool valid() const exprtk_override 15215 | { 15216 | return function_; 15217 | } 15218 | 15219 | protected: 15220 | 15221 | inline virtual bool populate_value_list() const 15222 | { 15223 | assert(branch_.size() == typestore_list_.size()); 15224 | 15225 | for (std::size_t i = 0; i < branch_.size(); ++i) 15226 | { 15227 | expr_as_vec1_store_[i] = branch_[i].first->value(); 15228 | } 15229 | 15230 | if (!range_param_list_.empty()) 15231 | { 15232 | assert(range_param_list_.size() <= branch_.size()); 15233 | 15234 | for (std::size_t i = 0; i < range_param_list_.size(); ++i) 15235 | { 15236 | const std::size_t index = range_param_list_[i]; 15237 | range_data_type_t& rdt = range_list_[index]; 15238 | 15239 | const range_t& rp = (*rdt.range); 15240 | std::size_t r0 = 0; 15241 | std::size_t r1 = 0; 15242 | 15243 | const std::size_t data_size = 15244 | #ifndef exprtk_disable_string_capabilities 15245 | rdt.str_node ? rdt.str_node->size() : rdt.size; 15246 | #else 15247 | rdt.size; 15248 | #endif 15249 | 15250 | if (!rp(r0, r1, data_size)) 15251 | { 15252 | return false; 15253 | } 15254 | 15255 | type_store_t& ts = typestore_list_[index]; 15256 | 15257 | ts.size = rp.cache_size(); 15258 | #ifndef exprtk_disable_string_capabilities 15259 | if (ts.type == type_store_t::e_string) 15260 | ts.data = const_cast<char_ptr>(rdt.str_node->base()) + rp.cache.first; 15261 | else 15262 | #endif 15263 | ts.data = static_cast<char_ptr>(rdt.data) + (rp.cache.first * rdt.type_size); 15264 | } 15265 | } 15266 | 15267 | return true; 15268 | } 15269 | 15270 | GenericFunction* function_; 15271 | mutable typestore_list_t typestore_list_; 15272 | 15273 | private: 15274 | 15275 | std::vector<expression_ptr> arg_list_; 15276 | std::vector<branch_t> branch_; 15277 | std::vector<vecview_t> vv_list_; 15278 | mutable tmp_vs_t expr_as_vec1_store_; 15279 | mutable range_list_t range_list_; 15280 | std::vector<std::size_t> range_param_list_; 15281 | }; 15282 | 15283 | #ifndef exprtk_disable_string_capabilities 15284 | template <typename T, typename StringFunction> 15285 | class string_function_node : public generic_function_node<T,StringFunction> 15286 | , public string_base_node<T> 15287 | , public range_interface <T> 15288 | { 15289 | public: 15290 | 15291 | typedef generic_function_node<T,StringFunction> gen_function_t; 15292 | typedef typename range_interface<T>::range_t range_t; 15293 | 15294 | string_function_node(StringFunction* func, 15295 | const std::vector<typename gen_function_t::expression_ptr>& arg_list) 15296 | : gen_function_t(arg_list,func) 15297 | { 15298 | range_.n0_c = std::make_pair<bool,std::size_t>(true,0); 15299 | range_.n1_c = std::make_pair<bool,std::size_t>(true,0); 15300 | range_.cache.first = range_.n0_c.second; 15301 | range_.cache.second = range_.n1_c.second; 15302 | assert(valid()); 15303 | } 15304 | 15305 | inline bool operator <(const string_function_node<T,StringFunction>& fn) const 15306 | { 15307 | return this < (&fn); 15308 | } 15309 | 15310 | inline T value() const exprtk_override 15311 | { 15312 | if (gen_function_t::populate_value_list()) 15313 | { 15314 | typedef typename StringFunction::parameter_list_t parameter_list_t; 15315 | 15316 | const T result = 15317 | (*gen_function_t::function_) 15318 | ( 15319 | ret_string_, 15320 | parameter_list_t(gen_function_t::typestore_list_) 15321 | ); 15322 | 15323 | range_.n1_c.second = ret_string_.size(); 15324 | range_.cache.second = range_.n1_c.second; 15325 | 15326 | return result; 15327 | } 15328 | 15329 | return std::numeric_limits<T>::quiet_NaN(); 15330 | } 15331 | 15332 | inline typename expression_node<T>::node_type type() const exprtk_override 15333 | { 15334 | return expression_node<T>::e_strfunction; 15335 | } 15336 | 15337 | inline bool valid() const exprtk_override 15338 | { 15339 | return gen_function_t::function_; 15340 | } 15341 | 15342 | std::string str() const exprtk_override 15343 | { 15344 | return ret_string_; 15345 | } 15346 | 15347 | char_cptr base() const exprtk_override 15348 | { 15349 | return &ret_string_[0]; 15350 | } 15351 | 15352 | std::size_t size() const exprtk_override 15353 | { 15354 | return ret_string_.size(); 15355 | } 15356 | 15357 | range_t& range_ref() exprtk_override 15358 | { 15359 | return range_; 15360 | } 15361 | 15362 | const range_t& range_ref() const exprtk_override 15363 | { 15364 | return range_; 15365 | } 15366 | 15367 | protected: 15368 | 15369 | mutable range_t range_; 15370 | mutable std::string ret_string_; 15371 | }; 15372 | #endif 15373 | 15374 | template <typename T, typename GenericFunction> 15375 | class multimode_genfunction_node : public generic_function_node<T,GenericFunction> 15376 | { 15377 | public: 15378 | 15379 | typedef generic_function_node<T,GenericFunction> gen_function_t; 15380 | typedef typename gen_function_t::range_t range_t; 15381 | 15382 | multimode_genfunction_node(GenericFunction* func, 15383 | const std::size_t& param_seq_index, 15384 | const std::vector<typename gen_function_t::expression_ptr>& arg_list) 15385 | : gen_function_t(arg_list,func) 15386 | , param_seq_index_(param_seq_index) 15387 | {} 15388 | 15389 | inline T value() const exprtk_override 15390 | { 15391 | assert(gen_function_t::valid()); 15392 | 15393 | if (gen_function_t::populate_value_list()) 15394 | { 15395 | typedef typename GenericFunction::parameter_list_t parameter_list_t; 15396 | 15397 | return 15398 | (*gen_function_t::function_) 15399 | ( 15400 | param_seq_index_, 15401 | parameter_list_t(gen_function_t::typestore_list_) 15402 | ); 15403 | } 15404 | 15405 | return std::numeric_limits<T>::quiet_NaN(); 15406 | } 15407 | 15408 | inline typename expression_node<T>::node_type type() const exprtk_override exprtk_final 15409 | { 15410 | return expression_node<T>::e_genfunction; 15411 | } 15412 | 15413 | private: 15414 | 15415 | std::size_t param_seq_index_; 15416 | }; 15417 | 15418 | #ifndef exprtk_disable_string_capabilities 15419 | template <typename T, typename StringFunction> 15420 | class multimode_strfunction_node exprtk_final : public string_function_node<T,StringFunction> 15421 | { 15422 | public: 15423 | 15424 | typedef string_function_node<T,StringFunction> str_function_t; 15425 | typedef typename str_function_t::range_t range_t; 15426 | 15427 | multimode_strfunction_node(StringFunction* func, 15428 | const std::size_t& param_seq_index, 15429 | const std::vector<typename str_function_t::expression_ptr>& arg_list) 15430 | : str_function_t(func,arg_list) 15431 | , param_seq_index_(param_seq_index) 15432 | {} 15433 | 15434 | inline T value() const exprtk_override 15435 | { 15436 | if (str_function_t::populate_value_list()) 15437 | { 15438 | typedef typename StringFunction::parameter_list_t parameter_list_t; 15439 | 15440 | const T result = 15441 | (*str_function_t::function_) 15442 | ( 15443 | param_seq_index_, 15444 | str_function_t::ret_string_, 15445 | parameter_list_t(str_function_t::typestore_list_) 15446 | ); 15447 | 15448 | str_function_t::range_.n1_c.second = str_function_t::ret_string_.size(); 15449 | str_function_t::range_.cache.second = str_function_t::range_.n1_c.second; 15450 | 15451 | return result; 15452 | } 15453 | 15454 | return std::numeric_limits<T>::quiet_NaN(); 15455 | } 15456 | 15457 | inline typename expression_node<T>::node_type type() const exprtk_override 15458 | { 15459 | return expression_node<T>::e_strfunction; 15460 | } 15461 | 15462 | private: 15463 | 15464 | const std::size_t param_seq_index_; 15465 | }; 15466 | #endif 15467 | 15468 | class return_exception {}; 15469 | 15470 | template <typename T> 15471 | class null_igenfunc 15472 | { 15473 | public: 15474 | 15475 | virtual ~null_igenfunc() 15476 | {} 15477 | 15478 | typedef type_store<T> generic_type; 15479 | typedef typename generic_type::parameter_list parameter_list_t; 15480 | 15481 | inline virtual T operator() (parameter_list_t) 15482 | { 15483 | return std::numeric_limits<T>::quiet_NaN(); 15484 | } 15485 | }; 15486 | 15487 | #ifndef exprtk_disable_return_statement 15488 | template <typename T> 15489 | class return_node exprtk_final : public generic_function_node<T,null_igenfunc<T> > 15490 | { 15491 | public: 15492 | 15493 | typedef results_context<T> results_context_t; 15494 | typedef null_igenfunc<T> igeneric_function_t; 15495 | typedef igeneric_function_t* igeneric_function_ptr; 15496 | typedef generic_function_node<T,igeneric_function_t> gen_function_t; 15497 | 15498 | return_node(const std::vector<typename gen_function_t::expression_ptr>& arg_list, 15499 | results_context_t& rc) 15500 | : gen_function_t (arg_list) 15501 | , results_context_(&rc) 15502 | { 15503 | assert(valid()); 15504 | } 15505 | 15506 | inline T value() const exprtk_override 15507 | { 15508 | if (gen_function_t::populate_value_list()) 15509 | { 15510 | prepare_typestore_list(); 15511 | 15512 | typedef typename type_store<T>::parameter_list parameter_list_t; 15513 | 15514 | results_context_-> 15515 | assign(parameter_list_t(gen_function_t::typestore_list_)); 15516 | 15517 | throw return_exception(); 15518 | } 15519 | 15520 | return std::numeric_limits<T>::quiet_NaN(); 15521 | } 15522 | 15523 | inline typename expression_node<T>::node_type type() const exprtk_override 15524 | { 15525 | return expression_node<T>::e_return; 15526 | } 15527 | 15528 | inline bool valid() const exprtk_override 15529 | { 15530 | return results_context_; 15531 | } 15532 | 15533 | private: 15534 | 15535 | void prepare_typestore_list() const 15536 | { 15537 | for (std::size_t i = 0; i < gen_function_t::typestore_list_.size(); ++i) 15538 | { 15539 | typename gen_function_t::type_store_t& ts = gen_function_t::typestore_list_[i]; 15540 | 15541 | if (ts.ivec) 15542 | { 15543 | ts.size = ts.ivec->size(); 15544 | } 15545 | } 15546 | } 15547 | 15548 | results_context_t* results_context_; 15549 | }; 15550 | 15551 | template <typename T> 15552 | class return_envelope_node exprtk_final : public expression_node<T> 15553 | { 15554 | public: 15555 | 15556 | typedef expression_node<T>* expression_ptr; 15557 | typedef results_context<T> results_context_t; 15558 | typedef std::pair<expression_ptr,bool> branch_t; 15559 | 15560 | return_envelope_node(expression_ptr body, results_context_t& rc) 15561 | : results_context_(&rc ) 15562 | , return_invoked_ (false) 15563 | { 15564 | construct_branch_pair(body_, body); 15565 | assert(valid()); 15566 | } 15567 | 15568 | inline T value() const exprtk_override 15569 | { 15570 | try 15571 | { 15572 | return_invoked_ = false; 15573 | results_context_->clear(); 15574 | 15575 | return body_.first->value(); 15576 | } 15577 | catch(const return_exception&) 15578 | { 15579 | return_invoked_ = true; 15580 | 15581 | return std::numeric_limits<T>::quiet_NaN(); 15582 | } 15583 | } 15584 | 15585 | inline typename expression_node<T>::node_type type() const exprtk_override 15586 | { 15587 | return expression_node<T>::e_retenv; 15588 | } 15589 | 15590 | inline bool valid() const exprtk_override 15591 | { 15592 | return results_context_ && body_.first; 15593 | } 15594 | 15595 | inline bool* retinvk_ptr() 15596 | { 15597 | return &return_invoked_; 15598 | } 15599 | 15600 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 15601 | { 15602 | expression_node<T>::ndb_t::collect(body_, node_delete_list); 15603 | } 15604 | 15605 | std::size_t node_depth() const exprtk_override 15606 | { 15607 | return expression_node<T>::ndb_t::compute_node_depth(body_); 15608 | } 15609 | 15610 | private: 15611 | 15612 | results_context_t* results_context_; 15613 | mutable bool return_invoked_; 15614 | branch_t body_; 15615 | }; 15616 | #endif 15617 | 15618 | #define exprtk_define_unary_op(OpName) \ 15619 | template <typename T> \ 15620 | struct OpName##_op \ 15621 | { \ 15622 | typedef typename functor_t<T>::Type Type; \ 15623 | typedef typename expression_node<T>::node_type node_t; \ 15624 | \ 15625 | static inline T process(Type v) \ 15626 | { \ 15627 | return numeric:: OpName (v); \ 15628 | } \ 15629 | \ 15630 | static inline node_t type() \ 15631 | { \ 15632 | return expression_node<T>::e_##OpName; \ 15633 | } \ 15634 | \ 15635 | static inline details::operator_type operation() \ 15636 | { \ 15637 | return details::e_##OpName; \ 15638 | } \ 15639 | }; \ 15640 | 15641 | exprtk_define_unary_op(abs ) 15642 | exprtk_define_unary_op(acos ) 15643 | exprtk_define_unary_op(acosh) 15644 | exprtk_define_unary_op(asin ) 15645 | exprtk_define_unary_op(asinh) 15646 | exprtk_define_unary_op(atan ) 15647 | exprtk_define_unary_op(atanh) 15648 | exprtk_define_unary_op(ceil ) 15649 | exprtk_define_unary_op(cos ) 15650 | exprtk_define_unary_op(cosh ) 15651 | exprtk_define_unary_op(cot ) 15652 | exprtk_define_unary_op(csc ) 15653 | exprtk_define_unary_op(d2g ) 15654 | exprtk_define_unary_op(d2r ) 15655 | exprtk_define_unary_op(erf ) 15656 | exprtk_define_unary_op(erfc ) 15657 | exprtk_define_unary_op(exp ) 15658 | exprtk_define_unary_op(expm1) 15659 | exprtk_define_unary_op(floor) 15660 | exprtk_define_unary_op(frac ) 15661 | exprtk_define_unary_op(g2d ) 15662 | exprtk_define_unary_op(log ) 15663 | exprtk_define_unary_op(log10) 15664 | exprtk_define_unary_op(log2 ) 15665 | exprtk_define_unary_op(log1p) 15666 | exprtk_define_unary_op(ncdf ) 15667 | exprtk_define_unary_op(neg ) 15668 | exprtk_define_unary_op(notl ) 15669 | exprtk_define_unary_op(pos ) 15670 | exprtk_define_unary_op(r2d ) 15671 | exprtk_define_unary_op(round) 15672 | exprtk_define_unary_op(sec ) 15673 | exprtk_define_unary_op(sgn ) 15674 | exprtk_define_unary_op(sin ) 15675 | exprtk_define_unary_op(sinc ) 15676 | exprtk_define_unary_op(sinh ) 15677 | exprtk_define_unary_op(sqrt ) 15678 | exprtk_define_unary_op(tan ) 15679 | exprtk_define_unary_op(tanh ) 15680 | exprtk_define_unary_op(trunc) 15681 | #undef exprtk_define_unary_op 15682 | 15683 | template <typename T> 15684 | struct opr_base 15685 | { 15686 | typedef typename details::functor_t<T>::Type Type; 15687 | typedef typename details::functor_t<T>::RefType RefType; 15688 | typedef typename details::functor_t<T> functor_t; 15689 | typedef typename functor_t::qfunc_t quaternary_functor_t; 15690 | typedef typename functor_t::tfunc_t trinary_functor_t; 15691 | typedef typename functor_t::bfunc_t binary_functor_t; 15692 | typedef typename functor_t::ufunc_t unary_functor_t; 15693 | }; 15694 | 15695 | template <typename T> 15696 | struct add_op : public opr_base<T> 15697 | { 15698 | typedef typename opr_base<T>::Type Type; 15699 | typedef typename opr_base<T>::RefType RefType; 15700 | 15701 | static inline T process(Type t1, Type t2) { return t1 + t2; } 15702 | static inline T process(Type t1, Type t2, Type t3) { return t1 + t2 + t3; } 15703 | static inline void assign(RefType t1, Type t2) { t1 += t2; } 15704 | static inline typename expression_node<T>::node_type type() { return expression_node<T>::e_add; } 15705 | static inline details::operator_type operation() { return details::e_add; } 15706 | }; 15707 | 15708 | template <typename T> 15709 | struct mul_op : public opr_base<T> 15710 | { 15711 | typedef typename opr_base<T>::Type Type; 15712 | typedef typename opr_base<T>::RefType RefType; 15713 | 15714 | static inline T process(Type t1, Type t2) { return t1 * t2; } 15715 | static inline T process(Type t1, Type t2, Type t3) { return t1 * t2 * t3; } 15716 | static inline void assign(RefType t1, Type t2) { t1 *= t2; } 15717 | static inline typename expression_node<T>::node_type type() { return expression_node<T>::e_mul; } 15718 | static inline details::operator_type operation() { return details::e_mul; } 15719 | }; 15720 | 15721 | template <typename T> 15722 | struct sub_op : public opr_base<T> 15723 | { 15724 | typedef typename opr_base<T>::Type Type; 15725 | typedef typename opr_base<T>::RefType RefType; 15726 | 15727 | static inline T process(Type t1, Type t2) { return t1 - t2; } 15728 | static inline T process(Type t1, Type t2, Type t3) { return t1 - t2 - t3; } 15729 | static inline void assign(RefType t1, Type t2) { t1 -= t2; } 15730 | static inline typename expression_node<T>::node_type type() { return expression_node<T>::e_sub; } 15731 | static inline details::operator_type operation() { return details::e_sub; } 15732 | }; 15733 | 15734 | template <typename T> 15735 | struct div_op : public opr_base<T> 15736 | { 15737 | typedef typename opr_base<T>::Type Type; 15738 | typedef typename opr_base<T>::RefType RefType; 15739 | 15740 | static inline T process(Type t1, Type t2) { return t1 / t2; } 15741 | static inline T process(Type t1, Type t2, Type t3) { return t1 / t2 / t3; } 15742 | static inline void assign(RefType t1, Type t2) { t1 /= t2; } 15743 | static inline typename expression_node<T>::node_type type() { return expression_node<T>::e_div; } 15744 | static inline details::operator_type operation() { return details::e_div; } 15745 | }; 15746 | 15747 | template <typename T> 15748 | struct mod_op : public opr_base<T> 15749 | { 15750 | typedef typename opr_base<T>::Type Type; 15751 | typedef typename opr_base<T>::RefType RefType; 15752 | 15753 | static inline T process(Type t1, Type t2) { return numeric::modulus<T>(t1,t2); } 15754 | static inline void assign(RefType t1, Type t2) { t1 = numeric::modulus<T>(t1,t2); } 15755 | static inline typename expression_node<T>::node_type type() { return expression_node<T>::e_mod; } 15756 | static inline details::operator_type operation() { return details::e_mod; } 15757 | }; 15758 | 15759 | template <typename T> 15760 | struct pow_op : public opr_base<T> 15761 | { 15762 | typedef typename opr_base<T>::Type Type; 15763 | typedef typename opr_base<T>::RefType RefType; 15764 | 15765 | static inline T process(Type t1, Type t2) { return numeric::pow<T>(t1,t2); } 15766 | static inline void assign(RefType t1, Type t2) { t1 = numeric::pow<T>(t1,t2); } 15767 | static inline typename expression_node<T>::node_type type() { return expression_node<T>::e_pow; } 15768 | static inline details::operator_type operation() { return details::e_pow; } 15769 | }; 15770 | 15771 | template <typename T> 15772 | struct lt_op : public opr_base<T> 15773 | { 15774 | typedef typename opr_base<T>::Type Type; 15775 | 15776 | static inline T process(Type t1, Type t2) { return ((t1 < t2) ? T(1) : T(0)); } 15777 | static inline T process(const std::string& t1, const std::string& t2) { return ((t1 < t2) ? T(1) : T(0)); } 15778 | static inline typename expression_node<T>::node_type type() { return expression_node<T>::e_lt; } 15779 | static inline details::operator_type operation() { return details::e_lt; } 15780 | }; 15781 | 15782 | template <typename T> 15783 | struct lte_op : public opr_base<T> 15784 | { 15785 | typedef typename opr_base<T>::Type Type; 15786 | 15787 | static inline T process(Type t1, Type t2) { return ((t1 <= t2) ? T(1) : T(0)); } 15788 | static inline T process(const std::string& t1, const std::string& t2) { return ((t1 <= t2) ? T(1) : T(0)); } 15789 | static inline typename expression_node<T>::node_type type() { return expression_node<T>::e_lte; } 15790 | static inline details::operator_type operation() { return details::e_lte; } 15791 | }; 15792 | 15793 | template <typename T> 15794 | struct gt_op : public opr_base<T> 15795 | { 15796 | typedef typename opr_base<T>::Type Type; 15797 | 15798 | static inline T process(Type t1, Type t2) { return ((t1 > t2) ? T(1) : T(0)); } 15799 | static inline T process(const std::string& t1, const std::string& t2) { return ((t1 > t2) ? T(1) : T(0)); } 15800 | static inline typename expression_node<T>::node_type type() { return expression_node<T>::e_gt; } 15801 | static inline details::operator_type operation() { return details::e_gt; } 15802 | }; 15803 | 15804 | template <typename T> 15805 | struct gte_op : public opr_base<T> 15806 | { 15807 | typedef typename opr_base<T>::Type Type; 15808 | 15809 | static inline T process(Type t1, Type t2) { return ((t1 >= t2) ? T(1) : T(0)); } 15810 | static inline T process(const std::string& t1, const std::string& t2) { return ((t1 >= t2) ? T(1) : T(0)); } 15811 | static inline typename expression_node<T>::node_type type() { return expression_node<T>::e_gte; } 15812 | static inline details::operator_type operation() { return details::e_gte; } 15813 | }; 15814 | 15815 | template <typename T> 15816 | struct eq_op : public opr_base<T> 15817 | { 15818 | typedef typename opr_base<T>::Type Type; 15819 | static inline T process(Type t1, Type t2) { return (std::equal_to<T>()(t1,t2) ? T(1) : T(0)); } 15820 | static inline T process(const std::string& t1, const std::string& t2) { return ((t1 == t2) ? T(1) : T(0)); } 15821 | static inline typename expression_node<T>::node_type type() { return expression_node<T>::e_eq; } 15822 | static inline details::operator_type operation() { return details::e_eq; } 15823 | }; 15824 | 15825 | template <typename T> 15826 | struct equal_op : public opr_base<T> 15827 | { 15828 | typedef typename opr_base<T>::Type Type; 15829 | 15830 | static inline T process(Type t1, Type t2) { return numeric::equal(t1,t2); } 15831 | static inline T process(const std::string& t1, const std::string& t2) { return ((t1 == t2) ? T(1) : T(0)); } 15832 | static inline typename expression_node<T>::node_type type() { return expression_node<T>::e_eq; } 15833 | static inline details::operator_type operation() { return details::e_equal; } 15834 | }; 15835 | 15836 | template <typename T> 15837 | struct ne_op : public opr_base<T> 15838 | { 15839 | typedef typename opr_base<T>::Type Type; 15840 | 15841 | static inline T process(Type t1, Type t2) { return (std::not_equal_to<T>()(t1,t2) ? T(1) : T(0)); } 15842 | static inline T process(const std::string& t1, const std::string& t2) { return ((t1 != t2) ? T(1) : T(0)); } 15843 | static inline typename expression_node<T>::node_type type() { return expression_node<T>::e_ne; } 15844 | static inline details::operator_type operation() { return details::e_ne; } 15845 | }; 15846 | 15847 | template <typename T> 15848 | struct and_op : public opr_base<T> 15849 | { 15850 | typedef typename opr_base<T>::Type Type; 15851 | 15852 | static inline T process(Type t1, Type t2) { return (details::is_true(t1) && details::is_true(t2)) ? T(1) : T(0); } 15853 | static inline typename expression_node<T>::node_type type() { return expression_node<T>::e_and; } 15854 | static inline details::operator_type operation() { return details::e_and; } 15855 | }; 15856 | 15857 | template <typename T> 15858 | struct nand_op : public opr_base<T> 15859 | { 15860 | typedef typename opr_base<T>::Type Type; 15861 | 15862 | static inline T process(Type t1, Type t2) { return (details::is_true(t1) && details::is_true(t2)) ? T(0) : T(1); } 15863 | static inline typename expression_node<T>::node_type type() { return expression_node<T>::e_nand; } 15864 | static inline details::operator_type operation() { return details::e_nand; } 15865 | }; 15866 | 15867 | template <typename T> 15868 | struct or_op : public opr_base<T> 15869 | { 15870 | typedef typename opr_base<T>::Type Type; 15871 | 15872 | static inline T process(Type t1, Type t2) { return (details::is_true(t1) || details::is_true(t2)) ? T(1) : T(0); } 15873 | static inline typename expression_node<T>::node_type type() { return expression_node<T>::e_or; } 15874 | static inline details::operator_type operation() { return details::e_or; } 15875 | }; 15876 | 15877 | template <typename T> 15878 | struct nor_op : public opr_base<T> 15879 | { 15880 | typedef typename opr_base<T>::Type Type; 15881 | 15882 | static inline T process(Type t1, Type t2) { return (details::is_true(t1) || details::is_true(t2)) ? T(0) : T(1); } 15883 | static inline typename expression_node<T>::node_type type() { return expression_node<T>::e_nor; } 15884 | static inline details::operator_type operation() { return details::e_nor; } 15885 | }; 15886 | 15887 | template <typename T> 15888 | struct xor_op : public opr_base<T> 15889 | { 15890 | typedef typename opr_base<T>::Type Type; 15891 | 15892 | static inline T process(Type t1, Type t2) { return numeric::xor_opr<T>(t1,t2); } 15893 | static inline typename expression_node<T>::node_type type() { return expression_node<T>::e_nor; } 15894 | static inline details::operator_type operation() { return details::e_xor; } 15895 | }; 15896 | 15897 | template <typename T> 15898 | struct xnor_op : public opr_base<T> 15899 | { 15900 | typedef typename opr_base<T>::Type Type; 15901 | 15902 | static inline T process(Type t1, Type t2) { return numeric::xnor_opr<T>(t1,t2); } 15903 | static inline typename expression_node<T>::node_type type() { return expression_node<T>::e_nor; } 15904 | static inline details::operator_type operation() { return details::e_xnor; } 15905 | }; 15906 | 15907 | template <typename T> 15908 | struct in_op : public opr_base<T> 15909 | { 15910 | typedef typename opr_base<T>::Type Type; 15911 | 15912 | static inline T process(const T&, const T&) { return std::numeric_limits<T>::quiet_NaN(); } 15913 | static inline T process(const std::string& t1, const std::string& t2) { return ((std::string::npos != t2.find(t1)) ? T(1) : T(0)); } 15914 | static inline typename expression_node<T>::node_type type() { return expression_node<T>::e_in; } 15915 | static inline details::operator_type operation() { return details::e_in; } 15916 | }; 15917 | 15918 | template <typename T> 15919 | struct like_op : public opr_base<T> 15920 | { 15921 | typedef typename opr_base<T>::Type Type; 15922 | 15923 | static inline T process(const T&, const T&) { return std::numeric_limits<T>::quiet_NaN(); } 15924 | static inline T process(const std::string& t1, const std::string& t2) { return (details::wc_match(t2,t1) ? T(1) : T(0)); } 15925 | static inline typename expression_node<T>::node_type type() { return expression_node<T>::e_like; } 15926 | static inline details::operator_type operation() { return details::e_like; } 15927 | }; 15928 | 15929 | template <typename T> 15930 | struct ilike_op : public opr_base<T> 15931 | { 15932 | typedef typename opr_base<T>::Type Type; 15933 | 15934 | static inline T process(const T&, const T&) { return std::numeric_limits<T>::quiet_NaN(); } 15935 | static inline T process(const std::string& t1, const std::string& t2) { return (details::wc_imatch(t2,t1) ? T(1) : T(0)); } 15936 | static inline typename expression_node<T>::node_type type() { return expression_node<T>::e_ilike; } 15937 | static inline details::operator_type operation() { return details::e_ilike; } 15938 | }; 15939 | 15940 | template <typename T> 15941 | struct inrange_op : public opr_base<T> 15942 | { 15943 | typedef typename opr_base<T>::Type Type; 15944 | 15945 | static inline T process(const T& t0, const T& t1, const T& t2) { return ((t0 <= t1) && (t1 <= t2)) ? T(1) : T(0); } 15946 | static inline T process(const std::string& t0, const std::string& t1, const std::string& t2) 15947 | { 15948 | return ((t0 <= t1) && (t1 <= t2)) ? T(1) : T(0); 15949 | } 15950 | static inline typename expression_node<T>::node_type type() { return expression_node<T>::e_inranges; } 15951 | static inline details::operator_type operation() { return details::e_inrange; } 15952 | }; 15953 | 15954 | template <typename T> 15955 | inline T value(details::expression_node<T>* n) 15956 | { 15957 | return n->value(); 15958 | } 15959 | 15960 | template <typename T> 15961 | inline T value(std::pair<details::expression_node<T>*,bool> n) 15962 | { 15963 | return n.first->value(); 15964 | } 15965 | 15966 | template <typename T> 15967 | inline T value(const T* t) 15968 | { 15969 | return (*t); 15970 | } 15971 | 15972 | template <typename T> 15973 | inline T value(const T& t) 15974 | { 15975 | return t; 15976 | } 15977 | 15978 | template <typename T> 15979 | struct vararg_add_op exprtk_final : public opr_base<T> 15980 | { 15981 | typedef typename opr_base<T>::Type Type; 15982 | 15983 | template <typename Type, 15984 | typename Allocator, 15985 | template <typename, typename> class Sequence> 15986 | static inline T process(const Sequence<Type,Allocator>& arg_list) 15987 | { 15988 | switch (arg_list.size()) 15989 | { 15990 | case 0 : return T(0); 15991 | case 1 : return process_1(arg_list); 15992 | case 2 : return process_2(arg_list); 15993 | case 3 : return process_3(arg_list); 15994 | case 4 : return process_4(arg_list); 15995 | case 5 : return process_5(arg_list); 15996 | default : 15997 | { 15998 | T result = T(0); 15999 | 16000 | for (std::size_t i = 0; i < arg_list.size(); ++i) 16001 | { 16002 | result += value(arg_list[i]); 16003 | } 16004 | 16005 | return result; 16006 | } 16007 | } 16008 | } 16009 | 16010 | template <typename Sequence> 16011 | static inline T process_1(const Sequence& arg_list) 16012 | { 16013 | return value(arg_list[0]); 16014 | } 16015 | 16016 | template <typename Sequence> 16017 | static inline T process_2(const Sequence& arg_list) 16018 | { 16019 | return value(arg_list[0]) + value(arg_list[1]); 16020 | } 16021 | 16022 | template <typename Sequence> 16023 | static inline T process_3(const Sequence& arg_list) 16024 | { 16025 | return value(arg_list[0]) + value(arg_list[1]) + 16026 | value(arg_list[2]) ; 16027 | } 16028 | 16029 | template <typename Sequence> 16030 | static inline T process_4(const Sequence& arg_list) 16031 | { 16032 | return value(arg_list[0]) + value(arg_list[1]) + 16033 | value(arg_list[2]) + value(arg_list[3]) ; 16034 | } 16035 | 16036 | template <typename Sequence> 16037 | static inline T process_5(const Sequence& arg_list) 16038 | { 16039 | return value(arg_list[0]) + value(arg_list[1]) + 16040 | value(arg_list[2]) + value(arg_list[3]) + 16041 | value(arg_list[4]) ; 16042 | } 16043 | }; 16044 | 16045 | template <typename T> 16046 | struct vararg_mul_op exprtk_final : public opr_base<T> 16047 | { 16048 | typedef typename opr_base<T>::Type Type; 16049 | 16050 | template <typename Type, 16051 | typename Allocator, 16052 | template <typename, typename> class Sequence> 16053 | static inline T process(const Sequence<Type,Allocator>& arg_list) 16054 | { 16055 | switch (arg_list.size()) 16056 | { 16057 | case 0 : return T(0); 16058 | case 1 : return process_1(arg_list); 16059 | case 2 : return process_2(arg_list); 16060 | case 3 : return process_3(arg_list); 16061 | case 4 : return process_4(arg_list); 16062 | case 5 : return process_5(arg_list); 16063 | default : 16064 | { 16065 | T result = T(value(arg_list[0])); 16066 | 16067 | for (std::size_t i = 1; i < arg_list.size(); ++i) 16068 | { 16069 | result *= value(arg_list[i]); 16070 | } 16071 | 16072 | return result; 16073 | } 16074 | } 16075 | } 16076 | 16077 | template <typename Sequence> 16078 | static inline T process_1(const Sequence& arg_list) 16079 | { 16080 | return value(arg_list[0]); 16081 | } 16082 | 16083 | template <typename Sequence> 16084 | static inline T process_2(const Sequence& arg_list) 16085 | { 16086 | return value(arg_list[0]) * value(arg_list[1]); 16087 | } 16088 | 16089 | template <typename Sequence> 16090 | static inline T process_3(const Sequence& arg_list) 16091 | { 16092 | return value(arg_list[0]) * value(arg_list[1]) * 16093 | value(arg_list[2]) ; 16094 | } 16095 | 16096 | template <typename Sequence> 16097 | static inline T process_4(const Sequence& arg_list) 16098 | { 16099 | return value(arg_list[0]) * value(arg_list[1]) * 16100 | value(arg_list[2]) * value(arg_list[3]) ; 16101 | } 16102 | 16103 | template <typename Sequence> 16104 | static inline T process_5(const Sequence& arg_list) 16105 | { 16106 | return value(arg_list[0]) * value(arg_list[1]) * 16107 | value(arg_list[2]) * value(arg_list[3]) * 16108 | value(arg_list[4]) ; 16109 | } 16110 | }; 16111 | 16112 | template <typename T> 16113 | struct vararg_avg_op exprtk_final : public opr_base<T> 16114 | { 16115 | typedef typename opr_base<T>::Type Type; 16116 | 16117 | template <typename Type, 16118 | typename Allocator, 16119 | template <typename, typename> class Sequence> 16120 | static inline T process(const Sequence<Type,Allocator>& arg_list) 16121 | { 16122 | switch (arg_list.size()) 16123 | { 16124 | case 0 : return T(0); 16125 | case 1 : return process_1(arg_list); 16126 | case 2 : return process_2(arg_list); 16127 | case 3 : return process_3(arg_list); 16128 | case 4 : return process_4(arg_list); 16129 | case 5 : return process_5(arg_list); 16130 | default : return vararg_add_op<T>::process(arg_list) / T(arg_list.size()); 16131 | } 16132 | } 16133 | 16134 | template <typename Sequence> 16135 | static inline T process_1(const Sequence& arg_list) 16136 | { 16137 | return value(arg_list[0]); 16138 | } 16139 | 16140 | template <typename Sequence> 16141 | static inline T process_2(const Sequence& arg_list) 16142 | { 16143 | return (value(arg_list[0]) + value(arg_list[1])) / T(2); 16144 | } 16145 | 16146 | template <typename Sequence> 16147 | static inline T process_3(const Sequence& arg_list) 16148 | { 16149 | return (value(arg_list[0]) + value(arg_list[1]) + value(arg_list[2])) / T(3); 16150 | } 16151 | 16152 | template <typename Sequence> 16153 | static inline T process_4(const Sequence& arg_list) 16154 | { 16155 | return (value(arg_list[0]) + value(arg_list[1]) + 16156 | value(arg_list[2]) + value(arg_list[3])) / T(4); 16157 | } 16158 | 16159 | template <typename Sequence> 16160 | static inline T process_5(const Sequence& arg_list) 16161 | { 16162 | return (value(arg_list[0]) + value(arg_list[1]) + 16163 | value(arg_list[2]) + value(arg_list[3]) + 16164 | value(arg_list[4])) / T(5); 16165 | } 16166 | }; 16167 | 16168 | template <typename T> 16169 | struct vararg_min_op exprtk_final : public opr_base<T> 16170 | { 16171 | typedef typename opr_base<T>::Type Type; 16172 | 16173 | template <typename Type, 16174 | typename Allocator, 16175 | template <typename, typename> class Sequence> 16176 | static inline T process(const Sequence<Type,Allocator>& arg_list) 16177 | { 16178 | switch (arg_list.size()) 16179 | { 16180 | case 0 : return T(0); 16181 | case 1 : return process_1(arg_list); 16182 | case 2 : return process_2(arg_list); 16183 | case 3 : return process_3(arg_list); 16184 | case 4 : return process_4(arg_list); 16185 | case 5 : return process_5(arg_list); 16186 | default : 16187 | { 16188 | T result = T(value(arg_list[0])); 16189 | 16190 | for (std::size_t i = 1; i < arg_list.size(); ++i) 16191 | { 16192 | const T v = value(arg_list[i]); 16193 | 16194 | if (v < result) 16195 | result = v; 16196 | } 16197 | 16198 | return result; 16199 | } 16200 | } 16201 | } 16202 | 16203 | template <typename Sequence> 16204 | static inline T process_1(const Sequence& arg_list) 16205 | { 16206 | return value(arg_list[0]); 16207 | } 16208 | 16209 | template <typename Sequence> 16210 | static inline T process_2(const Sequence& arg_list) 16211 | { 16212 | return std::min<T>(value(arg_list[0]),value(arg_list[1])); 16213 | } 16214 | 16215 | template <typename Sequence> 16216 | static inline T process_3(const Sequence& arg_list) 16217 | { 16218 | return std::min<T>(std::min<T>(value(arg_list[0]),value(arg_list[1])),value(arg_list[2])); 16219 | } 16220 | 16221 | template <typename Sequence> 16222 | static inline T process_4(const Sequence& arg_list) 16223 | { 16224 | return std::min<T>( 16225 | std::min<T>(value(arg_list[0]), value(arg_list[1])), 16226 | std::min<T>(value(arg_list[2]), value(arg_list[3]))); 16227 | } 16228 | 16229 | template <typename Sequence> 16230 | static inline T process_5(const Sequence& arg_list) 16231 | { 16232 | return std::min<T>( 16233 | std::min<T>(std::min<T>(value(arg_list[0]), value(arg_list[1])), 16234 | std::min<T>(value(arg_list[2]), value(arg_list[3]))), 16235 | value(arg_list[4])); 16236 | } 16237 | }; 16238 | 16239 | template <typename T> 16240 | struct vararg_max_op exprtk_final : public opr_base<T> 16241 | { 16242 | typedef typename opr_base<T>::Type Type; 16243 | 16244 | template <typename Type, 16245 | typename Allocator, 16246 | template <typename, typename> class Sequence> 16247 | static inline T process(const Sequence<Type,Allocator>& arg_list) 16248 | { 16249 | switch (arg_list.size()) 16250 | { 16251 | case 0 : return T(0); 16252 | case 1 : return process_1(arg_list); 16253 | case 2 : return process_2(arg_list); 16254 | case 3 : return process_3(arg_list); 16255 | case 4 : return process_4(arg_list); 16256 | case 5 : return process_5(arg_list); 16257 | default : 16258 | { 16259 | T result = T(value(arg_list[0])); 16260 | 16261 | for (std::size_t i = 1; i < arg_list.size(); ++i) 16262 | { 16263 | const T v = value(arg_list[i]); 16264 | 16265 | if (v > result) 16266 | result = v; 16267 | } 16268 | 16269 | return result; 16270 | } 16271 | } 16272 | } 16273 | 16274 | template <typename Sequence> 16275 | static inline T process_1(const Sequence& arg_list) 16276 | { 16277 | return value(arg_list[0]); 16278 | } 16279 | 16280 | template <typename Sequence> 16281 | static inline T process_2(const Sequence& arg_list) 16282 | { 16283 | return std::max<T>(value(arg_list[0]),value(arg_list[1])); 16284 | } 16285 | 16286 | template <typename Sequence> 16287 | static inline T process_3(const Sequence& arg_list) 16288 | { 16289 | return std::max<T>(std::max<T>(value(arg_list[0]),value(arg_list[1])),value(arg_list[2])); 16290 | } 16291 | 16292 | template <typename Sequence> 16293 | static inline T process_4(const Sequence& arg_list) 16294 | { 16295 | return std::max<T>( 16296 | std::max<T>(value(arg_list[0]), value(arg_list[1])), 16297 | std::max<T>(value(arg_list[2]), value(arg_list[3]))); 16298 | } 16299 | 16300 | template <typename Sequence> 16301 | static inline T process_5(const Sequence& arg_list) 16302 | { 16303 | return std::max<T>( 16304 | std::max<T>(std::max<T>(value(arg_list[0]), value(arg_list[1])), 16305 | std::max<T>(value(arg_list[2]), value(arg_list[3]))), 16306 | value(arg_list[4])); 16307 | } 16308 | }; 16309 | 16310 | template <typename T> 16311 | struct vararg_mand_op exprtk_final : public opr_base<T> 16312 | { 16313 | typedef typename opr_base<T>::Type Type; 16314 | 16315 | template <typename Type, 16316 | typename Allocator, 16317 | template <typename, typename> class Sequence> 16318 | static inline T process(const Sequence<Type,Allocator>& arg_list) 16319 | { 16320 | switch (arg_list.size()) 16321 | { 16322 | case 1 : return process_1(arg_list); 16323 | case 2 : return process_2(arg_list); 16324 | case 3 : return process_3(arg_list); 16325 | case 4 : return process_4(arg_list); 16326 | case 5 : return process_5(arg_list); 16327 | default : 16328 | { 16329 | for (std::size_t i = 0; i < arg_list.size(); ++i) 16330 | { 16331 | if (std::equal_to<T>()(T(0), value(arg_list[i]))) 16332 | return T(0); 16333 | } 16334 | 16335 | return T(1); 16336 | } 16337 | } 16338 | } 16339 | 16340 | template <typename Sequence> 16341 | static inline T process_1(const Sequence& arg_list) 16342 | { 16343 | return std::not_equal_to<T>() 16344 | (T(0), value(arg_list[0])) ? T(1) : T(0); 16345 | } 16346 | 16347 | template <typename Sequence> 16348 | static inline T process_2(const Sequence& arg_list) 16349 | { 16350 | return ( 16351 | std::not_equal_to<T>()(T(0), value(arg_list[0])) && 16352 | std::not_equal_to<T>()(T(0), value(arg_list[1])) 16353 | ) ? T(1) : T(0); 16354 | } 16355 | 16356 | template <typename Sequence> 16357 | static inline T process_3(const Sequence& arg_list) 16358 | { 16359 | return ( 16360 | std::not_equal_to<T>()(T(0), value(arg_list[0])) && 16361 | std::not_equal_to<T>()(T(0), value(arg_list[1])) && 16362 | std::not_equal_to<T>()(T(0), value(arg_list[2])) 16363 | ) ? T(1) : T(0); 16364 | } 16365 | 16366 | template <typename Sequence> 16367 | static inline T process_4(const Sequence& arg_list) 16368 | { 16369 | return ( 16370 | std::not_equal_to<T>()(T(0), value(arg_list[0])) && 16371 | std::not_equal_to<T>()(T(0), value(arg_list[1])) && 16372 | std::not_equal_to<T>()(T(0), value(arg_list[2])) && 16373 | std::not_equal_to<T>()(T(0), value(arg_list[3])) 16374 | ) ? T(1) : T(0); 16375 | } 16376 | 16377 | template <typename Sequence> 16378 | static inline T process_5(const Sequence& arg_list) 16379 | { 16380 | return ( 16381 | std::not_equal_to<T>()(T(0), value(arg_list[0])) && 16382 | std::not_equal_to<T>()(T(0), value(arg_list[1])) && 16383 | std::not_equal_to<T>()(T(0), value(arg_list[2])) && 16384 | std::not_equal_to<T>()(T(0), value(arg_list[3])) && 16385 | std::not_equal_to<T>()(T(0), value(arg_list[4])) 16386 | ) ? T(1) : T(0); 16387 | } 16388 | }; 16389 | 16390 | template <typename T> 16391 | struct vararg_mor_op exprtk_final : public opr_base<T> 16392 | { 16393 | typedef typename opr_base<T>::Type Type; 16394 | 16395 | template <typename Type, 16396 | typename Allocator, 16397 | template <typename, typename> class Sequence> 16398 | static inline T process(const Sequence<Type,Allocator>& arg_list) 16399 | { 16400 | switch (arg_list.size()) 16401 | { 16402 | case 1 : return process_1(arg_list); 16403 | case 2 : return process_2(arg_list); 16404 | case 3 : return process_3(arg_list); 16405 | case 4 : return process_4(arg_list); 16406 | case 5 : return process_5(arg_list); 16407 | default : 16408 | { 16409 | for (std::size_t i = 0; i < arg_list.size(); ++i) 16410 | { 16411 | if (std::not_equal_to<T>()(T(0), value(arg_list[i]))) 16412 | return T(1); 16413 | } 16414 | 16415 | return T(0); 16416 | } 16417 | } 16418 | } 16419 | 16420 | template <typename Sequence> 16421 | static inline T process_1(const Sequence& arg_list) 16422 | { 16423 | return std::not_equal_to<T>() 16424 | (T(0), value(arg_list[0])) ? T(1) : T(0); 16425 | } 16426 | 16427 | template <typename Sequence> 16428 | static inline T process_2(const Sequence& arg_list) 16429 | { 16430 | return ( 16431 | std::not_equal_to<T>()(T(0), value(arg_list[0])) || 16432 | std::not_equal_to<T>()(T(0), value(arg_list[1])) 16433 | ) ? T(1) : T(0); 16434 | } 16435 | 16436 | template <typename Sequence> 16437 | static inline T process_3(const Sequence& arg_list) 16438 | { 16439 | return ( 16440 | std::not_equal_to<T>()(T(0), value(arg_list[0])) || 16441 | std::not_equal_to<T>()(T(0), value(arg_list[1])) || 16442 | std::not_equal_to<T>()(T(0), value(arg_list[2])) 16443 | ) ? T(1) : T(0); 16444 | } 16445 | 16446 | template <typename Sequence> 16447 | static inline T process_4(const Sequence& arg_list) 16448 | { 16449 | return ( 16450 | std::not_equal_to<T>()(T(0), value(arg_list[0])) || 16451 | std::not_equal_to<T>()(T(0), value(arg_list[1])) || 16452 | std::not_equal_to<T>()(T(0), value(arg_list[2])) || 16453 | std::not_equal_to<T>()(T(0), value(arg_list[3])) 16454 | ) ? T(1) : T(0); 16455 | } 16456 | 16457 | template <typename Sequence> 16458 | static inline T process_5(const Sequence& arg_list) 16459 | { 16460 | return ( 16461 | std::not_equal_to<T>()(T(0), value(arg_list[0])) || 16462 | std::not_equal_to<T>()(T(0), value(arg_list[1])) || 16463 | std::not_equal_to<T>()(T(0), value(arg_list[2])) || 16464 | std::not_equal_to<T>()(T(0), value(arg_list[3])) || 16465 | std::not_equal_to<T>()(T(0), value(arg_list[4])) 16466 | ) ? T(1) : T(0); 16467 | } 16468 | }; 16469 | 16470 | template <typename T> 16471 | struct vararg_multi_op exprtk_final : public opr_base<T> 16472 | { 16473 | typedef typename opr_base<T>::Type Type; 16474 | 16475 | template <typename Type, 16476 | typename Allocator, 16477 | template <typename, typename> class Sequence> 16478 | static inline T process(const Sequence<Type,Allocator>& arg_list) 16479 | { 16480 | switch (arg_list.size()) 16481 | { 16482 | case 0 : return std::numeric_limits<T>::quiet_NaN(); 16483 | case 1 : return process_1(arg_list); 16484 | case 2 : return process_2(arg_list); 16485 | case 3 : return process_3(arg_list); 16486 | case 4 : return process_4(arg_list); 16487 | case 5 : return process_5(arg_list); 16488 | case 6 : return process_6(arg_list); 16489 | case 7 : return process_7(arg_list); 16490 | case 8 : return process_8(arg_list); 16491 | default : 16492 | { 16493 | for (std::size_t i = 0; i < (arg_list.size() - 1); ++i) 16494 | { 16495 | value(arg_list[i]); 16496 | } 16497 | return value(arg_list.back()); 16498 | } 16499 | } 16500 | } 16501 | 16502 | template <typename Sequence> 16503 | static inline T process_1(const Sequence& arg_list) 16504 | { 16505 | return value(arg_list[0]); 16506 | } 16507 | 16508 | template <typename Sequence> 16509 | static inline T process_2(const Sequence& arg_list) 16510 | { 16511 | value(arg_list[0]); 16512 | return value(arg_list[1]); 16513 | } 16514 | 16515 | template <typename Sequence> 16516 | static inline T process_3(const Sequence& arg_list) 16517 | { 16518 | value(arg_list[0]); 16519 | value(arg_list[1]); 16520 | return value(arg_list[2]); 16521 | } 16522 | 16523 | template <typename Sequence> 16524 | static inline T process_4(const Sequence& arg_list) 16525 | { 16526 | value(arg_list[0]); 16527 | value(arg_list[1]); 16528 | value(arg_list[2]); 16529 | return value(arg_list[3]); 16530 | } 16531 | 16532 | template <typename Sequence> 16533 | static inline T process_5(const Sequence& arg_list) 16534 | { 16535 | value(arg_list[0]); 16536 | value(arg_list[1]); 16537 | value(arg_list[2]); 16538 | value(arg_list[3]); 16539 | return value(arg_list[4]); 16540 | } 16541 | 16542 | template <typename Sequence> 16543 | static inline T process_6(const Sequence& arg_list) 16544 | { 16545 | value(arg_list[0]); 16546 | value(arg_list[1]); 16547 | value(arg_list[2]); 16548 | value(arg_list[3]); 16549 | value(arg_list[4]); 16550 | return value(arg_list[5]); 16551 | } 16552 | 16553 | template <typename Sequence> 16554 | static inline T process_7(const Sequence& arg_list) 16555 | { 16556 | value(arg_list[0]); 16557 | value(arg_list[1]); 16558 | value(arg_list[2]); 16559 | value(arg_list[3]); 16560 | value(arg_list[4]); 16561 | value(arg_list[5]); 16562 | return value(arg_list[6]); 16563 | } 16564 | 16565 | template <typename Sequence> 16566 | static inline T process_8(const Sequence& arg_list) 16567 | { 16568 | value(arg_list[0]); 16569 | value(arg_list[1]); 16570 | value(arg_list[2]); 16571 | value(arg_list[3]); 16572 | value(arg_list[4]); 16573 | value(arg_list[5]); 16574 | value(arg_list[6]); 16575 | return value(arg_list[7]); 16576 | } 16577 | }; 16578 | 16579 | template <typename T> 16580 | struct vec_add_op 16581 | { 16582 | typedef vector_interface<T>* ivector_ptr; 16583 | 16584 | static inline T process(const ivector_ptr v) 16585 | { 16586 | const T* vec = v->vec()->vds().data(); 16587 | const std::size_t vec_size = v->size(); 16588 | 16589 | loop_unroll::details lud(vec_size); 16590 | 16591 | if (vec_size <= static_cast<std::size_t>(lud.batch_size)) 16592 | { 16593 | T result = T(0); 16594 | int i = 0; 16595 | 16596 | switch (vec_size) 16597 | { 16598 | #define case_stmt(N,fall_through) \ 16599 | case N : result += vec[i++]; \ 16600 | fall_through \ 16601 | 16602 | #ifndef exprtk_disable_superscalar_unroll 16603 | case_stmt(16, exprtk_fallthrough) case_stmt(15, exprtk_fallthrough) 16604 | case_stmt(14, exprtk_fallthrough) case_stmt(13, exprtk_fallthrough) 16605 | case_stmt(12, exprtk_fallthrough) case_stmt(11, exprtk_fallthrough) 16606 | case_stmt(10, exprtk_fallthrough) case_stmt( 9, exprtk_fallthrough) 16607 | case_stmt( 8, exprtk_fallthrough) case_stmt( 7, exprtk_fallthrough) 16608 | case_stmt( 6, exprtk_fallthrough) case_stmt( 5, exprtk_fallthrough) 16609 | 16610 | #endif 16611 | case_stmt( 4, exprtk_fallthrough) case_stmt( 3, exprtk_fallthrough) 16612 | case_stmt( 2, exprtk_fallthrough) case_stmt( 1, (void)0;) 16613 | } 16614 | 16615 | #undef case_stmt 16616 | 16617 | return result; 16618 | } 16619 | 16620 | T r[] = { 16621 | T(0), T(0), T(0), T(0), T(0), T(0), T(0), T(0), 16622 | T(0), T(0), T(0), T(0), T(0), T(0), T(0), T(0) 16623 | }; 16624 | 16625 | const T* upper_bound = vec + lud.upper_bound; 16626 | 16627 | while (vec < upper_bound) 16628 | { 16629 | #define exprtk_loop(N) \ 16630 | r[N] += vec[N]; \ 16631 | 16632 | exprtk_loop( 0) exprtk_loop( 1) 16633 | exprtk_loop( 2) exprtk_loop( 3) 16634 | #ifndef exprtk_disable_superscalar_unroll 16635 | exprtk_loop( 4) exprtk_loop( 5) 16636 | exprtk_loop( 6) exprtk_loop( 7) 16637 | exprtk_loop( 8) exprtk_loop( 9) 16638 | exprtk_loop(10) exprtk_loop(11) 16639 | exprtk_loop(12) exprtk_loop(13) 16640 | exprtk_loop(14) exprtk_loop(15) 16641 | #endif 16642 | 16643 | vec += lud.batch_size; 16644 | } 16645 | 16646 | int i = 0; 16647 | 16648 | switch (lud.remainder) 16649 | { 16650 | #define case_stmt(N,fall_through) \ 16651 | case N : r[0] += vec[i++]; \ 16652 | fall_through \ 16653 | 16654 | #ifndef exprtk_disable_superscalar_unroll 16655 | case_stmt(15, exprtk_fallthrough) case_stmt(14, exprtk_fallthrough) 16656 | case_stmt(13, exprtk_fallthrough) case_stmt(12, exprtk_fallthrough) 16657 | case_stmt(11, exprtk_fallthrough) case_stmt(10, exprtk_fallthrough) 16658 | case_stmt( 9, exprtk_fallthrough) case_stmt( 8, exprtk_fallthrough) 16659 | case_stmt( 7, exprtk_fallthrough) case_stmt( 6, exprtk_fallthrough) 16660 | case_stmt( 5, exprtk_fallthrough) case_stmt( 4, exprtk_fallthrough) 16661 | #endif 16662 | case_stmt( 3, exprtk_fallthrough) case_stmt( 2, exprtk_fallthrough) 16663 | case_stmt( 1, (void)0;) 16664 | } 16665 | 16666 | #undef exprtk_loop 16667 | #undef case_stmt 16668 | 16669 | return (r[ 0] + r[ 1] + r[ 2] + r[ 3]) 16670 | #ifndef exprtk_disable_superscalar_unroll 16671 | + (r[ 4] + r[ 5] + r[ 6] + r[ 7]) 16672 | + (r[ 8] + r[ 9] + r[10] + r[11]) 16673 | + (r[12] + r[13] + r[14] + r[15]) 16674 | #endif 16675 | ; 16676 | } 16677 | }; 16678 | 16679 | template <typename T> 16680 | struct vec_mul_op 16681 | { 16682 | typedef vector_interface<T>* ivector_ptr; 16683 | 16684 | static inline T process(const ivector_ptr v) 16685 | { 16686 | const T* vec = v->vec()->vds().data(); 16687 | const std::size_t vec_size = v->vec()->size(); 16688 | 16689 | loop_unroll::details lud(vec_size); 16690 | 16691 | if (vec_size <= static_cast<std::size_t>(lud.batch_size)) 16692 | { 16693 | T result = T(1); 16694 | int i = 0; 16695 | 16696 | switch (vec_size) 16697 | { 16698 | #define case_stmt(N,fall_through) \ 16699 | case N : result *= vec[i++]; \ 16700 | fall_through \ 16701 | 16702 | #ifndef exprtk_disable_superscalar_unroll 16703 | case_stmt(16, exprtk_fallthrough) case_stmt(15, exprtk_fallthrough) 16704 | case_stmt(14, exprtk_fallthrough) case_stmt(13, exprtk_fallthrough) 16705 | case_stmt(12, exprtk_fallthrough) case_stmt(11, exprtk_fallthrough) 16706 | case_stmt(10, exprtk_fallthrough) case_stmt( 9, exprtk_fallthrough) 16707 | case_stmt( 8, exprtk_fallthrough) case_stmt( 7, exprtk_fallthrough) 16708 | case_stmt( 6, exprtk_fallthrough) case_stmt( 5, exprtk_fallthrough) 16709 | #endif 16710 | case_stmt( 4, exprtk_fallthrough) case_stmt( 3, exprtk_fallthrough) 16711 | case_stmt( 2, exprtk_fallthrough) case_stmt( 1, (void)0;) 16712 | } 16713 | 16714 | #undef case_stmt 16715 | 16716 | return result; 16717 | } 16718 | 16719 | T r[] = { 16720 | T(1), T(1), T(1), T(1), T(1), T(1), T(1), T(1), 16721 | T(1), T(1), T(1), T(1), T(1), T(1), T(1), T(1) 16722 | }; 16723 | 16724 | const T* upper_bound = vec + lud.upper_bound; 16725 | 16726 | while (vec < upper_bound) 16727 | { 16728 | #define exprtk_loop(N) \ 16729 | r[N] *= vec[N]; \ 16730 | 16731 | exprtk_loop( 0) exprtk_loop( 1) 16732 | exprtk_loop( 2) exprtk_loop( 3) 16733 | #ifndef exprtk_disable_superscalar_unroll 16734 | exprtk_loop( 4) exprtk_loop( 5) 16735 | exprtk_loop( 6) exprtk_loop( 7) 16736 | exprtk_loop( 8) exprtk_loop( 9) 16737 | exprtk_loop(10) exprtk_loop(11) 16738 | exprtk_loop(12) exprtk_loop(13) 16739 | exprtk_loop(14) exprtk_loop(15) 16740 | #endif 16741 | 16742 | vec += lud.batch_size; 16743 | } 16744 | 16745 | int i = 0; 16746 | 16747 | switch (lud.remainder) 16748 | { 16749 | #define case_stmt(N,fall_through) \ 16750 | case N : r[0] *= vec[i++]; \ 16751 | fall_through \ 16752 | 16753 | #ifndef exprtk_disable_superscalar_unroll 16754 | case_stmt(15, exprtk_fallthrough) case_stmt(14, exprtk_fallthrough) 16755 | case_stmt(13, exprtk_fallthrough) case_stmt(12, exprtk_fallthrough) 16756 | case_stmt(11, exprtk_fallthrough) case_stmt(10, exprtk_fallthrough) 16757 | case_stmt( 9, exprtk_fallthrough) case_stmt( 8, exprtk_fallthrough) 16758 | case_stmt( 7, exprtk_fallthrough) case_stmt( 6, exprtk_fallthrough) 16759 | case_stmt( 5, exprtk_fallthrough) case_stmt( 4, exprtk_fallthrough) 16760 | #endif 16761 | case_stmt( 3, exprtk_fallthrough) case_stmt( 2, exprtk_fallthrough) 16762 | case_stmt( 1, (void)0;) 16763 | } 16764 | 16765 | #undef exprtk_loop 16766 | #undef case_stmt 16767 | 16768 | return (r[ 0] * r[ 1] * r[ 2] * r[ 3]) 16769 | #ifndef exprtk_disable_superscalar_unroll 16770 | * (r[ 4] * r[ 5] * r[ 6] * r[ 7]) 16771 | * (r[ 8] * r[ 9] * r[10] * r[11]) 16772 | * (r[12] * r[13] * r[14] * r[15]) 16773 | #endif 16774 | ; 16775 | } 16776 | }; 16777 | 16778 | template <typename T> 16779 | struct vec_avg_op 16780 | { 16781 | typedef vector_interface<T>* ivector_ptr; 16782 | 16783 | static inline T process(const ivector_ptr v) 16784 | { 16785 | const T vec_size = T(v->vec()->size()); 16786 | return vec_add_op<T>::process(v) / vec_size; 16787 | } 16788 | }; 16789 | 16790 | template <typename T> 16791 | struct vec_min_op 16792 | { 16793 | typedef vector_interface<T>* ivector_ptr; 16794 | 16795 | static inline T process(const ivector_ptr v) 16796 | { 16797 | const T* vec = v->vec()->vds().data(); 16798 | const std::size_t vec_size = v->vec()->size(); 16799 | 16800 | T result = vec[0]; 16801 | 16802 | for (std::size_t i = 1; i < vec_size; ++i) 16803 | { 16804 | const T v_i = vec[i]; 16805 | 16806 | if (v_i < result) 16807 | result = v_i; 16808 | } 16809 | 16810 | return result; 16811 | } 16812 | }; 16813 | 16814 | template <typename T> 16815 | struct vec_max_op 16816 | { 16817 | typedef vector_interface<T>* ivector_ptr; 16818 | 16819 | static inline T process(const ivector_ptr v) 16820 | { 16821 | const T* vec = v->vec()->vds().data(); 16822 | const std::size_t vec_size = v->vec()->size(); 16823 | 16824 | T result = vec[0]; 16825 | 16826 | for (std::size_t i = 1; i < vec_size; ++i) 16827 | { 16828 | const T v_i = vec[i]; 16829 | 16830 | if (v_i > result) 16831 | result = v_i; 16832 | } 16833 | 16834 | return result; 16835 | } 16836 | }; 16837 | 16838 | template <typename T> 16839 | class vov_base_node : public expression_node<T> 16840 | { 16841 | public: 16842 | 16843 | virtual ~vov_base_node() 16844 | {} 16845 | 16846 | inline virtual operator_type operation() const 16847 | { 16848 | return details::e_default; 16849 | } 16850 | 16851 | virtual const T& v0() const = 0; 16852 | 16853 | virtual const T& v1() const = 0; 16854 | }; 16855 | 16856 | template <typename T> 16857 | class cov_base_node : public expression_node<T> 16858 | { 16859 | public: 16860 | 16861 | virtual ~cov_base_node() 16862 | {} 16863 | 16864 | inline virtual operator_type operation() const 16865 | { 16866 | return details::e_default; 16867 | } 16868 | 16869 | virtual const T c() const = 0; 16870 | 16871 | virtual const T& v() const = 0; 16872 | }; 16873 | 16874 | template <typename T> 16875 | class voc_base_node : public expression_node<T> 16876 | { 16877 | public: 16878 | 16879 | virtual ~voc_base_node() 16880 | {} 16881 | 16882 | inline virtual operator_type operation() const 16883 | { 16884 | return details::e_default; 16885 | } 16886 | 16887 | virtual const T c() const = 0; 16888 | 16889 | virtual const T& v() const = 0; 16890 | }; 16891 | 16892 | template <typename T> 16893 | class vob_base_node : public expression_node<T> 16894 | { 16895 | public: 16896 | 16897 | virtual ~vob_base_node() 16898 | {} 16899 | 16900 | virtual const T& v() const = 0; 16901 | }; 16902 | 16903 | template <typename T> 16904 | class bov_base_node : public expression_node<T> 16905 | { 16906 | public: 16907 | 16908 | virtual ~bov_base_node() 16909 | {} 16910 | 16911 | virtual const T& v() const = 0; 16912 | }; 16913 | 16914 | template <typename T> 16915 | class cob_base_node : public expression_node<T> 16916 | { 16917 | public: 16918 | 16919 | virtual ~cob_base_node() 16920 | {} 16921 | 16922 | inline virtual operator_type operation() const 16923 | { 16924 | return details::e_default; 16925 | } 16926 | 16927 | virtual const T c() const = 0; 16928 | 16929 | virtual void set_c(const T) = 0; 16930 | 16931 | virtual expression_node<T>* move_branch(const std::size_t& index) = 0; 16932 | }; 16933 | 16934 | template <typename T> 16935 | class boc_base_node : public expression_node<T> 16936 | { 16937 | public: 16938 | 16939 | virtual ~boc_base_node() 16940 | {} 16941 | 16942 | inline virtual operator_type operation() const 16943 | { 16944 | return details::e_default; 16945 | } 16946 | 16947 | virtual const T c() const = 0; 16948 | 16949 | virtual void set_c(const T) = 0; 16950 | 16951 | virtual expression_node<T>* move_branch(const std::size_t& index) = 0; 16952 | }; 16953 | 16954 | template <typename T> 16955 | class uv_base_node : public expression_node<T> 16956 | { 16957 | public: 16958 | 16959 | virtual ~uv_base_node() 16960 | {} 16961 | 16962 | inline virtual operator_type operation() const 16963 | { 16964 | return details::e_default; 16965 | } 16966 | 16967 | virtual const T& v() const = 0; 16968 | }; 16969 | 16970 | template <typename T> 16971 | class sos_base_node : public expression_node<T> 16972 | { 16973 | public: 16974 | 16975 | virtual ~sos_base_node() 16976 | {} 16977 | 16978 | inline virtual operator_type operation() const 16979 | { 16980 | return details::e_default; 16981 | } 16982 | }; 16983 | 16984 | template <typename T> 16985 | class sosos_base_node : public expression_node<T> 16986 | { 16987 | public: 16988 | 16989 | virtual ~sosos_base_node() 16990 | {} 16991 | 16992 | inline virtual operator_type operation() const 16993 | { 16994 | return details::e_default; 16995 | } 16996 | }; 16997 | 16998 | template <typename T> 16999 | class T0oT1oT2_base_node : public expression_node<T> 17000 | { 17001 | public: 17002 | 17003 | virtual ~T0oT1oT2_base_node() 17004 | {} 17005 | 17006 | virtual std::string type_id() const = 0; 17007 | }; 17008 | 17009 | template <typename T> 17010 | class T0oT1oT2oT3_base_node : public expression_node<T> 17011 | { 17012 | public: 17013 | 17014 | virtual ~T0oT1oT2oT3_base_node() 17015 | {} 17016 | 17017 | virtual std::string type_id() const = 0; 17018 | }; 17019 | 17020 | template <typename T, typename Operation> 17021 | class unary_variable_node exprtk_final : public uv_base_node<T> 17022 | { 17023 | public: 17024 | 17025 | typedef expression_node<T>* expression_ptr; 17026 | typedef Operation operation_t; 17027 | 17028 | explicit unary_variable_node(const T& var) 17029 | : v_(var) 17030 | {} 17031 | 17032 | inline T value() const exprtk_override 17033 | { 17034 | return Operation::process(v_); 17035 | } 17036 | 17037 | inline typename expression_node<T>::node_type type() const exprtk_override 17038 | { 17039 | return Operation::type(); 17040 | } 17041 | 17042 | inline operator_type operation() const exprtk_override 17043 | { 17044 | return Operation::operation(); 17045 | } 17046 | 17047 | inline const T& v() const exprtk_override 17048 | { 17049 | return v_; 17050 | } 17051 | 17052 | private: 17053 | 17054 | unary_variable_node(const unary_variable_node<T,Operation>&) exprtk_delete; 17055 | unary_variable_node<T,Operation>& operator=(const unary_variable_node<T,Operation>&) exprtk_delete; 17056 | 17057 | const T& v_; 17058 | }; 17059 | 17060 | template <typename T> 17061 | class uvouv_node exprtk_final : public expression_node<T> 17062 | { 17063 | public: 17064 | 17065 | // UOpr1(v0) Op UOpr2(v1) 17066 | typedef typename details::functor_t<T> functor_t; 17067 | typedef typename functor_t::bfunc_t bfunc_t; 17068 | typedef typename functor_t::ufunc_t ufunc_t; 17069 | typedef expression_node<T>* expression_ptr; 17070 | 17071 | explicit uvouv_node(const T& var0,const T& var1, 17072 | ufunc_t uf0, ufunc_t uf1, bfunc_t bf) 17073 | : v0_(var0) 17074 | , v1_(var1) 17075 | , u0_(uf0 ) 17076 | , u1_(uf1 ) 17077 | , f_ (bf ) 17078 | {} 17079 | 17080 | inline T value() const exprtk_override 17081 | { 17082 | return f_(u0_(v0_),u1_(v1_)); 17083 | } 17084 | 17085 | inline typename expression_node<T>::node_type type() const exprtk_override 17086 | { 17087 | return expression_node<T>::e_uvouv; 17088 | } 17089 | 17090 | inline const T& v0() 17091 | { 17092 | return v0_; 17093 | } 17094 | 17095 | inline const T& v1() 17096 | { 17097 | return v1_; 17098 | } 17099 | 17100 | inline ufunc_t u0() 17101 | { 17102 | return u0_; 17103 | } 17104 | 17105 | inline ufunc_t u1() 17106 | { 17107 | return u1_; 17108 | } 17109 | 17110 | inline ufunc_t f() 17111 | { 17112 | return f_; 17113 | } 17114 | 17115 | private: 17116 | 17117 | uvouv_node(const uvouv_node<T>&) exprtk_delete; 17118 | uvouv_node<T>& operator=(const uvouv_node<T>&) exprtk_delete; 17119 | 17120 | const T& v0_; 17121 | const T& v1_; 17122 | const ufunc_t u0_; 17123 | const ufunc_t u1_; 17124 | const bfunc_t f_; 17125 | }; 17126 | 17127 | template <typename T, typename Operation> 17128 | class unary_branch_node exprtk_final : public expression_node<T> 17129 | { 17130 | public: 17131 | 17132 | typedef Operation operation_t; 17133 | typedef expression_node<T>* expression_ptr; 17134 | typedef std::pair<expression_ptr,bool> branch_t; 17135 | 17136 | explicit unary_branch_node(expression_ptr branch) 17137 | { 17138 | construct_branch_pair(branch_, branch); 17139 | } 17140 | 17141 | inline T value() const exprtk_override 17142 | { 17143 | return Operation::process(branch_.first->value()); 17144 | } 17145 | 17146 | inline typename expression_node<T>::node_type type() const exprtk_override 17147 | { 17148 | return Operation::type(); 17149 | } 17150 | 17151 | inline bool valid() const exprtk_override 17152 | { 17153 | return branch_.first && branch_.first->valid(); 17154 | } 17155 | 17156 | inline operator_type operation() 17157 | { 17158 | return Operation::operation(); 17159 | } 17160 | 17161 | inline expression_node<T>* branch(const std::size_t&) const exprtk_override 17162 | { 17163 | return branch_.first; 17164 | } 17165 | 17166 | inline void release() 17167 | { 17168 | branch_.second = false; 17169 | } 17170 | 17171 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 17172 | { 17173 | expression_node<T>::ndb_t::collect(branch_, node_delete_list); 17174 | } 17175 | 17176 | std::size_t node_depth() const exprtk_override 17177 | { 17178 | return expression_node<T>::ndb_t::compute_node_depth(branch_); 17179 | } 17180 | 17181 | private: 17182 | 17183 | unary_branch_node(const unary_branch_node<T,Operation>&) exprtk_delete; 17184 | unary_branch_node<T,Operation>& operator=(const unary_branch_node<T,Operation>&) exprtk_delete; 17185 | 17186 | branch_t branch_; 17187 | }; 17188 | 17189 | template <typename T> struct is_const { enum {result = 0}; }; 17190 | template <typename T> struct is_const <const T> { enum {result = 1}; }; 17191 | template <typename T> struct is_const_ref { enum {result = 0}; }; 17192 | template <typename T> struct is_const_ref <const T&> { enum {result = 1}; }; 17193 | template <typename T> struct is_ref { enum {result = 0}; }; 17194 | template <typename T> struct is_ref<T&> { enum {result = 1}; }; 17195 | template <typename T> struct is_ref<const T&> { enum {result = 0}; }; 17196 | 17197 | template <std::size_t State> 17198 | struct param_to_str { static std::string result() { static const std::string r("v"); return r; } }; 17199 | 17200 | template <> 17201 | struct param_to_str<0> { static std::string result() { static const std::string r("c"); return r; } }; 17202 | 17203 | #define exprtk_crtype(Type) \ 17204 | param_to_str<is_const_ref< Type >::result>::result() \ 17205 | 17206 | template <typename T> 17207 | struct T0oT1oT2process 17208 | { 17209 | typedef typename details::functor_t<T> functor_t; 17210 | typedef typename functor_t::bfunc_t bfunc_t; 17211 | 17212 | struct mode0 17213 | { 17214 | static inline T process(const T& t0, const T& t1, const T& t2, const bfunc_t bf0, const bfunc_t bf1) 17215 | { 17216 | // (T0 o0 T1) o1 T2 17217 | return bf1(bf0(t0,t1),t2); 17218 | } 17219 | 17220 | template <typename T0, typename T1, typename T2> 17221 | static inline std::string id() 17222 | { 17223 | static const std::string result = "(" + exprtk_crtype(T0) + "o" + 17224 | exprtk_crtype(T1) + ")o(" + 17225 | exprtk_crtype(T2) + ")" ; 17226 | return result; 17227 | } 17228 | }; 17229 | 17230 | struct mode1 17231 | { 17232 | static inline T process(const T& t0, const T& t1, const T& t2, const bfunc_t bf0, const bfunc_t bf1) 17233 | { 17234 | // T0 o0 (T1 o1 T2) 17235 | return bf0(t0,bf1(t1,t2)); 17236 | } 17237 | 17238 | template <typename T0, typename T1, typename T2> 17239 | static inline std::string id() 17240 | { 17241 | static const std::string result = "(" + exprtk_crtype(T0) + ")o(" + 17242 | exprtk_crtype(T1) + "o" + 17243 | exprtk_crtype(T2) + ")" ; 17244 | return result; 17245 | } 17246 | }; 17247 | }; 17248 | 17249 | template <typename T> 17250 | struct T0oT1oT20T3process 17251 | { 17252 | typedef typename details::functor_t<T> functor_t; 17253 | typedef typename functor_t::bfunc_t bfunc_t; 17254 | 17255 | struct mode0 17256 | { 17257 | static inline T process(const T& t0, const T& t1, 17258 | const T& t2, const T& t3, 17259 | const bfunc_t bf0, const bfunc_t bf1, const bfunc_t bf2) 17260 | { 17261 | // (T0 o0 T1) o1 (T2 o2 T3) 17262 | return bf1(bf0(t0,t1),bf2(t2,t3)); 17263 | } 17264 | 17265 | template <typename T0, typename T1, typename T2, typename T3> 17266 | static inline std::string id() 17267 | { 17268 | static const std::string result = "(" + exprtk_crtype(T0) + "o" + 17269 | exprtk_crtype(T1) + ")o" + 17270 | "(" + exprtk_crtype(T2) + "o" + 17271 | exprtk_crtype(T3) + ")" ; 17272 | return result; 17273 | } 17274 | }; 17275 | 17276 | struct mode1 17277 | { 17278 | static inline T process(const T& t0, const T& t1, 17279 | const T& t2, const T& t3, 17280 | const bfunc_t bf0, const bfunc_t bf1, const bfunc_t bf2) 17281 | { 17282 | // (T0 o0 (T1 o1 (T2 o2 T3)) 17283 | return bf0(t0,bf1(t1,bf2(t2,t3))); 17284 | } 17285 | template <typename T0, typename T1, typename T2, typename T3> 17286 | static inline std::string id() 17287 | { 17288 | static const std::string result = "(" + exprtk_crtype(T0) + ")o((" + 17289 | exprtk_crtype(T1) + ")o(" + 17290 | exprtk_crtype(T2) + "o" + 17291 | exprtk_crtype(T3) + "))" ; 17292 | return result; 17293 | } 17294 | }; 17295 | 17296 | struct mode2 17297 | { 17298 | static inline T process(const T& t0, const T& t1, 17299 | const T& t2, const T& t3, 17300 | const bfunc_t bf0, const bfunc_t bf1, const bfunc_t bf2) 17301 | { 17302 | // (T0 o0 ((T1 o1 T2) o2 T3) 17303 | return bf0(t0,bf2(bf1(t1,t2),t3)); 17304 | } 17305 | 17306 | template <typename T0, typename T1, typename T2, typename T3> 17307 | static inline std::string id() 17308 | { 17309 | static const std::string result = "(" + exprtk_crtype(T0) + ")o((" + 17310 | exprtk_crtype(T1) + "o" + 17311 | exprtk_crtype(T2) + ")o(" + 17312 | exprtk_crtype(T3) + "))" ; 17313 | return result; 17314 | } 17315 | }; 17316 | 17317 | struct mode3 17318 | { 17319 | static inline T process(const T& t0, const T& t1, 17320 | const T& t2, const T& t3, 17321 | const bfunc_t bf0, const bfunc_t bf1, const bfunc_t bf2) 17322 | { 17323 | // (((T0 o0 T1) o1 T2) o2 T3) 17324 | return bf2(bf1(bf0(t0,t1),t2),t3); 17325 | } 17326 | 17327 | template <typename T0, typename T1, typename T2, typename T3> 17328 | static inline std::string id() 17329 | { 17330 | static const std::string result = "((" + exprtk_crtype(T0) + "o" + 17331 | exprtk_crtype(T1) + ")o(" + 17332 | exprtk_crtype(T2) + "))o(" + 17333 | exprtk_crtype(T3) + ")" 17334 | return result; 17335 | } 17336 | }; 17337 | 17338 | struct mode4 17339 | { 17340 | static inline T process(const T& t0, const T& t1, 17341 | const T& t2, const T& t3, 17342 | const bfunc_t bf0, const bfunc_t bf1, const bfunc_t bf2) 17343 | { 17344 | // ((T0 o0 (T1 o1 T2)) o2 T3 17345 | return bf2(bf0(t0,bf1(t1,t2)),t3); 17346 | } 17347 | 17348 | template <typename T0, typename T1, typename T2, typename T3> 17349 | static inline std::string id() 17350 | { 17351 | static const std::string result = "((" + exprtk_crtype(T0) + ")o(" + 17352 | exprtk_crtype(T1) + "o" + 17353 | exprtk_crtype(T2) + "))o(" + 17354 | exprtk_crtype(T3) + ")" ; 17355 | return result; 17356 | } 17357 | }; 17358 | }; 17359 | 17360 | #undef exprtk_crtype 17361 | 17362 | template <typename T, typename T0, typename T1> 17363 | struct nodetype_T0oT1 { static const typename expression_node<T>::node_type result; }; 17364 | template <typename T, typename T0, typename T1> 17365 | const typename expression_node<T>::node_type nodetype_T0oT1<T,T0,T1>::result = expression_node<T>::e_none; 17366 | 17367 | #define synthesis_node_type_define(T0_, T1_, v_) \ 17368 | template <typename T, typename T0, typename T1> \ 17369 | struct nodetype_T0oT1<T,T0_,T1_> { static const typename expression_node<T>::node_type result; }; \ 17370 | template <typename T, typename T0, typename T1> \ 17371 | const typename expression_node<T>::node_type nodetype_T0oT1<T,T0_,T1_>::result = expression_node<T>:: v_; \ 17372 | 17373 | synthesis_node_type_define(const T0&, const T1&, e_vov) 17374 | synthesis_node_type_define(const T0&, const T1 , e_voc) 17375 | synthesis_node_type_define(const T0 , const T1&, e_cov) 17376 | synthesis_node_type_define( T0&, T1&, e_none) 17377 | synthesis_node_type_define(const T0 , const T1 , e_none) 17378 | synthesis_node_type_define( T0&, const T1 , e_none) 17379 | synthesis_node_type_define(const T0 , T1&, e_none) 17380 | synthesis_node_type_define(const T0&, T1&, e_none) 17381 | synthesis_node_type_define( T0&, const T1&, e_none) 17382 | #undef synthesis_node_type_define 17383 | 17384 | template <typename T, typename T0, typename T1, typename T2> 17385 | struct nodetype_T0oT1oT2 { static const typename expression_node<T>::node_type result; }; 17386 | template <typename T, typename T0, typename T1, typename T2> 17387 | const typename expression_node<T>::node_type nodetype_T0oT1oT2<T,T0,T1,T2>::result = expression_node<T>::e_none; 17388 | 17389 | #define synthesis_node_type_define(T0_, T1_, T2_, v_) \ 17390 | template <typename T, typename T0, typename T1, typename T2> \ 17391 | struct nodetype_T0oT1oT2<T,T0_,T1_,T2_> { static const typename expression_node<T>::node_type result; }; \ 17392 | template <typename T, typename T0, typename T1, typename T2> \ 17393 | const typename expression_node<T>::node_type nodetype_T0oT1oT2<T,T0_,T1_,T2_>::result = expression_node<T>:: v_; \ 17394 | 17395 | synthesis_node_type_define(const T0&, const T1&, const T2&, e_vovov) 17396 | synthesis_node_type_define(const T0&, const T1&, const T2 , e_vovoc) 17397 | synthesis_node_type_define(const T0&, const T1 , const T2&, e_vocov) 17398 | synthesis_node_type_define(const T0 , const T1&, const T2&, e_covov) 17399 | synthesis_node_type_define(const T0 , const T1&, const T2 , e_covoc) 17400 | synthesis_node_type_define(const T0 , const T1 , const T2 , e_none ) 17401 | synthesis_node_type_define(const T0 , const T1 , const T2&, e_none ) 17402 | synthesis_node_type_define(const T0&, const T1 , const T2 , e_none ) 17403 | synthesis_node_type_define( T0&, T1&, T2&, e_none ) 17404 | #undef synthesis_node_type_define 17405 | 17406 | template <typename T, typename T0, typename T1, typename T2, typename T3> 17407 | struct nodetype_T0oT1oT2oT3 { static const typename expression_node<T>::node_type result; }; 17408 | template <typename T, typename T0, typename T1, typename T2, typename T3> 17409 | const typename expression_node<T>::node_type nodetype_T0oT1oT2oT3<T,T0,T1,T2,T3>::result = expression_node<T>::e_none; 17410 | 17411 | #define synthesis_node_type_define(T0_, T1_, T2_, T3_, v_) \ 17412 | template <typename T, typename T0, typename T1, typename T2, typename T3> \ 17413 | struct nodetype_T0oT1oT2oT3<T,T0_,T1_,T2_,T3_> { static const typename expression_node<T>::node_type result; }; \ 17414 | template <typename T, typename T0, typename T1, typename T2, typename T3> \ 17415 | const typename expression_node<T>::node_type nodetype_T0oT1oT2oT3<T,T0_,T1_,T2_,T3_>::result = expression_node<T>:: v_; \ 17416 | 17417 | synthesis_node_type_define(const T0&, const T1&, const T2&, const T3&, e_vovovov) 17418 | synthesis_node_type_define(const T0&, const T1&, const T2&, const T3 , e_vovovoc) 17419 | synthesis_node_type_define(const T0&, const T1&, const T2 , const T3&, e_vovocov) 17420 | synthesis_node_type_define(const T0&, const T1 , const T2&, const T3&, e_vocovov) 17421 | synthesis_node_type_define(const T0 , const T1&, const T2&, const T3&, e_covovov) 17422 | synthesis_node_type_define(const T0 , const T1&, const T2 , const T3&, e_covocov) 17423 | synthesis_node_type_define(const T0&, const T1 , const T2&, const T3 , e_vocovoc) 17424 | synthesis_node_type_define(const T0 , const T1&, const T2&, const T3 , e_covovoc) 17425 | synthesis_node_type_define(const T0&, const T1 , const T2 , const T3&, e_vococov) 17426 | synthesis_node_type_define(const T0 , const T1 , const T2 , const T3 , e_none ) 17427 | synthesis_node_type_define(const T0 , const T1 , const T2 , const T3&, e_none ) 17428 | synthesis_node_type_define(const T0 , const T1 , const T2&, const T3 , e_none ) 17429 | synthesis_node_type_define(const T0 , const T1&, const T2 , const T3 , e_none ) 17430 | synthesis_node_type_define(const T0&, const T1 , const T2 , const T3 , e_none ) 17431 | synthesis_node_type_define(const T0 , const T1 , const T2&, const T3&, e_none ) 17432 | synthesis_node_type_define(const T0&, const T1&, const T2 , const T3 , e_none ) 17433 | #undef synthesis_node_type_define 17434 | 17435 | template <typename T, typename T0, typename T1> 17436 | class T0oT1 exprtk_final : public expression_node<T> 17437 | { 17438 | public: 17439 | 17440 | typedef typename details::functor_t<T> functor_t; 17441 | typedef typename functor_t::bfunc_t bfunc_t; 17442 | typedef T value_type; 17443 | typedef T0oT1<T,T0,T1> node_type; 17444 | 17445 | T0oT1(T0 p0, T1 p1, const bfunc_t p2) 17446 | : t0_(p0) 17447 | , t1_(p1) 17448 | , f_ (p2) 17449 | {} 17450 | 17451 | inline typename expression_node<T>::node_type type() const exprtk_override 17452 | { 17453 | static const typename expression_node<T>::node_type result = nodetype_T0oT1<T,T0,T1>::result; 17454 | return result; 17455 | } 17456 | 17457 | inline operator_type operation() const exprtk_override 17458 | { 17459 | return e_default; 17460 | } 17461 | 17462 | inline T value() const exprtk_override 17463 | { 17464 | return f_(t0_,t1_); 17465 | } 17466 | 17467 | inline T0 t0() const 17468 | { 17469 | return t0_; 17470 | } 17471 | 17472 | inline T1 t1() const 17473 | { 17474 | return t1_; 17475 | } 17476 | 17477 | inline bfunc_t f() const 17478 | { 17479 | return f_; 17480 | } 17481 | 17482 | template <typename Allocator> 17483 | static inline expression_node<T>* allocate(Allocator& allocator, 17484 | T0 p0, T1 p1, 17485 | bfunc_t p2) 17486 | { 17487 | return allocator 17488 | .template allocate_type<node_type, T0, T1, bfunc_t&> 17489 | (p0, p1, p2); 17490 | } 17491 | 17492 | private: 17493 | 17494 | T0oT1(const T0oT1<T,T0,T1>&) exprtk_delete; 17495 | T0oT1<T,T0,T1>& operator=(const T0oT1<T,T0,T1>&) { return (*this); } 17496 | 17497 | T0 t0_; 17498 | T1 t1_; 17499 | const bfunc_t f_; 17500 | }; 17501 | 17502 | template <typename T, typename T0, typename T1, typename T2, typename ProcessMode> 17503 | class T0oT1oT2 exprtk_final : public T0oT1oT2_base_node<T> 17504 | { 17505 | public: 17506 | 17507 | typedef typename details::functor_t<T> functor_t; 17508 | typedef typename functor_t::bfunc_t bfunc_t; 17509 | typedef T value_type; 17510 | typedef T0oT1oT2<T,T0,T1,T2,ProcessMode> node_type; 17511 | typedef ProcessMode process_mode_t; 17512 | 17513 | T0oT1oT2(T0 p0, T1 p1, T2 p2, const bfunc_t p3, const bfunc_t p4) 17514 | : t0_(p0) 17515 | , t1_(p1) 17516 | , t2_(p2) 17517 | , f0_(p3) 17518 | , f1_(p4) 17519 | {} 17520 | 17521 | inline typename expression_node<T>::node_type type() const exprtk_override 17522 | { 17523 | static const typename expression_node<T>::node_type result = nodetype_T0oT1oT2<T,T0,T1,T2>::result; 17524 | return result; 17525 | } 17526 | 17527 | inline operator_type operation() 17528 | { 17529 | return e_default; 17530 | } 17531 | 17532 | inline T value() const exprtk_override 17533 | { 17534 | return ProcessMode::process(t0_, t1_, t2_, f0_, f1_); 17535 | } 17536 | 17537 | inline T0 t0() const 17538 | { 17539 | return t0_; 17540 | } 17541 | 17542 | inline T1 t1() const 17543 | { 17544 | return t1_; 17545 | } 17546 | 17547 | inline T2 t2() const 17548 | { 17549 | return t2_; 17550 | } 17551 | 17552 | bfunc_t f0() const 17553 | { 17554 | return f0_; 17555 | } 17556 | 17557 | bfunc_t f1() const 17558 | { 17559 | return f1_; 17560 | } 17561 | 17562 | std::string type_id() const exprtk_override 17563 | { 17564 | return id(); 17565 | } 17566 | 17567 | static inline std::string id() 17568 | { 17569 | return process_mode_t::template id<T0,T1,T2>(); 17570 | } 17571 | 17572 | template <typename Allocator> 17573 | static inline expression_node<T>* allocate(Allocator& allocator, T0 p0, T1 p1, T2 p2, bfunc_t p3, bfunc_t p4) 17574 | { 17575 | return allocator 17576 | .template allocate_type<node_type, T0, T1, T2, bfunc_t, bfunc_t> 17577 | (p0, p1, p2, p3, p4); 17578 | } 17579 | 17580 | private: 17581 | 17582 | T0oT1oT2(const node_type&) exprtk_delete; 17583 | node_type& operator=(const node_type&) exprtk_delete; 17584 | 17585 | T0 t0_; 17586 | T1 t1_; 17587 | T2 t2_; 17588 | const bfunc_t f0_; 17589 | const bfunc_t f1_; 17590 | }; 17591 | 17592 | template <typename T, typename T0_, typename T1_, typename T2_, typename T3_, typename ProcessMode> 17593 | class T0oT1oT2oT3 exprtk_final : public T0oT1oT2oT3_base_node<T> 17594 | { 17595 | public: 17596 | 17597 | typedef typename details::functor_t<T> functor_t; 17598 | typedef typename functor_t::bfunc_t bfunc_t; 17599 | typedef T value_type; 17600 | typedef T0_ T0; 17601 | typedef T1_ T1; 17602 | typedef T2_ T2; 17603 | typedef T3_ T3; 17604 | typedef T0oT1oT2oT3<T,T0,T1,T2,T3,ProcessMode> node_type; 17605 | typedef ProcessMode process_mode_t; 17606 | 17607 | T0oT1oT2oT3(T0 p0, T1 p1, T2 p2, T3 p3, bfunc_t p4, bfunc_t p5, bfunc_t p6) 17608 | : t0_(p0) 17609 | , t1_(p1) 17610 | , t2_(p2) 17611 | , t3_(p3) 17612 | , f0_(p4) 17613 | , f1_(p5) 17614 | , f2_(p6) 17615 | {} 17616 | 17617 | inline T value() const exprtk_override 17618 | { 17619 | return ProcessMode::process(t0_, t1_, t2_, t3_, f0_, f1_, f2_); 17620 | } 17621 | 17622 | inline T0 t0() const 17623 | { 17624 | return t0_; 17625 | } 17626 | 17627 | inline T1 t1() const 17628 | { 17629 | return t1_; 17630 | } 17631 | 17632 | inline T2 t2() const 17633 | { 17634 | return t2_; 17635 | } 17636 | 17637 | inline T3 t3() const 17638 | { 17639 | return t3_; 17640 | } 17641 | 17642 | inline bfunc_t f0() const 17643 | { 17644 | return f0_; 17645 | } 17646 | 17647 | inline bfunc_t f1() const 17648 | { 17649 | return f1_; 17650 | } 17651 | 17652 | inline bfunc_t f2() const 17653 | { 17654 | return f2_; 17655 | } 17656 | 17657 | inline std::string type_id() const exprtk_override 17658 | { 17659 | return id(); 17660 | } 17661 | 17662 | static inline std::string id() 17663 | { 17664 | return process_mode_t::template id<T0, T1, T2, T3>(); 17665 | } 17666 | 17667 | template <typename Allocator> 17668 | static inline expression_node<T>* allocate(Allocator& allocator, 17669 | T0 p0, T1 p1, T2 p2, T3 p3, 17670 | bfunc_t p4, bfunc_t p5, bfunc_t p6) 17671 | { 17672 | return allocator 17673 | .template allocate_type<node_type, T0, T1, T2, T3, bfunc_t, bfunc_t> 17674 | (p0, p1, p2, p3, p4, p5, p6); 17675 | } 17676 | 17677 | private: 17678 | 17679 | T0oT1oT2oT3(const node_type&) exprtk_delete; 17680 | node_type& operator=(const node_type&) exprtk_delete; 17681 | 17682 | T0 t0_; 17683 | T1 t1_; 17684 | T2 t2_; 17685 | T3 t3_; 17686 | const bfunc_t f0_; 17687 | const bfunc_t f1_; 17688 | const bfunc_t f2_; 17689 | }; 17690 | 17691 | template <typename T, typename T0, typename T1, typename T2> 17692 | class T0oT1oT2_sf3 exprtk_final : public T0oT1oT2_base_node<T> 17693 | { 17694 | public: 17695 | 17696 | typedef typename details::functor_t<T> functor_t; 17697 | typedef typename functor_t::tfunc_t tfunc_t; 17698 | typedef T value_type; 17699 | typedef T0oT1oT2_sf3<T,T0,T1,T2> node_type; 17700 | 17701 | T0oT1oT2_sf3(T0 p0, T1 p1, T2 p2, const tfunc_t p3) 17702 | : t0_(p0) 17703 | , t1_(p1) 17704 | , t2_(p2) 17705 | , f_ (p3) 17706 | {} 17707 | 17708 | inline typename expression_node<T>::node_type type() const exprtk_override 17709 | { 17710 | static const typename expression_node<T>::node_type result = nodetype_T0oT1oT2<T,T0,T1,T2>::result; 17711 | return result; 17712 | } 17713 | 17714 | inline operator_type operation() const exprtk_override 17715 | { 17716 | return e_default; 17717 | } 17718 | 17719 | inline T value() const exprtk_override 17720 | { 17721 | return f_(t0_, t1_, t2_); 17722 | } 17723 | 17724 | inline T0 t0() const 17725 | { 17726 | return t0_; 17727 | } 17728 | 17729 | inline T1 t1() const 17730 | { 17731 | return t1_; 17732 | } 17733 | 17734 | inline T2 t2() const 17735 | { 17736 | return t2_; 17737 | } 17738 | 17739 | tfunc_t f() const 17740 | { 17741 | return f_; 17742 | } 17743 | 17744 | std::string type_id() const 17745 | { 17746 | return id(); 17747 | } 17748 | 17749 | static inline std::string id() 17750 | { 17751 | return "sf3" 17752 | } 17753 | 17754 | template <typename Allocator> 17755 | static inline expression_node<T>* allocate(Allocator& allocator, T0 p0, T1 p1, T2 p2, tfunc_t p3) 17756 | { 17757 | return allocator 17758 | .template allocate_type<node_type, T0, T1, T2, tfunc_t> 17759 | (p0, p1, p2, p3); 17760 | } 17761 | 17762 | private: 17763 | 17764 | T0oT1oT2_sf3(const node_type&) exprtk_delete; 17765 | node_type& operator=(const node_type&) exprtk_delete; 17766 | 17767 | T0 t0_; 17768 | T1 t1_; 17769 | T2 t2_; 17770 | const tfunc_t f_; 17771 | }; 17772 | 17773 | template <typename T, typename T0, typename T1, typename T2> 17774 | class sf3ext_type_node : public T0oT1oT2_base_node<T> 17775 | { 17776 | public: 17777 | 17778 | virtual ~sf3ext_type_node() 17779 | {} 17780 | 17781 | virtual T0 t0() const = 0; 17782 | 17783 | virtual T1 t1() const = 0; 17784 | 17785 | virtual T2 t2() const = 0; 17786 | }; 17787 | 17788 | template <typename T, typename T0, typename T1, typename T2, typename SF3Operation> 17789 | class T0oT1oT2_sf3ext exprtk_final : public sf3ext_type_node<T,T0,T1,T2> 17790 | { 17791 | public: 17792 | 17793 | typedef T value_type; 17794 | typedef T0oT1oT2_sf3ext<T, T0, T1, T2, SF3Operation> node_type; 17795 | 17796 | T0oT1oT2_sf3ext(T0 p0, T1 p1, T2 p2) 17797 | : t0_(p0) 17798 | , t1_(p1) 17799 | , t2_(p2) 17800 | {} 17801 | 17802 | inline typename expression_node<T>::node_type type() const exprtk_override 17803 | { 17804 | static const typename expression_node<T>::node_type result = nodetype_T0oT1oT2<T,T0,T1,T2>::result; 17805 | return result; 17806 | } 17807 | 17808 | inline operator_type operation() 17809 | { 17810 | return e_default; 17811 | } 17812 | 17813 | inline T value() const exprtk_override 17814 | { 17815 | return SF3Operation::process(t0_, t1_, t2_); 17816 | } 17817 | 17818 | T0 t0() const exprtk_override 17819 | { 17820 | return t0_; 17821 | } 17822 | 17823 | T1 t1() const exprtk_override 17824 | { 17825 | return t1_; 17826 | } 17827 | 17828 | T2 t2() const exprtk_override 17829 | { 17830 | return t2_; 17831 | } 17832 | 17833 | std::string type_id() const exprtk_override 17834 | { 17835 | return id(); 17836 | } 17837 | 17838 | static inline std::string id() 17839 | { 17840 | return SF3Operation::id(); 17841 | } 17842 | 17843 | template <typename Allocator> 17844 | static inline expression_node<T>* allocate(Allocator& allocator, T0 p0, T1 p1, T2 p2) 17845 | { 17846 | return allocator 17847 | .template allocate_type<node_type, T0, T1, T2> 17848 | (p0, p1, p2); 17849 | } 17850 | 17851 | private: 17852 | 17853 | T0oT1oT2_sf3ext(const node_type&) exprtk_delete; 17854 | node_type& operator=(const node_type&) exprtk_delete; 17855 | 17856 | T0 t0_; 17857 | T1 t1_; 17858 | T2 t2_; 17859 | }; 17860 | 17861 | template <typename T> 17862 | inline bool is_sf3ext_node(const expression_node<T>* n) 17863 | { 17864 | switch (n->type()) 17865 | { 17866 | case expression_node<T>::e_vovov : return true; 17867 | case expression_node<T>::e_vovoc : return true; 17868 | case expression_node<T>::e_vocov : return true; 17869 | case expression_node<T>::e_covov : return true; 17870 | case expression_node<T>::e_covoc : return true; 17871 | default : return false; 17872 | } 17873 | } 17874 | 17875 | template <typename T, typename T0, typename T1, typename T2, typename T3> 17876 | class T0oT1oT2oT3_sf4 exprtk_final : public T0oT1oT2_base_node<T> 17877 | { 17878 | public: 17879 | 17880 | typedef typename details::functor_t<T> functor_t; 17881 | typedef typename functor_t::qfunc_t qfunc_t; 17882 | typedef T value_type; 17883 | typedef T0oT1oT2oT3_sf4<T, T0, T1, T2, T3> node_type; 17884 | 17885 | T0oT1oT2oT3_sf4(T0 p0, T1 p1, T2 p2, T3 p3, const qfunc_t p4) 17886 | : t0_(p0) 17887 | , t1_(p1) 17888 | , t2_(p2) 17889 | , t3_(p3) 17890 | , f_ (p4) 17891 | {} 17892 | 17893 | inline typename expression_node<T>::node_type type() const exprtk_override 17894 | { 17895 | static const typename expression_node<T>::node_type result = nodetype_T0oT1oT2oT3<T,T0,T1,T2,T3>::result; 17896 | return result; 17897 | } 17898 | 17899 | inline operator_type operation() const exprtk_override 17900 | { 17901 | return e_default; 17902 | } 17903 | 17904 | inline T value() const exprtk_override 17905 | { 17906 | return f_(t0_, t1_, t2_, t3_); 17907 | } 17908 | 17909 | inline T0 t0() const 17910 | { 17911 | return t0_; 17912 | } 17913 | 17914 | inline T1 t1() const 17915 | { 17916 | return t1_; 17917 | } 17918 | 17919 | inline T2 t2() const 17920 | { 17921 | return t2_; 17922 | } 17923 | 17924 | inline T3 t3() const 17925 | { 17926 | return t3_; 17927 | } 17928 | 17929 | qfunc_t f() const 17930 | { 17931 | return f_; 17932 | } 17933 | 17934 | std::string type_id() const 17935 | { 17936 | return id(); 17937 | } 17938 | 17939 | static inline std::string id() 17940 | { 17941 | return "sf4" 17942 | } 17943 | 17944 | template <typename Allocator> 17945 | static inline expression_node<T>* allocate(Allocator& allocator, T0 p0, T1 p1, T2 p2, T3 p3, qfunc_t p4) 17946 | { 17947 | return allocator 17948 | .template allocate_type<node_type, T0, T1, T2, T3, qfunc_t> 17949 | (p0, p1, p2, p3, p4); 17950 | } 17951 | 17952 | private: 17953 | 17954 | T0oT1oT2oT3_sf4(const node_type&) exprtk_delete; 17955 | node_type& operator=(const node_type&) exprtk_delete; 17956 | 17957 | T0 t0_; 17958 | T1 t1_; 17959 | T2 t2_; 17960 | T3 t3_; 17961 | const qfunc_t f_; 17962 | }; 17963 | 17964 | template <typename T, typename T0, typename T1, typename T2, typename T3, typename SF4Operation> 17965 | class T0oT1oT2oT3_sf4ext exprtk_final : public T0oT1oT2oT3_base_node<T> 17966 | { 17967 | public: 17968 | 17969 | typedef T value_type; 17970 | typedef T0oT1oT2oT3_sf4ext<T, T0, T1, T2, T3, SF4Operation> node_type; 17971 | 17972 | T0oT1oT2oT3_sf4ext(T0 p0, T1 p1, T2 p2, T3 p3) 17973 | : t0_(p0) 17974 | , t1_(p1) 17975 | , t2_(p2) 17976 | , t3_(p3) 17977 | {} 17978 | 17979 | inline typename expression_node<T>::node_type type() const exprtk_override 17980 | { 17981 | static const typename expression_node<T>::node_type result = nodetype_T0oT1oT2oT3<T,T0,T1,T2,T3>::result; 17982 | return result; 17983 | } 17984 | 17985 | inline T value() const exprtk_override 17986 | { 17987 | return SF4Operation::process(t0_, t1_, t2_, t3_); 17988 | } 17989 | 17990 | inline T0 t0() const 17991 | { 17992 | return t0_; 17993 | } 17994 | 17995 | inline T1 t1() const 17996 | { 17997 | return t1_; 17998 | } 17999 | 18000 | inline T2 t2() const 18001 | { 18002 | return t2_; 18003 | } 18004 | 18005 | inline T3 t3() const 18006 | { 18007 | return t3_; 18008 | } 18009 | 18010 | std::string type_id() const exprtk_override 18011 | { 18012 | return id(); 18013 | } 18014 | 18015 | static inline std::string id() 18016 | { 18017 | return SF4Operation::id(); 18018 | } 18019 | 18020 | template <typename Allocator> 18021 | static inline expression_node<T>* allocate(Allocator& allocator, T0 p0, T1 p1, T2 p2, T3 p3) 18022 | { 18023 | return allocator 18024 | .template allocate_type<node_type, T0, T1, T2, T3> 18025 | (p0, p1, p2, p3); 18026 | } 18027 | 18028 | private: 18029 | 18030 | T0oT1oT2oT3_sf4ext(const node_type&) exprtk_delete; 18031 | node_type& operator=(const node_type&) exprtk_delete; 18032 | 18033 | T0 t0_; 18034 | T1 t1_; 18035 | T2 t2_; 18036 | T3 t3_; 18037 | }; 18038 | 18039 | template <typename T> 18040 | inline bool is_sf4ext_node(const expression_node<T>* n) 18041 | { 18042 | switch (n->type()) 18043 | { 18044 | case expression_node<T>::e_vovovov : return true; 18045 | case expression_node<T>::e_vovovoc : return true; 18046 | case expression_node<T>::e_vovocov : return true; 18047 | case expression_node<T>::e_vocovov : return true; 18048 | case expression_node<T>::e_covovov : return true; 18049 | case expression_node<T>::e_covocov : return true; 18050 | case expression_node<T>::e_vocovoc : return true; 18051 | case expression_node<T>::e_covovoc : return true; 18052 | case expression_node<T>::e_vococov : return true; 18053 | default : return false; 18054 | } 18055 | } 18056 | 18057 | template <typename T, typename T0, typename T1> 18058 | struct T0oT1_define 18059 | { 18060 | typedef details::T0oT1<T, T0, T1> type0; 18061 | }; 18062 | 18063 | template <typename T, typename T0, typename T1, typename T2> 18064 | struct T0oT1oT2_define 18065 | { 18066 | typedef details::T0oT1oT2<T, T0, T1, T2, typename T0oT1oT2process<T>::mode0> type0; 18067 | typedef details::T0oT1oT2<T, T0, T1, T2, typename T0oT1oT2process<T>::mode1> type1; 18068 | typedef details::T0oT1oT2_sf3<T, T0, T1, T2> sf3_type; 18069 | typedef details::sf3ext_type_node<T, T0, T1, T2> sf3_type_node; 18070 | }; 18071 | 18072 | template <typename T, typename T0, typename T1, typename T2, typename T3> 18073 | struct T0oT1oT2oT3_define 18074 | { 18075 | typedef details::T0oT1oT2oT3<T, T0, T1, T2, T3, typename T0oT1oT20T3process<T>::mode0> type0; 18076 | typedef details::T0oT1oT2oT3<T, T0, T1, T2, T3, typename T0oT1oT20T3process<T>::mode1> type1; 18077 | typedef details::T0oT1oT2oT3<T, T0, T1, T2, T3, typename T0oT1oT20T3process<T>::mode2> type2; 18078 | typedef details::T0oT1oT2oT3<T, T0, T1, T2, T3, typename T0oT1oT20T3process<T>::mode3> type3; 18079 | typedef details::T0oT1oT2oT3<T, T0, T1, T2, T3, typename T0oT1oT20T3process<T>::mode4> type4; 18080 | typedef details::T0oT1oT2oT3_sf4<T, T0, T1, T2, T3> sf4_type; 18081 | }; 18082 | 18083 | template <typename T, typename Operation> 18084 | class vov_node exprtk_final : public vov_base_node<T> 18085 | { 18086 | public: 18087 | 18088 | typedef expression_node<T>* expression_ptr; 18089 | typedef Operation operation_t; 18090 | 18091 | // variable op variable node 18092 | explicit vov_node(const T& var0, const T& var1) 18093 | : v0_(var0) 18094 | , v1_(var1) 18095 | {} 18096 | 18097 | inline T value() const exprtk_override 18098 | { 18099 | return Operation::process(v0_,v1_); 18100 | } 18101 | 18102 | inline typename expression_node<T>::node_type type() const exprtk_override 18103 | { 18104 | return Operation::type(); 18105 | } 18106 | 18107 | inline operator_type operation() const exprtk_override 18108 | { 18109 | return Operation::operation(); 18110 | } 18111 | 18112 | inline const T& v0() const exprtk_override 18113 | { 18114 | return v0_; 18115 | } 18116 | 18117 | inline const T& v1() const exprtk_override 18118 | { 18119 | return v1_; 18120 | } 18121 | 18122 | protected: 18123 | 18124 | const T& v0_; 18125 | const T& v1_; 18126 | 18127 | private: 18128 | 18129 | vov_node(const vov_node<T,Operation>&) exprtk_delete; 18130 | vov_node<T,Operation>& operator=(const vov_node<T,Operation>&) exprtk_delete; 18131 | }; 18132 | 18133 | template <typename T, typename Operation> 18134 | class cov_node exprtk_final : public cov_base_node<T> 18135 | { 18136 | public: 18137 | 18138 | typedef expression_node<T>* expression_ptr; 18139 | typedef Operation operation_t; 18140 | 18141 | // constant op variable node 18142 | explicit cov_node(const T& const_var, const T& var) 18143 | : c_(const_var) 18144 | , v_(var) 18145 | {} 18146 | 18147 | inline T value() const exprtk_override 18148 | { 18149 | return Operation::process(c_,v_); 18150 | } 18151 | 18152 | inline typename expression_node<T>::node_type type() const exprtk_override 18153 | { 18154 | return Operation::type(); 18155 | } 18156 | 18157 | inline operator_type operation() const exprtk_override 18158 | { 18159 | return Operation::operation(); 18160 | } 18161 | 18162 | inline const T c() const exprtk_override 18163 | { 18164 | return c_; 18165 | } 18166 | 18167 | inline const T& v() const exprtk_override 18168 | { 18169 | return v_; 18170 | } 18171 | 18172 | protected: 18173 | 18174 | const T c_; 18175 | const T& v_; 18176 | 18177 | private: 18178 | 18179 | cov_node(const cov_node<T,Operation>&) exprtk_delete; 18180 | cov_node<T,Operation>& operator=(const cov_node<T,Operation>&) exprtk_delete; 18181 | }; 18182 | 18183 | template <typename T, typename Operation> 18184 | class voc_node exprtk_final : public voc_base_node<T> 18185 | { 18186 | public: 18187 | 18188 | typedef expression_node<T>* expression_ptr; 18189 | typedef Operation operation_t; 18190 | 18191 | // variable op constant node 18192 | explicit voc_node(const T& var, const T& const_var) 18193 | : v_(var) 18194 | , c_(const_var) 18195 | {} 18196 | 18197 | inline T value() const exprtk_override 18198 | { 18199 | return Operation::process(v_,c_); 18200 | } 18201 | 18202 | inline operator_type operation() const exprtk_override 18203 | { 18204 | return Operation::operation(); 18205 | } 18206 | 18207 | inline const T c() const exprtk_override 18208 | { 18209 | return c_; 18210 | } 18211 | 18212 | inline const T& v() const exprtk_override 18213 | { 18214 | return v_; 18215 | } 18216 | 18217 | protected: 18218 | 18219 | const T& v_; 18220 | const T c_; 18221 | 18222 | private: 18223 | 18224 | voc_node(const voc_node<T,Operation>&) exprtk_delete; 18225 | voc_node<T,Operation>& operator=(const voc_node<T,Operation>&) exprtk_delete; 18226 | }; 18227 | 18228 | template <typename T, typename Operation> 18229 | class vob_node exprtk_final : public vob_base_node<T> 18230 | { 18231 | public: 18232 | 18233 | typedef expression_node<T>* expression_ptr; 18234 | typedef std::pair<expression_ptr,bool> branch_t; 18235 | typedef Operation operation_t; 18236 | 18237 | // variable op binary node 18238 | explicit vob_node(const T& var, const expression_ptr branch) 18239 | : v_(var) 18240 | { 18241 | construct_branch_pair(branch_, branch); 18242 | assert(valid()); 18243 | } 18244 | 18245 | inline T value() const exprtk_override 18246 | { 18247 | return Operation::process(v_,branch_.first->value()); 18248 | } 18249 | 18250 | inline const T& v() const exprtk_override 18251 | { 18252 | return v_; 18253 | } 18254 | 18255 | inline bool valid() const exprtk_override 18256 | { 18257 | return branch_.first && branch_.first->valid(); 18258 | } 18259 | 18260 | inline expression_node<T>* branch(const std::size_t&) const exprtk_override 18261 | { 18262 | return branch_.first; 18263 | } 18264 | 18265 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 18266 | { 18267 | expression_node<T>::ndb_t::collect(branch_, node_delete_list); 18268 | } 18269 | 18270 | std::size_t node_depth() const exprtk_override 18271 | { 18272 | return expression_node<T>::ndb_t::compute_node_depth(branch_); 18273 | } 18274 | 18275 | private: 18276 | 18277 | vob_node(const vob_node<T,Operation>&) exprtk_delete; 18278 | vob_node<T,Operation>& operator=(const vob_node<T,Operation>&) exprtk_delete; 18279 | 18280 | const T& v_; 18281 | branch_t branch_; 18282 | }; 18283 | 18284 | template <typename T, typename Operation> 18285 | class bov_node exprtk_final : public bov_base_node<T> 18286 | { 18287 | public: 18288 | 18289 | typedef expression_node<T>* expression_ptr; 18290 | typedef std::pair<expression_ptr,bool> branch_t; 18291 | typedef Operation operation_t; 18292 | 18293 | // binary node op variable node 18294 | explicit bov_node(const expression_ptr branch, const T& var) 18295 | : v_(var) 18296 | { 18297 | construct_branch_pair(branch_, branch); 18298 | assert(valid()); 18299 | } 18300 | 18301 | inline T value() const exprtk_override 18302 | { 18303 | return Operation::process(branch_.first->value(),v_); 18304 | } 18305 | 18306 | inline const T& v() const exprtk_override 18307 | { 18308 | return v_; 18309 | } 18310 | 18311 | inline bool valid() const exprtk_override 18312 | { 18313 | return branch_.first && branch_.first->valid(); 18314 | } 18315 | 18316 | inline expression_node<T>* branch(const std::size_t&) const exprtk_override 18317 | { 18318 | return branch_.first; 18319 | } 18320 | 18321 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 18322 | { 18323 | expression_node<T>::ndb_t::collect(branch_, node_delete_list); 18324 | } 18325 | 18326 | std::size_t node_depth() const exprtk_override 18327 | { 18328 | return expression_node<T>::ndb_t::compute_node_depth(branch_); 18329 | } 18330 | 18331 | private: 18332 | 18333 | bov_node(const bov_node<T,Operation>&) exprtk_delete; 18334 | bov_node<T,Operation>& operator=(const bov_node<T,Operation>&) exprtk_delete; 18335 | 18336 | const T& v_; 18337 | branch_t branch_; 18338 | }; 18339 | 18340 | template <typename T, typename Operation> 18341 | class cob_node exprtk_final : public cob_base_node<T> 18342 | { 18343 | public: 18344 | 18345 | typedef expression_node<T>* expression_ptr; 18346 | typedef std::pair<expression_ptr,bool> branch_t; 18347 | typedef Operation operation_t; 18348 | 18349 | // constant op variable node 18350 | explicit cob_node(const T const_var, const expression_ptr branch) 18351 | : c_(const_var) 18352 | { 18353 | construct_branch_pair(branch_, branch); 18354 | assert(valid()); 18355 | } 18356 | 18357 | inline T value() const exprtk_override 18358 | { 18359 | return Operation::process(c_,branch_.first->value()); 18360 | } 18361 | 18362 | inline operator_type operation() const exprtk_override 18363 | { 18364 | return Operation::operation(); 18365 | } 18366 | 18367 | inline const T c() const exprtk_override 18368 | { 18369 | return c_; 18370 | } 18371 | 18372 | inline void set_c(const T new_c) exprtk_override 18373 | { 18374 | (*const_cast<T*>(&c_)) = new_c; 18375 | } 18376 | 18377 | inline bool valid() const exprtk_override 18378 | { 18379 | return branch_.first && branch_.first->valid(); 18380 | } 18381 | 18382 | inline expression_node<T>* branch(const std::size_t&) const exprtk_override 18383 | { 18384 | return branch_.first; 18385 | } 18386 | 18387 | inline expression_node<T>* move_branch(const std::size_t&) exprtk_override 18388 | { 18389 | branch_.second = false; 18390 | return branch_.first; 18391 | } 18392 | 18393 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 18394 | { 18395 | expression_node<T>::ndb_t::collect(branch_, node_delete_list); 18396 | } 18397 | 18398 | std::size_t node_depth() const exprtk_override 18399 | { 18400 | return expression_node<T>::ndb_t::compute_node_depth(branch_); 18401 | } 18402 | 18403 | private: 18404 | 18405 | cob_node(const cob_node<T,Operation>&) exprtk_delete; 18406 | cob_node<T,Operation>& operator=(const cob_node<T,Operation>&) exprtk_delete; 18407 | 18408 | const T c_; 18409 | branch_t branch_; 18410 | }; 18411 | 18412 | template <typename T, typename Operation> 18413 | class boc_node exprtk_final : public boc_base_node<T> 18414 | { 18415 | public: 18416 | 18417 | typedef expression_node<T>* expression_ptr; 18418 | typedef std::pair<expression_ptr,bool> branch_t; 18419 | typedef Operation operation_t; 18420 | 18421 | // binary node op constant node 18422 | explicit boc_node(const expression_ptr branch, const T const_var) 18423 | : c_(const_var) 18424 | { 18425 | construct_branch_pair(branch_, branch); 18426 | assert(valid()); 18427 | } 18428 | 18429 | inline T value() const exprtk_override 18430 | { 18431 | return Operation::process(branch_.first->value(),c_); 18432 | } 18433 | 18434 | inline operator_type operation() const exprtk_override 18435 | { 18436 | return Operation::operation(); 18437 | } 18438 | 18439 | inline const T c() const exprtk_override 18440 | { 18441 | return c_; 18442 | } 18443 | 18444 | inline void set_c(const T new_c) exprtk_override 18445 | { 18446 | (*const_cast<T*>(&c_)) = new_c; 18447 | } 18448 | 18449 | inline bool valid() const exprtk_override 18450 | { 18451 | return branch_.first && branch_.first->valid(); 18452 | } 18453 | 18454 | inline expression_node<T>* branch(const std::size_t&) const exprtk_override 18455 | { 18456 | return branch_.first; 18457 | } 18458 | 18459 | inline expression_node<T>* move_branch(const std::size_t&) exprtk_override 18460 | { 18461 | branch_.second = false; 18462 | return branch_.first; 18463 | } 18464 | 18465 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 18466 | { 18467 | expression_node<T>::ndb_t::collect(branch_, node_delete_list); 18468 | } 18469 | 18470 | std::size_t node_depth() const exprtk_override 18471 | { 18472 | return expression_node<T>::ndb_t::compute_node_depth(branch_); 18473 | } 18474 | 18475 | private: 18476 | 18477 | boc_node(const boc_node<T,Operation>&) exprtk_delete; 18478 | boc_node<T,Operation>& operator=(const boc_node<T,Operation>&) exprtk_delete; 18479 | 18480 | const T c_; 18481 | branch_t branch_; 18482 | }; 18483 | 18484 | #ifndef exprtk_disable_string_capabilities 18485 | template <typename T, typename SType0, typename SType1, typename Operation> 18486 | class sos_node exprtk_final : public sos_base_node<T> 18487 | { 18488 | public: 18489 | 18490 | typedef expression_node<T>* expression_ptr; 18491 | typedef Operation operation_t; 18492 | 18493 | // string op string node 18494 | explicit sos_node(SType0 p0, SType1 p1) 18495 | : s0_(p0) 18496 | , s1_(p1) 18497 | {} 18498 | 18499 | inline T value() const exprtk_override 18500 | { 18501 | return Operation::process(s0_,s1_); 18502 | } 18503 | 18504 | inline typename expression_node<T>::node_type type() const exprtk_override 18505 | { 18506 | return Operation::type(); 18507 | } 18508 | 18509 | inline operator_type operation() const exprtk_override 18510 | { 18511 | return Operation::operation(); 18512 | } 18513 | 18514 | inline std::string& s0() 18515 | { 18516 | return s0_; 18517 | } 18518 | 18519 | inline std::string& s1() 18520 | { 18521 | return s1_; 18522 | } 18523 | 18524 | protected: 18525 | 18526 | SType0 s0_; 18527 | SType1 s1_; 18528 | 18529 | private: 18530 | 18531 | sos_node(const sos_node<T,SType0,SType1,Operation>&) exprtk_delete; 18532 | sos_node<T,SType0,SType1,Operation>& operator=(const sos_node<T,SType0,SType1,Operation>&) exprtk_delete; 18533 | }; 18534 | 18535 | template <typename T, typename SType0, typename SType1, typename RangePack, typename Operation> 18536 | class str_xrox_node exprtk_final : public sos_base_node<T> 18537 | { 18538 | public: 18539 | 18540 | typedef expression_node<T>* expression_ptr; 18541 | typedef Operation operation_t; 18542 | typedef str_xrox_node<T,SType0,SType1,RangePack,Operation> node_type; 18543 | 18544 | // string-range op string node 18545 | explicit str_xrox_node(SType0 p0, SType1 p1, RangePack rp0) 18546 | : s0_ (p0 ) 18547 | , s1_ (p1 ) 18548 | , rp0_(rp0) 18549 | {} 18550 | 18551 | ~str_xrox_node() exprtk_override 18552 | { 18553 | rp0_.free(); 18554 | } 18555 | 18556 | inline T value() const exprtk_override 18557 | { 18558 | std::size_t r0 = 0; 18559 | std::size_t r1 = 0; 18560 | 18561 | if (rp0_(r0, r1, s0_.size())) 18562 | return Operation::process(s0_.substr(r0, (r1 - r0) + 1), s1_); 18563 | else 18564 | return T(0); 18565 | } 18566 | 18567 | inline typename expression_node<T>::node_type type() const exprtk_override 18568 | { 18569 | return Operation::type(); 18570 | } 18571 | 18572 | inline operator_type operation() const exprtk_override 18573 | { 18574 | return Operation::operation(); 18575 | } 18576 | 18577 | inline std::string& s0() 18578 | { 18579 | return s0_; 18580 | } 18581 | 18582 | inline std::string& s1() 18583 | { 18584 | return s1_; 18585 | } 18586 | 18587 | protected: 18588 | 18589 | SType0 s0_; 18590 | SType1 s1_; 18591 | RangePack rp0_; 18592 | 18593 | private: 18594 | 18595 | str_xrox_node(const node_type&) exprtk_delete; 18596 | node_type& operator=(const node_type&) exprtk_delete; 18597 | }; 18598 | 18599 | template <typename T, typename SType0, typename SType1, typename RangePack, typename Operation> 18600 | class str_xoxr_node exprtk_final : public sos_base_node<T> 18601 | { 18602 | public: 18603 | 18604 | typedef expression_node<T>* expression_ptr; 18605 | typedef Operation operation_t; 18606 | typedef str_xoxr_node<T,SType0,SType1,RangePack,Operation> node_type; 18607 | 18608 | // string op string range node 18609 | explicit str_xoxr_node(SType0 p0, SType1 p1, RangePack rp1) 18610 | : s0_ (p0 ) 18611 | , s1_ (p1 ) 18612 | , rp1_(rp1) 18613 | {} 18614 | 18615 | ~str_xoxr_node() 18616 | { 18617 | rp1_.free(); 18618 | } 18619 | 18620 | inline T value() const exprtk_override 18621 | { 18622 | std::size_t r0 = 0; 18623 | std::size_t r1 = 0; 18624 | 18625 | if (rp1_(r0, r1, s1_.size())) 18626 | { 18627 | return Operation::process 18628 | ( 18629 | s0_, 18630 | s1_.substr(r0, (r1 - r0) + 1) 18631 | ); 18632 | } 18633 | else 18634 | return T(0); 18635 | } 18636 | 18637 | inline typename expression_node<T>::node_type type() const exprtk_override 18638 | { 18639 | return Operation::type(); 18640 | } 18641 | 18642 | inline operator_type operation() const exprtk_override 18643 | { 18644 | return Operation::operation(); 18645 | } 18646 | 18647 | inline std::string& s0() 18648 | { 18649 | return s0_; 18650 | } 18651 | 18652 | inline std::string& s1() 18653 | { 18654 | return s1_; 18655 | } 18656 | 18657 | protected: 18658 | 18659 | SType0 s0_; 18660 | SType1 s1_; 18661 | RangePack rp1_; 18662 | 18663 | private: 18664 | 18665 | str_xoxr_node(const node_type&) exprtk_delete; 18666 | node_type& operator=(const node_type&) exprtk_delete; 18667 | }; 18668 | 18669 | template <typename T, typename SType0, typename SType1, typename RangePack, typename Operation> 18670 | class str_xroxr_node exprtk_final : public sos_base_node<T> 18671 | { 18672 | public: 18673 | 18674 | typedef expression_node<T>* expression_ptr; 18675 | typedef Operation operation_t; 18676 | typedef str_xroxr_node<T,SType0,SType1,RangePack,Operation> node_type; 18677 | 18678 | // string-range op string-range node 18679 | explicit str_xroxr_node(SType0 p0, SType1 p1, RangePack rp0, RangePack rp1) 18680 | : s0_ (p0 ) 18681 | , s1_ (p1 ) 18682 | , rp0_(rp0) 18683 | , rp1_(rp1) 18684 | {} 18685 | 18686 | ~str_xroxr_node() exprtk_override 18687 | { 18688 | rp0_.free(); 18689 | rp1_.free(); 18690 | } 18691 | 18692 | inline T value() const exprtk_override 18693 | { 18694 | std::size_t r0_0 = 0; 18695 | std::size_t r0_1 = 0; 18696 | std::size_t r1_0 = 0; 18697 | std::size_t r1_1 = 0; 18698 | 18699 | if ( 18700 | rp0_(r0_0, r1_0, s0_.size()) && 18701 | rp1_(r0_1, r1_1, s1_.size()) 18702 | ) 18703 | { 18704 | return Operation::process 18705 | ( 18706 | s0_.substr(r0_0, (r1_0 - r0_0) + 1), 18707 | s1_.substr(r0_1, (r1_1 - r0_1) + 1) 18708 | ); 18709 | } 18710 | else 18711 | return T(0); 18712 | } 18713 | 18714 | inline typename expression_node<T>::node_type type() const exprtk_override 18715 | { 18716 | return Operation::type(); 18717 | } 18718 | 18719 | inline operator_type operation() const exprtk_override 18720 | { 18721 | return Operation::operation(); 18722 | } 18723 | 18724 | inline std::string& s0() 18725 | { 18726 | return s0_; 18727 | } 18728 | 18729 | inline std::string& s1() 18730 | { 18731 | return s1_; 18732 | } 18733 | 18734 | protected: 18735 | 18736 | SType0 s0_; 18737 | SType1 s1_; 18738 | RangePack rp0_; 18739 | RangePack rp1_; 18740 | 18741 | private: 18742 | 18743 | str_xroxr_node(const node_type&) exprtk_delete; 18744 | node_type& operator=(const node_type&) exprtk_delete; 18745 | }; 18746 | 18747 | template <typename T, typename Operation> 18748 | class str_sogens_node exprtk_final : public binary_node<T> 18749 | { 18750 | public: 18751 | 18752 | typedef expression_node <T>* expression_ptr; 18753 | typedef string_base_node<T>* str_base_ptr; 18754 | typedef range_pack <T> range_t; 18755 | typedef range_t* range_ptr; 18756 | typedef range_interface <T> irange_t; 18757 | typedef irange_t* irange_ptr; 18758 | 18759 | using binary_node<T>::branch; 18760 | 18761 | str_sogens_node(const operator_type& opr, 18762 | expression_ptr branch0, 18763 | expression_ptr branch1) 18764 | : binary_node<T>(opr, branch0, branch1) 18765 | , str0_base_ptr_ (0) 18766 | , str1_base_ptr_ (0) 18767 | , str0_range_ptr_(0) 18768 | , str1_range_ptr_(0) 18769 | , initialised_ (false) 18770 | { 18771 | if (is_generally_string_node(branch(0))) 18772 | { 18773 | str0_base_ptr_ = dynamic_cast<str_base_ptr>(branch(0)); 18774 | 18775 | if (0 == str0_base_ptr_) 18776 | return; 18777 | 18778 | irange_ptr range = dynamic_cast<irange_ptr>(branch(0)); 18779 | 18780 | if (0 == range) 18781 | return; 18782 | 18783 | str0_range_ptr_ = &(range->range_ref()); 18784 | } 18785 | 18786 | if (is_generally_string_node(branch(1))) 18787 | { 18788 | str1_base_ptr_ = dynamic_cast<str_base_ptr>(branch(1)); 18789 | 18790 | if (0 == str1_base_ptr_) 18791 | return; 18792 | 18793 | irange_ptr range = dynamic_cast<irange_ptr>(branch(1)); 18794 | 18795 | if (0 == range) 18796 | return; 18797 | 18798 | str1_range_ptr_ = &(range->range_ref()); 18799 | } 18800 | 18801 | initialised_ = 18802 | str0_base_ptr_ && 18803 | str1_base_ptr_ && 18804 | str0_range_ptr_ && 18805 | str1_range_ptr_; 18806 | 18807 | assert(valid()); 18808 | } 18809 | 18810 | inline T value() const exprtk_override 18811 | { 18812 | branch(0)->value(); 18813 | branch(1)->value(); 18814 | 18815 | std::size_t str0_r0 = 0; 18816 | std::size_t str0_r1 = 0; 18817 | 18818 | std::size_t str1_r0 = 0; 18819 | std::size_t str1_r1 = 0; 18820 | 18821 | const range_t& range0 = (*str0_range_ptr_); 18822 | const range_t& range1 = (*str1_range_ptr_); 18823 | 18824 | if ( 18825 | range0(str0_r0, str0_r1, str0_base_ptr_->size()) && 18826 | range1(str1_r0, str1_r1, str1_base_ptr_->size()) 18827 | ) 18828 | { 18829 | return Operation::process 18830 | ( 18831 | str0_base_ptr_->str().substr(str0_r0,(str0_r1 - str0_r0)), 18832 | str1_base_ptr_->str().substr(str1_r0,(str1_r1 - str1_r0)) 18833 | ); 18834 | } 18835 | 18836 | return std::numeric_limits<T>::quiet_NaN(); 18837 | } 18838 | 18839 | inline typename expression_node<T>::node_type type() const exprtk_override 18840 | { 18841 | return Operation::type(); 18842 | } 18843 | 18844 | inline bool valid() const exprtk_override 18845 | { 18846 | return initialised_; 18847 | } 18848 | 18849 | private: 18850 | 18851 | str_sogens_node(const str_sogens_node<T,Operation>&) exprtk_delete; 18852 | str_sogens_node<T,Operation>& operator=(const str_sogens_node<T,Operation>&) exprtk_delete; 18853 | 18854 | str_base_ptr str0_base_ptr_; 18855 | str_base_ptr str1_base_ptr_; 18856 | range_ptr str0_range_ptr_; 18857 | range_ptr str1_range_ptr_; 18858 | bool initialised_; 18859 | }; 18860 | 18861 | template <typename T, typename SType0, typename SType1, typename SType2, typename Operation> 18862 | class sosos_node exprtk_final : public sosos_base_node<T> 18863 | { 18864 | public: 18865 | 18866 | typedef expression_node<T>* expression_ptr; 18867 | typedef Operation operation_t; 18868 | typedef sosos_node<T, SType0, SType1, SType2, Operation> node_type; 18869 | 18870 | // string op string op string node 18871 | explicit sosos_node(SType0 p0, SType1 p1, SType2 p2) 18872 | : s0_(p0) 18873 | , s1_(p1) 18874 | , s2_(p2) 18875 | {} 18876 | 18877 | inline T value() const exprtk_override 18878 | { 18879 | return Operation::process(s0_, s1_, s2_); 18880 | } 18881 | 18882 | inline typename expression_node<T>::node_type type() const exprtk_override 18883 | { 18884 | return Operation::type(); 18885 | } 18886 | 18887 | inline operator_type operation() const exprtk_override 18888 | { 18889 | return Operation::operation(); 18890 | } 18891 | 18892 | inline std::string& s0() 18893 | { 18894 | return s0_; 18895 | } 18896 | 18897 | inline std::string& s1() 18898 | { 18899 | return s1_; 18900 | } 18901 | 18902 | inline std::string& s2() 18903 | { 18904 | return s2_; 18905 | } 18906 | 18907 | protected: 18908 | 18909 | SType0 s0_; 18910 | SType1 s1_; 18911 | SType2 s2_; 18912 | 18913 | private: 18914 | 18915 | sosos_node(const node_type&) exprtk_delete; 18916 | node_type& operator=(const node_type&) exprtk_delete; 18917 | }; 18918 | #endif 18919 | 18920 | template <typename T, typename PowOp> 18921 | class ipow_node exprtk_final: public expression_node<T> 18922 | { 18923 | public: 18924 | 18925 | typedef expression_node<T>* expression_ptr; 18926 | typedef PowOp operation_t; 18927 | 18928 | explicit ipow_node(const T& v) 18929 | : v_(v) 18930 | {} 18931 | 18932 | inline T value() const exprtk_override 18933 | { 18934 | return PowOp::result(v_); 18935 | } 18936 | 18937 | inline typename expression_node<T>::node_type type() const exprtk_override 18938 | { 18939 | return expression_node<T>::e_ipow; 18940 | } 18941 | 18942 | private: 18943 | 18944 | ipow_node(const ipow_node<T,PowOp>&) exprtk_delete; 18945 | ipow_node<T,PowOp>& operator=(const ipow_node<T,PowOp>&) exprtk_delete; 18946 | 18947 | const T& v_; 18948 | }; 18949 | 18950 | template <typename T, typename PowOp> 18951 | class bipow_node exprtk_final : public expression_node<T> 18952 | { 18953 | public: 18954 | 18955 | typedef expression_node<T>* expression_ptr; 18956 | typedef std::pair<expression_ptr, bool> branch_t; 18957 | typedef PowOp operation_t; 18958 | 18959 | explicit bipow_node(expression_ptr branch) 18960 | { 18961 | construct_branch_pair(branch_, branch); 18962 | assert(valid()); 18963 | } 18964 | 18965 | inline T value() const exprtk_override 18966 | { 18967 | return PowOp::result(branch_.first->value()); 18968 | } 18969 | 18970 | inline typename expression_node<T>::node_type type() const exprtk_override 18971 | { 18972 | return expression_node<T>::e_ipow; 18973 | } 18974 | 18975 | inline bool valid() const exprtk_override 18976 | { 18977 | return branch_.first && branch_.first->valid(); 18978 | } 18979 | 18980 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 18981 | { 18982 | expression_node<T>::ndb_t::collect(branch_, node_delete_list); 18983 | } 18984 | 18985 | std::size_t node_depth() const exprtk_override 18986 | { 18987 | return expression_node<T>::ndb_t::compute_node_depth(branch_); 18988 | } 18989 | 18990 | private: 18991 | 18992 | bipow_node(const bipow_node<T,PowOp>&) exprtk_delete; 18993 | bipow_node<T,PowOp>& operator=(const bipow_node<T,PowOp>&) exprtk_delete; 18994 | 18995 | branch_t branch_; 18996 | }; 18997 | 18998 | template <typename T, typename PowOp> 18999 | class ipowinv_node exprtk_final : public expression_node<T> 19000 | { 19001 | public: 19002 | 19003 | typedef expression_node<T>* expression_ptr; 19004 | typedef PowOp operation_t; 19005 | 19006 | explicit ipowinv_node(const T& v) 19007 | : v_(v) 19008 | {} 19009 | 19010 | inline T value() const exprtk_override 19011 | { 19012 | return (T(1) / PowOp::result(v_)); 19013 | } 19014 | 19015 | inline typename expression_node<T>::node_type type() const exprtk_override 19016 | { 19017 | return expression_node<T>::e_ipowinv; 19018 | } 19019 | 19020 | private: 19021 | 19022 | ipowinv_node(const ipowinv_node<T,PowOp>&) exprtk_delete; 19023 | ipowinv_node<T,PowOp>& operator=(const ipowinv_node<T,PowOp>&) exprtk_delete; 19024 | 19025 | const T& v_; 19026 | }; 19027 | 19028 | template <typename T, typename PowOp> 19029 | class bipowinv_node exprtk_final : public expression_node<T> 19030 | { 19031 | public: 19032 | 19033 | typedef expression_node<T>* expression_ptr; 19034 | typedef std::pair<expression_ptr, bool> branch_t; 19035 | typedef PowOp operation_t; 19036 | 19037 | explicit bipowinv_node(expression_ptr branch) 19038 | { 19039 | construct_branch_pair(branch_, branch); 19040 | assert(valid()); 19041 | } 19042 | 19043 | inline T value() const exprtk_override 19044 | { 19045 | return (T(1) / PowOp::result(branch_.first->value())); 19046 | } 19047 | 19048 | inline typename expression_node<T>::node_type type() const exprtk_override 19049 | { 19050 | return expression_node<T>::e_ipowinv; 19051 | } 19052 | 19053 | inline bool valid() const exprtk_override 19054 | { 19055 | return branch_.first && branch_.first->valid(); 19056 | } 19057 | 19058 | void collect_nodes(typename expression_node<T>::noderef_list_t& node_delete_list) exprtk_override 19059 | { 19060 | expression_node<T>::ndb_t::collect(branch_, node_delete_list); 19061 | } 19062 | 19063 | std::size_t node_depth() const exprtk_override 19064 | { 19065 | return expression_node<T>::ndb_t::compute_node_depth(branch_); 19066 | } 19067 | 19068 | private: 19069 | 19070 | bipowinv_node(const bipowinv_node<T,PowOp>&) exprtk_delete; 19071 | bipowinv_node<T,PowOp>& operator=(const bipowinv_node<T,PowOp>&) exprtk_delete; 19072 | 19073 | branch_t branch_; 19074 | }; 19075 | 19076 | template <typename T> 19077 | inline bool is_vov_node(const expression_node<T>* node) 19078 | { 19079 | return (0 != dynamic_cast<const vov_base_node<T>*>(node)); 19080 | } 19081 | 19082 | template <typename T> 19083 | inline bool is_cov_node(const expression_node<T>* node) 19084 | { 19085 | return (0 != dynamic_cast<const cov_base_node<T>*>(node)); 19086 | } 19087 | 19088 | template <typename T> 19089 | inline bool is_voc_node(const expression_node<T>* node) 19090 | { 19091 | return (0 != dynamic_cast<const voc_base_node<T>*>(node)); 19092 | } 19093 | 19094 | template <typename T> 19095 | inline bool is_cob_node(const expression_node<T>* node) 19096 | { 19097 | return (0 != dynamic_cast<const cob_base_node<T>*>(node)); 19098 | } 19099 | 19100 | template <typename T> 19101 | inline bool is_boc_node(const expression_node<T>* node) 19102 | { 19103 | return (0 != dynamic_cast<const boc_base_node<T>*>(node)); 19104 | } 19105 | 19106 | template <typename T> 19107 | inline bool is_t0ot1ot2_node(const expression_node<T>* node) 19108 | { 19109 | return (0 != dynamic_cast<const T0oT1oT2_base_node<T>*>(node)); 19110 | } 19111 | 19112 | template <typename T> 19113 | inline bool is_t0ot1ot2ot3_node(const expression_node<T>* node) 19114 | { 19115 | return (0 != dynamic_cast<const T0oT1oT2oT3_base_node<T>*>(node)); 19116 | } 19117 | 19118 | template <typename T> 19119 | inline bool is_uv_node(const expression_node<T>* node) 19120 | { 19121 | return (0 != dynamic_cast<const uv_base_node<T>*>(node)); 19122 | } 19123 | 19124 | template <typename T> 19125 | inline bool is_string_node(const expression_node<T>* node) 19126 | { 19127 | return node && (expression_node<T>::e_stringvar == node->type()); 19128 | } 19129 | 19130 | template <typename T> 19131 | inline bool is_string_range_node(const expression_node<T>* node) 19132 | { 19133 | return node && (expression_node<T>::e_stringvarrng == node->type()); 19134 | } 19135 | 19136 | template <typename T> 19137 | inline bool is_const_string_node(const expression_node<T>* node) 19138 | { 19139 | return node && (expression_node<T>::e_stringconst == node->type()); 19140 | } 19141 | 19142 | template <typename T> 19143 | inline bool is_const_string_range_node(const expression_node<T>* node) 19144 | { 19145 | return node && (expression_node<T>::e_cstringvarrng == node->type()); 19146 | } 19147 | 19148 | template <typename T> 19149 | inline bool is_string_assignment_node(const expression_node<T>* node) 19150 | { 19151 | return node && (expression_node<T>::e_strass == node->type()); 19152 | } 19153 | 19154 | template <typename T> 19155 | inline bool is_string_concat_node(const expression_node<T>* node) 19156 | { 19157 | return node && (expression_node<T>::e_strconcat == node->type()); 19158 | } 19159 | 19160 | template <typename T> 19161 | inline bool is_string_function_node(const expression_node<T>* node) 19162 | { 19163 | return node && (expression_node<T>::e_strfunction == node->type()); 19164 | } 19165 | 19166 | template <typename T> 19167 | inline bool is_string_condition_node(const expression_node<T>* node) 19168 | { 19169 | return node && (expression_node<T>::e_strcondition == node->type()); 19170 | } 19171 | 19172 | template <typename T> 19173 | inline bool is_string_ccondition_node(const expression_node<T>* node) 19174 | { 19175 | return node && (expression_node<T>::e_strccondition == node->type()); 19176 | } 19177 | 19178 | template <typename T> 19179 | inline bool is_string_vararg_node(const expression_node<T>* node) 19180 | { 19181 | return node && (expression_node<T>::e_stringvararg == node->type()); 19182 | } 19183 | 19184 | template <typename T> 19185 | inline bool is_genricstring_range_node(const expression_node<T>* node) 19186 | { 19187 | return node && (expression_node<T>::e_strgenrange == node->type()); 19188 | } 19189 | 19190 | template <typename T> 19191 | inline bool is_generally_string_node(const expression_node<T>* node) 19192 | { 19193 | if (node) 19194 | { 19195 | switch (node->type()) 19196 | { 19197 | case expression_node<T>::e_stringvar : 19198 | case expression_node<T>::e_stringconst : 19199 | case expression_node<T>::e_stringvarrng : 19200 | case expression_node<T>::e_cstringvarrng : 19201 | case expression_node<T>::e_strgenrange : 19202 | case expression_node<T>::e_strass : 19203 | case expression_node<T>::e_strconcat : 19204 | case expression_node<T>::e_strfunction : 19205 | case expression_node<T>::e_strcondition : 19206 | case expression_node<T>::e_strccondition : 19207 | case expression_node<T>::e_stringvararg : return true; 19208 | default : return false; 19209 | } 19210 | } 19211 | 19212 | return false; 19213 | } 19214 | 19215 | template <typename T> 19216 | inline bool is_loop_node(const expression_node<T>* node) 19217 | { 19218 | if (node) 19219 | { 19220 | switch (node->type()) 19221 | { 19222 | case expression_node<T>::e_for : 19223 | case expression_node<T>::e_repeat : 19224 | case expression_node<T>::e_while : return true; 19225 | default : return false; 19226 | } 19227 | } 19228 | 19229 | return false; 19230 | } 19231 | 19232 | template <typename T> 19233 | inline bool is_block_node(const expression_node<T>* node) 19234 | { 19235 | if (node) 19236 | { 19237 | if (is_loop_node(node)) 19238 | { 19239 | return true; 19240 | } 19241 | 19242 | switch (node->type()) 19243 | { 19244 | case expression_node<T>::e_conditional : 19245 | case expression_node<T>::e_mswitch : 19246 | case expression_node<T>::e_switch : 19247 | case expression_node<T>::e_vararg : return true; 19248 | default : return false; 19249 | } 19250 | } 19251 | 19252 | return false; 19253 | } 19254 | 19255 | class node_allocator 19256 | { 19257 | public: 19258 | 19259 | template <typename ResultNode, typename OpType, typename ExprNode> 19260 | inline expression_node<typename ResultNode::value_type>* allocate(OpType& operation, ExprNode (&branch)[1]) 19261 | { 19262 | expression_node<typename ResultNode::value_type>* result = 19263 | allocate<ResultNode>(operation, branch[0]); 19264 | result->node_depth(); 19265 | return result; 19266 | } 19267 | 19268 | template <typename ResultNode, typename OpType, typename ExprNode> 19269 | inline expression_node<typename ResultNode::value_type>* allocate(OpType& operation, ExprNode (&branch)[2]) 19270 | { 19271 | expression_node<typename ResultNode::value_type>* result = 19272 | allocate<ResultNode>(operation, branch[0], branch[1]); 19273 | result->node_depth(); 19274 | return result; 19275 | } 19276 | 19277 | template <typename ResultNode, typename OpType, typename ExprNode> 19278 | inline expression_node<typename ResultNode::value_type>* allocate(OpType& operation, ExprNode (&branch)[3]) 19279 | { 19280 | expression_node<typename ResultNode::value_type>* result = 19281 | allocate<ResultNode>(operation, branch[0], branch[1], branch[2]); 19282 | result->node_depth(); 19283 | return result; 19284 | } 19285 | 19286 | template <typename ResultNode, typename OpType, typename ExprNode> 19287 | inline expression_node<typename ResultNode::value_type>* allocate(OpType& operation, ExprNode (&branch)[4]) 19288 | { 19289 | expression_node<typename ResultNode::value_type>* result = 19290 | allocate<ResultNode>(operation, branch[0], branch[1], branch[2], branch[3]); 19291 | result->node_depth(); 19292 | return result; 19293 | } 19294 | 19295 | template <typename ResultNode, typename OpType, typename ExprNode> 19296 | inline expression_node<typename ResultNode::value_type>* allocate(OpType& operation, ExprNode (&branch)[5]) 19297 | { 19298 | expression_node<typename ResultNode::value_type>* result = 19299 | allocate<ResultNode>(operation, branch[0],branch[1], branch[2], branch[3], branch[4]); 19300 | result->node_depth(); 19301 | return result; 19302 | } 19303 | 19304 | template <typename ResultNode, typename OpType, typename ExprNode> 19305 | inline expression_node<typename ResultNode::value_type>* allocate(OpType& operation, ExprNode (&branch)[6]) 19306 | { 19307 | expression_node<typename ResultNode::value_type>* result = 19308 | allocate<ResultNode>(operation, branch[0], branch[1], branch[2], branch[3], branch[4], branch[5]); 19309 | result->node_depth(); 19310 | return result; 19311 | } 19312 | 19313 | template <typename node_type> 19314 | inline expression_node<typename node_type::value_type>* allocate() const 19315 | { 19316 | return (new node_type()); 19317 | } 19318 | 19319 | template <typename node_type, 19320 | typename Type, 19321 | typename Allocator, 19322 | template <typename, typename> class Sequence> 19323 | inline expression_node<typename node_type::value_type>* allocate(const Sequence<Type,Allocator>& seq) const 19324 | { 19325 | expression_node<typename node_type::value_type>* 19326 | result = (new node_type(seq)); 19327 | result->node_depth(); 19328 | return result; 19329 | } 19330 | 19331 | template <typename node_type, typename T1> 19332 | inline expression_node<typename node_type::value_type>* allocate(T1& t1) const 19333 | { 19334 | expression_node<typename node_type::value_type>* 19335 | result = (new node_type(t1)); 19336 | result->node_depth(); 19337 | return result; 19338 | } 19339 | 19340 | template <typename node_type, typename T1> 19341 | inline expression_node<typename node_type::value_type>* allocate_c(const T1& t1) const 19342 | { 19343 | expression_node<typename node_type::value_type>* 19344 | result = (new node_type(t1)); 19345 | result->node_depth(); 19346 | return result; 19347 | } 19348 | 19349 | template <typename node_type, 19350 | typename T1, typename T2> 19351 | inline expression_node<typename node_type::value_type>* allocate(const T1& t1, const T2& t2) const 19352 | { 19353 | expression_node<typename node_type::value_type>* 19354 | result = (new node_type(t1, t2)); 19355 | result->node_depth(); 19356 | return result; 19357 | } 19358 | 19359 | template <typename node_type, 19360 | typename T1, typename T2> 19361 | inline expression_node<typename node_type::value_type>* allocate_cr(const T1& t1, T2& t2) const 19362 | { 19363 | expression_node<typename node_type::value_type>* 19364 | result = (new node_type(t1, t2)); 19365 | result->node_depth(); 19366 | return result; 19367 | } 19368 | 19369 | template <typename node_type, 19370 | typename T1, typename T2> 19371 | inline expression_node<typename node_type::value_type>* allocate_rc(T1& t1, const T2& t2) const 19372 | { 19373 | expression_node<typename node_type::value_type>* 19374 | result = (new node_type(t1, t2)); 19375 | result->node_depth(); 19376 | return result; 19377 | } 19378 | 19379 | template <typename node_type, 19380 | typename T1, typename T2> 19381 | inline expression_node<typename node_type::value_type>* allocate_rr(T1& t1, T2& t2) const 19382 | { 19383 | expression_node<typename node_type::value_type>* 19384 | result = (new node_type(t1, t2)); 19385 | result->node_depth(); 19386 | return result; 19387 | } 19388 | 19389 | template <typename node_type, 19390 | typename T1, typename T2> 19391 | inline expression_node<typename node_type::value_type>* allocate_tt(T1 t1, T2 t2) const 19392 | { 19393 | expression_node<typename node_type::value_type>* 19394 | result = (new node_type(t1, t2)); 19395 | result->node_depth(); 19396 | return result; 19397 | } 19398 | 19399 | template <typename node_type, 19400 | typename T1, typename T2, typename T3> 19401 | inline expression_node<typename node_type::value_type>* allocate_ttt(T1 t1, T2 t2, T3 t3) const 19402 | { 19403 | expression_node<typename node_type::value_type>* 19404 | result = (new node_type(t1, t2, t3)); 19405 | result->node_depth(); 19406 | return result; 19407 | } 19408 | 19409 | template <typename node_type, 19410 | typename T1, typename T2, typename T3, typename T4> 19411 | inline expression_node<typename node_type::value_type>* allocate_tttt(T1 t1, T2 t2, T3 t3, T4 t4) const 19412 | { 19413 | expression_node<typename node_type::value_type>* 19414 | result = (new node_type(t1, t2, t3, t4)); 19415 | result->node_depth(); 19416 | return result; 19417 | } 19418 | 19419 | template <typename node_type, 19420 | typename T1, typename T2, typename T3> 19421 | inline expression_node<typename node_type::value_type>* allocate_rrr(T1& t1, T2& t2, T3& t3) const 19422 | { 19423 | expression_node<typename node_type::value_type>* 19424 | result = (new node_type(t1, t2, t3)); 19425 | result->node_depth(); 19426 | return result; 19427 | } 19428 | 19429 | template <typename node_type, 19430 | typename T1, typename T2, typename T3, typename T4> 19431 | inline expression_node<typename node_type::value_type>* allocate_rrrr(T1& t1, T2& t2, T3& t3, T4& t4) const 19432 | { 19433 | expression_node<typename node_type::value_type>* 19434 | result = (new node_type(t1, t2, t3, t4)); 19435 | result->node_depth(); 19436 | return result; 19437 | } 19438 | 19439 | template <typename node_type, 19440 | typename T1, typename T2, typename T3, typename T4, typename T5> 19441 | inline expression_node<typename node_type::value_type>* allocate_rrrrr(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5) const 19442 | { 19443 | expression_node<typename node_type::value_type>* 19444 | result = (new node_type(t1, t2, t3, t4, t5)); 19445 | result->node_depth(); 19446 | return result; 19447 | } 19448 | 19449 | template <typename node_type, 19450 | typename T1, typename T2, typename T3> 19451 | inline expression_node<typename node_type::value_type>* allocate(const T1& t1, const T2& t2, 19452 | const T3& t3) const 19453 | { 19454 | expression_node<typename node_type::value_type>* 19455 | result = (new node_type(t1, t2, t3)); 19456 | result->node_depth(); 19457 | return result; 19458 | } 19459 | 19460 | template <typename node_type, 19461 | typename T1, typename T2, 19462 | typename T3, typename T4> 19463 | inline expression_node<typename node_type::value_type>* allocate(const T1& t1, const T2& t2, 19464 | const T3& t3, const T4& t4) const 19465 | { 19466 | expression_node<typename node_type::value_type>* 19467 | result = (new node_type(t1, t2, t3, t4)); 19468 | result->node_depth(); 19469 | return result; 19470 | } 19471 | 19472 | template <typename node_type, 19473 | typename T1, typename T2, 19474 | typename T3, typename T4, typename T5> 19475 | inline expression_node<typename node_type::value_type>* allocate(const T1& t1, const T2& t2, 19476 | const T3& t3, const T4& t4, 19477 | const T5& t5) const 19478 | { 19479 | expression_node<typename node_type::value_type>* 19480 | result = (new node_type(t1, t2, t3, t4, t5)); 19481 | result->node_depth(); 19482 | return result; 19483 | } 19484 | 19485 | template <typename node_type, 19486 | typename T1, typename T2, 19487 | typename T3, typename T4, typename T5, typename T6> 19488 | inline expression_node<typename node_type::value_type>* allocate(const T1& t1, const T2& t2, 19489 | const T3& t3, const T4& t4, 19490 | const T5& t5, const T6& t6) const 19491 | { 19492 | expression_node<typename node_type::value_type>* 19493 | result = (new node_type(t1, t2, t3, t4, t5, t6)); 19494 | result->node_depth(); 19495 | return result; 19496 | } 19497 | 19498 | template <typename node_type, 19499 | typename T1, typename T2, 19500 | typename T3, typename T4, 19501 | typename T5, typename T6, typename T7> 19502 | inline expression_node<typename node_type::value_type>* allocate(const T1& t1, const T2& t2, 19503 | const T3& t3, const T4& t4, 19504 | const T5& t5, const T6& t6, 19505 | const T7& t7) const 19506 | { 19507 | expression_node<typename node_type::value_type>* 19508 | result = (new node_type(t1, t2, t3, t4, t5, t6, t7)); 19509 | result->node_depth(); 19510 | return result; 19511 | } 19512 | 19513 | template <typename node_type, 19514 | typename T1, typename T2, 19515 | typename T3, typename T4, 19516 | typename T5, typename T6, 19517 | typename T7, typename T8> 19518 | inline expression_node<typename node_type::value_type>* allocate(const T1& t1, const T2& t2, 19519 | const T3& t3, const T4& t4, 19520 | const T5& t5, const T6& t6, 19521 | const T7& t7, const T8& t8) const 19522 | { 19523 | expression_node<typename node_type::value_type>* 19524 | result = (new node_type(t1, t2, t3, t4, t5, t6, t7, t8)); 19525 | result->node_depth(); 19526 | return result; 19527 | } 19528 | 19529 | template <typename node_type, 19530 | typename T1, typename T2, 19531 | typename T3, typename T4, 19532 | typename T5, typename T6, 19533 | typename T7, typename T8, typename T9> 19534 | inline expression_node<typename node_type::value_type>* allocate(const T1& t1, const T2& t2, 19535 | const T3& t3, const T4& t4, 19536 | const T5& t5, const T6& t6, 19537 | const T7& t7, const T8& t8, 19538 | const T9& t9) const 19539 | { 19540 | expression_node<typename node_type::value_type>* 19541 | result = (new node_type(t1, t2, t3, t4, t5, t6, t7, t8, t9)); 19542 | result->node_depth(); 19543 | return result; 19544 | } 19545 | 19546 | template <typename node_type, 19547 | typename T1, typename T2, 19548 | typename T3, typename T4, 19549 | typename T5, typename T6, 19550 | typename T7, typename T8, 19551 | typename T9, typename T10> 19552 | inline expression_node<typename node_type::value_type>* allocate(const T1& t1, const T2& t2, 19553 | const T3& t3, const T4& t4, 19554 | const T5& t5, const T6& t6, 19555 | const T7& t7, const T8& t8, 19556 | const T9& t9, const T10& t10) const 19557 | { 19558 | expression_node<typename node_type::value_type>* 19559 | result = (new node_type(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10)); 19560 | result->node_depth(); 19561 | return result; 19562 | } 19563 | 19564 | template <typename node_type, 19565 | typename T1, typename T2, typename T3> 19566 | inline expression_node<typename node_type::value_type>* allocate_type(T1 t1, T2 t2, T3 t3) const 19567 | { 19568 | expression_node<typename node_type::value_type>* 19569 | result = (new node_type(t1, t2, t3)); 19570 | result->node_depth(); 19571 | return result; 19572 | } 19573 | 19574 | template <typename node_type, 19575 | typename T1, typename T2, 19576 | typename T3, typename T4> 19577 | inline expression_node<typename node_type::value_type>* allocate_type(T1 t1, T2 t2, 19578 | T3 t3, T4 t4) const 19579 | { 19580 | expression_node<typename node_type::value_type>* 19581 | result = (new node_type(t1, t2, t3, t4)); 19582 | result->node_depth(); 19583 | return result; 19584 | } 19585 | 19586 | template <typename node_type, 19587 | typename T1, typename T2, 19588 | typename T3, typename T4, 19589 | typename T5> 19590 | inline expression_node<typename node_type::value_type>* allocate_type(T1 t1, T2 t2, 19591 | T3 t3, T4 t4, 19592 | T5 t5) const 19593 | { 19594 | expression_node<typename node_type::value_type>* 19595 | result = (new node_type(t1, t2, t3, t4, t5)); 19596 | result->node_depth(); 19597 | return result; 19598 | } 19599 | 19600 | template <typename node_type, 19601 | typename T1, typename T2, 19602 | typename T3, typename T4, 19603 | typename T5, typename T6> 19604 | inline expression_node<typename node_type::value_type>* allocate_type(T1 t1, T2 t2, 19605 | T3 t3, T4 t4, 19606 | T5 t5, T6 t6) const 19607 | { 19608 | expression_node<typename node_type::value_type>* 19609 | result = (new node_type(t1, t2, t3, t4, t5, t6)); 19610 | result->node_depth(); 19611 | return result; 19612 | } 19613 | 19614 | template <typename node_type, 19615 | typename T1, typename T2, 19616 | typename T3, typename T4, 19617 | typename T5, typename T6, typename T7> 19618 | inline expression_node<typename node_type::value_type>* allocate_type(T1 t1, T2 t2, 19619 | T3 t3, T4 t4, 19620 | T5 t5, T6 t6, 19621 | T7 t7) const 19622 | { 19623 | expression_node<typename node_type::value_type>* 19624 | result = (new node_type(t1, t2, t3, t4, t5, t6, t7)); 19625 | result->node_depth(); 19626 | return result; 19627 | } 19628 | 19629 | template <typename T> 19630 | void inline free(expression_node<T>*& e) const 19631 | { 19632 | exprtk_debug(("node_allocator::free() - deleting expression_node " 19633 | "type: %03d addr: %p\n", 19634 | static_cast<int>(e->type()), 19635 | reinterpret_cast<void*>(e))); 19636 | delete e; 19637 | e = 0; 19638 | } 19639 | }; 19640 | 19641 | inline void load_operations_map(std::multimap<std::string,details::base_operation_t,details::ilesscompare>& m) 19642 | { 19643 | #define register_op(Symbol, Type, Args) \ 19644 | m.insert(std::make_pair(std::string(Symbol),details::base_operation_t(Type,Args))); \ 19645 | 19646 | register_op("abs" , e_abs , 1) 19647 | register_op("acos" , e_acos , 1) 19648 | register_op("acosh" , e_acosh , 1) 19649 | register_op("asin" , e_asin , 1) 19650 | register_op("asinh" , e_asinh , 1) 19651 | register_op("atan" , e_atan , 1) 19652 | register_op("atanh" , e_atanh , 1) 19653 | register_op("ceil" , e_ceil , 1) 19654 | register_op("cos" , e_cos , 1) 19655 | register_op("cosh" , e_cosh , 1) 19656 | register_op("exp" , e_exp , 1) 19657 | register_op("expm1" , e_expm1 , 1) 19658 | register_op("floor" , e_floor , 1) 19659 | register_op("log" , e_log , 1) 19660 | register_op("log10" , e_log10 , 1) 19661 | register_op("log2" , e_log2 , 1) 19662 | register_op("log1p" , e_log1p , 1) 19663 | register_op("round" , e_round , 1) 19664 | register_op("sin" , e_sin , 1) 19665 | register_op("sinc" , e_sinc , 1) 19666 | register_op("sinh" , e_sinh , 1) 19667 | register_op("sec" , e_sec , 1) 19668 | register_op("csc" , e_csc , 1) 19669 | register_op("sqrt" , e_sqrt , 1) 19670 | register_op("tan" , e_tan , 1) 19671 | register_op("tanh" , e_tanh , 1) 19672 | register_op("cot" , e_cot , 1) 19673 | register_op("rad2deg" , e_r2d , 1) 19674 | register_op("deg2rad" , e_d2r , 1) 19675 | register_op("deg2grad" , e_d2g , 1) 19676 | register_op("grad2deg" , e_g2d , 1) 19677 | register_op("sgn" , e_sgn , 1) 19678 | register_op("not" , e_notl , 1) 19679 | register_op("erf" , e_erf , 1) 19680 | register_op("erfc" , e_erfc , 1) 19681 | register_op("ncdf" , e_ncdf , 1) 19682 | register_op("frac" , e_frac , 1) 19683 | register_op("trunc" , e_trunc , 1) 19684 | register_op("atan2" , e_atan2 , 2) 19685 | register_op("mod" , e_mod , 2) 19686 | register_op("logn" , e_logn , 2) 19687 | register_op("pow" , e_pow , 2) 19688 | register_op("root" , e_root , 2) 19689 | register_op("roundn" , e_roundn , 2) 19690 | register_op("equal" , e_equal , 2) 19691 | register_op("not_equal" , e_nequal , 2) 19692 | register_op("hypot" , e_hypot , 2) 19693 | register_op("shr" , e_shr , 2) 19694 | register_op("shl" , e_shl , 2) 19695 | register_op("clamp" , e_clamp , 3) 19696 | register_op("iclamp" , e_iclamp , 3) 19697 | register_op("inrange" , e_inrange , 3) 19698 | #undef register_op 19699 | } 19700 | 19701 | } // namespace details 19702 | 19703 | class function_traits 19704 | { 19705 | public: 19706 | 19707 | function_traits() 19708 | : allow_zero_parameters_(false) 19709 | , has_side_effects_(true) 19710 | , min_num_args_(0) 19711 | , max_num_args_(std::numeric_limits<std::size_t>::max()) 19712 | {} 19713 | 19714 | inline bool& allow_zero_parameters() 19715 | { 19716 | return allow_zero_parameters_; 19717 | } 19718 | 19719 | inline bool& has_side_effects() 19720 | { 19721 | return has_side_effects_; 19722 | } 19723 | 19724 | std::size_t& min_num_args() 19725 | { 19726 | return min_num_args_; 19727 | } 19728 | 19729 | std::size_t& max_num_args() 19730 | { 19731 | return max_num_args_; 19732 | } 19733 | 19734 | private: 19735 | 19736 | bool allow_zero_parameters_; 19737 | bool has_side_effects_; 19738 | std::size_t min_num_args_; 19739 | std::size_t max_num_args_; 19740 | }; 19741 | 19742 | template <typename FunctionType> 19743 | void enable_zero_parameters(FunctionType& func) 19744 | { 19745 | func.allow_zero_parameters() = true; 19746 | 19747 | if (0 != func.min_num_args()) 19748 | { 19749 | func.min_num_args() = 0; 19750 | } 19751 | } 19752 | 19753 | template <typename FunctionType> 19754 | void disable_zero_parameters(FunctionType& func) 19755 | { 19756 | func.allow_zero_parameters() = false; 19757 | } 19758 | 19759 | template <typename FunctionType> 19760 | void enable_has_side_effects(FunctionType& func) 19761 | { 19762 | func.has_side_effects() = true; 19763 | } 19764 | 19765 | template <typename FunctionType> 19766 | void disable_has_side_effects(FunctionType& func) 19767 | { 19768 | func.has_side_effects() = false; 19769 | } 19770 | 19771 | template <typename FunctionType> 19772 | void set_min_num_args(FunctionType& func, const std::size_t& num_args) 19773 | { 19774 | func.min_num_args() = num_args; 19775 | 19776 | if ((0 != func.min_num_args()) && func.allow_zero_parameters()) 19777 | func.allow_zero_parameters() = false; 19778 | } 19779 | 19780 | template <typename FunctionType> 19781 | void set_max_num_args(FunctionType& func, const std::size_t& num_args) 19782 | { 19783 | func.max_num_args() = num_args; 19784 | } 19785 | 19786 | template <typename T> 19787 | class ifunction : public function_traits 19788 | { 19789 | public: 19790 | 19791 | explicit ifunction(const std::size_t& pc) 19792 | : param_count(pc) 19793 | {} 19794 | 19795 | virtual ~ifunction() 19796 | {} 19797 | 19798 | #define empty_method_body(N) \ 19799 | { \ 19800 | exprtk_debug(("ifunction::operator() - Operator(" #N ") has not been overridden\n")); \ 19801 | return std::numeric_limits<T>::quiet_NaN(); \ 19802 | } \ 19803 | 19804 | inline virtual T operator() () 19805 | empty_method_body(0) 19806 | 19807 | inline virtual T operator() (const T&) 19808 | empty_method_body(1) 19809 | 19810 | inline virtual T operator() (const T&,const T&) 19811 | empty_method_body(2) 19812 | 19813 | inline virtual T operator() (const T&, const T&, const T&) 19814 | empty_method_body(3) 19815 | 19816 | inline virtual T operator() (const T&, const T&, const T&, const T&) 19817 | empty_method_body(4) 19818 | 19819 | inline virtual T operator() (const T&, const T&, const T&, const T&, const T&) 19820 | empty_method_body(5) 19821 | 19822 | inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&) 19823 | empty_method_body(6) 19824 | 19825 | inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&) 19826 | empty_method_body(7) 19827 | 19828 | inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&) 19829 | empty_method_body(8) 19830 | 19831 | inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&) 19832 | empty_method_body(9) 19833 | 19834 | inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&) 19835 | empty_method_body(10) 19836 | 19837 | inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, 19838 | const T&) 19839 | empty_method_body(11) 19840 | 19841 | inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, 19842 | const T&, const T&) 19843 | empty_method_body(12) 19844 | 19845 | inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, 19846 | const T&, const T&, const T&) 19847 | empty_method_body(13) 19848 | 19849 | inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, 19850 | const T&, const T&, const T&, const T&) 19851 | empty_method_body(14) 19852 | 19853 | inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, 19854 | const T&, const T&, const T&, const T&, const T&) 19855 | empty_method_body(15) 19856 | 19857 | inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, 19858 | const T&, const T&, const T&, const T&, const T&, const T&) 19859 | empty_method_body(16) 19860 | 19861 | inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, 19862 | const T&, const T&, const T&, const T&, const T&, const T&, const T&) 19863 | empty_method_body(17) 19864 | 19865 | inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, 19866 | const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&) 19867 | empty_method_body(18) 19868 | 19869 | inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, 19870 | const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&) 19871 | empty_method_body(19) 19872 | 19873 | inline virtual T operator() (const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, 19874 | const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&, const T&) 19875 | empty_method_body(20) 19876 | 19877 | #undef empty_method_body 19878 | 19879 | std::size_t param_count; 19880 | }; 19881 | 19882 | template <typename T> 19883 | class ivararg_function : public function_traits 19884 | { 19885 | public: 19886 | 19887 | virtual ~ivararg_function() 19888 | {} 19889 | 19890 | inline virtual T operator() (const std::vector<T>&) 19891 | { 19892 | exprtk_debug(("ivararg_function::operator() - Operator has not been overridden\n")); 19893 | return std::numeric_limits<T>::quiet_NaN(); 19894 | } 19895 | }; 19896 | 19897 | template <typename T> 19898 | class igeneric_function : public function_traits 19899 | { 19900 | public: 19901 | 19902 | enum return_type 19903 | { 19904 | e_rtrn_scalar = 0, 19905 | e_rtrn_string = 1, 19906 | e_rtrn_overload = 2 19907 | }; 19908 | 19909 | typedef T type; 19910 | typedef type_store<T> generic_type; 19911 | typedef typename generic_type::parameter_list parameter_list_t; 19912 | 19913 | explicit igeneric_function(const std::string& param_seq = "", const return_type rtr_type = e_rtrn_scalar) 19914 | : parameter_sequence(param_seq) 19915 | , rtrn_type(rtr_type) 19916 | {} 19917 | 19918 | virtual ~igeneric_function() 19919 | {} 19920 | 19921 | #define igeneric_function_empty_body(N) \ 19922 | { \ 19923 | exprtk_debug(("igeneric_function::operator() - Operator(" #N ") has not been overridden\n")); \ 19924 | return std::numeric_limits<T>::quiet_NaN(); \ 19925 | } \ 19926 | 19927 | // f(i_0,i_1,....,i_N) --> Scalar 19928 | inline virtual T operator() (parameter_list_t) 19929 | igeneric_function_empty_body(1) 19930 | 19931 | // f(i_0,i_1,....,i_N) --> String 19932 | inline virtual T operator() (std::string&, parameter_list_t) 19933 | igeneric_function_empty_body(2) 19934 | 19935 | // f(psi,i_0,i_1,....,i_N) --> Scalar 19936 | inline virtual T operator() (const std::size_t&, parameter_list_t) 19937 | igeneric_function_empty_body(3) 19938 | 19939 | // f(psi,i_0,i_1,....,i_N) --> String 19940 | inline virtual T operator() (const std::size_t&, std::string&, parameter_list_t) 19941 | igeneric_function_empty_body(4) 19942 | 19943 | #undef igeneric_function_empty_body 19944 | 19945 | std::string parameter_sequence; 19946 | return_type rtrn_type; 19947 | 19948 | static inline std::string generate_prefix_args(const std::string& prefix_args, std::size_t start = 0, std::size_t end = 10) 19949 | { 19950 | std::string result; 19951 | 19952 | for (std::size_t i = start; i <= end; ++i) 19953 | { 19954 | result += prefix_args + std::string(i,'?'); 19955 | result += (i != end) ? "|" : "" 19956 | } 19957 | 19958 | return result; 19959 | } 19960 | 19961 | static inline std::string generate_suffix_args(const std::string& suffix_args, std::size_t start = 0, std::size_t end = 10) 19962 | { 19963 | std::string result; 19964 | 19965 | for (std::size_t i = start; i <= end; ++i) 19966 | { 19967 | result += std::string(i,'?') + suffix_args; 19968 | result += (i != end) ? "|" : "" 19969 | } 19970 | 19971 | return result; 19972 | } 19973 | }; 19974 | 19975 | #ifndef exprtk_disable_string_capabilities 19976 | template <typename T> 19977 | class stringvar_base 19978 | { 19979 | public: 19980 | 19981 | typedef typename details::stringvar_node<T> stringvar_node_t; 19982 | 19983 | stringvar_base(const std::string& name, stringvar_node_t* svn) 19984 | : name_(name) 19985 | , string_varnode_(svn) 19986 | {} 19987 | 19988 | bool valid() const 19989 | { 19990 | return !name_.empty() && (0 != string_varnode_); 19991 | } 19992 | 19993 | std::string name() const 19994 | { 19995 | assert(string_varnode_); 19996 | return name_; 19997 | } 19998 | 19999 | void rebase(std::string& s) 20000 | { 20001 | assert(string_varnode_); 20002 | string_varnode_->rebase(s); 20003 | } 20004 | 20005 | private: 20006 | 20007 | std::string name_; 20008 | stringvar_node_t* string_varnode_; 20009 | }; 20010 | #endif 20011 | 20012 | template <typename T> class parser; 20013 | template <typename T> class expression_helper; 20014 | 20015 | template <typename T> 20016 | class symbol_table 20017 | { 20018 | public: 20019 | 20020 | enum symtab_mutability_type 20021 | { 20022 | e_unknown = 0, 20023 | e_mutable = 1, 20024 | e_immutable = 2 20025 | }; 20026 | 20027 | typedef T (*ff00_functor)(); 20028 | typedef T (*ff01_functor)(T); 20029 | typedef T (*ff02_functor)(T, T); 20030 | typedef T (*ff03_functor)(T, T, T); 20031 | typedef T (*ff04_functor)(T, T, T, T); 20032 | typedef T (*ff05_functor)(T, T, T, T, T); 20033 | typedef T (*ff06_functor)(T, T, T, T, T, T); 20034 | typedef T (*ff07_functor)(T, T, T, T, T, T, T); 20035 | typedef T (*ff08_functor)(T, T, T, T, T, T, T, T); 20036 | typedef T (*ff09_functor)(T, T, T, T, T, T, T, T, T); 20037 | typedef T (*ff10_functor)(T, T, T, T, T, T, T, T, T, T); 20038 | typedef T (*ff11_functor)(T, T, T, T, T, T, T, T, T, T, T); 20039 | typedef T (*ff12_functor)(T, T, T, T, T, T, T, T, T, T, T, T); 20040 | typedef T (*ff13_functor)(T, T, T, T, T, T, T, T, T, T, T, T, T); 20041 | typedef T (*ff14_functor)(T, T, T, T, T, T, T, T, T, T, T, T, T, T); 20042 | typedef T (*ff15_functor)(T, T, T, T, T, T, T, T, T, T, T, T, T, T, T); 20043 | 20044 | protected: 20045 | 20046 | struct freefunc00 exprtk_final : public exprtk::ifunction<T> 20047 | { 20048 | using exprtk::ifunction<T>::operator(); 20049 | 20050 | explicit freefunc00(ff00_functor ff) : exprtk::ifunction<T>(0), f(ff) {} 20051 | inline T operator() () exprtk_override 20052 | { return f(); } 20053 | ff00_functor f; 20054 | }; 20055 | 20056 | struct freefunc01 exprtk_final : public exprtk::ifunction<T> 20057 | { 20058 | using exprtk::ifunction<T>::operator(); 20059 | 20060 | explicit freefunc01(ff01_functor ff) : exprtk::ifunction<T>(1), f(ff) {} 20061 | inline T operator() (const T& v0) exprtk_override 20062 | { return f(v0); } 20063 | ff01_functor f; 20064 | }; 20065 | 20066 | struct freefunc02 exprtk_final : public exprtk::ifunction<T> 20067 | { 20068 | using exprtk::ifunction<T>::operator(); 20069 | 20070 | explicit freefunc02(ff02_functor ff) : exprtk::ifunction<T>(2), f(ff) {} 20071 | inline T operator() (const T& v0, const T& v1) exprtk_override 20072 | { return f(v0, v1); } 20073 | ff02_functor f; 20074 | }; 20075 | 20076 | struct freefunc03 exprtk_final : public exprtk::ifunction<T> 20077 | { 20078 | using exprtk::ifunction<T>::operator(); 20079 | 20080 | explicit freefunc03(ff03_functor ff) : exprtk::ifunction<T>(3), f(ff) {} 20081 | inline T operator() (const T& v0, const T& v1, const T& v2) exprtk_override 20082 | { return f(v0, v1, v2); } 20083 | ff03_functor f; 20084 | }; 20085 | 20086 | struct freefunc04 exprtk_final : public exprtk::ifunction<T> 20087 | { 20088 | using exprtk::ifunction<T>::operator(); 20089 | 20090 | explicit freefunc04(ff04_functor ff) : exprtk::ifunction<T>(4), f(ff) {} 20091 | inline T operator() (const T& v0, const T& v1, const T& v2, const T& v3) exprtk_override 20092 | { return f(v0, v1, v2, v3); } 20093 | ff04_functor f; 20094 | }; 20095 | 20096 | struct freefunc05 : public exprtk::ifunction<T> 20097 | { 20098 | using exprtk::ifunction<T>::operator(); 20099 | 20100 | explicit freefunc05(ff05_functor ff) : exprtk::ifunction<T>(5), f(ff) {} 20101 | inline T operator() (const T& v0, const T& v1, const T& v2, const T& v3, const T& v4) exprtk_override 20102 | { return f(v0, v1, v2, v3, v4); } 20103 | ff05_functor f; 20104 | }; 20105 | 20106 | struct freefunc06 exprtk_final : public exprtk::ifunction<T> 20107 | { 20108 | using exprtk::ifunction<T>::operator(); 20109 | 20110 | explicit freefunc06(ff06_functor ff) : exprtk::ifunction<T>(6), f(ff) {} 20111 | inline T operator() (const T& v0, const T& v1, const T& v2, const T& v3, const T& v4, const T& v5) exprtk_override 20112 | { return f(v0, v1, v2, v3, v4, v5); } 20113 | ff06_functor f; 20114 | }; 20115 | 20116 | struct freefunc07 exprtk_final : public exprtk::ifunction<T> 20117 | { 20118 | using exprtk::ifunction<T>::operator(); 20119 | 20120 | explicit freefunc07(ff07_functor ff) : exprtk::ifunction<T>(7), f(ff) {} 20121 | inline T operator() (const T& v0, const T& v1, const T& v2, const T& v3, const T& v4, 20122 | const T& v5, const T& v6) exprtk_override 20123 | { return f(v0, v1, v2, v3, v4, v5, v6); } 20124 | ff07_functor f; 20125 | }; 20126 | 20127 | struct freefunc08 exprtk_final : public exprtk::ifunction<T> 20128 | { 20129 | using exprtk::ifunction<T>::operator(); 20130 | 20131 | explicit freefunc08(ff08_functor ff) : exprtk::ifunction<T>(8), f(ff) {} 20132 | inline T operator() (const T& v0, const T& v1, const T& v2, const T& v3, const T& v4, 20133 | const T& v5, const T& v6, const T& v7) exprtk_override 20134 | { return f(v0, v1, v2, v3, v4, v5, v6, v7); } 20135 | ff08_functor f; 20136 | }; 20137 | 20138 | struct freefunc09 exprtk_final : public exprtk::ifunction<T> 20139 | { 20140 | using exprtk::ifunction<T>::operator(); 20141 | 20142 | explicit freefunc09(ff09_functor ff) : exprtk::ifunction<T>(9), f(ff) {} 20143 | inline T operator() (const T& v0, const T& v1, const T& v2, const T& v3, const T& v4, 20144 | const T& v5, const T& v6, const T& v7, const T& v8) exprtk_override 20145 | { return f(v0, v1, v2, v3, v4, v5, v6, v7, v8); } 20146 | ff09_functor f; 20147 | }; 20148 | 20149 | struct freefunc10 exprtk_final : public exprtk::ifunction<T> 20150 | { 20151 | using exprtk::ifunction<T>::operator(); 20152 | 20153 | explicit freefunc10(ff10_functor ff) : exprtk::ifunction<T>(10), f(ff) {} 20154 | inline T operator() (const T& v0, const T& v1, const T& v2, const T& v3, const T& v4, 20155 | const T& v5, const T& v6, const T& v7, const T& v8, const T& v9) exprtk_override 20156 | { return f(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9); } 20157 | ff10_functor f; 20158 | }; 20159 | 20160 | struct freefunc11 exprtk_final : public exprtk::ifunction<T> 20161 | { 20162 | using exprtk::ifunction<T>::operator(); 20163 | 20164 | explicit freefunc11(ff11_functor ff) : exprtk::ifunction<T>(11), f(ff) {} 20165 | inline T operator() (const T& v0, const T& v1, const T& v2, const T& v3, const T& v4, 20166 | const T& v5, const T& v6, const T& v7, const T& v8, const T& v9, const T& v10) exprtk_override 20167 | { return f(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10); } 20168 | ff11_functor f; 20169 | }; 20170 | 20171 | struct freefunc12 exprtk_final : public exprtk::ifunction<T> 20172 | { 20173 | using exprtk::ifunction<T>::operator(); 20174 | 20175 | explicit freefunc12(ff12_functor ff) : exprtk::ifunction<T>(12), f(ff) {} 20176 | inline T operator() (const T& v00, const T& v01, const T& v02, const T& v03, const T& v04, 20177 | const T& v05, const T& v06, const T& v07, const T& v08, const T& v09, 20178 | const T& v10, const T& v11) exprtk_override 20179 | { return f(v00, v01, v02, v03, v04, v05, v06, v07, v08, v09, v10, v11); } 20180 | ff12_functor f; 20181 | }; 20182 | 20183 | struct freefunc13 exprtk_final : public exprtk::ifunction<T> 20184 | { 20185 | using exprtk::ifunction<T>::operator(); 20186 | 20187 | explicit freefunc13(ff13_functor ff) : exprtk::ifunction<T>(13), f(ff) {} 20188 | inline T operator() (const T& v00, const T& v01, const T& v02, const T& v03, const T& v04, 20189 | const T& v05, const T& v06, const T& v07, const T& v08, const T& v09, 20190 | const T& v10, const T& v11, const T& v12) exprtk_override 20191 | { return f(v00, v01, v02, v03, v04, v05, v06, v07, v08, v09, v10, v11, v12); } 20192 | ff13_functor f; 20193 | }; 20194 | 20195 | struct freefunc14 exprtk_final : public exprtk::ifunction<T> 20196 | { 20197 | using exprtk::ifunction<T>::operator(); 20198 | 20199 | explicit freefunc14(ff14_functor ff) : exprtk::ifunction<T>(14), f(ff) {} 20200 | inline T operator() (const T& v00, const T& v01, const T& v02, const T& v03, const T& v04, 20201 | const T& v05, const T& v06, const T& v07, const T& v08, const T& v09, 20202 | const T& v10, const T& v11, const T& v12, const T& v13) exprtk_override 20203 | { return f(v00, v01, v02, v03, v04, v05, v06, v07, v08, v09, v10, v11, v12, v13); } 20204 | ff14_functor f; 20205 | }; 20206 | 20207 | struct freefunc15 exprtk_final : public exprtk::ifunction<T> 20208 | { 20209 | using exprtk::ifunction<T>::operator(); 20210 | 20211 | explicit freefunc15(ff15_functor ff) : exprtk::ifunction<T>(15), f(ff) {} 20212 | inline T operator() (const T& v00, const T& v01, const T& v02, const T& v03, const T& v04, 20213 | const T& v05, const T& v06, const T& v07, const T& v08, const T& v09, 20214 | const T& v10, const T& v11, const T& v12, const T& v13, const T& v14) exprtk_override 20215 | { return f(v00, v01, v02, v03, v04, v05, v06, v07, v08, v09, v10, v11, v12, v13, v14); } 20216 | ff15_functor f; 20217 | }; 20218 | 20219 | template <typename Type, typename RawType> 20220 | struct type_store 20221 | { 20222 | typedef details::expression_node<T>* expression_ptr; 20223 | typedef typename details::variable_node<T> variable_node_t; 20224 | typedef ifunction<T> ifunction_t; 20225 | typedef ivararg_function<T> ivararg_function_t; 20226 | typedef igeneric_function<T> igeneric_function_t; 20227 | typedef details::vector_holder<T> vector_t; 20228 | #ifndef exprtk_disable_string_capabilities 20229 | typedef typename details::stringvar_node<T> stringvar_node_t; 20230 | #endif 20231 | 20232 | typedef Type type_t; 20233 | typedef type_t* type_ptr; 20234 | typedef std::pair<bool,type_ptr> type_pair_t; 20235 | typedef std::map<std::string,type_pair_t,details::ilesscompare> type_map_t; 20236 | typedef typename type_map_t::iterator tm_itr_t; 20237 | typedef typename type_map_t::const_iterator tm_const_itr_t; 20238 | 20239 | enum { lut_size = 256 }; 20240 | 20241 | type_map_t map; 20242 | std::size_t size; 20243 | 20244 | type_store() 20245 | : size(0) 20246 | {} 20247 | 20248 | struct deleter 20249 | { 20250 | #define exprtk_define_process(Type) \ 20251 | static inline void process(std::pair<bool,Type*>& n) \ 20252 | { \ 20253 | delete n.second; \ 20254 | } \ 20255 | 20256 | exprtk_define_process(variable_node_t ) 20257 | exprtk_define_process(vector_t ) 20258 | #ifndef exprtk_disable_string_capabilities 20259 | exprtk_define_process(stringvar_node_t) 20260 | #endif 20261 | 20262 | #undef exprtk_define_process 20263 | 20264 | template <typename DeleteType> 20265 | static inline void process(std::pair<bool,DeleteType*>&) 20266 | {} 20267 | }; 20268 | 20269 | inline bool symbol_exists(const std::string& symbol_name) const 20270 | { 20271 | if (symbol_name.empty()) 20272 | return false; 20273 | else if (map.end() != map.find(symbol_name)) 20274 | return true; 20275 | else 20276 | return false; 20277 | } 20278 | 20279 | template <typename PtrType> 20280 | inline std::string entity_name(const PtrType& ptr) const 20281 | { 20282 | if (map.empty()) 20283 | return std::string(); 20284 | 20285 | tm_const_itr_t itr = map.begin(); 20286 | 20287 | while (map.end() != itr) 20288 | { 20289 | if (itr->second.second == ptr) 20290 | { 20291 | return itr->first; 20292 | } 20293 | else 20294 | ++itr; 20295 | } 20296 | 20297 | return std::string(); 20298 | } 20299 | 20300 | inline bool is_constant(const std::string& symbol_name) const 20301 | { 20302 | if (symbol_name.empty()) 20303 | return false; 20304 | else 20305 | { 20306 | const tm_const_itr_t itr = map.find(symbol_name); 20307 | 20308 | if (map.end() == itr) 20309 | return false; 20310 | else 20311 | return (*itr).second.first; 20312 | } 20313 | } 20314 | 20315 | template <typename Tie, typename RType> 20316 | inline bool add_impl(const std::string& symbol_name, RType t, const bool is_const) 20317 | { 20318 | if (symbol_name.size() > 1) 20319 | { 20320 | for (std::size_t i = 0; i < details::reserved_symbols_size; ++i) 20321 | { 20322 | if (details::imatch(symbol_name, details::reserved_symbols[i])) 20323 | { 20324 | return false; 20325 | } 20326 | } 20327 | } 20328 | 20329 | const tm_itr_t itr = map.find(symbol_name); 20330 | 20331 | if (map.end() == itr) 20332 | { 20333 | map[symbol_name] = Tie::make(t,is_const); 20334 | ++size; 20335 | } 20336 | 20337 | return true; 20338 | } 20339 | 20340 | struct tie_array 20341 | { 20342 | static inline std::pair<bool,vector_t*> make(std::pair<T*,std::size_t> v, const bool is_const = false) 20343 | { 20344 | return std::make_pair(is_const, new vector_t(v.first, v.second)); 20345 | } 20346 | }; 20347 | 20348 | struct tie_stdvec 20349 | { 20350 | template <typename Allocator> 20351 | static inline std::pair<bool,vector_t*> make(std::vector<T,Allocator>& v, const bool is_const = false) 20352 | { 20353 | return std::make_pair(is_const, new vector_t(v)); 20354 | } 20355 | }; 20356 | 20357 | struct tie_vecview 20358 | { 20359 | static inline std::pair<bool,vector_t*> make(exprtk::vector_view<T>& v, const bool is_const = false) 20360 | { 20361 | return std::make_pair(is_const, new vector_t(v)); 20362 | } 20363 | }; 20364 | 20365 | struct tie_stddeq 20366 | { 20367 | template <typename Allocator> 20368 | static inline std::pair<bool,vector_t*> make(std::deque<T,Allocator>& v, const bool is_const = false) 20369 | { 20370 | return std::make_pair(is_const, new vector_t(v)); 20371 | } 20372 | }; 20373 | 20374 | template <std::size_t v_size> 20375 | inline bool add(const std::string& symbol_name, T (&v)[v_size], const bool is_const = false) 20376 | { 20377 | return add_impl<tie_array,std::pair<T*,std::size_t> > 20378 | (symbol_name, std::make_pair(v,v_size), is_const); 20379 | } 20380 | 20381 | inline bool add(const std::string& symbol_name, T* v, const std::size_t v_size, const bool is_const = false) 20382 | { 20383 | return add_impl<tie_array,std::pair<T*,std::size_t> > 20384 | (symbol_name, std::make_pair(v,v_size), is_const); 20385 | } 20386 | 20387 | template <typename Allocator> 20388 | inline bool add(const std::string& symbol_name, std::vector<T,Allocator>& v, const bool is_const = false) 20389 | { 20390 | return add_impl<tie_stdvec,std::vector<T,Allocator>&> 20391 | (symbol_name, v, is_const); 20392 | } 20393 | 20394 | inline bool add(const std::string& symbol_name, exprtk::vector_view<T>& v, const bool is_const = false) 20395 | { 20396 | return add_impl<tie_vecview,exprtk::vector_view<T>&> 20397 | (symbol_name, v, is_const); 20398 | } 20399 | 20400 | template <typename Allocator> 20401 | inline bool add(const std::string& symbol_name, std::deque<T,Allocator>& v, const bool is_const = false) 20402 | { 20403 | return add_impl<tie_stddeq,std::deque<T,Allocator>&> 20404 | (symbol_name, v, is_const); 20405 | } 20406 | 20407 | inline bool add(const std::string& symbol_name, RawType& t_, const bool is_const = false) 20408 | { 20409 | struct tie 20410 | { 20411 | static inline std::pair<bool,variable_node_t*> make(T& t, const bool is_constant = false) 20412 | { 20413 | return std::make_pair(is_constant, new variable_node_t(t)); 20414 | } 20415 | 20416 | #ifndef exprtk_disable_string_capabilities 20417 | static inline std::pair<bool,stringvar_node_t*> make(std::string& t, const bool is_constant = false) 20418 | { 20419 | return std::make_pair(is_constant, new stringvar_node_t(t)); 20420 | } 20421 | #endif 20422 | 20423 | static inline std::pair<bool,function_t*> make(function_t& t, const bool is_constant = false) 20424 | { 20425 | return std::make_pair(is_constant,&t); 20426 | } 20427 | 20428 | static inline std::pair<bool,vararg_function_t*> make(vararg_function_t& t, const bool is_constant = false) 20429 | { 20430 | return std::make_pair(is_constant,&t); 20431 | } 20432 | 20433 | static inline std::pair<bool,generic_function_t*> make(generic_function_t& t, const bool is_constant = false) 20434 | { 20435 | return std::make_pair(is_constant,&t); 20436 | } 20437 | }; 20438 | 20439 | const tm_itr_t itr = map.find(symbol_name); 20440 | 20441 | if (map.end() == itr) 20442 | { 20443 | map[symbol_name] = tie::make(t_,is_const); 20444 | ++size; 20445 | } 20446 | 20447 | return true; 20448 | } 20449 | 20450 | inline type_ptr get(const std::string& symbol_name) const 20451 | { 20452 | const tm_const_itr_t itr = map.find(symbol_name); 20453 | 20454 | if (map.end() == itr) 20455 | return reinterpret_cast<type_ptr>(0); 20456 | else 20457 | return itr->second.second; 20458 | } 20459 | 20460 | template <typename TType, typename TRawType, typename PtrType> 20461 | struct ptr_match 20462 | { 20463 | static inline bool test(const PtrType, const void*) 20464 | { 20465 | return false; 20466 | } 20467 | }; 20468 | 20469 | template <typename TType, typename TRawType> 20470 | struct ptr_match<TType,TRawType,variable_node_t*> 20471 | { 20472 | static inline bool test(const variable_node_t* p, const void* ptr) 20473 | { 20474 | exprtk_debug(("ptr_match::test() - %p <--> %p\n", reinterpret_cast<const void*>(&(p->ref())), ptr)); 20475 | return (&(p->ref()) == ptr); 20476 | } 20477 | }; 20478 | 20479 | inline type_ptr get_from_varptr(const void* ptr) const 20480 | { 20481 | tm_const_itr_t itr = map.begin(); 20482 | 20483 | while (map.end() != itr) 20484 | { 20485 | type_ptr ret_ptr = itr->second.second; 20486 | 20487 | if (ptr_match<Type,RawType,type_ptr>::test(ret_ptr,ptr)) 20488 | { 20489 | return ret_ptr; 20490 | } 20491 | 20492 | ++itr; 20493 | } 20494 | 20495 | return type_ptr(0); 20496 | } 20497 | 20498 | inline bool remove(const std::string& symbol_name, const bool delete_node = true) 20499 | { 20500 | const tm_itr_t itr = map.find(symbol_name); 20501 | 20502 | if (map.end() != itr) 20503 | { 20504 | if (delete_node) 20505 | { 20506 | deleter::process((*itr).second); 20507 | } 20508 | 20509 | map.erase(itr); 20510 | --size; 20511 | 20512 | return true; 20513 | } 20514 | else 20515 | return false; 20516 | } 20517 | 20518 | inline RawType& type_ref(const std::string& symbol_name) 20519 | { 20520 | struct init_type 20521 | { 20522 | static inline double set(double) { return (0.0); } 20523 | static inline double set(long double) { return (0.0); } 20524 | static inline float set(float) { return (0.0f); } 20525 | static inline std::string set(std::string&) { return std::string(""); } 20526 | }; 20527 | 20528 | static RawType null_type = init_type::set(RawType()); 20529 | 20530 | const tm_const_itr_t itr = map.find(symbol_name); 20531 | 20532 | if (map.end() == itr) 20533 | return null_type; 20534 | else 20535 | return itr->second.second->ref(); 20536 | } 20537 | 20538 | inline void clear(const bool delete_node = true) 20539 | { 20540 | if (!map.empty()) 20541 | { 20542 | if (delete_node) 20543 | { 20544 | tm_itr_t itr = map.begin(); 20545 | tm_itr_t end = map.end (); 20546 | 20547 | while (end != itr) 20548 | { 20549 | deleter::process((*itr).second); 20550 | ++itr; 20551 | } 20552 | } 20553 | 20554 | map.clear(); 20555 | } 20556 | 20557 | size = 0; 20558 | } 20559 | 20560 | template <typename Allocator, 20561 | template <typename, typename> class Sequence> 20562 | inline std::size_t get_list(Sequence<std::pair<std::string,RawType>,Allocator>& list) const 20563 | { 20564 | std::size_t count = 0; 20565 | 20566 | if (!map.empty()) 20567 | { 20568 | tm_const_itr_t itr = map.begin(); 20569 | tm_const_itr_t end = map.end (); 20570 | 20571 | while (end != itr) 20572 | { 20573 | list.push_back(std::make_pair((*itr).first,itr->second.second->ref())); 20574 | ++itr; 20575 | ++count; 20576 | } 20577 | } 20578 | 20579 | return count; 20580 | } 20581 | 20582 | template <typename Allocator, 20583 | template <typename, typename> class Sequence> 20584 | inline std::size_t get_list(Sequence<std::string,Allocator>& vlist) const 20585 | { 20586 | std::size_t count = 0; 20587 | 20588 | if (!map.empty()) 20589 | { 20590 | tm_const_itr_t itr = map.begin(); 20591 | tm_const_itr_t end = map.end (); 20592 | 20593 | while (end != itr) 20594 | { 20595 | vlist.push_back((*itr).first); 20596 | ++itr; 20597 | ++count; 20598 | } 20599 | } 20600 | 20601 | return count; 20602 | } 20603 | }; 20604 | 20605 | typedef details::expression_node<T>* expression_ptr; 20606 | typedef typename details::variable_node<T> variable_t; 20607 | typedef typename details::vector_holder<T> vector_holder_t; 20608 | typedef variable_t* variable_ptr; 20609 | #ifndef exprtk_disable_string_capabilities 20610 | typedef typename details::stringvar_node<T> stringvar_t; 20611 | typedef stringvar_t* stringvar_ptr; 20612 | #endif 20613 | typedef ifunction <T> function_t; 20614 | typedef ivararg_function <T> vararg_function_t; 20615 | typedef igeneric_function<T> generic_function_t; 20616 | typedef function_t* function_ptr; 20617 | typedef vararg_function_t* vararg_function_ptr; 20618 | typedef generic_function_t* generic_function_ptr; 20619 | 20620 | static const std::size_t lut_size = 256; 20621 | 20622 | // Symbol Table Holder 20623 | struct control_block 20624 | { 20625 | struct st_data 20626 | { 20627 | type_store<variable_t , T > variable_store; 20628 | type_store<function_t , function_t > function_store; 20629 | type_store<vararg_function_t , vararg_function_t > vararg_function_store; 20630 | type_store<generic_function_t, generic_function_t> generic_function_store; 20631 | type_store<generic_function_t, generic_function_t> string_function_store; 20632 | type_store<generic_function_t, generic_function_t> overload_function_store; 20633 | type_store<vector_holder_t , vector_holder_t > vector_store; 20634 | #ifndef exprtk_disable_string_capabilities 20635 | type_store<stringvar_t , std::string > stringvar_store; 20636 | #endif 20637 | 20638 | st_data() 20639 | { 20640 | for (std::size_t i = 0; i < details::reserved_words_size; ++i) 20641 | { 20642 | reserved_symbol_table_.insert(details::reserved_words[i]); 20643 | } 20644 | 20645 | for (std::size_t i = 0; i < details::reserved_symbols_size; ++i) 20646 | { 20647 | reserved_symbol_table_.insert(details::reserved_symbols[i]); 20648 | } 20649 | } 20650 | 20651 | ~st_data() 20652 | { 20653 | for (std::size_t i = 0; i < free_function_list_.size(); ++i) 20654 | { 20655 | delete free_function_list_[i]; 20656 | } 20657 | } 20658 | 20659 | inline bool is_reserved_symbol(const std::string& symbol) const 20660 | { 20661 | return (reserved_symbol_table_.end() != reserved_symbol_table_.find(symbol)); 20662 | } 20663 | 20664 | static inline st_data* create() 20665 | { 20666 | return (new st_data); 20667 | } 20668 | 20669 | static inline void destroy(st_data*& sd) 20670 | { 20671 | delete sd; 20672 | sd = reinterpret_cast<st_data*>(0); 20673 | } 20674 | 20675 | std::list<T> local_symbol_list_; 20676 | std::list<std::string> local_stringvar_list_; 20677 | std::set<std::string> reserved_symbol_table_; 20678 | std::vector<ifunction<T>*> free_function_list_; 20679 | }; 20680 | 20681 | control_block() 20682 | : ref_count(1) 20683 | , data_(st_data::create()) 20684 | , mutability_(e_mutable) 20685 | {} 20686 | 20687 | explicit control_block(st_data* data) 20688 | : ref_count(1) 20689 | , data_(data) 20690 | , mutability_(e_mutable) 20691 | {} 20692 | 20693 | ~control_block() 20694 | { 20695 | if (data_ && (0 == ref_count)) 20696 | { 20697 | st_data::destroy(data_); 20698 | } 20699 | } 20700 | 20701 | static inline control_block* create() 20702 | { 20703 | return (new control_block); 20704 | } 20705 | 20706 | template <typename SymTab> 20707 | static inline void destroy(control_block*& cntrl_blck, SymTab* sym_tab) 20708 | { 20709 | if (cntrl_blck) 20710 | { 20711 | if ( 20712 | (0 != cntrl_blck->ref_count) && 20713 | (0 == --cntrl_blck->ref_count) 20714 | ) 20715 | { 20716 | if (sym_tab) 20717 | sym_tab->clear(); 20718 | 20719 | delete cntrl_blck; 20720 | } 20721 | 20722 | cntrl_blck = 0; 20723 | } 20724 | } 20725 | 20726 | void set_mutability(const symtab_mutability_type mutability) 20727 | { 20728 | mutability_ = mutability; 20729 | } 20730 | 20731 | std::size_t ref_count; 20732 | st_data* data_; 20733 | symtab_mutability_type mutability_; 20734 | }; 20735 | 20736 | public: 20737 | 20738 | explicit symbol_table(const symtab_mutability_type mutability = e_mutable) 20739 | : control_block_(control_block::create()) 20740 | { 20741 | control_block_->set_mutability(mutability); 20742 | clear(); 20743 | } 20744 | 20745 | ~symbol_table() 20746 | { 20747 | exprtk::details::dump_ptr("~symbol_table", this); 20748 | control_block::destroy(control_block_, this); 20749 | } 20750 | 20751 | symbol_table(const symbol_table<T>& st) 20752 | { 20753 | control_block_ = st.control_block_; 20754 | control_block_->ref_count++; 20755 | } 20756 | 20757 | inline symbol_table<T>& operator=(const symbol_table<T>& st) 20758 | { 20759 | if (this != &st) 20760 | { 20761 | control_block::destroy(control_block_,reinterpret_cast<symbol_table<T>*>(0)); 20762 | 20763 | control_block_ = st.control_block_; 20764 | control_block_->ref_count++; 20765 | } 20766 | 20767 | return (*this); 20768 | } 20769 | 20770 | inline bool operator==(const symbol_table<T>& st) const 20771 | { 20772 | return (this == &st) || (control_block_ == st.control_block_); 20773 | } 20774 | 20775 | inline symtab_mutability_type mutability() const 20776 | { 20777 | return valid() ? control_block_->mutability_ : e_unknown; 20778 | } 20779 | 20780 | inline void clear_variables(const bool delete_node = true) 20781 | { 20782 | local_data().variable_store.clear(delete_node); 20783 | } 20784 | 20785 | inline void clear_functions() 20786 | { 20787 | local_data().function_store.clear(); 20788 | } 20789 | 20790 | inline void clear_strings() 20791 | { 20792 | #ifndef exprtk_disable_string_capabilities 20793 | local_data().stringvar_store.clear(); 20794 | #endif 20795 | } 20796 | 20797 | inline void clear_vectors() 20798 | { 20799 | local_data().vector_store.clear(); 20800 | } 20801 | 20802 | inline void clear_local_constants() 20803 | { 20804 | local_data().local_symbol_list_.clear(); 20805 | } 20806 | 20807 | inline void clear() 20808 | { 20809 | if (!valid()) return; 20810 | clear_variables (); 20811 | clear_functions (); 20812 | clear_strings (); 20813 | clear_vectors (); 20814 | clear_local_constants(); 20815 | } 20816 | 20817 | inline std::size_t variable_count() const 20818 | { 20819 | if (valid()) 20820 | return local_data().variable_store.size; 20821 | else 20822 | return 0; 20823 | } 20824 | 20825 | #ifndef exprtk_disable_string_capabilities 20826 | inline std::size_t stringvar_count() const 20827 | { 20828 | if (valid()) 20829 | return local_data().stringvar_store.size; 20830 | else 20831 | return 0; 20832 | } 20833 | #endif 20834 | 20835 | inline std::size_t function_count() const 20836 | { 20837 | if (valid()) 20838 | return local_data().function_store.size; 20839 | else 20840 | return 0; 20841 | } 20842 | 20843 | inline std::size_t vector_count() const 20844 | { 20845 | if (valid()) 20846 | return local_data().vector_store.size; 20847 | else 20848 | return 0; 20849 | } 20850 | 20851 | inline variable_ptr get_variable(const std::string& variable_name) const 20852 | { 20853 | if (!valid()) 20854 | return reinterpret_cast<variable_ptr>(0); 20855 | else if (!valid_symbol(variable_name)) 20856 | return reinterpret_cast<variable_ptr>(0); 20857 | else 20858 | return local_data().variable_store.get(variable_name); 20859 | } 20860 | 20861 | inline variable_ptr get_variable(const T& var_ref) const 20862 | { 20863 | if (!valid()) 20864 | return reinterpret_cast<variable_ptr>(0); 20865 | else 20866 | return local_data().variable_store.get_from_varptr( 20867 | reinterpret_cast<const void*>(&var_ref)); 20868 | } 20869 | 20870 | #ifndef exprtk_disable_string_capabilities 20871 | inline stringvar_ptr get_stringvar(const std::string& string_name) const 20872 | { 20873 | if (!valid()) 20874 | return reinterpret_cast<stringvar_ptr>(0); 20875 | else if (!valid_symbol(string_name)) 20876 | return reinterpret_cast<stringvar_ptr>(0); 20877 | else 20878 | return local_data().stringvar_store.get(string_name); 20879 | } 20880 | 20881 | inline stringvar_base<T> get_stringvar_base(const std::string& string_name) const 20882 | { 20883 | static stringvar_base<T> null_stringvar_base("",reinterpret_cast<stringvar_ptr>(0)); 20884 | if (!valid()) 20885 | return null_stringvar_base; 20886 | else if (!valid_symbol(string_name)) 20887 | return null_stringvar_base; 20888 | 20889 | stringvar_ptr stringvar = local_data().stringvar_store.get(string_name); 20890 | 20891 | if (0 == stringvar) 20892 | { 20893 | return null_stringvar_base; 20894 | } 20895 | 20896 | return stringvar_base<T>(string_name,stringvar); 20897 | } 20898 | #endif 20899 | 20900 | inline function_ptr get_function(const std::string& function_name) const 20901 | { 20902 | if (!valid()) 20903 | return reinterpret_cast<function_ptr>(0); 20904 | else if (!valid_symbol(function_name)) 20905 | return reinterpret_cast<function_ptr>(0); 20906 | else 20907 | return local_data().function_store.get(function_name); 20908 | } 20909 | 20910 | inline vararg_function_ptr get_vararg_function(const std::string& vararg_function_name) const 20911 | { 20912 | if (!valid()) 20913 | return reinterpret_cast<vararg_function_ptr>(0); 20914 | else if (!valid_symbol(vararg_function_name)) 20915 | return reinterpret_cast<vararg_function_ptr>(0); 20916 | else 20917 | return local_data().vararg_function_store.get(vararg_function_name); 20918 | } 20919 | 20920 | inline generic_function_ptr get_generic_function(const std::string& function_name) const 20921 | { 20922 | if (!valid()) 20923 | return reinterpret_cast<generic_function_ptr>(0); 20924 | else if (!valid_symbol(function_name)) 20925 | return reinterpret_cast<generic_function_ptr>(0); 20926 | else 20927 | return local_data().generic_function_store.get(function_name); 20928 | } 20929 | 20930 | inline generic_function_ptr get_string_function(const std::string& function_name) const 20931 | { 20932 | if (!valid()) 20933 | return reinterpret_cast<generic_function_ptr>(0); 20934 | else if (!valid_symbol(function_name)) 20935 | return reinterpret_cast<generic_function_ptr>(0); 20936 | else 20937 | return local_data().string_function_store.get(function_name); 20938 | } 20939 | 20940 | inline generic_function_ptr get_overload_function(const std::string& function_name) const 20941 | { 20942 | if (!valid()) 20943 | return reinterpret_cast<generic_function_ptr>(0); 20944 | else if (!valid_symbol(function_name)) 20945 | return reinterpret_cast<generic_function_ptr>(0); 20946 | else 20947 | return local_data().overload_function_store.get(function_name); 20948 | } 20949 | 20950 | typedef vector_holder_t* vector_holder_ptr; 20951 | 20952 | inline vector_holder_ptr get_vector(const std::string& vector_name) const 20953 | { 20954 | if (!valid()) 20955 | return reinterpret_cast<vector_holder_ptr>(0); 20956 | else if (!valid_symbol(vector_name)) 20957 | return reinterpret_cast<vector_holder_ptr>(0); 20958 | else 20959 | return local_data().vector_store.get(vector_name); 20960 | } 20961 | 20962 | inline T& variable_ref(const std::string& symbol_name) 20963 | { 20964 | static T null_var = T(0); 20965 | if (!valid()) 20966 | return null_var; 20967 | else if (!valid_symbol(symbol_name)) 20968 | return null_var; 20969 | else 20970 | return local_data().variable_store.type_ref(symbol_name); 20971 | } 20972 | 20973 | #ifndef exprtk_disable_string_capabilities 20974 | inline std::string& stringvar_ref(const std::string& symbol_name) 20975 | { 20976 | static std::string null_stringvar; 20977 | if (!valid()) 20978 | return null_stringvar; 20979 | else if (!valid_symbol(symbol_name)) 20980 | return null_stringvar; 20981 | else 20982 | return local_data().stringvar_store.type_ref(symbol_name); 20983 | } 20984 | #endif 20985 | 20986 | inline bool is_constant_node(const std::string& symbol_name) const 20987 | { 20988 | if (!valid()) 20989 | return false; 20990 | else if (!valid_symbol(symbol_name)) 20991 | return false; 20992 | else 20993 | return local_data().variable_store.is_constant(symbol_name); 20994 | } 20995 | 20996 | #ifndef exprtk_disable_string_capabilities 20997 | inline bool is_constant_string(const std::string& symbol_name) const 20998 | { 20999 | if (!valid()) 21000 | return false; 21001 | else if (!valid_symbol(symbol_name)) 21002 | return false; 21003 | else if (!local_data().stringvar_store.symbol_exists(symbol_name)) 21004 | return false; 21005 | else 21006 | return local_data().stringvar_store.is_constant(symbol_name); 21007 | } 21008 | #endif 21009 | 21010 | inline bool create_variable(const std::string& variable_name, const T& value = T(0)) 21011 | { 21012 | if (!valid()) 21013 | return false; 21014 | else if (!valid_symbol(variable_name)) 21015 | return false; 21016 | else if (symbol_exists(variable_name)) 21017 | return false; 21018 | 21019 | local_data().local_symbol_list_.push_back(value); 21020 | T& t = local_data().local_symbol_list_.back(); 21021 | 21022 | return add_variable(variable_name,t); 21023 | } 21024 | 21025 | #ifndef exprtk_disable_string_capabilities 21026 | inline bool create_stringvar(const std::string& stringvar_name, const std::string& value = std::string("")) 21027 | { 21028 | if (!valid()) 21029 | return false; 21030 | else if (!valid_symbol(stringvar_name)) 21031 | return false; 21032 | else if (symbol_exists(stringvar_name)) 21033 | return false; 21034 | 21035 | local_data().local_stringvar_list_.push_back(value); 21036 | std::string& s = local_data().local_stringvar_list_.back(); 21037 | 21038 | return add_stringvar(stringvar_name,s); 21039 | } 21040 | #endif 21041 | 21042 | inline bool add_variable(const std::string& variable_name, T& t, const bool is_constant = false) 21043 | { 21044 | if (!valid()) 21045 | return false; 21046 | else if (!valid_symbol(variable_name)) 21047 | return false; 21048 | else if (symbol_exists(variable_name)) 21049 | return false; 21050 | else 21051 | return local_data().variable_store.add(variable_name, t, is_constant); 21052 | } 21053 | 21054 | inline bool add_constant(const std::string& constant_name, const T& value) 21055 | { 21056 | if (!valid()) 21057 | return false; 21058 | else if (!valid_symbol(constant_name)) 21059 | return false; 21060 | else if (symbol_exists(constant_name)) 21061 | return false; 21062 | 21063 | local_data().local_symbol_list_.push_back(value); 21064 | T& t = local_data().local_symbol_list_.back(); 21065 | 21066 | return add_variable(constant_name, t, true); 21067 | } 21068 | 21069 | #ifndef exprtk_disable_string_capabilities 21070 | inline bool add_stringvar(const std::string& stringvar_name, std::string& s, const bool is_constant = false) 21071 | { 21072 | if (!valid()) 21073 | return false; 21074 | else if (!valid_symbol(stringvar_name)) 21075 | return false; 21076 | else if (symbol_exists(stringvar_name)) 21077 | return false; 21078 | else 21079 | return local_data().stringvar_store.add(stringvar_name, s, is_constant); 21080 | } 21081 | #endif 21082 | 21083 | inline bool add_function(const std::string& function_name, function_t& function) 21084 | { 21085 | if (!valid()) 21086 | return false; 21087 | else if (!valid_symbol(function_name)) 21088 | return false; 21089 | else if (symbol_exists(function_name)) 21090 | return false; 21091 | else 21092 | return local_data().function_store.add(function_name,function); 21093 | } 21094 | 21095 | inline bool add_function(const std::string& vararg_function_name, vararg_function_t& vararg_function) 21096 | { 21097 | if (!valid()) 21098 | return false; 21099 | else if (!valid_symbol(vararg_function_name)) 21100 | return false; 21101 | else if (symbol_exists(vararg_function_name)) 21102 | return false; 21103 | else 21104 | return local_data().vararg_function_store.add(vararg_function_name,vararg_function); 21105 | } 21106 | 21107 | inline bool add_function(const std::string& function_name, generic_function_t& function) 21108 | { 21109 | if (!valid()) 21110 | return false; 21111 | else if (!valid_symbol(function_name)) 21112 | return false; 21113 | else if (symbol_exists(function_name)) 21114 | return false; 21115 | else 21116 | { 21117 | switch (function.rtrn_type) 21118 | { 21119 | case generic_function_t::e_rtrn_scalar : 21120 | return (std::string::npos == function.parameter_sequence.find_first_not_of("STVZ*?|")) ? 21121 | local_data().generic_function_store.add(function_name,function) : false; 21122 | 21123 | case generic_function_t::e_rtrn_string : 21124 | return (std::string::npos == function.parameter_sequence.find_first_not_of("STVZ*?|")) ? 21125 | local_data().string_function_store.add(function_name,function) : false; 21126 | 21127 | case generic_function_t::e_rtrn_overload : 21128 | return (std::string::npos == function.parameter_sequence.find_first_not_of("STVZ*?|:")) ? 21129 | local_data().overload_function_store.add(function_name,function) : false; 21130 | } 21131 | } 21132 | 21133 | return false; 21134 | } 21135 | 21136 | #define exprtk_define_freefunction(NN) \ 21137 | inline bool add_function(const std::string& function_name, ff##NN##_functor function) \ 21138 | { \ 21139 | if (!valid()) \ 21140 | { return false; } \ 21141 | if (!valid_symbol(function_name)) \ 21142 | { return false; } \ 21143 | if (symbol_exists(function_name)) \ 21144 | { return false; } \ 21145 | \ 21146 | exprtk::ifunction<T>* ifunc = new freefunc##NN(function); \ 21147 | \ 21148 | local_data().free_function_list_.push_back(ifunc); \ 21149 | \ 21150 | return add_function(function_name,(*local_data().free_function_list_.back())); \ 21151 | } \ 21152 | 21153 | exprtk_define_freefunction(00) exprtk_define_freefunction(01) 21154 | exprtk_define_freefunction(02) exprtk_define_freefunction(03) 21155 | exprtk_define_freefunction(04) exprtk_define_freefunction(05) 21156 | exprtk_define_freefunction(06) exprtk_define_freefunction(07) 21157 | exprtk_define_freefunction(08) exprtk_define_freefunction(09) 21158 | exprtk_define_freefunction(10) exprtk_define_freefunction(11) 21159 | exprtk_define_freefunction(12) exprtk_define_freefunction(13) 21160 | exprtk_define_freefunction(14) exprtk_define_freefunction(15) 21161 | 21162 | #undef exprtk_define_freefunction 21163 | 21164 | inline bool add_reserved_function(const std::string& function_name, function_t& function) 21165 | { 21166 | if (!valid()) 21167 | return false; 21168 | else if (!valid_symbol(function_name,false)) 21169 | return false; 21170 | else if (symbol_exists(function_name,false)) 21171 | return false; 21172 | else 21173 | return local_data().function_store.add(function_name,function); 21174 | } 21175 | 21176 | inline bool add_reserved_function(const std::string& vararg_function_name, vararg_function_t& vararg_function) 21177 | { 21178 | if (!valid()) 21179 | return false; 21180 | else if (!valid_symbol(vararg_function_name,false)) 21181 | return false; 21182 | else if (symbol_exists(vararg_function_name,false)) 21183 | return false; 21184 | else 21185 | return local_data().vararg_function_store.add(vararg_function_name,vararg_function); 21186 | } 21187 | 21188 | inline bool add_reserved_function(const std::string& function_name, generic_function_t& function) 21189 | { 21190 | if (!valid()) 21191 | return false; 21192 | else if (!valid_symbol(function_name,false)) 21193 | return false; 21194 | else if (symbol_exists(function_name,false)) 21195 | return false; 21196 | else 21197 | { 21198 | switch (function.rtrn_type) 21199 | { 21200 | case generic_function_t::e_rtrn_scalar : 21201 | return (std::string::npos == function.parameter_sequence.find_first_not_of("STVZ*?|")) ? 21202 | local_data().generic_function_store.add(function_name,function) : false; 21203 | 21204 | case generic_function_t::e_rtrn_string : 21205 | return (std::string::npos == function.parameter_sequence.find_first_not_of("STVZ*?|")) ? 21206 | local_data().string_function_store.add(function_name,function) : false; 21207 | 21208 | case generic_function_t::e_rtrn_overload : 21209 | return (std::string::npos == function.parameter_sequence.find_first_not_of("STVZ*?|:")) ? 21210 | local_data().overload_function_store.add(function_name,function) : false; 21211 | } 21212 | } 21213 | 21214 | return false; 21215 | } 21216 | 21217 | #define exprtk_define_reserved_function(NN) \ 21218 | inline bool add_reserved_function(const std::string& function_name, ff##NN##_functor function) \ 21219 | { \ 21220 | if (!valid()) \ 21221 | { return false; } \ 21222 | if (!valid_symbol(function_name,false)) \ 21223 | { return false; } \ 21224 | if (symbol_exists(function_name,false)) \ 21225 | { return false; } \ 21226 | \ 21227 | exprtk::ifunction<T>* ifunc = new freefunc##NN(function); \ 21228 | \ 21229 | local_data().free_function_list_.push_back(ifunc); \ 21230 | \ 21231 | return add_reserved_function(function_name,(*local_data().free_function_list_.back())); \ 21232 | } \ 21233 | 21234 | exprtk_define_reserved_function(00) exprtk_define_reserved_function(01) 21235 | exprtk_define_reserved_function(02) exprtk_define_reserved_function(03) 21236 | exprtk_define_reserved_function(04) exprtk_define_reserved_function(05) 21237 | exprtk_define_reserved_function(06) exprtk_define_reserved_function(07) 21238 | exprtk_define_reserved_function(08) exprtk_define_reserved_function(09) 21239 | exprtk_define_reserved_function(10) exprtk_define_reserved_function(11) 21240 | exprtk_define_reserved_function(12) exprtk_define_reserved_function(13) 21241 | exprtk_define_reserved_function(14) exprtk_define_reserved_function(15) 21242 | 21243 | #undef exprtk_define_reserved_function 21244 | 21245 | template <std::size_t N> 21246 | inline bool add_vector(const std::string& vector_name, T (&v)[N]) 21247 | { 21248 | if (!valid()) 21249 | return false; 21250 | else if (!valid_symbol(vector_name)) 21251 | return false; 21252 | else if (symbol_exists(vector_name)) 21253 | return false; 21254 | else 21255 | return local_data().vector_store.add(vector_name,v); 21256 | } 21257 | 21258 | inline bool add_vector(const std::string& vector_name, T* v, const std::size_t& v_size) 21259 | { 21260 | if (!valid()) 21261 | return false; 21262 | else if (!valid_symbol(vector_name)) 21263 | return false; 21264 | else if (symbol_exists(vector_name)) 21265 | return false; 21266 | else if (0 == v_size) 21267 | return false; 21268 | else 21269 | return local_data().vector_store.add(vector_name, v, v_size); 21270 | } 21271 | 21272 | template <typename Allocator> 21273 | inline bool add_vector(const std::string& vector_name, std::vector<T,Allocator>& v) 21274 | { 21275 | if (!valid()) 21276 | return false; 21277 | else if (!valid_symbol(vector_name)) 21278 | return false; 21279 | else if (symbol_exists(vector_name)) 21280 | return false; 21281 | else if (0 == v.size()) 21282 | return false; 21283 | else 21284 | return local_data().vector_store.add(vector_name,v); 21285 | } 21286 | 21287 | inline bool add_vector(const std::string& vector_name, exprtk::vector_view<T>& v) 21288 | { 21289 | if (!valid()) 21290 | return false; 21291 | else if (!valid_symbol(vector_name)) 21292 | return false; 21293 | else if (symbol_exists(vector_name)) 21294 | return false; 21295 | else if (0 == v.size()) 21296 | return false; 21297 | else 21298 | return local_data().vector_store.add(vector_name,v); 21299 | } 21300 | 21301 | inline bool remove_variable(const std::string& variable_name, const bool delete_node = true) 21302 | { 21303 | if (!valid()) 21304 | return false; 21305 | else 21306 | return local_data().variable_store.remove(variable_name, delete_node); 21307 | } 21308 | 21309 | #ifndef exprtk_disable_string_capabilities 21310 | inline bool remove_stringvar(const std::string& string_name) 21311 | { 21312 | if (!valid()) 21313 | return false; 21314 | else 21315 | return local_data().stringvar_store.remove(string_name); 21316 | } 21317 | #endif 21318 | 21319 | inline bool remove_function(const std::string& function_name) 21320 | { 21321 | if (!valid()) 21322 | return false; 21323 | else 21324 | return local_data().function_store.remove(function_name); 21325 | } 21326 | 21327 | inline bool remove_vararg_function(const std::string& vararg_function_name) 21328 | { 21329 | if (!valid()) 21330 | return false; 21331 | else 21332 | return local_data().vararg_function_store.remove(vararg_function_name); 21333 | } 21334 | 21335 | inline bool remove_vector(const std::string& vector_name) 21336 | { 21337 | if (!valid()) 21338 | return false; 21339 | else 21340 | return local_data().vector_store.remove(vector_name); 21341 | } 21342 | 21343 | inline bool add_constants() 21344 | { 21345 | return add_pi () && 21346 | add_epsilon () && 21347 | add_infinity() ; 21348 | } 21349 | 21350 | inline bool add_pi() 21351 | { 21352 | const typename details::numeric::details::number_type<T>::type num_type; 21353 | static const T local_pi = details::numeric::details::const_pi_impl<T>(num_type); 21354 | return add_constant("pi",local_pi); 21355 | } 21356 | 21357 | inline bool add_epsilon() 21358 | { 21359 | static const T local_epsilon = details::numeric::details::epsilon_type<T>::value(); 21360 | return add_constant("epsilon",local_epsilon); 21361 | } 21362 | 21363 | inline bool add_infinity() 21364 | { 21365 | static const T local_infinity = std::numeric_limits<T>::infinity(); 21366 | return add_constant("inf",local_infinity); 21367 | } 21368 | 21369 | template <typename Package> 21370 | inline bool add_package(Package& package) 21371 | { 21372 | return package.register_package(*this); 21373 | } 21374 | 21375 | template <typename Allocator, 21376 | template <typename, typename> class Sequence> 21377 | inline std::size_t get_variable_list(Sequence<std::pair<std::string,T>,Allocator>& vlist) const 21378 | { 21379 | if (!valid()) 21380 | return 0; 21381 | else 21382 | return local_data().variable_store.get_list(vlist); 21383 | } 21384 | 21385 | template <typename Allocator, 21386 | template <typename, typename> class Sequence> 21387 | inline std::size_t get_variable_list(Sequence<std::string,Allocator>& vlist) const 21388 | { 21389 | if (!valid()) 21390 | return 0; 21391 | else 21392 | return local_data().variable_store.get_list(vlist); 21393 | } 21394 | 21395 | #ifndef exprtk_disable_string_capabilities 21396 | template <typename Allocator, 21397 | template <typename, typename> class Sequence> 21398 | inline std::size_t get_stringvar_list(Sequence<std::pair<std::string,std::string>,Allocator>& svlist) const 21399 | { 21400 | if (!valid()) 21401 | return 0; 21402 | else 21403 | return local_data().stringvar_store.get_list(svlist); 21404 | } 21405 | 21406 | template <typename Allocator, 21407 | template <typename, typename> class Sequence> 21408 | inline std::size_t get_stringvar_list(Sequence<std::string,Allocator>& svlist) const 21409 | { 21410 | if (!valid()) 21411 | return 0; 21412 | else 21413 | return local_data().stringvar_store.get_list(svlist); 21414 | } 21415 | #endif 21416 | 21417 | template <typename Allocator, 21418 | template <typename, typename> class Sequence> 21419 | inline std::size_t get_vector_list(Sequence<std::string,Allocator>& vec_list) const 21420 | { 21421 | if (!valid()) 21422 | return 0; 21423 | else 21424 | return local_data().vector_store.get_list(vec_list); 21425 | } 21426 | 21427 | template <typename Allocator, 21428 | template <typename, typename> class Sequence> 21429 | inline std::size_t get_function_list(Sequence<std::string,Allocator>& function_list) const 21430 | { 21431 | if (!valid()) 21432 | return 0; 21433 | 21434 | std::vector<std::string> function_names; 21435 | std::size_t count = 0; 21436 | 21437 | count += local_data().function_store .get_list(function_names); 21438 | count += local_data().vararg_function_store .get_list(function_names); 21439 | count += local_data().generic_function_store .get_list(function_names); 21440 | count += local_data().string_function_store .get_list(function_names); 21441 | count += local_data().overload_function_store.get_list(function_names); 21442 | 21443 | std::set<std::string> function_set; 21444 | 21445 | for (std::size_t i = 0; i < function_names.size(); ++i) 21446 | { 21447 | function_set.insert(function_names[i]); 21448 | } 21449 | 21450 | std::copy(function_set.begin(), function_set.end(), 21451 | std::back_inserter(function_list)); 21452 | 21453 | return count; 21454 | } 21455 | 21456 | inline std::vector<std::string> get_function_list() const 21457 | { 21458 | std::vector<std::string> result; 21459 | get_function_list(result); 21460 | return result; 21461 | } 21462 | 21463 | inline bool symbol_exists(const std::string& symbol_name, const bool check_reserved_symb = true) const 21464 | { 21465 | /* 21466 | Function will return true if symbol_name exists as either a 21467 | reserved symbol, variable, stringvar, vector or function name 21468 | in any of the type stores. 21469 | */ 21470 | if (!valid()) 21471 | return false; 21472 | else if (local_data().variable_store.symbol_exists(symbol_name)) 21473 | return true; 21474 | #ifndef exprtk_disable_string_capabilities 21475 | else if (local_data().stringvar_store.symbol_exists(symbol_name)) 21476 | return true; 21477 | #endif 21478 | else if (local_data().vector_store.symbol_exists(symbol_name)) 21479 | return true; 21480 | else if (local_data().function_store.symbol_exists(symbol_name)) 21481 | return true; 21482 | else if (check_reserved_symb && local_data().is_reserved_symbol(symbol_name)) 21483 | return true; 21484 | else 21485 | return false; 21486 | } 21487 | 21488 | inline bool is_variable(const std::string& variable_name) const 21489 | { 21490 | if (!valid()) 21491 | return false; 21492 | else 21493 | return local_data().variable_store.symbol_exists(variable_name); 21494 | } 21495 | 21496 | #ifndef exprtk_disable_string_capabilities 21497 | inline bool is_stringvar(const std::string& stringvar_name) const 21498 | { 21499 | if (!valid()) 21500 | return false; 21501 | else 21502 | return local_data().stringvar_store.symbol_exists(stringvar_name); 21503 | } 21504 | 21505 | inline bool is_conststr_stringvar(const std::string& symbol_name) const 21506 | { 21507 | if (!valid()) 21508 | return false; 21509 | else if (!valid_symbol(symbol_name)) 21510 | return false; 21511 | else if (!local_data().stringvar_store.symbol_exists(symbol_name)) 21512 | return false; 21513 | 21514 | return ( 21515 | local_data().stringvar_store.symbol_exists(symbol_name) || 21516 | local_data().stringvar_store.is_constant (symbol_name) 21517 | ); 21518 | } 21519 | #endif 21520 | 21521 | inline bool is_function(const std::string& function_name) const 21522 | { 21523 | if (!valid()) 21524 | return false; 21525 | else 21526 | return local_data().function_store.symbol_exists(function_name); 21527 | } 21528 | 21529 | inline bool is_vararg_function(const std::string& vararg_function_name) const 21530 | { 21531 | if (!valid()) 21532 | return false; 21533 | else 21534 | return local_data().vararg_function_store.symbol_exists(vararg_function_name); 21535 | } 21536 | 21537 | inline bool is_vector(const std::string& vector_name) const 21538 | { 21539 | if (!valid()) 21540 | return false; 21541 | else 21542 | return local_data().vector_store.symbol_exists(vector_name); 21543 | } 21544 | 21545 | inline std::string get_variable_name(const expression_ptr& ptr) const 21546 | { 21547 | return local_data().variable_store.entity_name(ptr); 21548 | } 21549 | 21550 | inline std::string get_vector_name(const vector_holder_ptr& ptr) const 21551 | { 21552 | return local_data().vector_store.entity_name(ptr); 21553 | } 21554 | 21555 | #ifndef exprtk_disable_string_capabilities 21556 | inline std::string get_stringvar_name(const expression_ptr& ptr) const 21557 | { 21558 | return local_data().stringvar_store.entity_name(ptr); 21559 | } 21560 | 21561 | inline std::string get_conststr_stringvar_name(const expression_ptr& ptr) const 21562 | { 21563 | return local_data().stringvar_store.entity_name(ptr); 21564 | } 21565 | #endif 21566 | 21567 | inline bool valid() const 21568 | { 21569 | // Symbol table sanity check. 21570 | return control_block_ && control_block_->data_; 21571 | } 21572 | 21573 | inline void load_from(const symbol_table<T>& st) 21574 | { 21575 | { 21576 | std::vector<std::string> name_list; 21577 | 21578 | st.local_data().function_store.get_list(name_list); 21579 | 21580 | if (!name_list.empty()) 21581 | { 21582 | for (std::size_t i = 0; i < name_list.size(); ++i) 21583 | { 21584 | exprtk::ifunction<T>& ifunc = *st.get_function(name_list[i]); 21585 | add_function(name_list[i],ifunc); 21586 | } 21587 | } 21588 | } 21589 | 21590 | { 21591 | std::vector<std::string> name_list; 21592 | 21593 | st.local_data().vararg_function_store.get_list(name_list); 21594 | 21595 | if (!name_list.empty()) 21596 | { 21597 | for (std::size_t i = 0; i < name_list.size(); ++i) 21598 | { 21599 | exprtk::ivararg_function<T>& ivafunc = *st.get_vararg_function(name_list[i]); 21600 | add_function(name_list[i],ivafunc); 21601 | } 21602 | } 21603 | } 21604 | 21605 | { 21606 | std::vector<std::string> name_list; 21607 | 21608 | st.local_data().generic_function_store.get_list(name_list); 21609 | 21610 | if (!name_list.empty()) 21611 | { 21612 | for (std::size_t i = 0; i < name_list.size(); ++i) 21613 | { 21614 | exprtk::igeneric_function<T>& ifunc = *st.get_generic_function(name_list[i]); 21615 | add_function(name_list[i],ifunc); 21616 | } 21617 | } 21618 | } 21619 | 21620 | { 21621 | std::vector<std::string> name_list; 21622 | 21623 | st.local_data().string_function_store.get_list(name_list); 21624 | 21625 | if (!name_list.empty()) 21626 | { 21627 | for (std::size_t i = 0; i < name_list.size(); ++i) 21628 | { 21629 | exprtk::igeneric_function<T>& ifunc = *st.get_string_function(name_list[i]); 21630 | add_function(name_list[i],ifunc); 21631 | } 21632 | } 21633 | } 21634 | 21635 | { 21636 | std::vector<std::string> name_list; 21637 | 21638 | st.local_data().overload_function_store.get_list(name_list); 21639 | 21640 | if (!name_list.empty()) 21641 | { 21642 | for (std::size_t i = 0; i < name_list.size(); ++i) 21643 | { 21644 | exprtk::igeneric_function<T>& ifunc = *st.get_overload_function(name_list[i]); 21645 | add_function(name_list[i],ifunc); 21646 | } 21647 | } 21648 | } 21649 | } 21650 | 21651 | inline void load_variables_from(const symbol_table<T>& st) 21652 | { 21653 | std::vector<std::string> name_list; 21654 | 21655 | st.local_data().variable_store.get_list(name_list); 21656 | 21657 | if (!name_list.empty()) 21658 | { 21659 | for (std::size_t i = 0; i < name_list.size(); ++i) 21660 | { 21661 | T& variable = st.get_variable(name_list[i])->ref(); 21662 | add_variable(name_list[i], variable); 21663 | } 21664 | } 21665 | } 21666 | 21667 | inline void load_vectors_from(const symbol_table<T>& st) 21668 | { 21669 | std::vector<std::string> name_list; 21670 | 21671 | st.local_data().vector_store.get_list(name_list); 21672 | 21673 | if (!name_list.empty()) 21674 | { 21675 | for (std::size_t i = 0; i < name_list.size(); ++i) 21676 | { 21677 | vector_holder_t& vecholder = *st.get_vector(name_list[i]); 21678 | add_vector(name_list[i], vecholder.data(), vecholder.size()); 21679 | } 21680 | } 21681 | } 21682 | 21683 | private: 21684 | 21685 | inline bool valid_symbol(const std::string& symbol, const bool check_reserved_symb = true) const 21686 | { 21687 | if (symbol.empty()) 21688 | return false; 21689 | else if (!details::is_letter(symbol[0])) 21690 | return false; 21691 | else if (symbol.size() > 1) 21692 | { 21693 | for (std::size_t i = 1; i < symbol.size(); ++i) 21694 | { 21695 | if ( 21696 | !details::is_letter_or_digit(symbol[i]) && 21697 | ('_' != symbol[i]) 21698 | ) 21699 | { 21700 | if ((i < (symbol.size() - 1)) && ('.' == symbol[i])) 21701 | continue; 21702 | else 21703 | return false; 21704 | } 21705 | } 21706 | } 21707 | 21708 | return (check_reserved_symb) ? (!local_data().is_reserved_symbol(symbol)) : true; 21709 | } 21710 | 21711 | inline bool valid_function(const std::string& symbol) const 21712 | { 21713 | if (symbol.empty()) 21714 | return false; 21715 | else if (!details::is_letter(symbol[0])) 21716 | return false; 21717 | else if (symbol.size() > 1) 21718 | { 21719 | for (std::size_t i = 1; i < symbol.size(); ++i) 21720 | { 21721 | if ( 21722 | !details::is_letter_or_digit(symbol[i]) && 21723 | ('_' != symbol[i]) 21724 | ) 21725 | { 21726 | if ((i < (symbol.size() - 1)) && ('.' == symbol[i])) 21727 | continue; 21728 | else 21729 | return false; 21730 | } 21731 | } 21732 | } 21733 | 21734 | return true; 21735 | } 21736 | 21737 | typedef typename control_block::st_data local_data_t; 21738 | 21739 | inline local_data_t& local_data() 21740 | { 21741 | return *(control_block_->data_); 21742 | } 21743 | 21744 | inline const local_data_t& local_data() const 21745 | { 21746 | return *(control_block_->data_); 21747 | } 21748 | 21749 | control_block* control_block_; 21750 | 21751 | friend class parser<T>; 21752 | }; // class symbol_table 21753 | 21754 | template <typename T> 21755 | class function_compositor; 21756 | 21757 | template <typename T> 21758 | class expression 21759 | { 21760 | private: 21761 | 21762 | typedef details::expression_node<T>* expression_ptr; 21763 | typedef details::vector_holder<T>* vector_holder_ptr; 21764 | typedef std::vector<symbol_table<T> > symtab_list_t; 21765 | 21766 | struct control_block 21767 | { 21768 | enum data_type 21769 | { 21770 | e_unknown , 21771 | e_expr , 21772 | e_vecholder, 21773 | e_data , 21774 | e_vecdata , 21775 | e_string 21776 | }; 21777 | 21778 | static std::string to_str(data_type dt) 21779 | { 21780 | switch (dt) 21781 | { 21782 | case e_unknown : return "e_unknown " 21783 | case e_expr : return "e_expr" ; 21784 | case e_vecholder : return "e_vecholder" 21785 | case e_data : return "e_data" ; 21786 | case e_vecdata : return "e_vecdata" ; 21787 | case e_string : return "e_string" ; 21788 | } 21789 | 21790 | return "" 21791 | } 21792 | 21793 | struct data_pack 21794 | { 21795 | data_pack() 21796 | : pointer(0) 21797 | , type(e_unknown) 21798 | , size(0) 21799 | {} 21800 | 21801 | data_pack(void* ptr, const data_type dt, const std::size_t sz = 0) 21802 | : pointer(ptr) 21803 | , type(dt) 21804 | , size(sz) 21805 | {} 21806 | 21807 | void* pointer; 21808 | data_type type; 21809 | std::size_t size; 21810 | }; 21811 | 21812 | typedef std::vector<data_pack> local_data_list_t; 21813 | typedef results_context<T> results_context_t; 21814 | typedef control_block* cntrl_blck_ptr_t; 21815 | 21816 | control_block() 21817 | : ref_count(0) 21818 | , expr (0) 21819 | , results (0) 21820 | , retinv_null(false) 21821 | , return_invoked(&retinv_null) 21822 | {} 21823 | 21824 | explicit control_block(expression_ptr e) 21825 | : ref_count(1) 21826 | , expr (e) 21827 | , results (0) 21828 | , retinv_null(false) 21829 | , return_invoked(&retinv_null) 21830 | {} 21831 | 21832 | ~control_block() 21833 | { 21834 | if (expr && details::branch_deletable(expr)) 21835 | { 21836 | destroy_node(expr); 21837 | } 21838 | 21839 | if (!local_data_list.empty()) 21840 | { 21841 | for (std::size_t i = 0; i < local_data_list.size(); ++i) 21842 | { 21843 | switch (local_data_list[i].type) 21844 | { 21845 | case e_expr : delete reinterpret_cast<expression_ptr>(local_data_list[i].pointer); 21846 | break; 21847 | 21848 | case e_vecholder : delete reinterpret_cast<vector_holder_ptr>(local_data_list[i].pointer); 21849 | break; 21850 | 21851 | case e_data : delete reinterpret_cast<T*>(local_data_list[i].pointer); 21852 | break; 21853 | 21854 | case e_vecdata : delete [] reinterpret_cast<T*>(local_data_list[i].pointer); 21855 | break; 21856 | 21857 | case e_string : delete reinterpret_cast<std::string*>(local_data_list[i].pointer); 21858 | break; 21859 | 21860 | default : break; 21861 | } 21862 | } 21863 | } 21864 | 21865 | if (results) 21866 | { 21867 | delete results; 21868 | } 21869 | } 21870 | 21871 | static inline cntrl_blck_ptr_t create(expression_ptr e) 21872 | { 21873 | return new control_block(e); 21874 | } 21875 | 21876 | static inline void destroy(cntrl_blck_ptr_t& cntrl_blck) 21877 | { 21878 | if (cntrl_blck) 21879 | { 21880 | if ( 21881 | (0 != cntrl_blck->ref_count) && 21882 | (0 == --cntrl_blck->ref_count) 21883 | ) 21884 | { 21885 | delete cntrl_blck; 21886 | } 21887 | 21888 | cntrl_blck = 0; 21889 | } 21890 | } 21891 | 21892 | std::size_t ref_count; 21893 | expression_ptr expr; 21894 | local_data_list_t local_data_list; 21895 | results_context_t* results; 21896 | bool retinv_null; 21897 | bool* return_invoked; 21898 | 21899 | friend class function_compositor<T>; 21900 | }; 21901 | 21902 | public: 21903 | 21904 | expression() 21905 | : control_block_(0) 21906 | { 21907 | set_expression(new details::null_node<T>()); 21908 | } 21909 | 21910 | expression(const expression<T>& e) 21911 | : control_block_ (e.control_block_ ) 21912 | , symbol_table_list_(e.symbol_table_list_) 21913 | { 21914 | control_block_->ref_count++; 21915 | } 21916 | 21917 | explicit expression(const symbol_table<T>& symbol_table) 21918 | : control_block_(0) 21919 | { 21920 | set_expression(new details::null_node<T>()); 21921 | symbol_table_list_.push_back(symbol_table); 21922 | } 21923 | 21924 | inline expression<T>& operator=(const expression<T>& e) 21925 | { 21926 | if (this != &e) 21927 | { 21928 | if (control_block_) 21929 | { 21930 | if ( 21931 | (0 != control_block_->ref_count) && 21932 | (0 == --control_block_->ref_count) 21933 | ) 21934 | { 21935 | delete control_block_; 21936 | } 21937 | 21938 | control_block_ = 0; 21939 | } 21940 | 21941 | control_block_ = e.control_block_; 21942 | control_block_->ref_count++; 21943 | symbol_table_list_ = e.symbol_table_list_; 21944 | } 21945 | 21946 | return *this; 21947 | } 21948 | 21949 | inline bool operator==(const expression<T>& e) const 21950 | { 21951 | return (this == &e); 21952 | } 21953 | 21954 | inline bool operator!() const 21955 | { 21956 | return ( 21957 | (0 == control_block_ ) || 21958 | (0 == control_block_->expr) 21959 | ); 21960 | } 21961 | 21962 | inline expression<T>& release() 21963 | { 21964 | exprtk::details::dump_ptr("expression::release", this); 21965 | control_block::destroy(control_block_); 21966 | 21967 | return (*this); 21968 | } 21969 | 21970 | ~expression() 21971 | { 21972 | control_block::destroy(control_block_); 21973 | } 21974 | 21975 | inline T value() const 21976 | { 21977 | assert(control_block_ ); 21978 | assert(control_block_->expr); 21979 | 21980 | return control_block_->expr->value(); 21981 | } 21982 | 21983 | inline T operator() () const 21984 | { 21985 | return value(); 21986 | } 21987 | 21988 | inline operator T() const 21989 | { 21990 | return value(); 21991 | } 21992 | 21993 | inline operator bool() const 21994 | { 21995 | return details::is_true(value()); 21996 | } 21997 | 21998 | inline bool register_symbol_table(symbol_table<T>& st) 21999 | { 22000 | for (std::size_t i = 0; i < symbol_table_list_.size(); ++i) 22001 | { 22002 | if (st == symbol_table_list_[i]) 22003 | { 22004 | return false; 22005 | } 22006 | } 22007 | 22008 | symbol_table_list_.push_back(st); 22009 | return true; 22010 | } 22011 | 22012 | inline const symbol_table<T>& get_symbol_table(const std::size_t& index = 0) const 22013 | { 22014 | return symbol_table_list_[index]; 22015 | } 22016 | 22017 | inline symbol_table<T>& get_symbol_table(const std::size_t& index = 0) 22018 | { 22019 | return symbol_table_list_[index]; 22020 | } 22021 | 22022 | std::size_t num_symbol_tables() const 22023 | { 22024 | return symbol_table_list_.size(); 22025 | } 22026 | 22027 | typedef results_context<T> results_context_t; 22028 | 22029 | inline const results_context_t& results() const 22030 | { 22031 | if (control_block_->results) 22032 | return (*control_block_->results); 22033 | else 22034 | { 22035 | static const results_context_t null_results; 22036 | return null_results; 22037 | } 22038 | } 22039 | 22040 | inline bool return_invoked() const 22041 | { 22042 | return (*control_block_->return_invoked); 22043 | } 22044 | 22045 | private: 22046 | 22047 | inline symtab_list_t get_symbol_table_list() const 22048 | { 22049 | return symbol_table_list_; 22050 | } 22051 | 22052 | inline void set_expression(const expression_ptr expr) 22053 | { 22054 | if (expr) 22055 | { 22056 | if (control_block_) 22057 | { 22058 | if (0 == --control_block_->ref_count) 22059 | { 22060 | delete control_block_; 22061 | } 22062 | } 22063 | 22064 | control_block_ = control_block::create(expr); 22065 | } 22066 | } 22067 | 22068 | inline void register_local_var(expression_ptr expr) 22069 | { 22070 | if (expr) 22071 | { 22072 | if (control_block_) 22073 | { 22074 | control_block_-> 22075 | local_data_list.push_back( 22076 | typename expression<T>::control_block:: 22077 | data_pack(reinterpret_cast<void*>(expr), 22078 | control_block::e_expr)); 22079 | } 22080 | } 22081 | } 22082 | 22083 | inline void register_local_var(vector_holder_ptr vec_holder) 22084 | { 22085 | if (vec_holder) 22086 | { 22087 | if (control_block_) 22088 | { 22089 | control_block_-> 22090 | local_data_list.push_back( 22091 | typename expression<T>::control_block:: 22092 | data_pack(reinterpret_cast<void*>(vec_holder), 22093 | control_block::e_vecholder)); 22094 | } 22095 | } 22096 | } 22097 | 22098 | inline void register_local_data(void* data, const std::size_t& size = 0, const std::size_t data_mode = 0) 22099 | { 22100 | if (data) 22101 | { 22102 | if (control_block_) 22103 | { 22104 | typename control_block::data_type dt = control_block::e_data; 22105 | 22106 | switch (data_mode) 22107 | { 22108 | case 0 : dt = control_block::e_data; break; 22109 | case 1 : dt = control_block::e_vecdata; break; 22110 | case 2 : dt = control_block::e_string; break; 22111 | } 22112 | 22113 | control_block_-> 22114 | local_data_list.push_back( 22115 | typename expression<T>::control_block:: 22116 | data_pack(reinterpret_cast<void*>(data), dt, size)); 22117 | } 22118 | } 22119 | } 22120 | 22121 | inline const typename control_block::local_data_list_t& local_data_list() 22122 | { 22123 | if (control_block_) 22124 | { 22125 | return control_block_->local_data_list; 22126 | } 22127 | else 22128 | { 22129 | static typename control_block::local_data_list_t null_local_data_list; 22130 | return null_local_data_list; 22131 | } 22132 | } 22133 | 22134 | inline void register_return_results(results_context_t* rc) 22135 | { 22136 | if (control_block_ && rc) 22137 | { 22138 | control_block_->results = rc; 22139 | } 22140 | } 22141 | 22142 | inline void set_retinvk(bool* retinvk_ptr) 22143 | { 22144 | if (control_block_) 22145 | { 22146 | control_block_->return_invoked = retinvk_ptr; 22147 | } 22148 | } 22149 | 22150 | control_block* control_block_; 22151 | symtab_list_t symbol_table_list_; 22152 | 22153 | friend class parser<T>; 22154 | friend class expression_helper<T>; 22155 | friend class function_compositor<T>; 22156 | template <typename TT> 22157 | friend bool is_valid(const expression<TT>& expr); 22158 | }; // class expression 22159 | 22160 | template <typename T> 22161 | class expression_helper 22162 | { 22163 | public: 22164 | 22165 | enum node_types 22166 | { 22167 | e_literal, 22168 | e_variable, 22169 | e_string, 22170 | e_unary, 22171 | e_binary, 22172 | e_function, 22173 | e_vararg, 22174 | e_null, 22175 | e_assert, 22176 | e_sf3ext, 22177 | e_sf4ext 22178 | }; 22179 | 22180 | static inline bool is_literal(const expression<T>& expr) 22181 | { 22182 | return expr.control_block_ && details::is_literal_node(expr.control_block_->expr); 22183 | } 22184 | 22185 | static inline bool is_variable(const expression<T>& expr) 22186 | { 22187 | return expr.control_block_ && details::is_variable_node(expr.control_block_->expr); 22188 | } 22189 | 22190 | static inline bool is_string(const expression<T>& expr) 22191 | { 22192 | return expr.control_block_ && details::is_generally_string_node(expr.control_block_->expr); 22193 | } 22194 | 22195 | static inline bool is_unary(const expression<T>& expr) 22196 | { 22197 | return expr.control_block_ && details::is_unary_node(expr.control_block_->expr); 22198 | } 22199 | 22200 | static inline bool is_binary(const expression<T>& expr) 22201 | { 22202 | return expr.control_block_ && details::is_binary_node(expr.control_block_->expr); 22203 | } 22204 | 22205 | static inline bool is_function(const expression<T>& expr) 22206 | { 22207 | return expr.control_block_ && details::is_function(expr.control_block_->expr); 22208 | } 22209 | 22210 | static inline bool is_vararg(const expression<T>& expr) 22211 | { 22212 | return expr.control_block_ && details::is_vararg_node(expr.control_block_->expr); 22213 | } 22214 | 22215 | static inline bool is_null(const expression<T>& expr) 22216 | { 22217 | return expr.control_block_ && details::is_null_node(expr.control_block_->expr); 22218 | } 22219 | 22220 | static inline bool is_assert(const expression<T>& expr) 22221 | { 22222 | return expr.control_block_ && details::is_assert_node(expr.control_block_->expr); 22223 | } 22224 | 22225 | static inline bool is_sf3ext(const expression<T>& expr) 22226 | { 22227 | return expr.control_block_ && details::is_sf3ext_node(expr.control_block_->expr); 22228 | } 22229 | 22230 | static inline bool is_sf4ext(const expression<T>& expr) 22231 | { 22232 | return expr.control_block_ && details::is_sf4ext_node(expr.control_block_->expr); 22233 | } 22234 | 22235 | static inline bool is_type(const expression<T>& expr, const node_types node_type) 22236 | { 22237 | if (0 == expr.control_block_) 22238 | { 22239 | return false; 22240 | } 22241 | 22242 | switch (node_type) 22243 | { 22244 | case e_literal : return is_literal_node(expr); 22245 | case e_variable : return is_variable (expr); 22246 | case e_string : return is_string (expr); 22247 | case e_unary : return is_unary (expr); 22248 | case e_binary : return is_binary (expr); 22249 | case e_function : return is_function (expr); 22250 | case e_null : return is_null (expr); 22251 | case e_assert : return is_assert (expr); 22252 | case e_sf3ext : return is_sf3ext (expr); 22253 | case e_sf4ext : return is_sf4ext (expr); 22254 | }; 22255 | 22256 | return false; 22257 | } 22258 | 22259 | static inline bool match_type_sequence(const expression<T>& expr, const std::vector<node_types>& type_seq) 22260 | { 22261 | if ((0 == expr.control_block_) || !is_vararg(expr)) 22262 | { 22263 | return false; 22264 | } 22265 | 22266 | typedef details::vararg_node<T, exprtk::details::vararg_multi_op<T> > mo_vararg_t; 22267 | 22268 | mo_vararg_t* vnode = dynamic_cast<mo_vararg_t*>(expr.control_block_->expr); 22269 | 22270 | if ( 22271 | (0 == vnode) || 22272 | type_seq.empty() || 22273 | (vnode->size() < type_seq.size()) 22274 | ) 22275 | { 22276 | return false; 22277 | } 22278 | 22279 | for (std::size_t i = 0; i < type_seq.size(); ++i) 22280 | { 22281 | assert((*vnode)[i]); 22282 | 22283 | switch (type_seq[i]) 22284 | { 22285 | case e_literal : { if (details::is_literal_node ((*vnode)[i])) continue; } break; 22286 | case e_variable : { if (details::is_variable_node ((*vnode)[i])) continue; } break; 22287 | case e_string : { if (details::is_generally_string_node((*vnode)[i])) continue; } break; 22288 | case e_unary : { if (details::is_unary_node ((*vnode)[i])) continue; } break; 22289 | case e_binary : { if (details::is_binary_node ((*vnode)[i])) continue; } break; 22290 | case e_function : { if (details::is_function ((*vnode)[i])) continue; } break; 22291 | case e_null : { if (details::is_null_node ((*vnode)[i])) continue; } break; 22292 | case e_assert : { if (details::is_assert_node ((*vnode)[i])) continue; } break; 22293 | case e_sf3ext : { if (details::is_sf3ext_node ((*vnode)[i])) continue; } break; 22294 | case e_sf4ext : { if (details::is_sf4ext_node ((*vnode)[i])) continue; } break; 22295 | case e_vararg : break; 22296 | } 22297 | 22298 | return false; 22299 | } 22300 | 22301 | return true; 22302 | } 22303 | }; 22304 | 22305 | template <typename T> 22306 | inline bool is_valid(const expression<T>& expr) 22307 | { 22308 | return expr.control_block_ && !expression_helper<T>::is_null(expr); 22309 | } 22310 | 22311 | namespace parser_error 22312 | { 22313 | enum error_mode 22314 | { 22315 | e_unknown = 0, 22316 | e_syntax = 1, 22317 | e_token = 2, 22318 | e_numeric = 4, 22319 | e_symtab = 5, 22320 | e_lexer = 6, 22321 | e_synthesis = 7, 22322 | e_helper = 8, 22323 | e_parser = 9 22324 | }; 22325 | 22326 | struct type 22327 | { 22328 | type() 22329 | : mode(parser_error::e_unknown) 22330 | , line_no (0) 22331 | , column_no(0) 22332 | {} 22333 | 22334 | lexer::token token; 22335 | error_mode mode; 22336 | std::string diagnostic; 22337 | std::string src_location; 22338 | std::string error_line; 22339 | std::size_t line_no; 22340 | std::size_t column_no; 22341 | }; 22342 | 22343 | inline type make_error(const error_mode mode, 22344 | const std::string& diagnostic = "", 22345 | const std::string& src_location = "") 22346 | { 22347 | type t; 22348 | t.mode = mode; 22349 | t.token.type = lexer::token::e_error; 22350 | t.diagnostic = diagnostic; 22351 | t.src_location = src_location; 22352 | exprtk_debug(("%s\n", diagnostic .c_str())); 22353 | return t; 22354 | } 22355 | 22356 | inline type make_error(const error_mode mode, 22357 | const lexer::token& tk, 22358 | const std::string& diagnostic = "", 22359 | const std::string& src_location = "") 22360 | { 22361 | type t; 22362 | t.mode = mode; 22363 | t.token = tk; 22364 | t.diagnostic = diagnostic; 22365 | t.src_location = src_location; 22366 | exprtk_debug(("%s\n", diagnostic .c_str())); 22367 | return t; 22368 | } 22369 | 22370 | inline std::string to_str(error_mode mode) 22371 | { 22372 | switch (mode) 22373 | { 22374 | case e_unknown : return std::string("Unknown Error"); 22375 | case e_syntax : return std::string("Syntax Error" ); 22376 | case e_token : return std::string("Token Error" ); 22377 | case e_numeric : return std::string("Numeric Error"); 22378 | case e_symtab : return std::string("Symbol Error" ); 22379 | case e_lexer : return std::string("Lexer Error" ); 22380 | case e_helper : return std::string("Helper Error" ); 22381 | case e_parser : return std::string("Parser Error" ); 22382 | default : return std::string("Unknown Error"); 22383 | } 22384 | } 22385 | 22386 | inline bool update_error(type& error, const std::string& expression) 22387 | { 22388 | if ( 22389 | expression.empty() || 22390 | (error.token.position > expression.size()) || 22391 | (std::numeric_limits<std::size_t>::max() == error.token.position) 22392 | ) 22393 | { 22394 | return false; 22395 | } 22396 | 22397 | std::size_t error_line_start = 0; 22398 | 22399 | for (std::size_t i = error.token.position; i > 0; --i) 22400 | { 22401 | const details::char_t c = expression[i]; 22402 | 22403 | if (('\n' == c) || ('\r' == c)) 22404 | { 22405 | error_line_start = i + 1; 22406 | break; 22407 | } 22408 | } 22409 | 22410 | std::size_t next_nl_position = std::min(expression.size(), 22411 | expression.find_first_of('\n',error.token.position + 1)); 22412 | 22413 | error.column_no = error.token.position - error_line_start; 22414 | error.error_line = expression.substr(error_line_start, 22415 | next_nl_position - error_line_start); 22416 | 22417 | error.line_no = 0; 22418 | 22419 | for (std::size_t i = 0; i < next_nl_position; ++i) 22420 | { 22421 | if ('\n' == expression[i]) 22422 | ++error.line_no; 22423 | } 22424 | 22425 | return true; 22426 | } 22427 | 22428 | inline void dump_error(const type& error) 22429 | { 22430 | printf("Position: %02d Type: [%s] Msg: %s\n", 22431 | static_cast<int>(error.token.position), 22432 | exprtk::parser_error::to_str(error.mode).c_str(), 22433 | error.diagnostic.c_str()); 22434 | } 22435 | } 22436 | 22437 | namespace details 22438 | { 22439 | template <typename Parser> 22440 | inline void disable_type_checking(Parser& p) 22441 | { 22442 | p.state_.type_check_enabled = false; 22443 | } 22444 | } 22445 | 22446 | template <typename T> 22447 | class parser : public lexer::parser_helper 22448 | { 22449 | private: 22450 | 22451 | enum precedence_level 22452 | { 22453 | e_level00, e_level01, e_level02, e_level03, e_level04, 22454 | e_level05, e_level06, e_level07, e_level08, e_level09, 22455 | e_level10, e_level11, e_level12, e_level13, e_level14 22456 | }; 22457 | 22458 | typedef const T& cref_t; 22459 | typedef const T const_t; 22460 | typedef ifunction<T> F; 22461 | typedef ivararg_function<T> VAF; 22462 | typedef igeneric_function<T> GF; 22463 | typedef ifunction<T> ifunction_t; 22464 | typedef ivararg_function<T> ivararg_function_t; 22465 | typedef igeneric_function<T> igeneric_function_t; 22466 | typedef details::expression_node<T> expression_node_t; 22467 | typedef details::literal_node<T> literal_node_t; 22468 | typedef details::unary_node<T> unary_node_t; 22469 | typedef details::binary_node<T> binary_node_t; 22470 | typedef details::trinary_node<T> trinary_node_t; 22471 | typedef details::quaternary_node<T> quaternary_node_t; 22472 | typedef details::conditional_node<T> conditional_node_t; 22473 | typedef details::cons_conditional_node<T> cons_conditional_node_t; 22474 | typedef details::while_loop_node<T> while_loop_node_t; 22475 | typedef details::repeat_until_loop_node<T> repeat_until_loop_node_t; 22476 | typedef details::for_loop_node<T> for_loop_node_t; 22477 | typedef details::while_loop_rtc_node<T> while_loop_rtc_node_t; 22478 | typedef details::repeat_until_loop_rtc_node<T> repeat_until_loop_rtc_node_t; 22479 | typedef details::for_loop_rtc_node<T> for_loop_rtc_node_t; 22480 | #ifndef exprtk_disable_break_continue 22481 | typedef details::while_loop_bc_node<T> while_loop_bc_node_t; 22482 | typedef details::repeat_until_loop_bc_node<T> repeat_until_loop_bc_node_t; 22483 | typedef details::for_loop_bc_node<T> for_loop_bc_node_t; 22484 | typedef details::while_loop_bc_rtc_node<T> while_loop_bc_rtc_node_t; 22485 | typedef details::repeat_until_loop_bc_rtc_node<T> repeat_until_loop_bc_rtc_node_t; 22486 | typedef details::for_loop_bc_rtc_node<T> for_loop_bc_rtc_node_t; 22487 | #endif 22488 | typedef details::switch_node<T> switch_node_t; 22489 | typedef details::variable_node<T> variable_node_t; 22490 | typedef details::vector_elem_node<T> vector_elem_node_t; 22491 | typedef details::vector_celem_node<T> vector_celem_node_t; 22492 | typedef details::vector_elem_rtc_node<T> vector_elem_rtc_node_t; 22493 | typedef details::vector_celem_rtc_node<T> vector_celem_rtc_node_t; 22494 | typedef details::rebasevector_elem_node<T> rebasevector_elem_node_t; 22495 | typedef details::rebasevector_celem_node<T> rebasevector_celem_node_t; 22496 | typedef details::rebasevector_elem_rtc_node<T> rebasevector_elem_rtc_node_t; 22497 | typedef details::rebasevector_celem_rtc_node<T> rebasevector_celem_rtc_node_t; 22498 | typedef details::vector_node<T> vector_node_t; 22499 | typedef details::vector_size_node<T> vector_size_node_t; 22500 | typedef details::range_pack<T> range_t; 22501 | #ifndef exprtk_disable_string_capabilities 22502 | typedef details::stringvar_node<T> stringvar_node_t; 22503 | typedef details::string_literal_node<T> string_literal_node_t; 22504 | typedef details::string_range_node<T> string_range_node_t; 22505 | typedef details::const_string_range_node<T> const_string_range_node_t; 22506 | typedef details::generic_string_range_node<T> generic_string_range_node_t; 22507 | typedef details::string_concat_node<T> string_concat_node_t; 22508 | typedef details::assignment_string_node<T> assignment_string_node_t; 22509 | typedef details::assignment_string_range_node<T> assignment_string_range_node_t; 22510 | typedef details::conditional_string_node<T> conditional_string_node_t; 22511 | typedef details::cons_conditional_str_node<T> cons_conditional_str_node_t; 22512 | #endif 22513 | typedef details::assignment_node<T> assignment_node_t; 22514 | typedef details::assignment_vec_elem_node<T> assignment_vec_elem_node_t; 22515 | typedef details::assignment_vec_elem_rtc_node<T> assignment_vec_elem_rtc_node_t; 22516 | typedef details::assignment_rebasevec_elem_node<T> assignment_rebasevec_elem_node_t; 22517 | typedef details::assignment_rebasevec_elem_rtc_node<T> assignment_rebasevec_elem_rtc_node_t; 22518 | typedef details::assignment_rebasevec_celem_node<T> assignment_rebasevec_celem_node_t; 22519 | typedef details::assignment_vec_node<T> assignment_vec_node_t; 22520 | typedef details::assignment_vecvec_node<T> assignment_vecvec_node_t; 22521 | typedef details::conditional_vector_node<T> conditional_vector_node_t; 22522 | typedef details::scand_node<T> scand_node_t; 22523 | typedef details::scor_node<T> scor_node_t; 22524 | typedef lexer::token token_t; 22525 | typedef expression_node_t* expression_node_ptr; 22526 | typedef expression<T> expression_t; 22527 | typedef symbol_table<T> symbol_table_t; 22528 | typedef typename expression<T>::symtab_list_t symbol_table_list_t; 22529 | typedef details::vector_holder<T> vector_holder_t; 22530 | typedef vector_holder_t* vector_holder_ptr; 22531 | 22532 | typedef typename details::functor_t<T> functor_t; 22533 | typedef typename functor_t::qfunc_t quaternary_functor_t; 22534 | typedef typename functor_t::tfunc_t trinary_functor_t; 22535 | typedef typename functor_t::bfunc_t binary_functor_t; 22536 | typedef typename functor_t::ufunc_t unary_functor_t; 22537 | 22538 | typedef details::operator_type operator_t; 22539 | 22540 | typedef std::map<operator_t, unary_functor_t > unary_op_map_t; 22541 | typedef std::map<operator_t, binary_functor_t > binary_op_map_t; 22542 | typedef std::map<operator_t, trinary_functor_t> trinary_op_map_t; 22543 | 22544 | typedef std::map<std::string,std::pair<trinary_functor_t ,operator_t> > sf3_map_t; 22545 | typedef std::map<std::string,std::pair<quaternary_functor_t,operator_t> > sf4_map_t; 22546 | 22547 | typedef std::map<binary_functor_t,operator_t> inv_binary_op_map_t; 22548 | typedef std::multimap<std::string,details::base_operation_t,details::ilesscompare> base_ops_map_t; 22549 | typedef std::set<std::string,details::ilesscompare> disabled_func_set_t; 22550 | 22551 | typedef details::T0oT1_define<T, cref_t , cref_t > vov_t; 22552 | typedef details::T0oT1_define<T, const_t, cref_t > cov_t; 22553 | typedef details::T0oT1_define<T, cref_t , const_t> voc_t; 22554 | 22555 | typedef details::T0oT1oT2_define<T, cref_t , cref_t , cref_t > vovov_t; 22556 | typedef details::T0oT1oT2_define<T, cref_t , cref_t , const_t> vovoc_t; 22557 | typedef details::T0oT1oT2_define<T, cref_t , const_t, cref_t > vocov_t; 22558 | typedef details::T0oT1oT2_define<T, const_t, cref_t , cref_t > covov_t; 22559 | typedef details::T0oT1oT2_define<T, const_t, cref_t , const_t> covoc_t; 22560 | typedef details::T0oT1oT2_define<T, const_t, const_t, cref_t > cocov_t; 22561 | typedef details::T0oT1oT2_define<T, cref_t , const_t, const_t> vococ_t; 22562 | 22563 | typedef details::T0oT1oT2oT3_define<T, cref_t , cref_t , cref_t , cref_t > vovovov_t; 22564 | typedef details::T0oT1oT2oT3_define<T, cref_t , cref_t , cref_t , const_t> vovovoc_t; 22565 | typedef details::T0oT1oT2oT3_define<T, cref_t , cref_t , const_t, cref_t > vovocov_t; 22566 | typedef details::T0oT1oT2oT3_define<T, cref_t , const_t, cref_t , cref_t > vocovov_t; 22567 | typedef details::T0oT1oT2oT3_define<T, const_t, cref_t , cref_t , cref_t > covovov_t; 22568 | 22569 | typedef details::T0oT1oT2oT3_define<T, const_t, cref_t , const_t, cref_t > covocov_t; 22570 | typedef details::T0oT1oT2oT3_define<T, cref_t , const_t, cref_t , const_t> vocovoc_t; 22571 | typedef details::T0oT1oT2oT3_define<T, const_t, cref_t , cref_t , const_t> covovoc_t; 22572 | typedef details::T0oT1oT2oT3_define<T, cref_t , const_t, const_t, cref_t > vococov_t; 22573 | 22574 | typedef results_context<T> results_context_t; 22575 | 22576 | typedef parser_helper prsrhlpr_t; 22577 | 22578 | struct scope_element 22579 | { 22580 | enum element_type 22581 | { 22582 | e_none , 22583 | e_literal , 22584 | e_variable, 22585 | e_vector , 22586 | e_vecelem , 22587 | e_string 22588 | }; 22589 | 22590 | typedef details::vector_holder<T> vector_holder_t; 22591 | typedef literal_node_t* literal_node_ptr; 22592 | typedef variable_node_t* variable_node_ptr; 22593 | typedef vector_holder_t* vector_holder_ptr; 22594 | typedef expression_node_t* expression_node_ptr; 22595 | #ifndef exprtk_disable_string_capabilities 22596 | typedef stringvar_node_t* stringvar_node_ptr; 22597 | #endif 22598 | 22599 | scope_element() 22600 | : name("???") 22601 | , size (std::numeric_limits<std::size_t>::max()) 22602 | , index(std::numeric_limits<std::size_t>::max()) 22603 | , depth(std::numeric_limits<std::size_t>::max()) 22604 | , ref_count(0) 22605 | , ip_index (0) 22606 | , type (e_none) 22607 | , active (false) 22608 | , data (0) 22609 | , var_node (0) 22610 | , vec_node (0) 22611 | #ifndef exprtk_disable_string_capabilities 22612 | , str_node(0) 22613 | #endif 22614 | {} 22615 | 22616 | bool operator < (const scope_element& se) const 22617 | { 22618 | if (ip_index < se.ip_index) 22619 | return true; 22620 | else if (ip_index > se.ip_index) 22621 | return false; 22622 | else if (depth < se.depth) 22623 | return true; 22624 | else if (depth > se.depth) 22625 | return false; 22626 | else if (index < se.index) 22627 | return true; 22628 | else if (index > se.index) 22629 | return false; 22630 | else 22631 | return (name < se.name); 22632 | } 22633 | 22634 | void clear() 22635 | { 22636 | name = "???" 22637 | size = std::numeric_limits<std::size_t>::max(); 22638 | index = std::numeric_limits<std::size_t>::max(); 22639 | depth = std::numeric_limits<std::size_t>::max(); 22640 | type = e_none; 22641 | active = false; 22642 | ref_count = 0; 22643 | ip_index = 0; 22644 | data = 0; 22645 | var_node = 0; 22646 | vec_node = 0; 22647 | #ifndef exprtk_disable_string_capabilities 22648 | str_node = 0; 22649 | #endif 22650 | } 22651 | 22652 | std::string name; 22653 | std::size_t size; 22654 | std::size_t index; 22655 | std::size_t depth; 22656 | std::size_t ref_count; 22657 | std::size_t ip_index; 22658 | element_type type; 22659 | bool active; 22660 | void* data; 22661 | expression_node_ptr var_node; 22662 | vector_holder_ptr vec_node; 22663 | #ifndef exprtk_disable_string_capabilities 22664 | stringvar_node_ptr str_node; 22665 | #endif 22666 | }; 22667 | 22668 | class scope_element_manager 22669 | { 22670 | public: 22671 | 22672 | typedef expression_node_t* expression_node_ptr; 22673 | typedef variable_node_t* variable_node_ptr; 22674 | typedef parser<T> parser_t; 22675 | 22676 | explicit scope_element_manager(parser<T>& p) 22677 | : parser_(p) 22678 | , input_param_cnt_(0) 22679 | , total_local_symb_size_bytes_(0) 22680 | {} 22681 | 22682 | inline std::size_t size() const 22683 | { 22684 | return element_.size(); 22685 | } 22686 | 22687 | inline bool empty() const 22688 | { 22689 | return element_.empty(); 22690 | } 22691 | 22692 | inline scope_element& get_element(const std::size_t& index) 22693 | { 22694 | if (index < element_.size()) 22695 | return element_[index]; 22696 | else 22697 | return null_element_; 22698 | } 22699 | 22700 | inline scope_element& get_element(const std::string& var_name, 22701 | const std::size_t index = std::numeric_limits<std::size_t>::max()) 22702 | { 22703 | const std::size_t current_depth = parser_.state_.scope_depth; 22704 | 22705 | for (std::size_t i = 0; i < element_.size(); ++i) 22706 | { 22707 | scope_element& se = element_[i]; 22708 | 22709 | if (se.depth > current_depth) 22710 | continue; 22711 | else if ( 22712 | details::imatch(se.name, var_name) && 22713 | (se.index == index) 22714 | ) 22715 | return se; 22716 | } 22717 | 22718 | return null_element_; 22719 | } 22720 | 22721 | inline scope_element& get_active_element(const std::string& var_name, 22722 | const std::size_t index = std::numeric_limits<std::size_t>::max()) 22723 | { 22724 | const std::size_t current_depth = parser_.state_.scope_depth; 22725 | 22726 | for (std::size_t i = 0; i < element_.size(); ++i) 22727 | { 22728 | scope_element& se = element_[i]; 22729 | 22730 | if (se.depth > current_depth) 22731 | continue; 22732 | else if ( 22733 | details::imatch(se.name, var_name) && 22734 | (se.index == index) && 22735 | (se.active) 22736 | ) 22737 | return se; 22738 | } 22739 | 22740 | return null_element_; 22741 | } 22742 | 22743 | inline bool add_element(const scope_element& se) 22744 | { 22745 | for (std::size_t i = 0; i < element_.size(); ++i) 22746 | { 22747 | scope_element& cse = element_[i]; 22748 | 22749 | if ( 22750 | details::imatch(cse.name, se.name) && 22751 | (cse.depth <= se.depth) && 22752 | (cse.index == se.index) && 22753 | (cse.size == se.size ) && 22754 | (cse.type == se.type ) && 22755 | (cse.active) 22756 | ) 22757 | return false; 22758 | } 22759 | 22760 | switch (se.type) 22761 | { 22762 | case scope_element::e_variable : total_local_symb_size_bytes_ += sizeof(T); 22763 | break; 22764 | 22765 | case scope_element::e_literal : total_local_symb_size_bytes_ += sizeof(T); 22766 | break; 22767 | 22768 | case scope_element::e_vector : total_local_symb_size_bytes_ += sizeof(T) * se.size; 22769 | break; 22770 | 22771 | default : break; 22772 | } 22773 | 22774 | element_.push_back(se); 22775 | std::sort(element_.begin(),element_.end()); 22776 | 22777 | return true; 22778 | } 22779 | 22780 | inline void deactivate(const std::size_t& scope_depth) 22781 | { 22782 | exprtk_debug(("deactivate() - Scope depth: %d\n", 22783 | static_cast<int>(parser_.state_.scope_depth))); 22784 | 22785 | for (std::size_t i = 0; i < element_.size(); ++i) 22786 | { 22787 | scope_element& se = element_[i]; 22788 | 22789 | if (se.active && (se.depth >= scope_depth)) 22790 | { 22791 | exprtk_debug(("deactivate() - element[%02d] '%s'\n", 22792 | static_cast<int>(i), 22793 | se.name.c_str())); 22794 | 22795 | se.active = false; 22796 | } 22797 | } 22798 | } 22799 | 22800 | inline void free_element(scope_element& se) 22801 | { 22802 | exprtk_debug(("free_element() - se[%s]\n", se.name.c_str())); 22803 | 22804 | switch (se.type) 22805 | { 22806 | case scope_element::e_literal : delete reinterpret_cast<T*>(se.data); 22807 | delete se.var_node; 22808 | break; 22809 | 22810 | case scope_element::e_variable : delete reinterpret_cast<T*>(se.data); 22811 | delete se.var_node; 22812 | break; 22813 | 22814 | case scope_element::e_vector : delete[] reinterpret_cast<T*>(se.data); 22815 | delete se.vec_node; 22816 | break; 22817 | 22818 | case scope_element::e_vecelem : delete se.var_node; 22819 | break; 22820 | 22821 | #ifndef exprtk_disable_string_capabilities 22822 | case scope_element::e_string : delete reinterpret_cast<std::string*>(se.data); 22823 | delete se.str_node; 22824 | break; 22825 | #endif 22826 | 22827 | default : return; 22828 | } 22829 | 22830 | se.clear(); 22831 | } 22832 | 22833 | inline void cleanup() 22834 | { 22835 | for (std::size_t i = 0; i < element_.size(); ++i) 22836 | { 22837 | free_element(element_[i]); 22838 | } 22839 | 22840 | element_.clear(); 22841 | 22842 | input_param_cnt_ = 0; 22843 | total_local_symb_size_bytes_ = 0; 22844 | } 22845 | 22846 | inline std::size_t total_local_symb_size_bytes() const 22847 | { 22848 | return total_local_symb_size_bytes_; 22849 | } 22850 | 22851 | inline std::size_t next_ip_index() 22852 | { 22853 | return ++input_param_cnt_; 22854 | } 22855 | 22856 | inline expression_node_ptr get_variable(const T& v) 22857 | { 22858 | for (std::size_t i = 0; i < element_.size(); ++i) 22859 | { 22860 | scope_element& se = element_[i]; 22861 | 22862 | if ( 22863 | se.active && 22864 | se.var_node && 22865 | details::is_variable_node(se.var_node) 22866 | ) 22867 | { 22868 | variable_node_ptr vn = reinterpret_cast<variable_node_ptr>(se.var_node); 22869 | 22870 | if (&(vn->ref()) == (&v)) 22871 | { 22872 | return se.var_node; 22873 | } 22874 | } 22875 | } 22876 | 22877 | return expression_node_ptr(0); 22878 | } 22879 | 22880 | inline std::string get_vector_name(const T* data) 22881 | { 22882 | for (std::size_t i = 0; i < element_.size(); ++i) 22883 | { 22884 | scope_element& se = element_[i]; 22885 | 22886 | if ( 22887 | se.active && 22888 | se.vec_node && 22889 | (se.vec_node->data() == data) 22890 | ) 22891 | { 22892 | return se.name; 22893 | } 22894 | } 22895 | 22896 | return "neo-vector" 22897 | } 22898 | 22899 | private: 22900 | 22901 | scope_element_manager(const scope_element_manager&) exprtk_delete; 22902 | scope_element_manager& operator=(const scope_element_manager&) exprtk_delete; 22903 | 22904 | parser_t& parser_; 22905 | std::vector<scope_element> element_; 22906 | scope_element null_element_; 22907 | std::size_t input_param_cnt_; 22908 | std::size_t total_local_symb_size_bytes_; 22909 | }; 22910 | 22911 | class scope_handler 22912 | { 22913 | public: 22914 | 22915 | typedef parser<T> parser_t; 22916 | 22917 | explicit scope_handler(parser<T>& p) 22918 | : parser_(p) 22919 | { 22920 | parser_.state_.scope_depth++; 22921 | #ifdef exprtk_enable_debugging 22922 | const std::string depth(2 * parser_.state_.scope_depth,'-'); 22923 | exprtk_debug(("%s> Scope Depth: %02d\n", 22924 | depth.c_str(), 22925 | static_cast<int>(parser_.state_.scope_depth))); 22926 | #endif 22927 | } 22928 | 22929 | ~scope_handler() 22930 | { 22931 | parser_.sem_.deactivate(parser_.state_.scope_depth); 22932 | parser_.state_.scope_depth--; 22933 | #ifdef exprtk_enable_debugging 22934 | const std::string depth(2 * parser_.state_.scope_depth,'-'); 22935 | exprtk_debug(("<%s Scope Depth: %02d\n", 22936 | depth.c_str(), 22937 | static_cast<int>(parser_.state_.scope_depth))); 22938 | #endif 22939 | } 22940 | 22941 | private: 22942 | 22943 | scope_handler(const scope_handler&) exprtk_delete; 22944 | scope_handler& operator=(const scope_handler&) exprtk_delete; 22945 | 22946 | parser_t& parser_; 22947 | }; 22948 | 22949 | template <typename T_> 22950 | struct halfopen_range_policy 22951 | { 22952 | static inline bool is_within(const T_& v, const T_& begin, const T_& end) 22953 | { 22954 | assert(begin <= end); 22955 | return (begin <= v) && (v < end); 22956 | } 22957 | 22958 | static inline bool is_less(const T_& v, const T_& begin) 22959 | { 22960 | return (v < begin); 22961 | } 22962 | 22963 | static inline bool is_greater(const T_& v, const T_& end) 22964 | { 22965 | return (end <= v); 22966 | } 22967 | 22968 | static inline bool end_inclusive() 22969 | { 22970 | return false; 22971 | } 22972 | }; 22973 | 22974 | template <typename T_> 22975 | struct closed_range_policy 22976 | { 22977 | static inline bool is_within(const T_& v, const T_& begin, const T_& end) 22978 | { 22979 | assert(begin <= end); 22980 | return (begin <= v) && (v <= end); 22981 | } 22982 | 22983 | static inline bool is_less(const T_& v, const T_& begin) 22984 | { 22985 | return (v < begin); 22986 | } 22987 | 22988 | static inline bool is_greater(const T_& v, const T_& end) 22989 | { 22990 | return (end < v); 22991 | } 22992 | 22993 | static inline bool end_inclusive() 22994 | { 22995 | return true; 22996 | } 22997 | }; 22998 | 22999 | template <typename IntervalPointType, 23000 | typename RangePolicy = halfopen_range_policy<IntervalPointType> > 23001 | class interval_container_t 23002 | { 23003 | public: 23004 | 23005 | typedef IntervalPointType interval_point_t; 23006 | typedef std::pair<interval_point_t, interval_point_t> interval_t; 23007 | typedef std::map<interval_point_t, interval_t> interval_map_t; 23008 | typedef typename interval_map_t::const_iterator interval_map_citr_t; 23009 | 23010 | std::size_t size() const 23011 | { 23012 | return interval_map_.size(); 23013 | } 23014 | 23015 | void reset() 23016 | { 23017 | interval_map_.clear(); 23018 | } 23019 | 23020 | bool in_interval(const interval_point_t point, interval_t& interval) const 23021 | { 23022 | interval_map_citr_t itr = RangePolicy::end_inclusive() ? 23023 | interval_map_.lower_bound(point): 23024 | interval_map_.upper_bound(point); 23025 | 23026 | for (; itr != interval_map_.end(); ++itr) 23027 | { 23028 | const interval_point_t& begin = itr->second.first; 23029 | const interval_point_t& end = itr->second.second; 23030 | 23031 | if (RangePolicy::is_within(point, begin, end)) 23032 | { 23033 | interval = interval_t(begin,end); 23034 | return true; 23035 | } 23036 | else if (RangePolicy::is_greater(point, end)) 23037 | { 23038 | break; 23039 | } 23040 | } 23041 | 23042 | return false; 23043 | } 23044 | 23045 | bool in_interval(const interval_point_t point) const 23046 | { 23047 | interval_t interval; 23048 | return in_interval(point,interval); 23049 | } 23050 | 23051 | bool add_interval(const interval_point_t begin, const interval_point_t end) 23052 | { 23053 | if ((end <= begin) || in_interval(begin) || in_interval(end)) 23054 | { 23055 | return false; 23056 | } 23057 | 23058 | interval_map_[end] = std::make_pair(begin, end); 23059 | 23060 | return true; 23061 | } 23062 | 23063 | bool add_interval(const interval_t interval) 23064 | { 23065 | return add_interval(interval.first, interval.second); 23066 | } 23067 | 23068 | private: 23069 | 23070 | interval_map_t interval_map_; 23071 | }; 23072 | 23073 | class stack_limit_handler 23074 | { 23075 | public: 23076 | 23077 | typedef parser<T> parser_t; 23078 | 23079 | explicit stack_limit_handler(parser<T>& p) 23080 | : parser_(p) 23081 | , limit_exceeded_(false) 23082 | { 23083 | if (++parser_.state_.stack_depth > parser_.settings_.max_stack_depth_) 23084 | { 23085 | limit_exceeded_ = true; 23086 | parser_.set_error(make_error( 23087 | parser_error::e_parser, 23088 | "ERR000 - Current stack depth " + details::to_str(parser_.state_.stack_depth) + 23089 | " exceeds maximum allowed stack depth of " + details::to_str(parser_.settings_.max_stack_depth_), 23090 | exprtk_error_location)); 23091 | } 23092 | } 23093 | 23094 | ~stack_limit_handler() 23095 | { 23096 | assert(parser_.state_.stack_depth > 0); 23097 | parser_.state_.stack_depth--; 23098 | } 23099 | 23100 | bool operator!() 23101 | { 23102 | return limit_exceeded_; 23103 | } 23104 | 23105 | private: 23106 | 23107 | stack_limit_handler(const stack_limit_handler&) exprtk_delete; 23108 | stack_limit_handler& operator=(const stack_limit_handler&) exprtk_delete; 23109 | 23110 | parser_t& parser_; 23111 | bool limit_exceeded_; 23112 | }; 23113 | 23114 | struct symtab_store 23115 | { 23116 | symbol_table_list_t symtab_list_; 23117 | 23118 | typedef typename symbol_table_t::local_data_t local_data_t; 23119 | typedef typename symbol_table_t::variable_ptr variable_ptr; 23120 | typedef typename symbol_table_t::function_ptr function_ptr; 23121 | #ifndef exprtk_disable_string_capabilities 23122 | typedef typename symbol_table_t::stringvar_ptr stringvar_ptr; 23123 | #endif 23124 | typedef typename symbol_table_t::vector_holder_ptr vector_holder_ptr; 23125 | typedef typename symbol_table_t::vararg_function_ptr vararg_function_ptr; 23126 | typedef typename symbol_table_t::generic_function_ptr generic_function_ptr; 23127 | 23128 | struct variable_context 23129 | { 23130 | variable_context() 23131 | : symbol_table(0) 23132 | , variable(0) 23133 | {} 23134 | 23135 | const symbol_table_t* symbol_table; 23136 | variable_ptr variable; 23137 | }; 23138 | 23139 | struct vector_context 23140 | { 23141 | vector_context() 23142 | : symbol_table(0) 23143 | , vector_holder(0) 23144 | {} 23145 | 23146 | const symbol_table_t* symbol_table; 23147 | vector_holder_ptr vector_holder; 23148 | }; 23149 | 23150 | #ifndef exprtk_disable_string_capabilities 23151 | struct string_context 23152 | { 23153 | string_context() 23154 | : symbol_table(0) 23155 | , str_var(0) 23156 | {} 23157 | 23158 | const symbol_table_t* symbol_table; 23159 | stringvar_ptr str_var; 23160 | }; 23161 | #endif 23162 | 23163 | inline bool empty() const 23164 | { 23165 | return symtab_list_.empty(); 23166 | } 23167 | 23168 | inline void clear() 23169 | { 23170 | symtab_list_.clear(); 23171 | } 23172 | 23173 | inline bool valid() const 23174 | { 23175 | if (!empty()) 23176 | { 23177 | for (std::size_t i = 0; i < symtab_list_.size(); ++i) 23178 | { 23179 | if (symtab_list_[i].valid()) 23180 | return true; 23181 | } 23182 | } 23183 | 23184 | return false; 23185 | } 23186 | 23187 | inline bool valid_symbol(const std::string& symbol) const 23188 | { 23189 | if (!symtab_list_.empty()) 23190 | return symtab_list_[0].valid_symbol(symbol); 23191 | else 23192 | return false; 23193 | } 23194 | 23195 | inline bool valid_function_name(const std::string& symbol) const 23196 | { 23197 | if (!symtab_list_.empty()) 23198 | return symtab_list_[0].valid_function(symbol); 23199 | else 23200 | return false; 23201 | } 23202 | 23203 | inline variable_context get_variable_context(const std::string& variable_name) const 23204 | { 23205 | variable_context result; 23206 | 23207 | if (valid_symbol(variable_name)) 23208 | { 23209 | for (std::size_t i = 0; i < symtab_list_.size(); ++i) 23210 | { 23211 | if (!symtab_list_[i].valid()) 23212 | { 23213 | continue; 23214 | } 23215 | 23216 | result.variable = local_data(i) 23217 | .variable_store.get(variable_name); 23218 | if (result.variable) 23219 | { 23220 | result.symbol_table = &symtab_list_[i]; 23221 | break; 23222 | } 23223 | } 23224 | } 23225 | 23226 | return result; 23227 | } 23228 | 23229 | inline variable_ptr get_variable(const std::string& variable_name) const 23230 | { 23231 | if (!valid_symbol(variable_name)) 23232 | return reinterpret_cast<variable_ptr>(0); 23233 | 23234 | variable_ptr result = reinterpret_cast<variable_ptr>(0); 23235 | 23236 | for (std::size_t i = 0; i < symtab_list_.size(); ++i) 23237 | { 23238 | if (!symtab_list_[i].valid()) 23239 | continue; 23240 | else 23241 | result = local_data(i) 23242 | .variable_store.get(variable_name); 23243 | 23244 | if (result) break; 23245 | } 23246 | 23247 | return result; 23248 | } 23249 | 23250 | inline variable_ptr get_variable(const T& var_ref) const 23251 | { 23252 | variable_ptr result = reinterpret_cast<variable_ptr>(0); 23253 | 23254 | for (std::size_t i = 0; i < symtab_list_.size(); ++i) 23255 | { 23256 | if (!symtab_list_[i].valid()) 23257 | continue; 23258 | else 23259 | result = local_data(i).variable_store 23260 | .get_from_varptr(reinterpret_cast<const void*>(&var_ref)); 23261 | 23262 | if (result) break; 23263 | } 23264 | 23265 | return result; 23266 | } 23267 | 23268 | #ifndef exprtk_disable_string_capabilities 23269 | inline string_context get_string_context(const std::string& string_name) const 23270 | { 23271 | string_context result; 23272 | 23273 | if (!valid_symbol(string_name)) 23274 | return result; 23275 | 23276 | for (std::size_t i = 0; i < symtab_list_.size(); ++i) 23277 | { 23278 | if (!symtab_list_[i].valid()) 23279 | { 23280 | continue; 23281 | } 23282 | 23283 | result.str_var = local_data(i).stringvar_store.get(string_name); 23284 | 23285 | if (result.str_var) 23286 | { 23287 | result.symbol_table = &symtab_list_[i]; 23288 | break; 23289 | } 23290 | } 23291 | 23292 | return result; 23293 | } 23294 | 23295 | inline stringvar_ptr get_stringvar(const std::string& string_name) const 23296 | { 23297 | if (!valid_symbol(string_name)) 23298 | return reinterpret_cast<stringvar_ptr>(0); 23299 | 23300 | stringvar_ptr result = reinterpret_cast<stringvar_ptr>(0); 23301 | 23302 | for (std::size_t i = 0; i < symtab_list_.size(); ++i) 23303 | { 23304 | if (!symtab_list_[i].valid()) 23305 | continue; 23306 | else 23307 | result = local_data(i) 23308 | .stringvar_store.get(string_name); 23309 | 23310 | if (result) break; 23311 | } 23312 | 23313 | return result; 23314 | } 23315 | #endif 23316 | 23317 | inline function_ptr get_function(const std::string& function_name) const 23318 | { 23319 | if (!valid_function_name(function_name)) 23320 | return reinterpret_cast<function_ptr>(0); 23321 | 23322 | function_ptr result = reinterpret_cast<function_ptr>(0); 23323 | 23324 | for (std::size_t i = 0; i < symtab_list_.size(); ++i) 23325 | { 23326 | if (!symtab_list_[i].valid()) 23327 | continue; 23328 | else 23329 | result = local_data(i) 23330 | .function_store.get(function_name); 23331 | 23332 | if (result) break; 23333 | } 23334 | 23335 | return result; 23336 | } 23337 | 23338 | inline vararg_function_ptr get_vararg_function(const std::string& vararg_function_name) const 23339 | { 23340 | if (!valid_function_name(vararg_function_name)) 23341 | return reinterpret_cast<vararg_function_ptr>(0); 23342 | 23343 | vararg_function_ptr result = reinterpret_cast<vararg_function_ptr>(0); 23344 | 23345 | for (std::size_t i = 0; i < symtab_list_.size(); ++i) 23346 | { 23347 | if (!symtab_list_[i].valid()) 23348 | continue; 23349 | else 23350 | result = local_data(i) 23351 | .vararg_function_store.get(vararg_function_name); 23352 | 23353 | if (result) break; 23354 | } 23355 | 23356 | return result; 23357 | } 23358 | 23359 | inline generic_function_ptr get_generic_function(const std::string& function_name) const 23360 | { 23361 | if (!valid_function_name(function_name)) 23362 | return reinterpret_cast<generic_function_ptr>(0); 23363 | 23364 | generic_function_ptr result = reinterpret_cast<generic_function_ptr>(0); 23365 | 23366 | for (std::size_t i = 0; i < symtab_list_.size(); ++i) 23367 | { 23368 | if (!symtab_list_[i].valid()) 23369 | continue; 23370 | else 23371 | result = local_data(i) 23372 | .generic_function_store.get(function_name); 23373 | 23374 | if (result) break; 23375 | } 23376 | 23377 | return result; 23378 | } 23379 | 23380 | inline generic_function_ptr get_string_function(const std::string& function_name) const 23381 | { 23382 | if (!valid_function_name(function_name)) 23383 | return reinterpret_cast<generic_function_ptr>(0); 23384 | 23385 | generic_function_ptr result = reinterpret_cast<generic_function_ptr>(0); 23386 | 23387 | for (std::size_t i = 0; i < symtab_list_.size(); ++i) 23388 | { 23389 | if (!symtab_list_[i].valid()) 23390 | continue; 23391 | else 23392 | result = 23393 | local_data(i).string_function_store.get(function_name); 23394 | 23395 | if (result) break; 23396 | } 23397 | 23398 | return result; 23399 | } 23400 | 23401 | inline generic_function_ptr get_overload_function(const std::string& function_name) const 23402 | { 23403 | if (!valid_function_name(function_name)) 23404 | return reinterpret_cast<generic_function_ptr>(0); 23405 | 23406 | generic_function_ptr result = reinterpret_cast<generic_function_ptr>(0); 23407 | 23408 | for (std::size_t i = 0; i < symtab_list_.size(); ++i) 23409 | { 23410 | if (!symtab_list_[i].valid()) 23411 | continue; 23412 | else 23413 | result = 23414 | local_data(i).overload_function_store.get(function_name); 23415 | 23416 | if (result) break; 23417 | } 23418 | 23419 | return result; 23420 | } 23421 | 23422 | inline vector_context get_vector_context(const std::string& vector_name) const 23423 | { 23424 | vector_context result; 23425 | if (!valid_symbol(vector_name)) 23426 | return result; 23427 | 23428 | for (std::size_t i = 0; i < symtab_list_.size(); ++i) 23429 | { 23430 | if (!symtab_list_[i].valid()) 23431 | { 23432 | continue; 23433 | } 23434 | 23435 | result.vector_holder = local_data(i).vector_store.get(vector_name); 23436 | 23437 | if (result.vector_holder) 23438 | { 23439 | result.symbol_table = &symtab_list_[i]; 23440 | break; 23441 | } 23442 | } 23443 | 23444 | return result; 23445 | } 23446 | 23447 | inline vector_holder_ptr get_vector(const std::string& vector_name) const 23448 | { 23449 | if (!valid_symbol(vector_name)) 23450 | return reinterpret_cast<vector_holder_ptr>(0); 23451 | 23452 | vector_holder_ptr result = reinterpret_cast<vector_holder_ptr>(0); 23453 | 23454 | for (std::size_t i = 0; i < symtab_list_.size(); ++i) 23455 | { 23456 | if (!symtab_list_[i].valid()) 23457 | { 23458 | continue; 23459 | } 23460 | 23461 | result = local_data(i).vector_store.get(vector_name); 23462 | 23463 | if (result) 23464 | { 23465 | break; 23466 | } 23467 | } 23468 | 23469 | return result; 23470 | } 23471 | 23472 | inline bool is_constant_node(const std::string& symbol_name) const 23473 | { 23474 | if (!valid_symbol(symbol_name)) 23475 | return false; 23476 | 23477 | for (std::size_t i = 0; i < symtab_list_.size(); ++i) 23478 | { 23479 | if (!symtab_list_[i].valid()) 23480 | { 23481 | continue; 23482 | } 23483 | 23484 | if (local_data(i).variable_store.is_constant(symbol_name)) 23485 | { 23486 | return true; 23487 | } 23488 | } 23489 | 23490 | return false; 23491 | } 23492 | 23493 | #ifndef exprtk_disable_string_capabilities 23494 | inline bool is_constant_string(const std::string& symbol_name) const 23495 | { 23496 | if (!valid_symbol(symbol_name)) 23497 | return false; 23498 | 23499 | for (std::size_t i = 0; i < symtab_list_.size(); ++i) 23500 | { 23501 | if (!symtab_list_[i].valid()) 23502 | continue; 23503 | else if (!local_data(i).stringvar_store.symbol_exists(symbol_name)) 23504 | continue; 23505 | else if (local_data(i).stringvar_store.is_constant(symbol_name)) 23506 | return true; 23507 | } 23508 | 23509 | return false; 23510 | } 23511 | #endif 23512 | 23513 | inline bool symbol_exists(const std::string& symbol) const 23514 | { 23515 | for (std::size_t i = 0; i < symtab_list_.size(); ++i) 23516 | { 23517 | if (!symtab_list_[i].valid()) 23518 | { 23519 | continue; 23520 | } 23521 | 23522 | if (symtab_list_[i].symbol_exists(symbol)) 23523 | { 23524 | return true; 23525 | } 23526 | } 23527 | 23528 | return false; 23529 | } 23530 | 23531 | inline bool is_variable(const std::string& variable_name) const 23532 | { 23533 | for (std::size_t i = 0; i < symtab_list_.size(); ++i) 23534 | { 23535 | if (!symtab_list_[i].valid()) 23536 | continue; 23537 | else if ( 23538 | symtab_list_[i].local_data().variable_store 23539 | .symbol_exists(variable_name) 23540 | ) 23541 | return true; 23542 | } 23543 | 23544 | return false; 23545 | } 23546 | 23547 | #ifndef exprtk_disable_string_capabilities 23548 | inline bool is_stringvar(const std::string& stringvar_name) const 23549 | { 23550 | for (std::size_t i = 0; i < symtab_list_.size(); ++i) 23551 | { 23552 | if (!symtab_list_[i].valid()) 23553 | continue; 23554 | else if ( 23555 | symtab_list_[i].local_data().stringvar_store 23556 | .symbol_exists(stringvar_name) 23557 | ) 23558 | return true; 23559 | } 23560 | 23561 | return false; 23562 | } 23563 | 23564 | inline bool is_conststr_stringvar(const std::string& symbol_name) const 23565 | { 23566 | for (std::size_t i = 0; i < symtab_list_.size(); ++i) 23567 | { 23568 | if (!symtab_list_[i].valid()) 23569 | continue; 23570 | else if ( 23571 | symtab_list_[i].local_data().stringvar_store 23572 | .symbol_exists(symbol_name) 23573 | ) 23574 | { 23575 | return ( 23576 | local_data(i).stringvar_store.symbol_exists(symbol_name) || 23577 | local_data(i).stringvar_store.is_constant (symbol_name) 23578 | ); 23579 | 23580 | } 23581 | } 23582 | 23583 | return false; 23584 | } 23585 | #endif 23586 | 23587 | inline bool is_function(const std::string& function_name) const 23588 | { 23589 | for (std::size_t i = 0; i < symtab_list_.size(); ++i) 23590 | { 23591 | if (!symtab_list_[i].valid()) 23592 | continue; 23593 | else if ( 23594 | local_data(i).vararg_function_store 23595 | .symbol_exists(function_name) 23596 | ) 23597 | return true; 23598 | } 23599 | 23600 | return false; 23601 | } 23602 | 23603 | inline bool is_vararg_function(const std::string& vararg_function_name) const 23604 | { 23605 | for (std::size_t i = 0; i < symtab_list_.size(); ++i) 23606 | { 23607 | if (!symtab_list_[i].valid()) 23608 | continue; 23609 | else if ( 23610 | local_data(i).vararg_function_store 23611 | .symbol_exists(vararg_function_name) 23612 | ) 23613 | return true; 23614 | } 23615 | 23616 | return false; 23617 | } 23618 | 23619 | inline bool is_vector(const std::string& vector_name) const 23620 | { 23621 | for (std::size_t i = 0; i < symtab_list_.size(); ++i) 23622 | { 23623 | if (!symtab_list_[i].valid()) 23624 | continue; 23625 | else if ( 23626 | local_data(i).vector_store 23627 | .symbol_exists(vector_name) 23628 | ) 23629 | return true; 23630 | } 23631 | 23632 | return false; 23633 | } 23634 | 23635 | inline std::string get_variable_name(const expression_node_ptr& ptr) const 23636 | { 23637 | return local_data().variable_store.entity_name(ptr); 23638 | } 23639 | 23640 | inline std::string get_vector_name(const vector_holder_ptr& ptr) const 23641 | { 23642 | return local_data().vector_store.entity_name(ptr); 23643 | } 23644 | 23645 | #ifndef exprtk_disable_string_capabilities 23646 | inline std::string get_stringvar_name(const expression_node_ptr& ptr) const 23647 | { 23648 | return local_data().stringvar_store.entity_name(ptr); 23649 | } 23650 | 23651 | inline std::string get_conststr_stringvar_name(const expression_node_ptr& ptr) const 23652 | { 23653 | return local_data().stringvar_store.entity_name(ptr); 23654 | } 23655 | #endif 23656 | 23657 | inline local_data_t& local_data(const std::size_t& index = 0) 23658 | { 23659 | return symtab_list_[index].local_data(); 23660 | } 23661 | 23662 | inline const local_data_t& local_data(const std::size_t& index = 0) const 23663 | { 23664 | return symtab_list_[index].local_data(); 23665 | } 23666 | 23667 | inline symbol_table_t& get_symbol_table(const std::size_t& index = 0) 23668 | { 23669 | return symtab_list_[index]; 23670 | } 23671 | }; 23672 | 23673 | struct parser_state 23674 | { 23675 | parser_state() 23676 | : type_check_enabled(true) 23677 | { 23678 | reset(); 23679 | } 23680 | 23681 | void reset() 23682 | { 23683 | parsing_return_stmt = false; 23684 | parsing_break_stmt = false; 23685 | parsing_assert_stmt = false; 23686 | return_stmt_present = false; 23687 | side_effect_present = false; 23688 | scope_depth = 0; 23689 | stack_depth = 0; 23690 | parsing_loop_stmt_count = 0; 23691 | } 23692 | 23693 | #ifndef exprtk_enable_debugging 23694 | void activate_side_effect(const std::string&) 23695 | #else 23696 | void activate_side_effect(const std::string& source) 23697 | #endif 23698 | { 23699 | if (!side_effect_present) 23700 | { 23701 | side_effect_present = true; 23702 | 23703 | exprtk_debug(("activate_side_effect() - caller: %s\n", source.c_str())); 23704 | } 23705 | } 23706 | 23707 | bool parsing_return_stmt; 23708 | bool parsing_break_stmt; 23709 | bool parsing_assert_stmt; 23710 | bool return_stmt_present; 23711 | bool side_effect_present; 23712 | bool type_check_enabled; 23713 | std::size_t scope_depth; 23714 | std::size_t stack_depth; 23715 | std::size_t parsing_loop_stmt_count; 23716 | }; 23717 | 23718 | public: 23719 | 23720 | struct unknown_symbol_resolver 23721 | { 23722 | 23723 | enum usr_symbol_type 23724 | { 23725 | e_usr_unknown_type = 0, 23726 | e_usr_variable_type = 1, 23727 | e_usr_constant_type = 2 23728 | }; 23729 | 23730 | enum usr_mode 23731 | { 23732 | e_usrmode_default = 0, 23733 | e_usrmode_extended = 1 23734 | }; 23735 | 23736 | usr_mode mode; 23737 | 23738 | explicit unknown_symbol_resolver(const usr_mode m = e_usrmode_default) 23739 | : mode(m) 23740 | {} 23741 | 23742 | virtual ~unknown_symbol_resolver() 23743 | {} 23744 | 23745 | virtual bool process(const std::string& /*unknown_symbol*/, 23746 | usr_symbol_type& st, 23747 | T& default_value, 23748 | std::string& error_message) 23749 | { 23750 | if (e_usrmode_default != mode) 23751 | return false; 23752 | 23753 | st = e_usr_variable_type; 23754 | default_value = T(0); 23755 | error_message.clear(); 23756 | 23757 | return true; 23758 | } 23759 | 23760 | virtual bool process(const std::string& /* unknown_symbol */, 23761 | symbol_table_t& /* symbol_table */, 23762 | std::string& /* error_message */) 23763 | { 23764 | return false; 23765 | } 23766 | }; 23767 | 23768 | enum collect_type 23769 | { 23770 | e_ct_none = 0, 23771 | e_ct_variables = 1, 23772 | e_ct_functions = 2, 23773 | e_ct_assignments = 4 23774 | }; 23775 | 23776 | enum symbol_type 23777 | { 23778 | e_st_unknown = 0, 23779 | e_st_variable = 1, 23780 | e_st_vector = 2, 23781 | e_st_vecelem = 3, 23782 | e_st_string = 4, 23783 | e_st_function = 5, 23784 | e_st_local_variable = 6, 23785 | e_st_local_vector = 7, 23786 | e_st_local_string = 8 23787 | }; 23788 | 23789 | class dependent_entity_collector 23790 | { 23791 | public: 23792 | 23793 | typedef std::pair<std::string,symbol_type> symbol_t; 23794 | typedef std::vector<symbol_t> symbol_list_t; 23795 | 23796 | explicit dependent_entity_collector(const std::size_t options = e_ct_none) 23797 | : options_(options) 23798 | , collect_variables_ ((options_ & e_ct_variables ) == e_ct_variables ) 23799 | , collect_functions_ ((options_ & e_ct_functions ) == e_ct_functions ) 23800 | , collect_assignments_((options_ & e_ct_assignments) == e_ct_assignments) 23801 | , return_present_ (false) 23802 | , final_stmt_return_(false) 23803 | {} 23804 | 23805 | template <typename Allocator, 23806 | template <typename, typename> class Sequence> 23807 | inline std::size_t symbols(Sequence<symbol_t,Allocator>& symbols_list) 23808 | { 23809 | if (!collect_variables_ && !collect_functions_) 23810 | return 0; 23811 | else if (symbol_name_list_.empty()) 23812 | return 0; 23813 | 23814 | for (std::size_t i = 0; i < symbol_name_list_.size(); ++i) 23815 | { 23816 | details::case_normalise(symbol_name_list_[i].first); 23817 | } 23818 | 23819 | std::sort(symbol_name_list_.begin(), symbol_name_list_.end()); 23820 | 23821 | std::unique_copy 23822 | ( 23823 | symbol_name_list_.begin(), 23824 | symbol_name_list_.end (), 23825 | std::back_inserter(symbols_list) 23826 | ); 23827 | 23828 | return symbols_list.size(); 23829 | } 23830 | 23831 | template <typename Allocator, 23832 | template <typename, typename> class Sequence> 23833 | inline std::size_t assignment_symbols(Sequence<symbol_t,Allocator>& assignment_list) 23834 | { 23835 | if (!collect_assignments_) 23836 | return 0; 23837 | else if (assignment_name_list_.empty()) 23838 | return 0; 23839 | 23840 | for (std::size_t i = 0; i < assignment_name_list_.size(); ++i) 23841 | { 23842 | details::case_normalise(assignment_name_list_[i].first); 23843 | } 23844 | 23845 | std::sort(assignment_name_list_.begin(),assignment_name_list_.end()); 23846 | 23847 | std::unique_copy 23848 | ( 23849 | assignment_name_list_.begin(), 23850 | assignment_name_list_.end (), 23851 | std::back_inserter(assignment_list) 23852 | ); 23853 | 23854 | return assignment_list.size(); 23855 | } 23856 | 23857 | void clear() 23858 | { 23859 | symbol_name_list_ .clear(); 23860 | assignment_name_list_.clear(); 23861 | retparam_list_ .clear(); 23862 | return_present_ = false; 23863 | final_stmt_return_ = false; 23864 | } 23865 | 23866 | bool& collect_variables() 23867 | { 23868 | return collect_variables_; 23869 | } 23870 | 23871 | bool& collect_functions() 23872 | { 23873 | return collect_functions_; 23874 | } 23875 | 23876 | bool& collect_assignments() 23877 | { 23878 | return collect_assignments_; 23879 | } 23880 | 23881 | bool return_present() const 23882 | { 23883 | return return_present_; 23884 | } 23885 | 23886 | bool final_stmt_return() const 23887 | { 23888 | return final_stmt_return_; 23889 | } 23890 | 23891 | typedef std::vector<std::string> retparam_list_t; 23892 | 23893 | retparam_list_t return_param_type_list() const 23894 | { 23895 | return retparam_list_; 23896 | } 23897 | 23898 | private: 23899 | 23900 | inline void add_symbol(const std::string& symbol, const symbol_type st) 23901 | { 23902 | switch (st) 23903 | { 23904 | case e_st_variable : 23905 | case e_st_vector : 23906 | case e_st_string : 23907 | case e_st_local_variable : 23908 | case e_st_local_vector : 23909 | case e_st_local_string : if (collect_variables_) 23910 | symbol_name_list_ 23911 | .push_back(std::make_pair(symbol, st)); 23912 | break; 23913 | 23914 | case e_st_function : if (collect_functions_) 23915 | symbol_name_list_ 23916 | .push_back(std::make_pair(symbol, st)); 23917 | break; 23918 | 23919 | default : return; 23920 | } 23921 | } 23922 | 23923 | inline void add_assignment(const std::string& symbol, const symbol_type st) 23924 | { 23925 | switch (st) 23926 | { 23927 | case e_st_variable : 23928 | case e_st_vector : 23929 | case e_st_string : if (collect_assignments_) 23930 | assignment_name_list_ 23931 | .push_back(std::make_pair(symbol, st)); 23932 | break; 23933 | 23934 | default : return; 23935 | } 23936 | } 23937 | 23938 | std::size_t options_; 23939 | bool collect_variables_; 23940 | bool collect_functions_; 23941 | bool collect_assignments_; 23942 | bool return_present_; 23943 | bool final_stmt_return_; 23944 | symbol_list_t symbol_name_list_; 23945 | symbol_list_t assignment_name_list_; 23946 | retparam_list_t retparam_list_; 23947 | 23948 | friend class parser<T>; 23949 | }; 23950 | 23951 | class settings_store 23952 | { 23953 | private: 23954 | 23955 | typedef std::set<std::string,details::ilesscompare> disabled_entity_set_t; 23956 | typedef disabled_entity_set_t::iterator des_itr_t; 23957 | 23958 | public: 23959 | 23960 | enum settings_compilation_options 23961 | { 23962 | e_unknown = 0, 23963 | e_replacer = 1, 23964 | e_joiner = 2, 23965 | e_numeric_check = 4, 23966 | e_bracket_check = 8, 23967 | e_sequence_check = 16, 23968 | e_commutative_check = 32, 23969 | e_strength_reduction = 64, 23970 | e_disable_vardef = 128, 23971 | e_collect_vars = 256, 23972 | e_collect_funcs = 512, 23973 | e_collect_assings = 1024, 23974 | e_disable_usr_on_rsrvd = 2048, 23975 | e_disable_zero_return = 4096 23976 | }; 23977 | 23978 | enum settings_base_funcs 23979 | { 23980 | e_bf_unknown = 0, 23981 | e_bf_abs , e_bf_acos , e_bf_acosh , e_bf_asin , 23982 | e_bf_asinh , e_bf_atan , e_bf_atan2 , e_bf_atanh , 23983 | e_bf_avg , e_bf_ceil , e_bf_clamp , e_bf_cos , 23984 | e_bf_cosh , e_bf_cot , e_bf_csc , e_bf_equal , 23985 | e_bf_erf , e_bf_erfc , e_bf_exp , e_bf_expm1 , 23986 | e_bf_floor , e_bf_frac , e_bf_hypot , e_bf_iclamp , 23987 | e_bf_like , e_bf_log , e_bf_log10 , e_bf_log1p , 23988 | e_bf_log2 , e_bf_logn , e_bf_mand , e_bf_max , 23989 | e_bf_min , e_bf_mod , e_bf_mor , e_bf_mul , 23990 | e_bf_ncdf , e_bf_pow , e_bf_root , e_bf_round , 23991 | e_bf_roundn , e_bf_sec , e_bf_sgn , e_bf_sin , 23992 | e_bf_sinc , e_bf_sinh , e_bf_sqrt , e_bf_sum , 23993 | e_bf_swap , e_bf_tan , e_bf_tanh , e_bf_trunc , 23994 | e_bf_not_equal , e_bf_inrange , e_bf_deg2grad , e_bf_deg2rad , 23995 | e_bf_rad2deg , e_bf_grad2deg 23996 | }; 23997 | 23998 | enum settings_control_structs 23999 | { 24000 | e_ctrl_unknown = 0, 24001 | e_ctrl_ifelse, 24002 | e_ctrl_switch, 24003 | e_ctrl_for_loop, 24004 | e_ctrl_while_loop, 24005 | e_ctrl_repeat_loop, 24006 | e_ctrl_return 24007 | }; 24008 | 24009 | enum settings_logic_opr 24010 | { 24011 | e_logic_unknown = 0, 24012 | e_logic_and, e_logic_nand , e_logic_nor , 24013 | e_logic_not, e_logic_or , e_logic_xnor, 24014 | e_logic_xor, e_logic_scand, e_logic_scor 24015 | }; 24016 | 24017 | enum settings_arithmetic_opr 24018 | { 24019 | e_arith_unknown = 0, 24020 | e_arith_add, e_arith_sub, e_arith_mul, 24021 | e_arith_div, e_arith_mod, e_arith_pow 24022 | }; 24023 | 24024 | enum settings_assignment_opr 24025 | { 24026 | e_assign_unknown = 0, 24027 | e_assign_assign, e_assign_addass, e_assign_subass, 24028 | e_assign_mulass, e_assign_divass, e_assign_modass 24029 | }; 24030 | 24031 | enum settings_inequality_opr 24032 | { 24033 | e_ineq_unknown = 0, 24034 | e_ineq_lt , e_ineq_lte, e_ineq_eq , 24035 | e_ineq_equal, e_ineq_ne , e_ineq_nequal, 24036 | e_ineq_gte , e_ineq_gt 24037 | }; 24038 | 24039 | static const std::size_t default_compile_all_opts = 24040 | e_replacer + 24041 | e_joiner + 24042 | e_numeric_check + 24043 | e_bracket_check + 24044 | e_sequence_check + 24045 | e_commutative_check + 24046 | e_strength_reduction; 24047 | 24048 | settings_store(const std::size_t compile_options = default_compile_all_opts) 24049 | : max_stack_depth_(400) 24050 | , max_node_depth_(10000) 24051 | , max_total_local_symbol_size_bytes_(2000000000) 24052 | , max_local_vector_size_(max_total_local_symbol_size_bytes_ / sizeof(T)) 24053 | { 24054 | load_compile_options(compile_options); 24055 | } 24056 | 24057 | settings_store& enable_all_base_functions() 24058 | { 24059 | disabled_func_set_.clear(); 24060 | return (*this); 24061 | } 24062 | 24063 | settings_store& enable_all_control_structures() 24064 | { 24065 | disabled_ctrl_set_.clear(); 24066 | return (*this); 24067 | } 24068 | 24069 | settings_store& enable_all_logic_ops() 24070 | { 24071 | disabled_logic_set_.clear(); 24072 | return (*this); 24073 | } 24074 | 24075 | settings_store& enable_all_arithmetic_ops() 24076 | { 24077 | disabled_arithmetic_set_.clear(); 24078 | return (*this); 24079 | } 24080 | 24081 | settings_store& enable_all_assignment_ops() 24082 | { 24083 | disabled_assignment_set_.clear(); 24084 | return (*this); 24085 | } 24086 | 24087 | settings_store& enable_all_inequality_ops() 24088 | { 24089 | disabled_inequality_set_.clear(); 24090 | return (*this); 24091 | } 24092 | 24093 | settings_store& enable_local_vardef() 24094 | { 24095 | disable_vardef_ = false; 24096 | return (*this); 24097 | } 24098 | 24099 | settings_store& enable_commutative_check() 24100 | { 24101 | enable_commutative_check_ = true; 24102 | return (*this); 24103 | } 24104 | 24105 | settings_store& enable_strength_reduction() 24106 | { 24107 | enable_strength_reduction_ = true; 24108 | return (*this); 24109 | } 24110 | 24111 | settings_store& disable_all_base_functions() 24112 | { 24113 | std::copy(details::base_function_list, 24114 | details::base_function_list + details::base_function_list_size, 24115 | std::insert_iterator<disabled_entity_set_t> 24116 | (disabled_func_set_, disabled_func_set_.begin())); 24117 | return (*this); 24118 | } 24119 | 24120 | settings_store& disable_all_control_structures() 24121 | { 24122 | std::copy(details::cntrl_struct_list, 24123 | details::cntrl_struct_list + details::cntrl_struct_list_size, 24124 | std::insert_iterator<disabled_entity_set_t> 24125 | (disabled_ctrl_set_, disabled_ctrl_set_.begin())); 24126 | return (*this); 24127 | } 24128 | 24129 | settings_store& disable_all_logic_ops() 24130 | { 24131 | std::copy(details::logic_ops_list, 24132 | details::logic_ops_list + details::logic_ops_list_size, 24133 | std::insert_iterator<disabled_entity_set_t> 24134 | (disabled_logic_set_, disabled_logic_set_.begin())); 24135 | return (*this); 24136 | } 24137 | 24138 | settings_store& disable_all_arithmetic_ops() 24139 | { 24140 | std::copy(details::arithmetic_ops_list, 24141 | details::arithmetic_ops_list + details::arithmetic_ops_list_size, 24142 | std::insert_iterator<disabled_entity_set_t> 24143 | (disabled_arithmetic_set_, disabled_arithmetic_set_.begin())); 24144 | return (*this); 24145 | } 24146 | 24147 | settings_store& disable_all_assignment_ops() 24148 | { 24149 | std::copy(details::assignment_ops_list, 24150 | details::assignment_ops_list + details::assignment_ops_list_size, 24151 | std::insert_iterator<disabled_entity_set_t> 24152 | (disabled_assignment_set_, disabled_assignment_set_.begin())); 24153 | return (*this); 24154 | } 24155 | 24156 | settings_store& disable_all_inequality_ops() 24157 | { 24158 | std::copy(details::inequality_ops_list, 24159 | details::inequality_ops_list + details::inequality_ops_list_size, 24160 | std::insert_iterator<disabled_entity_set_t> 24161 | (disabled_inequality_set_, disabled_inequality_set_.begin())); 24162 | return (*this); 24163 | } 24164 | 24165 | settings_store& disable_local_vardef() 24166 | { 24167 | disable_vardef_ = true; 24168 | return (*this); 24169 | } 24170 | 24171 | settings_store& disable_commutative_check() 24172 | { 24173 | enable_commutative_check_ = false; 24174 | return (*this); 24175 | } 24176 | 24177 | settings_store& disable_strength_reduction() 24178 | { 24179 | enable_strength_reduction_ = false; 24180 | return (*this); 24181 | } 24182 | 24183 | bool replacer_enabled () const { return enable_replacer_; } 24184 | bool commutative_check_enabled () const { return enable_commutative_check_; } 24185 | bool joiner_enabled () const { return enable_joiner_; } 24186 | bool numeric_check_enabled () const { return enable_numeric_check_; } 24187 | bool bracket_check_enabled () const { return enable_bracket_check_; } 24188 | bool sequence_check_enabled () const { return enable_sequence_check_; } 24189 | bool strength_reduction_enabled () const { return enable_strength_reduction_; } 24190 | bool collect_variables_enabled () const { return enable_collect_vars_; } 24191 | bool collect_functions_enabled () const { return enable_collect_funcs_; } 24192 | bool collect_assignments_enabled() const { return enable_collect_assings_; } 24193 | bool vardef_disabled () const { return disable_vardef_; } 24194 | bool rsrvd_sym_usr_disabled () const { return disable_rsrvd_sym_usr_; } 24195 | bool zero_return_disabled () const { return disable_zero_return_; } 24196 | 24197 | bool function_enabled(const std::string& function_name) const 24198 | { 24199 | if (disabled_func_set_.empty()) 24200 | return true; 24201 | else 24202 | return (disabled_func_set_.end() == disabled_func_set_.find(function_name)); 24203 | } 24204 | 24205 | bool control_struct_enabled(const std::string& control_struct) const 24206 | { 24207 | if (disabled_ctrl_set_.empty()) 24208 | return true; 24209 | else 24210 | return (disabled_ctrl_set_.end() == disabled_ctrl_set_.find(control_struct)); 24211 | } 24212 | 24213 | bool logic_enabled(const std::string& logic_operation) const 24214 | { 24215 | if (disabled_logic_set_.empty()) 24216 | return true; 24217 | else 24218 | return (disabled_logic_set_.end() == disabled_logic_set_.find(logic_operation)); 24219 | } 24220 | 24221 | bool arithmetic_enabled(const details::operator_type& arithmetic_operation) const 24222 | { 24223 | if (disabled_logic_set_.empty()) 24224 | return true; 24225 | else 24226 | return disabled_arithmetic_set_.end() == disabled_arithmetic_set_ 24227 | .find(arith_opr_to_string(arithmetic_operation)); 24228 | } 24229 | 24230 | bool assignment_enabled(const details::operator_type& assignment) const 24231 | { 24232 | if (disabled_assignment_set_.empty()) 24233 | return true; 24234 | else 24235 | return disabled_assignment_set_.end() == disabled_assignment_set_ 24236 | .find(assign_opr_to_string(assignment)); 24237 | } 24238 | 24239 | bool inequality_enabled(const details::operator_type& inequality) const 24240 | { 24241 | if (disabled_inequality_set_.empty()) 24242 | return true; 24243 | else 24244 | return disabled_inequality_set_.end() == disabled_inequality_set_ 24245 | .find(inequality_opr_to_string(inequality)); 24246 | } 24247 | 24248 | bool function_disabled(const std::string& function_name) const 24249 | { 24250 | if (disabled_func_set_.empty()) 24251 | return false; 24252 | else 24253 | return (disabled_func_set_.end() != disabled_func_set_.find(function_name)); 24254 | } 24255 | 24256 | bool control_struct_disabled(const std::string& control_struct) const 24257 | { 24258 | if (disabled_ctrl_set_.empty()) 24259 | return false; 24260 | else 24261 | return (disabled_ctrl_set_.end() != disabled_ctrl_set_.find(control_struct)); 24262 | } 24263 | 24264 | bool logic_disabled(const std::string& logic_operation) const 24265 | { 24266 | if (disabled_logic_set_.empty()) 24267 | return false; 24268 | else 24269 | return (disabled_logic_set_.end() != disabled_logic_set_.find(logic_operation)); 24270 | } 24271 | 24272 | bool assignment_disabled(const details::operator_type assignment_operation) const 24273 | { 24274 | if (disabled_assignment_set_.empty()) 24275 | return false; 24276 | else 24277 | return disabled_assignment_set_.end() != disabled_assignment_set_ 24278 | .find(assign_opr_to_string(assignment_operation)); 24279 | } 24280 | 24281 | bool logic_disabled(const details::operator_type logic_operation) const 24282 | { 24283 | if (disabled_logic_set_.empty()) 24284 | return false; 24285 | else 24286 | return disabled_logic_set_.end() != disabled_logic_set_ 24287 | .find(logic_opr_to_string(logic_operation)); 24288 | } 24289 | 24290 | bool arithmetic_disabled(const details::operator_type arithmetic_operation) const 24291 | { 24292 | if (disabled_arithmetic_set_.empty()) 24293 | return false; 24294 | else 24295 | return disabled_arithmetic_set_.end() != disabled_arithmetic_set_ 24296 | .find(arith_opr_to_string(arithmetic_operation)); 24297 | } 24298 | 24299 | bool inequality_disabled(const details::operator_type& inequality) const 24300 | { 24301 | if (disabled_inequality_set_.empty()) 24302 | return false; 24303 | else 24304 | return disabled_inequality_set_.end() != disabled_inequality_set_ 24305 | .find(inequality_opr_to_string(inequality)); 24306 | } 24307 | 24308 | settings_store& disable_base_function(const settings_base_funcs bf) 24309 | { 24310 | if ( 24311 | (e_bf_unknown != bf) && 24312 | (static_cast<std::size_t>(bf) < (details::base_function_list_size + 1)) 24313 | ) 24314 | { 24315 | disabled_func_set_.insert(details::base_function_list[bf - 1]); 24316 | } 24317 | 24318 | return (*this); 24319 | } 24320 | 24321 | settings_store& disable_control_structure(const settings_control_structs ctrl_struct) 24322 | { 24323 | if ( 24324 | (e_ctrl_unknown != ctrl_struct) && 24325 | (static_cast<std::size_t>(ctrl_struct) < (details::cntrl_struct_list_size + 1)) 24326 | ) 24327 | { 24328 | disabled_ctrl_set_.insert(details::cntrl_struct_list[ctrl_struct - 1]); 24329 | } 24330 | 24331 | return (*this); 24332 | } 24333 | 24334 | settings_store& disable_logic_operation(const settings_logic_opr logic) 24335 | { 24336 | if ( 24337 | (e_logic_unknown != logic) && 24338 | (static_cast<std::size_t>(logic) < (details::logic_ops_list_size + 1)) 24339 | ) 24340 | { 24341 | disabled_logic_set_.insert(details::logic_ops_list[logic - 1]); 24342 | } 24343 | 24344 | return (*this); 24345 | } 24346 | 24347 | settings_store& disable_arithmetic_operation(const settings_arithmetic_opr arithmetic) 24348 | { 24349 | if ( 24350 | (e_arith_unknown != arithmetic) && 24351 | (static_cast<std::size_t>(arithmetic) < (details::arithmetic_ops_list_size + 1)) 24352 | ) 24353 | { 24354 | disabled_arithmetic_set_.insert(details::arithmetic_ops_list[arithmetic - 1]); 24355 | } 24356 | 24357 | return (*this); 24358 | } 24359 | 24360 | settings_store& disable_assignment_operation(const settings_assignment_opr assignment) 24361 | { 24362 | if ( 24363 | (e_assign_unknown != assignment) && 24364 | (static_cast<std::size_t>(assignment) < (details::assignment_ops_list_size + 1)) 24365 | ) 24366 | { 24367 | disabled_assignment_set_.insert(details::assignment_ops_list[assignment - 1]); 24368 | } 24369 | 24370 | return (*this); 24371 | } 24372 | 24373 | settings_store& disable_inequality_operation(const settings_inequality_opr inequality) 24374 | { 24375 | if ( 24376 | (e_ineq_unknown != inequality) && 24377 | (static_cast<std::size_t>(inequality) < (details::inequality_ops_list_size + 1)) 24378 | ) 24379 | { 24380 | disabled_inequality_set_.insert(details::inequality_ops_list[inequality - 1]); 24381 | } 24382 | 24383 | return (*this); 24384 | } 24385 | 24386 | settings_store& enable_base_function(const settings_base_funcs bf) 24387 | { 24388 | if ( 24389 | (e_bf_unknown != bf) && 24390 | (static_cast<std::size_t>(bf) < (details::base_function_list_size + 1)) 24391 | ) 24392 | { 24393 | const des_itr_t itr = disabled_func_set_.find(details::base_function_list[bf - 1]); 24394 | 24395 | if (disabled_func_set_.end() != itr) 24396 | { 24397 | disabled_func_set_.erase(itr); 24398 | } 24399 | } 24400 | 24401 | return (*this); 24402 | } 24403 | 24404 | settings_store& enable_control_structure(const settings_control_structs ctrl_struct) 24405 | { 24406 | if ( 24407 | (e_ctrl_unknown != ctrl_struct) && 24408 | (static_cast<std::size_t>(ctrl_struct) < (details::cntrl_struct_list_size + 1)) 24409 | ) 24410 | { 24411 | const des_itr_t itr = disabled_ctrl_set_.find(details::cntrl_struct_list[ctrl_struct - 1]); 24412 | 24413 | if (disabled_ctrl_set_.end() != itr) 24414 | { 24415 | disabled_ctrl_set_.erase(itr); 24416 | } 24417 | } 24418 | 24419 | return (*this); 24420 | } 24421 | 24422 | settings_store& enable_logic_operation(const settings_logic_opr logic) 24423 | { 24424 | if ( 24425 | (e_logic_unknown != logic) && 24426 | (static_cast<std::size_t>(logic) < (details::logic_ops_list_size + 1)) 24427 | ) 24428 | { 24429 | const des_itr_t itr = disabled_logic_set_.find(details::logic_ops_list[logic - 1]); 24430 | 24431 | if (disabled_logic_set_.end() != itr) 24432 | { 24433 | disabled_logic_set_.erase(itr); 24434 | } 24435 | } 24436 | 24437 | return (*this); 24438 | } 24439 | 24440 | settings_store& enable_arithmetic_operation(const settings_arithmetic_opr arithmetic) 24441 | { 24442 | if ( 24443 | (e_arith_unknown != arithmetic) && 24444 | (static_cast<std::size_t>(arithmetic) < (details::arithmetic_ops_list_size + 1)) 24445 | ) 24446 | { 24447 | const des_itr_t itr = disabled_arithmetic_set_.find(details::arithmetic_ops_list[arithmetic - 1]); 24448 | 24449 | if (disabled_arithmetic_set_.end() != itr) 24450 | { 24451 | disabled_arithmetic_set_.erase(itr); 24452 | } 24453 | } 24454 | 24455 | return (*this); 24456 | } 24457 | 24458 | settings_store& enable_assignment_operation(const settings_assignment_opr assignment) 24459 | { 24460 | if ( 24461 | (e_assign_unknown != assignment) && 24462 | (static_cast<std::size_t>(assignment) < (details::assignment_ops_list_size + 1)) 24463 | ) 24464 | { 24465 | const des_itr_t itr = disabled_assignment_set_.find(details::assignment_ops_list[assignment - 1]); 24466 | 24467 | if (disabled_assignment_set_.end() != itr) 24468 | { 24469 | disabled_assignment_set_.erase(itr); 24470 | } 24471 | } 24472 | 24473 | return (*this); 24474 | } 24475 | 24476 | settings_store& enable_inequality_operation(const settings_inequality_opr inequality) 24477 | { 24478 | if ( 24479 | (e_ineq_unknown != inequality) && 24480 | (static_cast<std::size_t>(inequality) < (details::inequality_ops_list_size + 1)) 24481 | ) 24482 | { 24483 | const des_itr_t itr = disabled_inequality_set_.find(details::inequality_ops_list[inequality - 1]); 24484 | 24485 | if (disabled_inequality_set_.end() != itr) 24486 | { 24487 | disabled_inequality_set_.erase(itr); 24488 | } 24489 | } 24490 | 24491 | return (*this); 24492 | } 24493 | 24494 | void set_max_stack_depth(const std::size_t max_stack_depth) 24495 | { 24496 | max_stack_depth_ = max_stack_depth; 24497 | } 24498 | 24499 | void set_max_node_depth(const std::size_t max_node_depth) 24500 | { 24501 | max_node_depth_ = max_node_depth; 24502 | } 24503 | 24504 | void set_max_local_vector_size(const std::size_t max_local_vector_size) 24505 | { 24506 | max_local_vector_size_ = max_local_vector_size; 24507 | } 24508 | 24509 | void set_max_total_local_symbol_size_bytes(const std::size_t max_total_lcl_symb_size) 24510 | { 24511 | max_total_local_symbol_size_bytes_ = max_total_lcl_symb_size; 24512 | } 24513 | 24514 | std::size_t max_stack_depth() const 24515 | { 24516 | return max_stack_depth_; 24517 | } 24518 | 24519 | std::size_t max_node_depth() const 24520 | { 24521 | return max_node_depth_; 24522 | } 24523 | 24524 | std::size_t max_local_vector_size() const 24525 | { 24526 | return max_local_vector_size_; 24527 | } 24528 | 24529 | std::size_t max_total_local_symbol_size_bytes() const 24530 | { 24531 | return max_total_local_symbol_size_bytes_; 24532 | } 24533 | 24534 | private: 24535 | 24536 | void load_compile_options(const std::size_t compile_options) 24537 | { 24538 | enable_replacer_ = (compile_options & e_replacer ) == e_replacer; 24539 | enable_joiner_ = (compile_options & e_joiner ) == e_joiner; 24540 | enable_numeric_check_ = (compile_options & e_numeric_check ) == e_numeric_check; 24541 | enable_bracket_check_ = (compile_options & e_bracket_check ) == e_bracket_check; 24542 | enable_sequence_check_ = (compile_options & e_sequence_check ) == e_sequence_check; 24543 | enable_commutative_check_ = (compile_options & e_commutative_check ) == e_commutative_check; 24544 | enable_strength_reduction_ = (compile_options & e_strength_reduction ) == e_strength_reduction; 24545 | enable_collect_vars_ = (compile_options & e_collect_vars ) == e_collect_vars; 24546 | enable_collect_funcs_ = (compile_options & e_collect_funcs ) == e_collect_funcs; 24547 | enable_collect_assings_ = (compile_options & e_collect_assings ) == e_collect_assings; 24548 | disable_vardef_ = (compile_options & e_disable_vardef ) == e_disable_vardef; 24549 | disable_rsrvd_sym_usr_ = (compile_options & e_disable_usr_on_rsrvd) == e_disable_usr_on_rsrvd; 24550 | disable_zero_return_ = (compile_options & e_disable_zero_return ) == e_disable_zero_return; 24551 | } 24552 | 24553 | std::string assign_opr_to_string(details::operator_type opr) const 24554 | { 24555 | switch (opr) 24556 | { 24557 | case details::e_assign : return ":=" 24558 | case details::e_addass : return "+=" 24559 | case details::e_subass : return "-=" 24560 | case details::e_mulass : return "*=" 24561 | case details::e_divass : return "/=" 24562 | case details::e_modass : return "%=" 24563 | default : return "" ; 24564 | } 24565 | } 24566 | 24567 | std::string arith_opr_to_string(details::operator_type opr) const 24568 | { 24569 | switch (opr) 24570 | { 24571 | case details::e_add : return "+" 24572 | case details::e_sub : return "-" 24573 | case details::e_mul : return "*" 24574 | case details::e_div : return "/" 24575 | case details::e_mod : return "%" 24576 | case details::e_pow : return "^" 24577 | default : return "" ; 24578 | } 24579 | } 24580 | 24581 | std::string inequality_opr_to_string(details::operator_type opr) const 24582 | { 24583 | switch (opr) 24584 | { 24585 | case details::e_lt : return "<" ; 24586 | case details::e_lte : return "<=" 24587 | case details::e_eq : return "==" 24588 | case details::e_equal : return "=" ; 24589 | case details::e_ne : return "!=" 24590 | case details::e_nequal: return "<>" 24591 | case details::e_gte : return ">=" 24592 | case details::e_gt : return ">" ; 24593 | default : return "" ; 24594 | } 24595 | } 24596 | 24597 | std::string logic_opr_to_string(details::operator_type opr) const 24598 | { 24599 | switch (opr) 24600 | { 24601 | case details::e_and : return "and" ; 24602 | case details::e_or : return "or" ; 24603 | case details::e_xor : return "xor" ; 24604 | case details::e_nand : return "nand" 24605 | case details::e_nor : return "nor" ; 24606 | case details::e_xnor : return "xnor" 24607 | case details::e_notl : return "not" ; 24608 | default : return "" ; 24609 | } 24610 | } 24611 | 24612 | bool enable_replacer_; 24613 | bool enable_joiner_; 24614 | bool enable_numeric_check_; 24615 | bool enable_bracket_check_; 24616 | bool enable_sequence_check_; 24617 | bool enable_commutative_check_; 24618 | bool enable_strength_reduction_; 24619 | bool enable_collect_vars_; 24620 | bool enable_collect_funcs_; 24621 | bool enable_collect_assings_; 24622 | bool disable_vardef_; 24623 | bool disable_rsrvd_sym_usr_; 24624 | bool disable_zero_return_; 24625 | 24626 | disabled_entity_set_t disabled_func_set_ ; 24627 | disabled_entity_set_t disabled_ctrl_set_ ; 24628 | disabled_entity_set_t disabled_logic_set_; 24629 | disabled_entity_set_t disabled_arithmetic_set_; 24630 | disabled_entity_set_t disabled_assignment_set_; 24631 | disabled_entity_set_t disabled_inequality_set_; 24632 | 24633 | std::size_t max_stack_depth_; 24634 | std::size_t max_node_depth_; 24635 | std::size_t max_total_local_symbol_size_bytes_; 24636 | std::size_t max_local_vector_size_; 24637 | 24638 | friend class parser<T>; 24639 | }; 24640 | 24641 | typedef settings_store settings_t; 24642 | 24643 | explicit parser(const settings_t& settings = settings_t()) 24644 | : settings_(settings) 24645 | , resolve_unknown_symbol_(false) 24646 | , results_context_(0) 24647 | , unknown_symbol_resolver_(reinterpret_cast<unknown_symbol_resolver*>(0)) 24648 | #ifdef _MSC_VER 24649 | #pragma warning(push) 24650 | #pragma warning (disable:4355) 24651 | #endif 24652 | , sem_(*this) 24653 | #ifdef _MSC_VER 24654 | #pragma warning(pop) 24655 | #endif 24656 | , operator_joiner_2_(2) 24657 | , operator_joiner_3_(3) 24658 | , loop_runtime_check_(0) 24659 | , vector_access_runtime_check_(0) 24660 | , compilation_check_ptr_(0) 24661 | , assert_check_(0) 24662 | { 24663 | init_precompilation(); 24664 | 24665 | load_operations_map (base_ops_map_ ); 24666 | load_unary_operations_map (unary_op_map_ ); 24667 | load_binary_operations_map (binary_op_map_ ); 24668 | load_inv_binary_operations_map(inv_binary_op_map_); 24669 | load_sf3_map (sf3_map_ ); 24670 | load_sf4_map (sf4_map_ ); 24671 | 24672 | expression_generator_.init_synthesize_map(); 24673 | expression_generator_.set_parser(*this); 24674 | expression_generator_.set_uom (unary_op_map_ ); 24675 | expression_generator_.set_bom (binary_op_map_ ); 24676 | expression_generator_.set_ibom(inv_binary_op_map_); 24677 | expression_generator_.set_sf3m(sf3_map_ ); 24678 | expression_generator_.set_sf4m(sf4_map_ ); 24679 | expression_generator_.set_strength_reduction_state(settings_.strength_reduction_enabled()); 24680 | } 24681 | 24682 | ~parser() 24683 | {} 24684 | 24685 | inline void init_precompilation() 24686 | { 24687 | dec_.collect_variables() = 24688 | settings_.collect_variables_enabled(); 24689 | 24690 | dec_.collect_functions() = 24691 | settings_.collect_functions_enabled(); 24692 | 24693 | dec_.collect_assignments() = 24694 | settings_.collect_assignments_enabled(); 24695 | 24696 | if (settings_.replacer_enabled()) 24697 | { 24698 | symbol_replacer_.clear(); 24699 | symbol_replacer_.add_replace("true" , "1", lexer::token::e_number); 24700 | symbol_replacer_.add_replace("false", "0", lexer::token::e_number); 24701 | helper_assembly_.token_modifier_list.clear(); 24702 | helper_assembly_.register_modifier(&symbol_replacer_); 24703 | } 24704 | 24705 | if (settings_.commutative_check_enabled()) 24706 | { 24707 | for (std::size_t i = 0; i < details::reserved_words_size; ++i) 24708 | { 24709 | commutative_inserter_.ignore_symbol(details::reserved_words[i]); 24710 | } 24711 | 24712 | helper_assembly_.token_inserter_list.clear(); 24713 | helper_assembly_.register_inserter(&commutative_inserter_); 24714 | } 24715 | 24716 | if (settings_.joiner_enabled()) 24717 | { 24718 | helper_assembly_.token_joiner_list.clear(); 24719 | helper_assembly_.register_joiner(&operator_joiner_2_); 24720 | helper_assembly_.register_joiner(&operator_joiner_3_); 24721 | } 24722 | 24723 | if ( 24724 | settings_.numeric_check_enabled () || 24725 | settings_.bracket_check_enabled () || 24726 | settings_.sequence_check_enabled() 24727 | ) 24728 | { 24729 | helper_assembly_.token_scanner_list.clear(); 24730 | 24731 | if (settings_.numeric_check_enabled()) 24732 | { 24733 | helper_assembly_.register_scanner(&numeric_checker_); 24734 | } 24735 | 24736 | if (settings_.bracket_check_enabled()) 24737 | { 24738 | helper_assembly_.register_scanner(&bracket_checker_); 24739 | } 24740 | 24741 | if (settings_.sequence_check_enabled()) 24742 | { 24743 | helper_assembly_.register_scanner(&sequence_validator_ ); 24744 | helper_assembly_.register_scanner(&sequence_validator_3tkns_); 24745 | } 24746 | } 24747 | } 24748 | 24749 | inline bool compile(const std::string& expression_string, expression<T>& expr) 24750 | { 24751 | state_ .reset(); 24752 | error_list_ .clear(); 24753 | brkcnt_list_ .clear(); 24754 | synthesis_error_ .clear(); 24755 | immutable_memory_map_.reset(); 24756 | immutable_symtok_map_.clear(); 24757 | current_state_stack_ .clear(); 24758 | assert_ids_ .clear(); 24759 | sem_ .cleanup(); 24760 | 24761 | return_cleanup(); 24762 | 24763 | if (!valid_settings()) 24764 | { 24765 | return false; 24766 | } 24767 | 24768 | expression_generator_.set_allocator(node_allocator_); 24769 | 24770 | if (expression_string.empty()) 24771 | { 24772 | set_error(make_error( 24773 | parser_error::e_syntax, 24774 | "ERR001 - Empty expression!", 24775 | exprtk_error_location)); 24776 | 24777 | return false; 24778 | } 24779 | 24780 | if (!init(expression_string)) 24781 | { 24782 | process_lexer_errors(); 24783 | return false; 24784 | } 24785 | 24786 | if (lexer().empty()) 24787 | { 24788 | set_error(make_error( 24789 | parser_error::e_syntax, 24790 | "ERR002 - Empty expression!", 24791 | exprtk_error_location)); 24792 | 24793 | return false; 24794 | } 24795 | 24796 | if (halt_compilation_check()) 24797 | { 24798 | exprtk_debug(("halt_compilation_check() - compile checkpoint 0\n")); 24799 | sem_.cleanup(); 24800 | return false; 24801 | } 24802 | 24803 | if (!run_assemblies()) 24804 | { 24805 | sem_.cleanup(); 24806 | return false; 24807 | } 24808 | 24809 | if (halt_compilation_check()) 24810 | { 24811 | exprtk_debug(("halt_compilation_check() - compile checkpoint 1\n")); 24812 | sem_.cleanup(); 24813 | return false; 24814 | } 24815 | 24816 | symtab_store_.symtab_list_ = expr.get_symbol_table_list(); 24817 | dec_.clear(); 24818 | 24819 | lexer().begin(); 24820 | 24821 | next_token(); 24822 | 24823 | expression_node_ptr e = parse_corpus(); 24824 | 24825 | if ((0 != e) && (token_t::e_eof == current_token().type)) 24826 | { 24827 | bool* retinvk_ptr = 0; 24828 | 24829 | if (state_.return_stmt_present) 24830 | { 24831 | dec_.return_present_ = true; 24832 | 24833 | e = expression_generator_ 24834 | .return_envelope(e, results_context_, retinvk_ptr); 24835 | } 24836 | 24837 | expr.set_expression(e); 24838 | expr.set_retinvk(retinvk_ptr); 24839 | 24840 | register_local_vars(expr); 24841 | register_return_results(expr); 24842 | 24843 | return !(!expr); 24844 | } 24845 | else 24846 | { 24847 | if (error_list_.empty()) 24848 | { 24849 | set_error(make_error( 24850 | parser_error::e_syntax, 24851 | current_token(), 24852 | "ERR003 - Invalid expression encountered", 24853 | exprtk_error_location)); 24854 | } 24855 | 24856 | if ((0 != e) && branch_deletable(e)) 24857 | { 24858 | destroy_node(e); 24859 | } 24860 | 24861 | dec_.clear (); 24862 | sem_.cleanup (); 24863 | return_cleanup(); 24864 | 24865 | return false; 24866 | } 24867 | } 24868 | 24869 | inline expression_t compile(const std::string& expression_string, symbol_table_t& symtab) 24870 | { 24871 | expression_t expression; 24872 | expression.register_symbol_table(symtab); 24873 | compile(expression_string,expression); 24874 | return expression; 24875 | } 24876 | 24877 | void process_lexer_errors() 24878 | { 24879 | for (std::size_t i = 0; i < lexer().size(); ++i) 24880 | { 24881 | if (lexer()[i].is_error()) 24882 | { 24883 | std::string diagnostic = "ERR004 - " 24884 | 24885 | switch (lexer()[i].type) 24886 | { 24887 | case lexer::token::e_error : diagnostic += "General token error" 24888 | break; 24889 | 24890 | case lexer::token::e_err_symbol : diagnostic += "Symbol error" 24891 | break; 24892 | 24893 | case lexer::token::e_err_number : diagnostic += "Invalid numeric token" 24894 | break; 24895 | 24896 | case lexer::token::e_err_string : diagnostic += "Invalid string token" 24897 | break; 24898 | 24899 | case lexer::token::e_err_sfunc : diagnostic += "Invalid special function token" 24900 | break; 24901 | 24902 | default : diagnostic += "Unknown compiler error" 24903 | } 24904 | 24905 | set_error(make_error( 24906 | parser_error::e_lexer, 24907 | lexer()[i], 24908 | diagnostic + ": " + lexer()[i].value, 24909 | exprtk_error_location)); 24910 | } 24911 | } 24912 | } 24913 | 24914 | inline bool run_assemblies() 24915 | { 24916 | if (settings_.commutative_check_enabled()) 24917 | { 24918 | helper_assembly_.run_inserters(lexer()); 24919 | } 24920 | 24921 | if (settings_.joiner_enabled()) 24922 | { 24923 | helper_assembly_.run_joiners(lexer()); 24924 | } 24925 | 24926 | if (settings_.replacer_enabled()) 24927 | { 24928 | helper_assembly_.run_modifiers(lexer()); 24929 | } 24930 | 24931 | if ( 24932 | settings_.numeric_check_enabled () || 24933 | settings_.bracket_check_enabled () || 24934 | settings_.sequence_check_enabled() 24935 | ) 24936 | { 24937 | if (!helper_assembly_.run_scanners(lexer())) 24938 | { 24939 | if (helper_assembly_.error_token_scanner) 24940 | { 24941 | lexer::helper::bracket_checker* bracket_checker_ptr = 0; 24942 | lexer::helper::numeric_checker<T>* numeric_checker_ptr = 0; 24943 | lexer::helper::sequence_validator* sequence_validator_ptr = 0; 24944 | lexer::helper::sequence_validator_3tokens* sequence_validator3_ptr = 0; 24945 | 24946 | if (0 != (bracket_checker_ptr = dynamic_cast<lexer::helper::bracket_checker*>(helper_assembly_.error_token_scanner))) 24947 | { 24948 | set_error(make_error( 24949 | parser_error::e_token, 24950 | bracket_checker_ptr->error_token(), 24951 | "ERR005 - Mismatched brackets: '" + bracket_checker_ptr->error_token().value + "'", 24952 | exprtk_error_location)); 24953 | } 24954 | else if (0 != (numeric_checker_ptr = dynamic_cast<lexer::helper::numeric_checker<T>*>(helper_assembly_.error_token_scanner))) 24955 | { 24956 | for (std::size_t i = 0; i < numeric_checker_ptr->error_count(); ++i) 24957 | { 24958 | lexer::token error_token = lexer()[numeric_checker_ptr->error_index(i)]; 24959 | 24960 | set_error(make_error( 24961 | parser_error::e_token, 24962 | error_token, 24963 | "ERR006 - Invalid numeric token: '" + error_token.value + "'", 24964 | exprtk_error_location)); 24965 | } 24966 | 24967 | if (numeric_checker_ptr->error_count()) 24968 | { 24969 | numeric_checker_ptr->clear_errors(); 24970 | } 24971 | } 24972 | else if (0 != (sequence_validator_ptr = dynamic_cast<lexer::helper::sequence_validator*>(helper_assembly_.error_token_scanner))) 24973 | { 24974 | for (std::size_t i = 0; i < sequence_validator_ptr->error_count(); ++i) 24975 | { 24976 | std::pair<lexer::token,lexer::token> error_token = sequence_validator_ptr->error(i); 24977 | 24978 | set_error(make_error( 24979 | parser_error::e_token, 24980 | error_token.first, 24981 | "ERR007 - Invalid token sequence: '" + 24982 | error_token.first.value + "' and '" + 24983 | error_token.second.value + "'", 24984 | exprtk_error_location)); 24985 | } 24986 | 24987 | if (sequence_validator_ptr->error_count()) 24988 | { 24989 | sequence_validator_ptr->clear_errors(); 24990 | } 24991 | } 24992 | else if (0 != (sequence_validator3_ptr = dynamic_cast<lexer::helper::sequence_validator_3tokens*>(helper_assembly_.error_token_scanner))) 24993 | { 24994 | for (std::size_t i = 0; i < sequence_validator3_ptr->error_count(); ++i) 24995 | { 24996 | std::pair<lexer::token,lexer::token> error_token = sequence_validator3_ptr->error(i); 24997 | 24998 | set_error(make_error( 24999 | parser_error::e_token, 25000 | error_token.first, 25001 | "ERR008 - Invalid token sequence: '" + 25002 | error_token.first.value + "' and '" + 25003 | error_token.second.value + "'", 25004 | exprtk_error_location)); 25005 | } 25006 | 25007 | if (sequence_validator3_ptr->error_count()) 25008 | { 25009 | sequence_validator3_ptr->clear_errors(); 25010 | } 25011 | } 25012 | } 25013 | 25014 | return false; 25015 | } 25016 | } 25017 | 25018 | return true; 25019 | } 25020 | 25021 | inline settings_store& settings() 25022 | { 25023 | return settings_; 25024 | } 25025 | 25026 | inline parser_error::type get_error(const std::size_t& index) const 25027 | { 25028 | if (index < error_list_.size()) 25029 | { 25030 | return error_list_[index]; 25031 | } 25032 | 25033 | throw std::invalid_argument("parser::get_error() - Invalid error index specified"); 25034 | } 25035 | 25036 | inline std::string error() const 25037 | { 25038 | if (!error_list_.empty()) 25039 | { 25040 | return error_list_[0].diagnostic; 25041 | } 25042 | else 25043 | return std::string("No Error"); 25044 | } 25045 | 25046 | inline std::size_t error_count() const 25047 | { 25048 | return error_list_.size(); 25049 | } 25050 | 25051 | inline dependent_entity_collector& dec() 25052 | { 25053 | return dec_; 25054 | } 25055 | 25056 | inline std::size_t total_local_symbol_size_bytes() const 25057 | { 25058 | return sem_.total_local_symb_size_bytes(); 25059 | } 25060 | 25061 | inline bool replace_symbol(const std::string& old_symbol, const std::string& new_symbol) 25062 | { 25063 | if (!settings_.replacer_enabled()) 25064 | return false; 25065 | else if (details::is_reserved_word(old_symbol)) 25066 | return false; 25067 | else 25068 | return symbol_replacer_.add_replace(old_symbol,new_symbol,lexer::token::e_symbol); 25069 | } 25070 | 25071 | inline bool remove_replace_symbol(const std::string& symbol) 25072 | { 25073 | if (!settings_.replacer_enabled()) 25074 | return false; 25075 | else if (details::is_reserved_word(symbol)) 25076 | return false; 25077 | else 25078 | return symbol_replacer_.remove(symbol); 25079 | } 25080 | 25081 | inline void enable_unknown_symbol_resolver(unknown_symbol_resolver* usr = reinterpret_cast<unknown_symbol_resolver*>(0)) 25082 | { 25083 | resolve_unknown_symbol_ = true; 25084 | 25085 | if (usr) 25086 | unknown_symbol_resolver_ = usr; 25087 | else 25088 | unknown_symbol_resolver_ = &default_usr_; 25089 | } 25090 | 25091 | inline void enable_unknown_symbol_resolver(unknown_symbol_resolver& usr) 25092 | { 25093 | enable_unknown_symbol_resolver(&usr); 25094 | } 25095 | 25096 | inline void disable_unknown_symbol_resolver() 25097 | { 25098 | resolve_unknown_symbol_ = false; 25099 | unknown_symbol_resolver_ = &default_usr_; 25100 | } 25101 | 25102 | inline void register_loop_runtime_check(loop_runtime_check& lrtchk) 25103 | { 25104 | loop_runtime_check_ = &lrtchk; 25105 | } 25106 | 25107 | inline void register_vector_access_runtime_check(vector_access_runtime_check& vartchk) 25108 | { 25109 | vector_access_runtime_check_ = &vartchk; 25110 | } 25111 | 25112 | inline void register_compilation_timeout_check(compilation_check& compchk) 25113 | { 25114 | compilation_check_ptr_ = &compchk; 25115 | } 25116 | 25117 | inline void register_assert_check(assert_check& assrt_chck) 25118 | { 25119 | assert_check_ = &assrt_chck; 25120 | } 25121 | 25122 | inline void clear_loop_runtime_check() 25123 | { 25124 | loop_runtime_check_ = loop_runtime_check_ptr(0); 25125 | } 25126 | 25127 | inline void clear_vector_access_runtime_check() 25128 | { 25129 | vector_access_runtime_check_ = vector_access_runtime_check_ptr(0); 25130 | } 25131 | 25132 | inline void clear_compilation_timeout_check() 25133 | { 25134 | compilation_check_ptr_ = compilation_check_ptr(0); 25135 | } 25136 | 25137 | inline void clear_assert_check() 25138 | { 25139 | assert_check_ = assert_check_ptr(0); 25140 | } 25141 | 25142 | private: 25143 | 25144 | inline bool valid_base_operation(const std::string& symbol) const 25145 | { 25146 | const std::size_t length = symbol.size(); 25147 | 25148 | if ( 25149 | (length < 3) || // Shortest base op symbol length 25150 | (length > 9) // Longest base op symbol length 25151 | ) 25152 | return false; 25153 | else 25154 | return settings_.function_enabled(symbol) && 25155 | (base_ops_map_.end() != base_ops_map_.find(symbol)); 25156 | } 25157 | 25158 | inline bool valid_vararg_operation(const std::string& symbol) const 25159 | { 25160 | static const std::string s_sum = "sum" ; 25161 | static const std::string s_mul = "mul" ; 25162 | static const std::string s_avg = "avg" ; 25163 | static const std::string s_min = "min" ; 25164 | static const std::string s_max = "max" ; 25165 | static const std::string s_mand = "mand" 25166 | static const std::string s_mor = "mor" ; 25167 | static const std::string s_multi = "~" ; 25168 | static const std::string s_mswitch = "[*]" ; 25169 | 25170 | return 25171 | ( 25172 | details::imatch(symbol,s_sum ) || 25173 | details::imatch(symbol,s_mul ) || 25174 | details::imatch(symbol,s_avg ) || 25175 | details::imatch(symbol,s_min ) || 25176 | details::imatch(symbol,s_max ) || 25177 | details::imatch(symbol,s_mand ) || 25178 | details::imatch(symbol,s_mor ) || 25179 | details::imatch(symbol,s_multi ) || 25180 | details::imatch(symbol,s_mswitch) 25181 | ) && 25182 | settings_.function_enabled(symbol); 25183 | } 25184 | 25185 | bool is_invalid_logic_operation(const details::operator_type operation) const 25186 | { 25187 | return settings_.logic_disabled(operation); 25188 | } 25189 | 25190 | bool is_invalid_arithmetic_operation(const details::operator_type operation) const 25191 | { 25192 | return settings_.arithmetic_disabled(operation); 25193 | } 25194 | 25195 | bool is_invalid_assignment_operation(const details::operator_type operation) const 25196 | { 25197 | return settings_.assignment_disabled(operation); 25198 | } 25199 | 25200 | bool is_invalid_inequality_operation(const details::operator_type operation) const 25201 | { 25202 | return settings_.inequality_disabled(operation); 25203 | } 25204 | 25205 | #ifdef exprtk_enable_debugging 25206 | inline void next_token() 25207 | { 25208 | const std::string ct_str = current_token().value; 25209 | const std::size_t ct_pos = current_token().position; 25210 | parser_helper::next_token(); 25211 | const std::string depth(2 * state_.scope_depth,' '); 25212 | exprtk_debug(("%s" 25213 | "prev[%s | %04d] --> curr[%s | %04d] stack_level: %3d\n", 25214 | depth.c_str(), 25215 | ct_str.c_str(), 25216 | static_cast<unsigned int>(ct_pos), 25217 | current_token().value.c_str(), 25218 | static_cast<unsigned int>(current_token().position), 25219 | static_cast<unsigned int>(state_.stack_depth))); 25220 | } 25221 | #endif 25222 | 25223 | inline expression_node_ptr parse_corpus() 25224 | { 25225 | std::vector<expression_node_ptr> arg_list; 25226 | std::vector<bool> side_effect_list; 25227 | 25228 | scoped_vec_delete<expression_node_t> svd((*this), arg_list); 25229 | 25230 | lexer::token begin_token; 25231 | lexer::token end_token; 25232 | 25233 | for ( ; ; ) 25234 | { 25235 | state_.side_effect_present = false; 25236 | 25237 | begin_token = current_token(); 25238 | 25239 | expression_node_ptr arg = parse_expression(); 25240 | 25241 | if (0 == arg) 25242 | { 25243 | if (error_list_.empty()) 25244 | { 25245 | set_error(make_error( 25246 | parser_error::e_syntax, 25247 | current_token(), 25248 | "ERR009 - Invalid expression encountered", 25249 | exprtk_error_location)); 25250 | } 25251 | 25252 | return error_node(); 25253 | } 25254 | else 25255 | { 25256 | arg_list.push_back(arg); 25257 | 25258 | side_effect_list.push_back(state_.side_effect_present); 25259 | 25260 | end_token = current_token(); 25261 | 25262 | const std::string sub_expr = construct_subexpr(begin_token, end_token); 25263 | 25264 | exprtk_debug(("parse_corpus(%02d) Subexpr: %s\n", 25265 | static_cast<int>(arg_list.size() - 1), 25266 | sub_expr.c_str())); 25267 | 25268 | exprtk_debug(("parse_corpus(%02d) - Side effect present: %s\n", 25269 | static_cast<int>(arg_list.size() - 1), 25270 | state_.side_effect_present ? "true" : "false")); 25271 | 25272 | exprtk_debug(("-------------------------------------------------\n")); 25273 | } 25274 | 25275 | if (token_is(token_t::e_eof,prsrhlpr_t::e_hold)) 25276 | { 25277 | if (lexer().finished()) 25278 | break; 25279 | else 25280 | next_token(); 25281 | } 25282 | else if ( 25283 | !settings_.commutative_check_enabled() && 25284 | ( 25285 | current_token().type == token_t::e_symbol || 25286 | current_token().type == token_t::e_number || 25287 | current_token().type == token_t::e_string || 25288 | token_is_bracket(prsrhlpr_t::e_hold) 25289 | ) 25290 | ) 25291 | { 25292 | set_error(make_error( 25293 | parser_error::e_syntax, 25294 | current_token(), 25295 | "ERR010 - Invalid syntax '" + current_token().value + "' possible missing operator or context", 25296 | exprtk_error_location)); 25297 | 25298 | return error_node(); 25299 | } 25300 | } 25301 | 25302 | if ( 25303 | !arg_list.empty() && 25304 | is_return_node(arg_list.back()) 25305 | ) 25306 | { 25307 | dec_.final_stmt_return_ = true; 25308 | } 25309 | 25310 | const expression_node_ptr result = simplify(arg_list,side_effect_list); 25311 | 25312 | svd.delete_ptr = (0 == result); 25313 | 25314 | return result; 25315 | } 25316 | 25317 | std::string construct_subexpr(lexer::token& begin_token, 25318 | lexer::token& end_token, 25319 | const bool cleanup_whitespace = true) 25320 | { 25321 | std::string result = lexer().substr(begin_token.position,end_token.position); 25322 | if (cleanup_whitespace) 25323 | { 25324 | for (std::size_t i = 0; i < result.size(); ++i) 25325 | { 25326 | if (details::is_whitespace(result[i])) result[i] = ' '; 25327 | } 25328 | } 25329 | 25330 | return result; 25331 | } 25332 | 25333 | static const precedence_level default_precedence = e_level00; 25334 | 25335 | struct state_t 25336 | { 25337 | inline void set(const precedence_level& l, 25338 | const precedence_level& r, 25339 | const details::operator_type& o, 25340 | const token_t& tkn = token_t()) 25341 | { 25342 | left = l; 25343 | right = r; 25344 | operation = o; 25345 | token = tkn; 25346 | } 25347 | 25348 | inline void reset() 25349 | { 25350 | left = e_level00; 25351 | right = e_level00; 25352 | operation = details::e_default; 25353 | } 25354 | 25355 | precedence_level left; 25356 | precedence_level right; 25357 | details::operator_type operation; 25358 | token_t token; 25359 | }; 25360 | 25361 | inline void push_current_state(const state_t current_state) 25362 | { 25363 | current_state_stack_.push_back(current_state); 25364 | } 25365 | 25366 | inline void pop_current_state() 25367 | { 25368 | if (!current_state_stack_.empty()) 25369 | { 25370 | current_state_stack_.pop_back(); 25371 | } 25372 | } 25373 | 25374 | inline state_t current_state() const 25375 | { 25376 | return (!current_state_stack_.empty()) ? 25377 | current_state_stack_.back() : 25378 | state_t(); 25379 | } 25380 | 25381 | inline bool halt_compilation_check() 25382 | { 25383 | compilation_check::compilation_context context; 25384 | 25385 | if (compilation_check_ptr_ && !compilation_check_ptr_->continue_compilation(context)) 25386 | { 25387 | const std::string error_message = 25388 | !context.error_message.empty() ? " Details: " + context.error_message : "" 25389 | 25390 | set_error(make_error( 25391 | parser_error::e_parser, 25392 | token_t(), 25393 | "ERR011 - Internal compilation check failed." + error_message, 25394 | exprtk_error_location)); 25395 | 25396 | return true; 25397 | } 25398 | 25399 | return false; 25400 | } 25401 | 25402 | inline expression_node_ptr parse_expression(precedence_level precedence = e_level00) 25403 | { 25404 | if (halt_compilation_check()) 25405 | { 25406 | exprtk_debug(("halt_compilation_check() - parse_expression checkpoint 2\n")); 25407 | return error_node(); 25408 | } 25409 | 25410 | stack_limit_handler slh(*this); 25411 | 25412 | if (!slh) 25413 | { 25414 | return error_node(); 25415 | } 25416 | 25417 | expression_node_ptr expression = parse_branch(precedence); 25418 | 25419 | if (0 == expression) 25420 | { 25421 | return error_node(); 25422 | } 25423 | 25424 | if (token_is(token_t::e_eof,prsrhlpr_t::e_hold)) 25425 | { 25426 | return expression; 25427 | } 25428 | 25429 | bool break_loop = false; 25430 | 25431 | state_t current_state; 25432 | 25433 | for ( ; ; ) 25434 | { 25435 | current_state.reset(); 25436 | 25437 | switch (current_token().type) 25438 | { 25439 | case token_t::e_assign : current_state.set(e_level00, e_level00, details::e_assign, current_token()); break; 25440 | case token_t::e_addass : current_state.set(e_level00, e_level00, details::e_addass, current_token()); break; 25441 | case token_t::e_subass : current_state.set(e_level00, e_level00, details::e_subass, current_token()); break; 25442 | case token_t::e_mulass : current_state.set(e_level00, e_level00, details::e_mulass, current_token()); break; 25443 | case token_t::e_divass : current_state.set(e_level00, e_level00, details::e_divass, current_token()); break; 25444 | case token_t::e_modass : current_state.set(e_level00, e_level00, details::e_modass, current_token()); break; 25445 | case token_t::e_swap : current_state.set(e_level00, e_level00, details::e_swap , current_token()); break; 25446 | case token_t::e_lt : current_state.set(e_level05, e_level06, details::e_lt , current_token()); break; 25447 | case token_t::e_lte : current_state.set(e_level05, e_level06, details::e_lte , current_token()); break; 25448 | case token_t::e_eq : current_state.set(e_level05, e_level06, details::e_eq , current_token()); break; 25449 | case token_t::e_ne : current_state.set(e_level05, e_level06, details::e_ne , current_token()); break; 25450 | case token_t::e_gte : current_state.set(e_level05, e_level06, details::e_gte , current_token()); break; 25451 | case token_t::e_gt : current_state.set(e_level05, e_level06, details::e_gt , current_token()); break; 25452 | case token_t::e_add : current_state.set(e_level07, e_level08, details::e_add , current_token()); break; 25453 | case token_t::e_sub : current_state.set(e_level07, e_level08, details::e_sub , current_token()); break; 25454 | case token_t::e_div : current_state.set(e_level10, e_level11, details::e_div , current_token()); break; 25455 | case token_t::e_mul : current_state.set(e_level10, e_level11, details::e_mul , current_token()); break; 25456 | case token_t::e_mod : current_state.set(e_level10, e_level11, details::e_mod , current_token()); break; 25457 | case token_t::e_pow : current_state.set(e_level12, e_level12, details::e_pow , current_token()); break; 25458 | default : 25459 | if (token_t::e_symbol == current_token().type) 25460 | { 25461 | static const std::string s_and = "and" ; 25462 | static const std::string s_nand = "nand" ; 25463 | static const std::string s_or = "or" ; 25464 | static const std::string s_nor = "nor" ; 25465 | static const std::string s_xor = "xor" ; 25466 | static const std::string s_xnor = "xnor" ; 25467 | static const std::string s_in = "in" ; 25468 | static const std::string s_like = "like" ; 25469 | static const std::string s_ilike = "ilike" 25470 | static const std::string s_and1 = "&" ; 25471 | static const std::string s_or1 = "|" ; 25472 | static const std::string s_not = "not" ; 25473 | 25474 | if (details::imatch(current_token().value,s_and)) 25475 | { 25476 | current_state.set(e_level03, e_level04, details::e_and, current_token()); 25477 | break; 25478 | } 25479 | else if (details::imatch(current_token().value,s_and1)) 25480 | { 25481 | #ifndef exprtk_disable_sc_andor 25482 | current_state.set(e_level03, e_level04, details::e_scand, current_token()); 25483 | #else 25484 | current_state.set(e_level03, e_level04, details::e_and, current_token()); 25485 | #endif 25486 | break; 25487 | } 25488 | else if (details::imatch(current_token().value,s_nand)) 25489 | { 25490 | current_state.set(e_level03, e_level04, details::e_nand, current_token()); 25491 | break; 25492 | } 25493 | else if (details::imatch(current_token().value,s_or)) 25494 | { 25495 | current_state.set(e_level01, e_level02, details::e_or, current_token()); 25496 | break; 25497 | } 25498 | else if (details::imatch(current_token().value,s_or1)) 25499 | { 25500 | #ifndef exprtk_disable_sc_andor 25501 | current_state.set(e_level01, e_level02, details::e_scor, current_token()); 25502 | #else 25503 | current_state.set(e_level01, e_level02, details::e_or, current_token()); 25504 | #endif 25505 | break; 25506 | } 25507 | else if (details::imatch(current_token().value,s_nor)) 25508 | { 25509 | current_state.set(e_level01, e_level02, details::e_nor, current_token()); 25510 | break; 25511 | } 25512 | else if (details::imatch(current_token().value,s_xor)) 25513 | { 25514 | current_state.set(e_level01, e_level02, details::e_xor, current_token()); 25515 | break; 25516 | } 25517 | else if (details::imatch(current_token().value,s_xnor)) 25518 | { 25519 | current_state.set(e_level01, e_level02, details::e_xnor, current_token()); 25520 | break; 25521 | } 25522 | else if (details::imatch(current_token().value,s_in)) 25523 | { 25524 | current_state.set(e_level04, e_level04, details::e_in, current_token()); 25525 | break; 25526 | } 25527 | else if (details::imatch(current_token().value,s_like)) 25528 | { 25529 | current_state.set(e_level04, e_level04, details::e_like, current_token()); 25530 | break; 25531 | } 25532 | else if (details::imatch(current_token().value,s_ilike)) 25533 | { 25534 | current_state.set(e_level04, e_level04, details::e_ilike, current_token()); 25535 | break; 25536 | } 25537 | else if (details::imatch(current_token().value,s_not)) 25538 | { 25539 | break; 25540 | } 25541 | } 25542 | 25543 | break_loop = true; 25544 | } 25545 | 25546 | if (break_loop) 25547 | { 25548 | parse_pending_string_rangesize(expression); 25549 | break; 25550 | } 25551 | else if (current_state.left < precedence) 25552 | break; 25553 | 25554 | const lexer::token prev_token = current_token(); 25555 | 25556 | next_token(); 25557 | 25558 | expression_node_ptr right_branch = error_node(); 25559 | expression_node_ptr new_expression = error_node(); 25560 | 25561 | if (is_invalid_logic_operation(current_state.operation)) 25562 | { 25563 | free_node(node_allocator_, expression); 25564 | 25565 | set_error(make_error( 25566 | parser_error::e_syntax, 25567 | prev_token, 25568 | "ERR012 - Invalid or disabled logic operation '" + details::to_str(current_state.operation) + "'", 25569 | exprtk_error_location)); 25570 | 25571 | return error_node(); 25572 | } 25573 | else if (is_invalid_arithmetic_operation(current_state.operation)) 25574 | { 25575 | free_node(node_allocator_, expression); 25576 | 25577 | set_error(make_error( 25578 | parser_error::e_syntax, 25579 | prev_token, 25580 | "ERR013 - Invalid or disabled arithmetic operation '" + details::to_str(current_state.operation) + "'", 25581 | exprtk_error_location)); 25582 | 25583 | return error_node(); 25584 | } 25585 | else if (is_invalid_inequality_operation(current_state.operation)) 25586 | { 25587 | free_node(node_allocator_, expression); 25588 | 25589 | set_error(make_error( 25590 | parser_error::e_syntax, 25591 | prev_token, 25592 | "ERR014 - Invalid inequality operation '" + details::to_str(current_state.operation) + "'", 25593 | exprtk_error_location)); 25594 | 25595 | return error_node(); 25596 | } 25597 | else if (is_invalid_assignment_operation(current_state.operation)) 25598 | { 25599 | free_node(node_allocator_, expression); 25600 | 25601 | set_error(make_error( 25602 | parser_error::e_syntax, 25603 | prev_token, 25604 | "ERR015 - Invalid or disabled assignment operation '" + details::to_str(current_state.operation) + "'", 25605 | exprtk_error_location)); 25606 | 25607 | return error_node(); 25608 | } 25609 | 25610 | if (0 != (right_branch = parse_expression(current_state.right))) 25611 | { 25612 | if ( 25613 | details::is_return_node(expression ) || 25614 | details::is_return_node(right_branch) 25615 | ) 25616 | { 25617 | free_node(node_allocator_, expression ); 25618 | free_node(node_allocator_, right_branch); 25619 | 25620 | set_error(make_error( 25621 | parser_error::e_syntax, 25622 | prev_token, 25623 | "ERR016 - Return statements cannot be part of sub-expressions", 25624 | exprtk_error_location)); 25625 | 25626 | return error_node(); 25627 | } 25628 | 25629 | push_current_state(current_state); 25630 | 25631 | new_expression = expression_generator_ 25632 | ( 25633 | current_state.operation, 25634 | expression, 25635 | right_branch 25636 | ); 25637 | 25638 | pop_current_state(); 25639 | } 25640 | 25641 | if (0 == new_expression) 25642 | { 25643 | if (error_list_.empty()) 25644 | { 25645 | set_error(make_error( 25646 | parser_error::e_syntax, 25647 | prev_token, 25648 | !synthesis_error_.empty() ? 25649 | synthesis_error_ : 25650 | "ERR017 - General parsing error at token: '" + prev_token.value + "'", 25651 | exprtk_error_location)); 25652 | } 25653 | 25654 | free_node(node_allocator_, expression ); 25655 | free_node(node_allocator_, right_branch); 25656 | 25657 | return error_node(); 25658 | } 25659 | else 25660 | { 25661 | if ( 25662 | token_is(token_t::e_ternary,prsrhlpr_t::e_hold) && 25663 | (e_level00 == precedence) 25664 | ) 25665 | { 25666 | expression = parse_ternary_conditional_statement(new_expression); 25667 | } 25668 | else 25669 | expression = new_expression; 25670 | 25671 | parse_pending_string_rangesize(expression); 25672 | } 25673 | } 25674 | 25675 | if ((0 != expression) && (expression->node_depth() > settings_.max_node_depth_)) 25676 | { 25677 | set_error(make_error( 25678 | parser_error::e_syntax, 25679 | current_token(), 25680 | "ERR018 - Expression depth of " + details::to_str(static_cast<int>(expression->node_depth())) + 25681 | " exceeds maximum allowed expression depth of " + details::to_str(static_cast<int>(settings_.max_node_depth_)), 25682 | exprtk_error_location)); 25683 | 25684 | free_node(node_allocator_, expression); 25685 | 25686 | return error_node(); 25687 | } 25688 | else if ( 25689 | !settings_.commutative_check_enabled() && 25690 | !details::is_logic_opr(current_token().value) && 25691 | (current_state.operation == details::e_default) && 25692 | ( 25693 | current_token().type == token_t::e_symbol || 25694 | current_token().type == token_t::e_number || 25695 | current_token().type == token_t::e_string 25696 | ) 25697 | ) 25698 | { 25699 | set_error(make_error( 25700 | parser_error::e_syntax, 25701 | current_token(), 25702 | "ERR019 - Invalid syntax '" + current_token().value + "' possible missing operator or context", 25703 | exprtk_error_location)); 25704 | 25705 | free_node(node_allocator_, expression); 25706 | 25707 | return error_node(); 25708 | } 25709 | 25710 | return expression; 25711 | } 25712 | 25713 | bool simplify_unary_negation_branch(expression_node_ptr& node) 25714 | { 25715 | { 25716 | typedef details::unary_branch_node<T,details::neg_op<T> > ubn_t; 25717 | ubn_t* n = dynamic_cast<ubn_t*>(node); 25718 | 25719 | if (n) 25720 | { 25721 | expression_node_ptr un_r = n->branch(0); 25722 | n->release(); 25723 | free_node(node_allocator_, node); 25724 | node = un_r; 25725 | 25726 | return true; 25727 | } 25728 | } 25729 | 25730 | { 25731 | typedef details::unary_variable_node<T,details::neg_op<T> > uvn_t; 25732 | 25733 | uvn_t* n = dynamic_cast<uvn_t*>(node); 25734 | 25735 | if (n) 25736 | { 25737 | const T& v = n->v(); 25738 | expression_node_ptr return_node = error_node(); 25739 | 25740 | if ( 25741 | (0 != (return_node = symtab_store_.get_variable(v))) || 25742 | (0 != (return_node = sem_ .get_variable(v))) 25743 | ) 25744 | { 25745 | free_node(node_allocator_, node); 25746 | node = return_node; 25747 | 25748 | return true; 25749 | } 25750 | else 25751 | { 25752 | set_error(make_error( 25753 | parser_error::e_syntax, 25754 | current_token(), 25755 | "ERR020 - Failed to find variable node in symbol table", 25756 | exprtk_error_location)); 25757 | 25758 | free_node(node_allocator_, node); 25759 | 25760 | return false; 25761 | } 25762 | } 25763 | } 25764 | 25765 | return false; 25766 | } 25767 | 25768 | static inline expression_node_ptr error_node() 25769 | { 25770 | return reinterpret_cast<expression_node_ptr>(0); 25771 | } 25772 | 25773 | struct scoped_expression_delete 25774 | { 25775 | scoped_expression_delete(parser<T>& pr, expression_node_ptr& expression) 25776 | : delete_ptr(true) 25777 | , parser_(pr) 25778 | , expression_(expression) 25779 | {} 25780 | 25781 | ~scoped_expression_delete() 25782 | { 25783 | if (delete_ptr) 25784 | { 25785 | free_node(parser_.node_allocator_, expression_); 25786 | } 25787 | } 25788 | 25789 | bool delete_ptr; 25790 | parser<T>& parser_; 25791 | expression_node_ptr& expression_; 25792 | 25793 | private: 25794 | 25795 | scoped_expression_delete(const scoped_expression_delete&) exprtk_delete; 25796 | scoped_expression_delete& operator=(const scoped_expression_delete&) exprtk_delete; 25797 | }; 25798 | 25799 | template <typename Type, std::size_t N> 25800 | struct scoped_delete 25801 | { 25802 | typedef Type* ptr_t; 25803 | 25804 | scoped_delete(parser<T>& pr, ptr_t& p) 25805 | : delete_ptr(true) 25806 | , parser_(pr) 25807 | , p_(&p) 25808 | {} 25809 | 25810 | scoped_delete(parser<T>& pr, ptr_t (&p)[N]) 25811 | : delete_ptr(true) 25812 | , parser_(pr) 25813 | , p_(&p[0]) 25814 | {} 25815 | 25816 | ~scoped_delete() 25817 | { 25818 | if (delete_ptr) 25819 | { 25820 | for (std::size_t i = 0; i < N; ++i) 25821 | { 25822 | free_node(parser_.node_allocator_, p_[i]); 25823 | } 25824 | } 25825 | } 25826 | 25827 | bool delete_ptr; 25828 | parser<T>& parser_; 25829 | ptr_t* p_; 25830 | 25831 | private: 25832 | 25833 | scoped_delete(const scoped_delete<Type,N>&) exprtk_delete; 25834 | scoped_delete<Type,N>& operator=(const scoped_delete<Type,N>&) exprtk_delete; 25835 | }; 25836 | 25837 | template <typename Type> 25838 | struct scoped_deq_delete 25839 | { 25840 | typedef Type* ptr_t; 25841 | 25842 | scoped_deq_delete(parser<T>& pr, std::deque<ptr_t>& deq) 25843 | : delete_ptr(true) 25844 | , parser_(pr) 25845 | , deq_(deq) 25846 | {} 25847 | 25848 | ~scoped_deq_delete() 25849 | { 25850 | if (delete_ptr && !deq_.empty()) 25851 | { 25852 | for (std::size_t i = 0; i < deq_.size(); ++i) 25853 | { 25854 | exprtk_debug(("~scoped_deq_delete() - deleting node: %p\n", reinterpret_cast<void*>(deq_[i]))); 25855 | free_node(parser_.node_allocator_,deq_[i]); 25856 | } 25857 | 25858 | deq_.clear(); 25859 | } 25860 | } 25861 | 25862 | bool delete_ptr; 25863 | parser<T>& parser_; 25864 | std::deque<ptr_t>& deq_; 25865 | 25866 | private: 25867 | 25868 | scoped_deq_delete(const scoped_deq_delete<Type>&) exprtk_delete; 25869 | scoped_deq_delete<Type>& operator=(const scoped_deq_delete<Type>&) exprtk_delete; 25870 | }; 25871 | 25872 | template <typename Type> 25873 | struct scoped_vec_delete 25874 | { 25875 | typedef Type* ptr_t; 25876 | 25877 | scoped_vec_delete(parser<T>& pr, std::vector<ptr_t>& vec) 25878 | : delete_ptr(true) 25879 | , parser_(pr) 25880 | , vec_(vec) 25881 | {} 25882 | 25883 | ~scoped_vec_delete() 25884 | { 25885 | if (delete_ptr && !vec_.empty()) 25886 | { 25887 | for (std::size_t i = 0; i < vec_.size(); ++i) 25888 | { 25889 | exprtk_debug(("~scoped_vec_delete() - deleting node: %p\n", reinterpret_cast<void*>(vec_[i]))); 25890 | free_node(parser_.node_allocator_,vec_[i]); 25891 | } 25892 | 25893 | vec_.clear(); 25894 | } 25895 | } 25896 | 25897 | ptr_t operator[](const std::size_t index) 25898 | { 25899 | return vec_[index]; 25900 | } 25901 | 25902 | bool delete_ptr; 25903 | parser<T>& parser_; 25904 | std::vector<ptr_t>& vec_; 25905 | 25906 | private: 25907 | 25908 | scoped_vec_delete(const scoped_vec_delete<Type>&) exprtk_delete; 25909 | scoped_vec_delete<Type>& operator=(const scoped_vec_delete<Type>&) exprtk_delete; 25910 | }; 25911 | 25912 | struct scoped_bool_negator 25913 | { 25914 | explicit scoped_bool_negator(bool& bb) 25915 | : b(bb) 25916 | { b = !b; } 25917 | 25918 | ~scoped_bool_negator() 25919 | { b = !b; } 25920 | 25921 | bool& b; 25922 | }; 25923 | 25924 | struct scoped_bool_or_restorer 25925 | { 25926 | explicit scoped_bool_or_restorer(bool& bb) 25927 | : b(bb) 25928 | , original_value_(bb) 25929 | {} 25930 | 25931 | ~scoped_bool_or_restorer() 25932 | { 25933 | b = b || original_value_; 25934 | } 25935 | 25936 | bool& b; 25937 | bool original_value_; 25938 | }; 25939 | 25940 | struct scoped_inc_dec 25941 | { 25942 | explicit scoped_inc_dec(std::size_t& v) 25943 | : v_(v) 25944 | { ++v_; } 25945 | 25946 | ~scoped_inc_dec() 25947 | { 25948 | assert(v_ > 0); 25949 | --v_; 25950 | } 25951 | 25952 | std::size_t& v_; 25953 | }; 25954 | 25955 | inline expression_node_ptr parse_function_invocation(ifunction<T>* function, const std::string& function_name) 25956 | { 25957 | expression_node_ptr func_node = reinterpret_cast<expression_node_ptr>(0); 25958 | 25959 | switch (function->param_count) 25960 | { 25961 | case 0 : func_node = parse_function_call_0 (function,function_name); break; 25962 | case 1 : func_node = parse_function_call< 1>(function,function_name); break; 25963 | case 2 : func_node = parse_function_call< 2>(function,function_name); break; 25964 | case 3 : func_node = parse_function_call< 3>(function,function_name); break; 25965 | case 4 : func_node = parse_function_call< 4>(function,function_name); break; 25966 | case 5 : func_node = parse_function_call< 5>(function,function_name); break; 25967 | case 6 : func_node = parse_function_call< 6>(function,function_name); break; 25968 | case 7 : func_node = parse_function_call< 7>(function,function_name); break; 25969 | case 8 : func_node = parse_function_call< 8>(function,function_name); break; 25970 | case 9 : func_node = parse_function_call< 9>(function,function_name); break; 25971 | case 10 : func_node = parse_function_call<10>(function,function_name); break; 25972 | case 11 : func_node = parse_function_call<11>(function,function_name); break; 25973 | case 12 : func_node = parse_function_call<12>(function,function_name); break; 25974 | case 13 : func_node = parse_function_call<13>(function,function_name); break; 25975 | case 14 : func_node = parse_function_call<14>(function,function_name); break; 25976 | case 15 : func_node = parse_function_call<15>(function,function_name); break; 25977 | case 16 : func_node = parse_function_call<16>(function,function_name); break; 25978 | case 17 : func_node = parse_function_call<17>(function,function_name); break; 25979 | case 18 : func_node = parse_function_call<18>(function,function_name); break; 25980 | case 19 : func_node = parse_function_call<19>(function,function_name); break; 25981 | case 20 : func_node = parse_function_call<20>(function,function_name); break; 25982 | default : { 25983 | set_error(make_error( 25984 | parser_error::e_syntax, 25985 | current_token(), 25986 | "ERR021 - Invalid number of parameters for function: '" + function_name + "'", 25987 | exprtk_error_location)); 25988 | 25989 | return error_node(); 25990 | } 25991 | } 25992 | 25993 | if (func_node) 25994 | return func_node; 25995 | else 25996 | { 25997 | set_error(make_error( 25998 | parser_error::e_syntax, 25999 | current_token(), 26000 | "ERR022 - Failed to generate call to function: '" + function_name + "'", 26001 | exprtk_error_location)); 26002 | 26003 | return error_node(); 26004 | } 26005 | } 26006 | 26007 | template <std::size_t NumberofParameters> 26008 | inline expression_node_ptr parse_function_call(ifunction<T>* function, const std::string& function_name) 26009 | { 26010 | #ifdef _MSC_VER 26011 | #pragma warning(push) 26012 | #pragma warning(disable: 4127) 26013 | #endif 26014 | if (0 == NumberofParameters) 26015 | { 26016 | set_error(make_error( 26017 | parser_error::e_syntax, 26018 | current_token(), 26019 | "ERR023 - Expecting ifunction '" + function_name + "' to have non-zero parameter count", 26020 | exprtk_error_location)); 26021 | 26022 | return error_node(); 26023 | } 26024 | #ifdef _MSC_VER 26025 | #pragma warning(pop) 26026 | #endif 26027 | 26028 | expression_node_ptr branch[NumberofParameters]; 26029 | expression_node_ptr result = error_node(); 26030 | 26031 | std::fill_n(branch, NumberofParameters, reinterpret_cast<expression_node_ptr>(0)); 26032 | 26033 | scoped_delete<expression_node_t,NumberofParameters> sd((*this),branch); 26034 | 26035 | next_token(); 26036 | 26037 | if (!token_is(token_t::e_lbracket)) 26038 | { 26039 | set_error(make_error( 26040 | parser_error::e_syntax, 26041 | current_token(), 26042 | "ERR024 - Expecting argument list for function: '" + function_name + "'", 26043 | exprtk_error_location)); 26044 | 26045 | return error_node(); 26046 | } 26047 | 26048 | for (int i = 0; i < static_cast<int>(NumberofParameters); ++i) 26049 | { 26050 | branch[i] = parse_expression(); 26051 | 26052 | if (0 == branch[i]) 26053 | { 26054 | set_error(make_error( 26055 | parser_error::e_syntax, 26056 | current_token(), 26057 | "ERR025 - Failed to parse argument " + details::to_str(i) + " for function: '" + function_name + "'", 26058 | exprtk_error_location)); 26059 | 26060 | return error_node(); 26061 | } 26062 | else if (i < static_cast<int>(NumberofParameters - 1)) 26063 | { 26064 | if (!token_is(token_t::e_comma)) 26065 | { 26066 | set_error(make_error( 26067 | parser_error::e_syntax, 26068 | current_token(), 26069 | "ERR026 - Invalid number of arguments for function: '" + function_name + "'", 26070 | exprtk_error_location)); 26071 | 26072 | return error_node(); 26073 | } 26074 | } 26075 | } 26076 | 26077 | if (!token_is(token_t::e_rbracket)) 26078 | { 26079 | set_error(make_error( 26080 | parser_error::e_syntax, 26081 | current_token(), 26082 | "ERR027 - Invalid number of arguments for function: '" + function_name + "'", 26083 | exprtk_error_location)); 26084 | 26085 | return error_node(); 26086 | } 26087 | else 26088 | result = expression_generator_.function(function,branch); 26089 | 26090 | sd.delete_ptr = (0 == result); 26091 | 26092 | return result; 26093 | } 26094 | 26095 | inline expression_node_ptr parse_function_call_0(ifunction<T>* function, const std::string& function_name) 26096 | { 26097 | expression_node_ptr result = expression_generator_.function(function); 26098 | 26099 | state_.side_effect_present = function->has_side_effects(); 26100 | 26101 | next_token(); 26102 | 26103 | if ( 26104 | token_is(token_t::e_lbracket) && 26105 | !token_is(token_t::e_rbracket) 26106 | ) 26107 | { 26108 | set_error(make_error( 26109 | parser_error::e_syntax, 26110 | current_token(), 26111 | "ERR028 - Expecting '()' to proceed call to function: '" + function_name + "'", 26112 | exprtk_error_location)); 26113 | 26114 | free_node(node_allocator_, result); 26115 | 26116 | return error_node(); 26117 | } 26118 | else 26119 | return result; 26120 | } 26121 | 26122 | template <std::size_t MaxNumberofParameters> 26123 | inline std::size_t parse_base_function_call(expression_node_ptr (¶m_list)[MaxNumberofParameters], const std::string& function_name = "") 26124 | { 26125 | std::fill_n(param_list, MaxNumberofParameters, reinterpret_cast<expression_node_ptr>(0)); 26126 | 26127 | scoped_delete<expression_node_t,MaxNumberofParameters> sd((*this),param_list); 26128 | 26129 | next_token(); 26130 | 26131 | if (!token_is(token_t::e_lbracket)) 26132 | { 26133 | set_error(make_error( 26134 | parser_error::e_syntax, 26135 | current_token(), 26136 | "ERR029 - Expected a '(' at start of function call to '" + function_name + 26137 | "', instead got: '" + current_token().value + "'", 26138 | exprtk_error_location)); 26139 | 26140 | return 0; 26141 | } 26142 | 26143 | if (token_is(token_t::e_rbracket, e_hold)) 26144 | { 26145 | set_error(make_error( 26146 | parser_error::e_syntax, 26147 | current_token(), 26148 | "ERR030 - Expected at least one input parameter for function call '" + function_name + "'", 26149 | exprtk_error_location)); 26150 | 26151 | return 0; 26152 | } 26153 | 26154 | std::size_t param_index = 0; 26155 | 26156 | for (; param_index < MaxNumberofParameters; ++param_index) 26157 | { 26158 | param_list[param_index] = parse_expression(); 26159 | 26160 | if (0 == param_list[param_index]) 26161 | return 0; 26162 | else if (token_is(token_t::e_rbracket)) 26163 | { 26164 | sd.delete_ptr = false; 26165 | break; 26166 | } 26167 | else if (token_is(token_t::e_comma)) 26168 | continue; 26169 | else 26170 | { 26171 | set_error(make_error( 26172 | parser_error::e_syntax, 26173 | current_token(), 26174 | "ERR031 - Expected a ',' between function input parameters, instead got: '" + current_token().value + "'", 26175 | exprtk_error_location)); 26176 | 26177 | return 0; 26178 | } 26179 | } 26180 | 26181 | if (sd.delete_ptr) 26182 | { 26183 | set_error(make_error( 26184 | parser_error::e_syntax, 26185 | current_token(), 26186 | "ERR032 - Invalid number of input parameters passed to function '" + function_name + "'", 26187 | exprtk_error_location)); 26188 | 26189 | return 0; 26190 | } 26191 | 26192 | return (param_index + 1); 26193 | } 26194 | 26195 | inline expression_node_ptr parse_base_operation() 26196 | { 26197 | typedef std::pair<base_ops_map_t::iterator,base_ops_map_t::iterator> map_range_t; 26198 | 26199 | const std::string operation_name = current_token().value; 26200 | const token_t diagnostic_token = current_token(); 26201 | 26202 | map_range_t itr_range = base_ops_map_.equal_range(operation_name); 26203 | 26204 | if (0 == std::distance(itr_range.first,itr_range.second)) 26205 | { 26206 | set_error(make_error( 26207 | parser_error::e_syntax, 26208 | diagnostic_token, 26209 | "ERR033 - No entry found for base operation: " + operation_name, 26210 | exprtk_error_location)); 26211 | 26212 | return error_node(); 26213 | } 26214 | 26215 | static const std::size_t MaxNumberofParameters = 4; 26216 | expression_node_ptr param_list[MaxNumberofParameters] = {0}; 26217 | 26218 | const std::size_t parameter_count = parse_base_function_call(param_list, operation_name); 26219 | 26220 | if ((parameter_count > 0) && (parameter_count <= MaxNumberofParameters)) 26221 | { 26222 | for (base_ops_map_t::iterator itr = itr_range.first; itr != itr_range.second; ++itr) 26223 | { 26224 | const details::base_operation_t& operation = itr->second; 26225 | 26226 | if (operation.num_params == parameter_count) 26227 | { 26228 | switch (parameter_count) 26229 | { 26230 | #define base_opr_case(N) \ 26231 | case N : { \ 26232 | expression_node_ptr pl##N[N] = {0}; \ 26233 | std::copy(param_list, param_list + N, pl##N); \ 26234 | lodge_symbol(operation_name, e_st_function); \ 26235 | return expression_generator_(operation.type, pl##N); \ 26236 | } \ 26237 | 26238 | base_opr_case(1) 26239 | base_opr_case(2) 26240 | base_opr_case(3) 26241 | base_opr_case(4) 26242 | #undef base_opr_case 26243 | } 26244 | } 26245 | } 26246 | } 26247 | 26248 | for (std::size_t i = 0; i < MaxNumberofParameters; ++i) 26249 | { 26250 | free_node(node_allocator_, param_list[i]); 26251 | } 26252 | 26253 | set_error(make_error( 26254 | parser_error::e_syntax, 26255 | diagnostic_token, 26256 | "ERR034 - Invalid number of input parameters for call to function: '" + operation_name + "'", 26257 | exprtk_error_location)); 26258 | 26259 | return error_node(); 26260 | } 26261 | 26262 | inline expression_node_ptr parse_conditional_statement_01(expression_node_ptr condition) 26263 | { 26264 | // Parse: [if][(][condition][,][consequent][,][alternative][)] 26265 | 26266 | expression_node_ptr consequent = error_node(); 26267 | expression_node_ptr alternative = error_node(); 26268 | 26269 | bool result = true; 26270 | 26271 | if (!token_is(token_t::e_comma)) 26272 | { 26273 | set_error(make_error( 26274 | parser_error::e_syntax, 26275 | current_token(), 26276 | "ERR035 - Expected ',' between if-statement condition and consequent", 26277 | exprtk_error_location)); 26278 | 26279 | result = false; 26280 | } 26281 | else if (0 == (consequent = parse_expression())) 26282 | { 26283 | set_error(make_error( 26284 | parser_error::e_syntax, 26285 | current_token(), 26286 | "ERR036 - Failed to parse consequent for if-statement", 26287 | exprtk_error_location)); 26288 | 26289 | result = false; 26290 | } 26291 | else if (!token_is(token_t::e_comma)) 26292 | { 26293 | set_error(make_error( 26294 | parser_error::e_syntax, 26295 | current_token(), 26296 | "ERR037 - Expected ',' between if-statement consequent and alternative", 26297 | exprtk_error_location)); 26298 | 26299 | result = false; 26300 | } 26301 | else if (0 == (alternative = parse_expression())) 26302 | { 26303 | set_error(make_error( 26304 | parser_error::e_syntax, 26305 | current_token(), 26306 | "ERR038 - Failed to parse alternative for if-statement", 26307 | exprtk_error_location)); 26308 | 26309 | result = false; 26310 | } 26311 | else if (!token_is(token_t::e_rbracket)) 26312 | { 26313 | set_error(make_error( 26314 | parser_error::e_syntax, 26315 | current_token(), 26316 | "ERR039 - Expected ')' at the end of if-statement", 26317 | exprtk_error_location)); 26318 | 26319 | result = false; 26320 | } 26321 | 26322 | #ifndef exprtk_disable_string_capabilities 26323 | if (result) 26324 | { 26325 | const bool consq_is_str = is_generally_string_node(consequent ); 26326 | const bool alter_is_str = is_generally_string_node(alternative); 26327 | 26328 | if (consq_is_str || alter_is_str) 26329 | { 26330 | if (consq_is_str && alter_is_str) 26331 | { 26332 | expression_node_ptr result_node = 26333 | expression_generator_ 26334 | .conditional_string(condition, consequent, alternative); 26335 | 26336 | if (result_node && result_node->valid()) 26337 | { 26338 | return result_node; 26339 | } 26340 | 26341 | set_error(make_error( 26342 | parser_error::e_synthesis, 26343 | current_token(), 26344 | "ERR040 - Failed to synthesize node: conditional_string", 26345 | exprtk_error_location)); 26346 | 26347 | free_node(node_allocator_, result_node); 26348 | return error_node(); 26349 | } 26350 | 26351 | set_error(make_error( 26352 | parser_error::e_syntax, 26353 | current_token(), 26354 | "ERR041 - Return types of if-statement differ: string/non-string", 26355 | exprtk_error_location)); 26356 | 26357 | result = false; 26358 | } 26359 | } 26360 | #endif 26361 | 26362 | if (result) 26363 | { 26364 | const bool consq_is_vec = is_ivector_node(consequent ); 26365 | const bool alter_is_vec = is_ivector_node(alternative); 26366 | 26367 | if (consq_is_vec || alter_is_vec) 26368 | { 26369 | if (consq_is_vec && alter_is_vec) 26370 | { 26371 | return expression_generator_ 26372 | .conditional_vector(condition, consequent, alternative); 26373 | } 26374 | 26375 | set_error(make_error( 26376 | parser_error::e_syntax, 26377 | current_token(), 26378 | "ERR042 - Return types of if-statement differ: vector/non-vector", 26379 | exprtk_error_location)); 26380 | 26381 | result = false; 26382 | } 26383 | } 26384 | 26385 | if (!result) 26386 | { 26387 | free_node(node_allocator_, condition ); 26388 | free_node(node_allocator_, consequent ); 26389 | free_node(node_allocator_, alternative); 26390 | 26391 | return error_node(); 26392 | } 26393 | else 26394 | return expression_generator_ 26395 | .conditional(condition, consequent, alternative); 26396 | } 26397 | 26398 | inline expression_node_ptr parse_conditional_statement_02(expression_node_ptr condition) 26399 | { 26400 | expression_node_ptr consequent = error_node(); 26401 | expression_node_ptr alternative = error_node(); 26402 | 26403 | bool result = true; 26404 | 26405 | if (token_is(token_t::e_lcrlbracket,prsrhlpr_t::e_hold)) 26406 | { 26407 | if (0 == (consequent = parse_multi_sequence("if-statement-01"))) 26408 | { 26409 | set_error(make_error( 26410 | parser_error::e_syntax, 26411 | current_token(), 26412 | "ERR043 - Failed to parse body of consequent for if-statement", 26413 | exprtk_error_location)); 26414 | 26415 | result = false; 26416 | } 26417 | else if 26418 | ( 26419 | !settings_.commutative_check_enabled() && 26420 | !token_is("else",prsrhlpr_t::e_hold) && 26421 | !token_is_loop(prsrhlpr_t::e_hold) && 26422 | !token_is_arithmetic_opr(prsrhlpr_t::e_hold) && 26423 | !token_is_right_bracket (prsrhlpr_t::e_hold) && 26424 | !token_is_ineq_opr (prsrhlpr_t::e_hold) && 26425 | !token_is(token_t::e_ternary,prsrhlpr_t::e_hold) && 26426 | !token_is(token_t::e_eof ,prsrhlpr_t::e_hold) 26427 | ) 26428 | { 26429 | set_error(make_error( 26430 | parser_error::e_syntax, 26431 | current_token(), 26432 | "ERR044 - Expected ';' at the end of the consequent for if-statement (1)", 26433 | exprtk_error_location)); 26434 | 26435 | result = false; 26436 | } 26437 | } 26438 | else 26439 | { 26440 | if ( 26441 | settings_.commutative_check_enabled() && 26442 | token_is(token_t::e_mul,prsrhlpr_t::e_hold) 26443 | ) 26444 | { 26445 | next_token(); 26446 | } 26447 | 26448 | if (0 != (consequent = parse_expression())) 26449 | { 26450 | if (!token_is(token_t::e_eof, prsrhlpr_t::e_hold)) 26451 | { 26452 | set_error(make_error( 26453 | parser_error::e_syntax, 26454 | current_token(), 26455 | "ERR045 - Expected ';' at the end of the consequent for if-statement (2)", 26456 | exprtk_error_location)); 26457 | 26458 | result = false; 26459 | } 26460 | } 26461 | else 26462 | { 26463 | set_error(make_error( 26464 | parser_error::e_syntax, 26465 | current_token(), 26466 | "ERR046 - Failed to parse body of consequent for if-statement", 26467 | exprtk_error_location)); 26468 | 26469 | result = false; 26470 | } 26471 | } 26472 | 26473 | if (result) 26474 | { 26475 | if ( 26476 | details::imatch(current_token().value,"else") || 26477 | (token_is(token_t::e_eof, prsrhlpr_t::e_hold) && peek_token_is("else")) 26478 | ) 26479 | { 26480 | next_token(); 26481 | 26482 | if (details::imatch(current_token().value,"else")) 26483 | { 26484 | next_token(); 26485 | } 26486 | 26487 | if (token_is(token_t::e_lcrlbracket,prsrhlpr_t::e_hold)) 26488 | { 26489 | if (0 == (alternative = parse_multi_sequence("else-statement-01"))) 26490 | { 26491 | set_error(make_error( 26492 | parser_error::e_syntax, 26493 | current_token(), 26494 | "ERR047 - Failed to parse body of the 'else' for if-statement", 26495 | exprtk_error_location)); 26496 | 26497 | result = false; 26498 | } 26499 | } 26500 | else if (details::imatch(current_token().value,"if")) 26501 | { 26502 | if (0 == (alternative = parse_conditional_statement())) 26503 | { 26504 | set_error(make_error( 26505 | parser_error::e_syntax, 26506 | current_token(), 26507 | "ERR048 - Failed to parse body of if-else statement", 26508 | exprtk_error_location)); 26509 | 26510 | result = false; 26511 | } 26512 | } 26513 | else if (0 != (alternative = parse_expression())) 26514 | { 26515 | if ( 26516 | !token_is(token_t::e_ternary , prsrhlpr_t::e_hold) && 26517 | !token_is(token_t::e_rcrlbracket, prsrhlpr_t::e_hold) && 26518 | !token_is(token_t::e_eof) 26519 | ) 26520 | { 26521 | set_error(make_error( 26522 | parser_error::e_syntax, 26523 | current_token(), 26524 | "ERR049 - Expected ';' at the end of the 'else-if' for the if-statement", 26525 | exprtk_error_location)); 26526 | 26527 | result = false; 26528 | } 26529 | } 26530 | else 26531 | { 26532 | set_error(make_error( 26533 | parser_error::e_syntax, 26534 | current_token(), 26535 | "ERR050 - Failed to parse body of the 'else' for if-statement", 26536 | exprtk_error_location)); 26537 | 26538 | result = false; 26539 | } 26540 | } 26541 | } 26542 | 26543 | #ifndef exprtk_disable_string_capabilities 26544 | if (result) 26545 | { 26546 | const bool consq_is_str = is_generally_string_node(consequent ); 26547 | const bool alter_is_str = is_generally_string_node(alternative); 26548 | 26549 | if (consq_is_str || alter_is_str) 26550 | { 26551 | if (consq_is_str && alter_is_str) 26552 | { 26553 | return expression_generator_ 26554 | .conditional_string(condition, consequent, alternative); 26555 | } 26556 | 26557 | set_error(make_error( 26558 | parser_error::e_syntax, 26559 | current_token(), 26560 | "ERR051 - Return types of if-statement differ: string/non-string", 26561 | exprtk_error_location)); 26562 | 26563 | result = false; 26564 | } 26565 | } 26566 | #endif 26567 | 26568 | if (result) 26569 | { 26570 | const bool consq_is_vec = is_ivector_node(consequent ); 26571 | const bool alter_is_vec = is_ivector_node(alternative); 26572 | 26573 | if (consq_is_vec || alter_is_vec) 26574 | { 26575 | if (consq_is_vec && alter_is_vec) 26576 | { 26577 | return expression_generator_ 26578 | .conditional_vector(condition, consequent, alternative); 26579 | } 26580 | 26581 | set_error(make_error( 26582 | parser_error::e_syntax, 26583 | current_token(), 26584 | "ERR052 - Return types of if-statement differ: vector/non-vector", 26585 | exprtk_error_location)); 26586 | 26587 | result = false; 26588 | } 26589 | } 26590 | 26591 | if (!result) 26592 | { 26593 | free_node(node_allocator_, condition ); 26594 | free_node(node_allocator_, consequent ); 26595 | free_node(node_allocator_, alternative); 26596 | 26597 | return error_node(); 26598 | } 26599 | else 26600 | return expression_generator_ 26601 | .conditional(condition, consequent, alternative); 26602 | } 26603 | 26604 | inline expression_node_ptr parse_conditional_statement() 26605 | { 26606 | expression_node_ptr condition = error_node(); 26607 | 26608 | next_token(); 26609 | 26610 | if (!token_is(token_t::e_lbracket)) 26611 | { 26612 | set_error(make_error( 26613 | parser_error::e_syntax, 26614 | current_token(), 26615 | "ERR053 - Expected '(' at start of if-statement, instead got: '" + current_token().value + "'", 26616 | exprtk_error_location)); 26617 | 26618 | return error_node(); 26619 | } 26620 | else if (0 == (condition = parse_expression())) 26621 | { 26622 | set_error(make_error( 26623 | parser_error::e_syntax, 26624 | current_token(), 26625 | "ERR054 - Failed to parse condition for if-statement", 26626 | exprtk_error_location)); 26627 | 26628 | return error_node(); 26629 | } 26630 | else if (token_is(token_t::e_comma,prsrhlpr_t::e_hold)) 26631 | { 26632 | // if (x,y,z) 26633 | return parse_conditional_statement_01(condition); 26634 | } 26635 | else if (token_is(token_t::e_rbracket)) 26636 | { 26637 | /* 26638 | 00. if (x) y; 26639 | 01. if (x) y; else z; 26640 | 02. if (x) y; else {z0; ... zn;} 26641 | 03. if (x) y; else if (z) w; 26642 | 04. if (x) y; else if (z) w; else u; 26643 | 05. if (x) y; else if (z) w; else {u0; ... un;} 26644 | 06. if (x) y; else if (z) {w0; ... wn;} 26645 | 07. if (x) {y0; ... yn;} 26646 | 08. if (x) {y0; ... yn;} else z; 26647 | 09. if (x) {y0; ... yn;} else {z0; ... zn;}; 26648 | 10. if (x) {y0; ... yn;} else if (z) w; 26649 | 11. if (x) {y0; ... yn;} else if (z) w; else u; 26650 | 12. if (x) {y0; ... nex;} else if (z) w; else {u0 ... un;} 26651 | 13. if (x) {y0; ... yn;} else if (z) {w0; ... wn;} 26652 | */ 26653 | return parse_conditional_statement_02(condition); 26654 | } 26655 | 26656 | set_error(make_error( 26657 | parser_error::e_syntax, 26658 | current_token(), 26659 | "ERR055 - Invalid if-statement", 26660 | exprtk_error_location)); 26661 | 26662 | free_node(node_allocator_, condition); 26663 | 26664 | return error_node(); 26665 | } 26666 | 26667 | inline expression_node_ptr parse_ternary_conditional_statement(expression_node_ptr condition) 26668 | { 26669 | // Parse: [condition][?][consequent][:][alternative] 26670 | expression_node_ptr consequent = error_node(); 26671 | expression_node_ptr alternative = error_node(); 26672 | 26673 | bool result = true; 26674 | 26675 | if (0 == condition) 26676 | { 26677 | set_error(make_error( 26678 | parser_error::e_syntax, 26679 | current_token(), 26680 | "ERR056 - Encountered invalid condition branch for ternary if-statement", 26681 | exprtk_error_location)); 26682 | 26683 | return error_node(); 26684 | } 26685 | else if (!token_is(token_t::e_ternary)) 26686 | { 26687 | set_error(make_error( 26688 | parser_error::e_syntax, 26689 | current_token(), 26690 | "ERR057 - Expected '?' after condition of ternary if-statement", 26691 | exprtk_error_location)); 26692 | 26693 | result = false; 26694 | } 26695 | else if (0 == (consequent = parse_expression())) 26696 | { 26697 | set_error(make_error( 26698 | parser_error::e_syntax, 26699 | current_token(), 26700 | "ERR058 - Failed to parse consequent for ternary if-statement", 26701 | exprtk_error_location)); 26702 | 26703 | result = false; 26704 | } 26705 | else if (!token_is(token_t::e_colon)) 26706 | { 26707 | set_error(make_error( 26708 | parser_error::e_syntax, 26709 | current_token(), 26710 | "ERR059 - Expected ':' between ternary if-statement consequent and alternative", 26711 | exprtk_error_location)); 26712 | 26713 | result = false; 26714 | } 26715 | else if (0 == (alternative = parse_expression())) 26716 | { 26717 | set_error(make_error( 26718 | parser_error::e_syntax, 26719 | current_token(), 26720 | "ERR060 - Failed to parse alternative for ternary if-statement", 26721 | exprtk_error_location)); 26722 | 26723 | result = false; 26724 | } 26725 | 26726 | #ifndef exprtk_disable_string_capabilities 26727 | if (result) 26728 | { 26729 | const bool consq_is_str = is_generally_string_node(consequent ); 26730 | const bool alter_is_str = is_generally_string_node(alternative); 26731 | 26732 | if (consq_is_str || alter_is_str) 26733 | { 26734 | if (consq_is_str && alter_is_str) 26735 | { 26736 | return expression_generator_ 26737 | .conditional_string(condition, consequent, alternative); 26738 | } 26739 | 26740 | set_error(make_error( 26741 | parser_error::e_syntax, 26742 | current_token(), 26743 | "ERR061 - Return types of ternary differ: string/non-string", 26744 | exprtk_error_location)); 26745 | 26746 | result = false; 26747 | } 26748 | } 26749 | #endif 26750 | 26751 | if (result) 26752 | { 26753 | const bool consq_is_vec = is_ivector_node(consequent ); 26754 | const bool alter_is_vec = is_ivector_node(alternative); 26755 | 26756 | if (consq_is_vec || alter_is_vec) 26757 | { 26758 | if (consq_is_vec && alter_is_vec) 26759 | { 26760 | return expression_generator_ 26761 | .conditional_vector(condition, consequent, alternative); 26762 | } 26763 | 26764 | set_error(make_error( 26765 | parser_error::e_syntax, 26766 | current_token(), 26767 | "ERR062 - Return types of ternary differ: vector/non-vector", 26768 | exprtk_error_location)); 26769 | 26770 | result = false; 26771 | } 26772 | } 26773 | 26774 | if (!result) 26775 | { 26776 | free_node(node_allocator_, condition ); 26777 | free_node(node_allocator_, consequent ); 26778 | free_node(node_allocator_, alternative); 26779 | 26780 | return error_node(); 26781 | } 26782 | else 26783 | return expression_generator_ 26784 | .conditional(condition, consequent, alternative); 26785 | } 26786 | 26787 | inline expression_node_ptr parse_not_statement() 26788 | { 26789 | if (settings_.logic_disabled("not")) 26790 | { 26791 | set_error(make_error( 26792 | parser_error::e_syntax, 26793 | current_token(), 26794 | "ERR063 - Invalid or disabled logic operation 'not'", 26795 | exprtk_error_location)); 26796 | 26797 | return error_node(); 26798 | } 26799 | 26800 | return parse_base_operation(); 26801 | } 26802 | 26803 | void handle_brkcnt_scope_exit() 26804 | { 26805 | assert(!brkcnt_list_.empty()); 26806 | brkcnt_list_.pop_front(); 26807 | } 26808 | 26809 | inline expression_node_ptr parse_while_loop() 26810 | { 26811 | // Parse: [while][(][test expr][)][{][expression][}] 26812 | expression_node_ptr condition = error_node(); 26813 | expression_node_ptr branch = error_node(); 26814 | expression_node_ptr result_node = error_node(); 26815 | 26816 | bool result = true; 26817 | 26818 | next_token(); 26819 | 26820 | if (!token_is(token_t::e_lbracket)) 26821 | { 26822 | set_error(make_error( 26823 | parser_error::e_syntax, 26824 | current_token(), 26825 | "ERR064 - Expected '(' at start of while-loop condition statement", 26826 | exprtk_error_location)); 26827 | 26828 | return error_node(); 26829 | } 26830 | else if (0 == (condition = parse_expression())) 26831 | { 26832 | set_error(make_error( 26833 | parser_error::e_syntax, 26834 | current_token(), 26835 | "ERR065 - Failed to parse condition for while-loop", 26836 | exprtk_error_location)); 26837 | 26838 | return error_node(); 26839 | } 26840 | else if (!token_is(token_t::e_rbracket)) 26841 | { 26842 | set_error(make_error( 26843 | parser_error::e_syntax, 26844 | current_token(), 26845 | "ERR066 - Expected ')' at end of while-loop condition statement", 26846 | exprtk_error_location)); 26847 | 26848 | result = false; 26849 | } 26850 | 26851 | brkcnt_list_.push_front(false); 26852 | 26853 | if (result) 26854 | { 26855 | scoped_inc_dec sid(state_.parsing_loop_stmt_count); 26856 | 26857 | if (0 == (branch = parse_multi_sequence("while-loop", true))) 26858 | { 26859 | set_error(make_error( 26860 | parser_error::e_syntax, 26861 | current_token(), 26862 | "ERR067 - Failed to parse body of while-loop")); 26863 | result = false; 26864 | } 26865 | else if (0 == (result_node = expression_generator_.while_loop(condition, 26866 | branch, 26867 | brkcnt_list_.front()))) 26868 | { 26869 | set_error(make_error( 26870 | parser_error::e_syntax, 26871 | current_token(), 26872 | "ERR068 - Failed to synthesize while-loop", 26873 | exprtk_error_location)); 26874 | 26875 | result = false; 26876 | } 26877 | } 26878 | 26879 | handle_brkcnt_scope_exit(); 26880 | 26881 | if (!result) 26882 | { 26883 | free_node(node_allocator_, branch ); 26884 | free_node(node_allocator_, condition ); 26885 | free_node(node_allocator_, result_node); 26886 | 26887 | return error_node(); 26888 | } 26889 | 26890 | if (result_node && result_node->valid()) 26891 | { 26892 | return result_node; 26893 | } 26894 | 26895 | set_error(make_error( 26896 | parser_error::e_synthesis, 26897 | current_token(), 26898 | "ERR069 - Failed to synthesize 'valid' while-loop", 26899 | exprtk_error_location)); 26900 | 26901 | free_node(node_allocator_, result_node); 26902 | 26903 | return error_node(); 26904 | } 26905 | 26906 | inline expression_node_ptr parse_repeat_until_loop() 26907 | { 26908 | // Parse: [repeat][{][expression][}][until][(][test expr][)] 26909 | expression_node_ptr condition = error_node(); 26910 | expression_node_ptr branch = error_node(); 26911 | next_token(); 26912 | 26913 | std::vector<expression_node_ptr> arg_list; 26914 | std::vector<bool> side_effect_list; 26915 | 26916 | scoped_vec_delete<expression_node_t> svd((*this), arg_list); 26917 | 26918 | brkcnt_list_.push_front(false); 26919 | 26920 | if (details::imatch(current_token().value,"until")) 26921 | { 26922 | next_token(); 26923 | branch = node_allocator_.allocate<details::null_node<T> >(); 26924 | } 26925 | else 26926 | { 26927 | const token_t::token_type separator = token_t::e_eof; 26928 | 26929 | scope_handler sh(*this); 26930 | 26931 | scoped_bool_or_restorer sbr(state_.side_effect_present); 26932 | 26933 | scoped_inc_dec sid(state_.parsing_loop_stmt_count); 26934 | 26935 | for ( ; ; ) 26936 | { 26937 | state_.side_effect_present = false; 26938 | 26939 | expression_node_ptr arg = parse_expression(); 26940 | 26941 | if (0 == arg) 26942 | return error_node(); 26943 | else 26944 | { 26945 | arg_list.push_back(arg); 26946 | side_effect_list.push_back(state_.side_effect_present); 26947 | } 26948 | 26949 | if (details::imatch(current_token().value,"until")) 26950 | { 26951 | next_token(); 26952 | break; 26953 | } 26954 | 26955 | const bool is_next_until = peek_token_is(token_t::e_symbol) && 26956 | peek_token_is("until"); 26957 | 26958 | if (!token_is(separator) && is_next_until) 26959 | { 26960 | set_error(make_error( 26961 | parser_error::e_syntax, 26962 | current_token(), 26963 | "ERR070 - Expected '" + token_t::to_str(separator) + "' in body of repeat until loop", 26964 | exprtk_error_location)); 26965 | 26966 | return error_node(); 26967 | } 26968 | 26969 | if (details::imatch(current_token().value,"until")) 26970 | { 26971 | next_token(); 26972 | break; 26973 | } 26974 | } 26975 | 26976 | branch = simplify(arg_list,side_effect_list); 26977 | 26978 | svd.delete_ptr = (0 == branch); 26979 | 26980 | if (svd.delete_ptr) 26981 | { 26982 | set_error(make_error( 26983 | parser_error::e_syntax, 26984 | current_token(), 26985 | "ERR071 - Failed to parse body of repeat until loop", 26986 | exprtk_error_location)); 26987 | 26988 | return error_node(); 26989 | } 26990 | } 26991 | 26992 | if (!token_is(token_t::e_lbracket)) 26993 | { 26994 | set_error(make_error( 26995 | parser_error::e_syntax, 26996 | current_token(), 26997 | "ERR072 - Expected '(' before condition statement of repeat until loop", 26998 | exprtk_error_location)); 26999 | 27000 | free_node(node_allocator_, branch); 27001 | return error_node(); 27002 | } 27003 | else if (0 == (condition = parse_expression())) 27004 | { 27005 | set_error(make_error( 27006 | parser_error::e_syntax, 27007 | current_token(), 27008 | "ERR073 - Failed to parse condition for repeat until loop", 27009 | exprtk_error_location)); 27010 | 27011 | free_node(node_allocator_, branch); 27012 | return error_node(); 27013 | } 27014 | else if (!token_is(token_t::e_rbracket)) 27015 | { 27016 | set_error(make_error( 27017 | parser_error::e_syntax, 27018 | current_token(), 27019 | "ERR074 - Expected ')' after condition of repeat until loop", 27020 | exprtk_error_location)); 27021 | 27022 | free_node(node_allocator_, branch ); 27023 | free_node(node_allocator_, condition); 27024 | 27025 | return error_node(); 27026 | } 27027 | 27028 | expression_node_ptr result_node = 27029 | expression_generator_ 27030 | .repeat_until_loop( 27031 | condition, 27032 | branch, 27033 | brkcnt_list_.front()); 27034 | 27035 | if (0 == result_node) 27036 | { 27037 | set_error(make_error( 27038 | parser_error::e_syntax, 27039 | current_token(), 27040 | "ERR075 - Failed to synthesize repeat until loop", 27041 | exprtk_error_location)); 27042 | 27043 | free_node(node_allocator_, condition); 27044 | 27045 | return error_node(); 27046 | } 27047 | 27048 | handle_brkcnt_scope_exit(); 27049 | 27050 | if (result_node && result_node->valid()) 27051 | { 27052 | return result_node; 27053 | } 27054 | 27055 | set_error(make_error( 27056 | parser_error::e_synthesis, 27057 | current_token(), 27058 | "ERR076 - Failed to synthesize 'valid' repeat until loop", 27059 | exprtk_error_location)); 27060 | 27061 | free_node(node_allocator_, result_node); 27062 | 27063 | return error_node(); 27064 | } 27065 | 27066 | inline expression_node_ptr parse_for_loop() 27067 | { 27068 | expression_node_ptr initialiser = error_node(); 27069 | expression_node_ptr condition = error_node(); 27070 | expression_node_ptr incrementor = error_node(); 27071 | expression_node_ptr loop_body = error_node(); 27072 | 27073 | scope_element* se = 0; 27074 | bool result = true; 27075 | 27076 | next_token(); 27077 | 27078 | scope_handler sh(*this); 27079 | 27080 | if (!token_is(token_t::e_lbracket)) 27081 | { 27082 | set_error(make_error( 27083 | parser_error::e_syntax, 27084 | current_token(), 27085 | "ERR077 - Expected '(' at start of for-loop", 27086 | exprtk_error_location)); 27087 | 27088 | return error_node(); 27089 | } 27090 | 27091 | if (!token_is(token_t::e_eof)) 27092 | { 27093 | if ( 27094 | !token_is(token_t::e_symbol,prsrhlpr_t::e_hold) && 27095 | details::imatch(current_token().value,"var") 27096 | ) 27097 | { 27098 | next_token(); 27099 | 27100 | if (!token_is(token_t::e_symbol,prsrhlpr_t::e_hold)) 27101 | { 27102 | set_error(make_error( 27103 | parser_error::e_syntax, 27104 | current_token(), 27105 | "ERR078 - Expected a variable at the start of initialiser section of for-loop", 27106 | exprtk_error_location)); 27107 | 27108 | return error_node(); 27109 | } 27110 | else if (!peek_token_is(token_t::e_assign)) 27111 | { 27112 | set_error(make_error( 27113 | parser_error::e_syntax, 27114 | current_token(), 27115 | "ERR079 - Expected variable assignment of initialiser section of for-loop", 27116 | exprtk_error_location)); 27117 | 27118 | return error_node(); 27119 | } 27120 | 27121 | const std::string loop_counter_symbol = current_token().value; 27122 | 27123 | se = &sem_.get_element(loop_counter_symbol); 27124 | 27125 | if ((se->name == loop_counter_symbol) && se->active) 27126 | { 27127 | set_error(make_error( 27128 | parser_error::e_syntax, 27129 | current_token(), 27130 | "ERR080 - For-loop variable '" + loop_counter_symbol+ "' is being shadowed by a previous declaration", 27131 | exprtk_error_location)); 27132 | 27133 | return error_node(); 27134 | } 27135 | else if (!symtab_store_.is_variable(loop_counter_symbol)) 27136 | { 27137 | if ( 27138 | !se->active && 27139 | (se->name == loop_counter_symbol) && 27140 | (se->type == scope_element::e_variable) 27141 | ) 27142 | { 27143 | se->active = true; 27144 | se->ref_count++; 27145 | } 27146 | else 27147 | { 27148 | scope_element nse; 27149 | nse.name = loop_counter_symbol; 27150 | nse.active = true; 27151 | nse.ref_count = 1; 27152 | nse.type = scope_element::e_variable; 27153 | nse.depth = state_.scope_depth; 27154 | nse.data = new T(T(0)); 27155 | nse.var_node = node_allocator_.allocate<variable_node_t>(*reinterpret_cast<T*>(nse.data)); 27156 | 27157 | if (!sem_.add_element(nse)) 27158 | { 27159 | set_error(make_error( 27160 | parser_error::e_syntax, 27161 | current_token(), 27162 | "ERR081 - Failed to add new local variable '" + loop_counter_symbol + "' to SEM", 27163 | exprtk_error_location)); 27164 | 27165 | sem_.free_element(nse); 27166 | 27167 | result = false; 27168 | } 27169 | else 27170 | { 27171 | exprtk_debug(("parse_for_loop() - INFO - Added new local variable: %s\n", nse.name.c_str())); 27172 | 27173 | state_.activate_side_effect("parse_for_loop()"); 27174 | } 27175 | } 27176 | } 27177 | } 27178 | 27179 | if (0 == (initialiser = parse_expression())) 27180 | { 27181 | set_error(make_error( 27182 | parser_error::e_syntax, 27183 | current_token(), 27184 | "ERR082 - Failed to parse initialiser of for-loop", 27185 | exprtk_error_location)); 27186 | 27187 | result = false; 27188 | } 27189 | else if (!token_is(token_t::e_eof)) 27190 | { 27191 | set_error(make_error( 27192 | parser_error::e_syntax, 27193 | current_token(), 27194 | "ERR083 - Expected ';' after initialiser of for-loop", 27195 | exprtk_error_location)); 27196 | 27197 | result = false; 27198 | } 27199 | } 27200 | 27201 | if (!token_is(token_t::e_eof)) 27202 | { 27203 | if (0 == (condition = parse_expression())) 27204 | { 27205 | set_error(make_error( 27206 | parser_error::e_syntax, 27207 | current_token(), 27208 | "ERR084 - Failed to parse condition of for-loop", 27209 | exprtk_error_location)); 27210 | 27211 | result = false; 27212 | } 27213 | else if (!token_is(token_t::e_eof)) 27214 | { 27215 | set_error(make_error( 27216 | parser_error::e_syntax, 27217 | current_token(), 27218 | "ERR085 - Expected ';' after condition section of for-loop", 27219 | exprtk_error_location)); 27220 | 27221 | result = false; 27222 | } 27223 | } 27224 | 27225 | if (!token_is(token_t::e_rbracket)) 27226 | { 27227 | if (0 == (incrementor = parse_expression())) 27228 | { 27229 | set_error(make_error( 27230 | parser_error::e_syntax, 27231 | current_token(), 27232 | "ERR086 - Failed to parse incrementor of for-loop", 27233 | exprtk_error_location)); 27234 | 27235 | result = false; 27236 | } 27237 | else if (!token_is(token_t::e_rbracket)) 27238 | { 27239 | set_error(make_error( 27240 | parser_error::e_syntax, 27241 | current_token(), 27242 | "ERR087 - Expected ')' after incrementor section of for-loop", 27243 | exprtk_error_location)); 27244 | 27245 | result = false; 27246 | } 27247 | } 27248 | 27249 | if (result) 27250 | { 27251 | brkcnt_list_.push_front(false); 27252 | 27253 | scoped_inc_dec sid(state_.parsing_loop_stmt_count); 27254 | 27255 | if (0 == (loop_body = parse_multi_sequence("for-loop", true))) 27256 | { 27257 | set_error(make_error( 27258 | parser_error::e_syntax, 27259 | current_token(), 27260 | "ERR088 - Failed to parse body of for-loop", 27261 | exprtk_error_location)); 27262 | 27263 | result = false; 27264 | } 27265 | } 27266 | 27267 | if (!result) 27268 | { 27269 | if (se) 27270 | { 27271 | se->ref_count--; 27272 | } 27273 | 27274 | free_node(node_allocator_, initialiser); 27275 | free_node(node_allocator_, condition ); 27276 | free_node(node_allocator_, incrementor); 27277 | free_node(node_allocator_, loop_body ); 27278 | return error_node(); 27279 | } 27280 | 27281 | expression_node_ptr result_node = 27282 | expression_generator_.for_loop(initialiser, 27283 | condition, 27284 | incrementor, 27285 | loop_body, 27286 | brkcnt_list_.front()); 27287 | handle_brkcnt_scope_exit(); 27288 | 27289 | if (result_node && result_node->valid()) 27290 | { 27291 | return result_node; 27292 | } 27293 | 27294 | set_error(make_error( 27295 | parser_error::e_synthesis, 27296 | current_token(), 27297 | "ERR089 - Failed to synthesize 'valid' for-loop", 27298 | exprtk_error_location)); 27299 | 27300 | free_node(node_allocator_, result_node); 27301 | 27302 | return error_node(); 27303 | } 27304 | 27305 | inline expression_node_ptr parse_switch_statement() 27306 | { 27307 | std::vector<expression_node_ptr> arg_list; 27308 | 27309 | if (!details::imatch(current_token().value,"switch")) 27310 | { 27311 | set_error(make_error( 27312 | parser_error::e_syntax, 27313 | current_token(), 27314 | "ERR090 - Expected keyword 'switch'", 27315 | exprtk_error_location)); 27316 | 27317 | return error_node(); 27318 | } 27319 | 27320 | scoped_vec_delete<expression_node_t> svd((*this), arg_list); 27321 | 27322 | next_token(); 27323 | 27324 | if (!token_is(token_t::e_lcrlbracket)) 27325 | { 27326 | set_error(make_error( 27327 | parser_error::e_syntax, 27328 | current_token(), 27329 | "ERR091 - Expected '{' for call to switch statement", 27330 | exprtk_error_location)); 27331 | 27332 | return error_node(); 27333 | } 27334 | 27335 | expression_node_ptr default_statement = error_node(); 27336 | 27337 | scoped_expression_delete defstmt_delete((*this), default_statement); 27338 | 27339 | for ( ; ; ) 27340 | { 27341 | if (details::imatch("case",current_token().value)) 27342 | { 27343 | next_token(); 27344 | 27345 | expression_node_ptr condition = parse_expression(); 27346 | 27347 | if (0 == condition) 27348 | return error_node(); 27349 | else if (!token_is(token_t::e_colon)) 27350 | { 27351 | set_error(make_error( 27352 | parser_error::e_syntax, 27353 | current_token(), 27354 | "ERR092 - Expected ':' for case of switch statement", 27355 | exprtk_error_location)); 27356 | 27357 | free_node(node_allocator_, condition); 27358 | 27359 | return error_node(); 27360 | } 27361 | 27362 | expression_node_ptr consequent = 27363 | (token_is(token_t::e_lcrlbracket,prsrhlpr_t::e_hold)) ? 27364 | parse_multi_sequence("switch-consequent") : 27365 | parse_expression(); 27366 | 27367 | if (0 == consequent) 27368 | { 27369 | free_node(node_allocator_, condition); 27370 | 27371 | return error_node(); 27372 | } 27373 | else if (!token_is(token_t::e_eof)) 27374 | { 27375 | set_error(make_error( 27376 | parser_error::e_syntax, 27377 | current_token(), 27378 | "ERR093 - Expected ';' at end of case for switch statement", 27379 | exprtk_error_location)); 27380 | 27381 | free_node(node_allocator_, condition ); 27382 | free_node(node_allocator_, consequent); 27383 | 27384 | return error_node(); 27385 | } 27386 | 27387 | // Can we optimise away the case statement? 27388 | if (is_constant_node(condition) && is_false(condition)) 27389 | { 27390 | free_node(node_allocator_, condition ); 27391 | free_node(node_allocator_, consequent); 27392 | } 27393 | else 27394 | { 27395 | arg_list.push_back(condition ); 27396 | arg_list.push_back(consequent); 27397 | } 27398 | 27399 | } 27400 | else if (details::imatch("default",current_token().value)) 27401 | { 27402 | if (0 != default_statement) 27403 | { 27404 | set_error(make_error( 27405 | parser_error::e_syntax, 27406 | current_token(), 27407 | "ERR094 - Multiple default cases for switch statement", 27408 | exprtk_error_location)); 27409 | 27410 | return error_node(); 27411 | } 27412 | 27413 | next_token(); 27414 | 27415 | if (!token_is(token_t::e_colon)) 27416 | { 27417 | set_error(make_error( 27418 | parser_error::e_syntax, 27419 | current_token(), 27420 | "ERR095 - Expected ':' for default of switch statement", 27421 | exprtk_error_location)); 27422 | 27423 | return error_node(); 27424 | } 27425 | 27426 | default_statement = 27427 | (token_is(token_t::e_lcrlbracket,prsrhlpr_t::e_hold)) ? 27428 | parse_multi_sequence("switch-default"): 27429 | parse_expression(); 27430 | 27431 | if (0 == default_statement) 27432 | return error_node(); 27433 | else if (!token_is(token_t::e_eof)) 27434 | { 27435 | set_error(make_error( 27436 | parser_error::e_syntax, 27437 | current_token(), 27438 | "ERR096 - Expected ';' at end of default for switch statement", 27439 | exprtk_error_location)); 27440 | 27441 | return error_node(); 27442 | } 27443 | } 27444 | else if (token_is(token_t::e_rcrlbracket)) 27445 | break; 27446 | else 27447 | { 27448 | set_error(make_error( 27449 | parser_error::e_syntax, 27450 | current_token(), 27451 | "ERR097 - Expected '}' at end of switch statement", 27452 | exprtk_error_location)); 27453 | 27454 | return error_node(); 27455 | } 27456 | } 27457 | 27458 | const bool default_statement_present = (0 != default_statement); 27459 | 27460 | if (default_statement_present) 27461 | { 27462 | arg_list.push_back(default_statement); 27463 | } 27464 | else 27465 | { 27466 | arg_list.push_back(node_allocator_.allocate_c<literal_node_t>(std::numeric_limits<T>::quiet_NaN())); 27467 | } 27468 | 27469 | expression_node_ptr result = expression_generator_.switch_statement(arg_list, (0 != default_statement)); 27470 | 27471 | svd.delete_ptr = (0 == result); 27472 | defstmt_delete.delete_ptr = (0 == result); 27473 | 27474 | return result; 27475 | } 27476 | 27477 | inline expression_node_ptr parse_multi_switch_statement() 27478 | { 27479 | std::vector<expression_node_ptr> arg_list; 27480 | 27481 | if (!details::imatch(current_token().value,"[*]")) 27482 | { 27483 | set_error(make_error( 27484 | parser_error::e_syntax, 27485 | current_token(), 27486 | "ERR098 - Expected token '[*]'", 27487 | exprtk_error_location)); 27488 | 27489 | return error_node(); 27490 | } 27491 | 27492 | scoped_vec_delete<expression_node_t> svd((*this), arg_list); 27493 | 27494 | next_token(); 27495 | 27496 | if (!token_is(token_t::e_lcrlbracket)) 27497 | { 27498 | set_error(make_error( 27499 | parser_error::e_syntax, 27500 | current_token(), 27501 | "ERR099 - Expected '{' for call to [*] statement", 27502 | exprtk_error_location)); 27503 | 27504 | return error_node(); 27505 | } 27506 | 27507 | for ( ; ; ) 27508 | { 27509 | if (!details::imatch("case",current_token().value)) 27510 | { 27511 | set_error(make_error( 27512 | parser_error::e_syntax, 27513 | current_token(), 27514 | "ERR100 - Expected a 'case' statement for multi-switch", 27515 | exprtk_error_location)); 27516 | 27517 | return error_node(); 27518 | } 27519 | 27520 | next_token(); 27521 | 27522 | expression_node_ptr condition = parse_expression(); 27523 | 27524 | if (0 == condition) 27525 | return error_node(); 27526 | 27527 | if (!token_is(token_t::e_colon)) 27528 | { 27529 | set_error(make_error( 27530 | parser_error::e_syntax, 27531 | current_token(), 27532 | "ERR101 - Expected ':' for case of [*] statement", 27533 | exprtk_error_location)); 27534 | 27535 | return error_node(); 27536 | } 27537 | 27538 | expression_node_ptr consequent = 27539 | (token_is(token_t::e_lcrlbracket,prsrhlpr_t::e_hold)) ? 27540 | parse_multi_sequence("multi-switch-consequent") : 27541 | parse_expression(); 27542 | 27543 | if (0 == consequent) 27544 | return error_node(); 27545 | 27546 | if (!token_is(token_t::e_eof)) 27547 | { 27548 | set_error(make_error( 27549 | parser_error::e_syntax, 27550 | current_token(), 27551 | "ERR102 - Expected ';' at end of case for [*] statement", 27552 | exprtk_error_location)); 27553 | 27554 | return error_node(); 27555 | } 27556 | 27557 | // Can we optimise away the case statement? 27558 | if (is_constant_node(condition) && is_false(condition)) 27559 | { 27560 | free_node(node_allocator_, condition ); 27561 | free_node(node_allocator_, consequent); 27562 | } 27563 | else 27564 | { 27565 | arg_list.push_back(condition ); 27566 | arg_list.push_back(consequent); 27567 | } 27568 | 27569 | if (token_is(token_t::e_rcrlbracket,prsrhlpr_t::e_hold)) 27570 | { 27571 | break; 27572 | } 27573 | } 27574 | 27575 | if (!token_is(token_t::e_rcrlbracket)) 27576 | { 27577 | set_error(make_error( 27578 | parser_error::e_syntax, 27579 | current_token(), 27580 | "ERR103 - Expected '}' at end of [*] statement", 27581 | exprtk_error_location)); 27582 | 27583 | return error_node(); 27584 | } 27585 | 27586 | const expression_node_ptr result = expression_generator_.multi_switch_statement(arg_list); 27587 | 27588 | svd.delete_ptr = (0 == result); 27589 | 27590 | return result; 27591 | } 27592 | 27593 | inline expression_node_ptr parse_vararg_function() 27594 | { 27595 | std::vector<expression_node_ptr> arg_list; 27596 | 27597 | details::operator_type opt_type = details::e_default; 27598 | const std::string symbol = current_token().value; 27599 | 27600 | if (details::imatch(symbol,"~")) 27601 | { 27602 | next_token(); 27603 | return check_block_statement_closure(parse_multi_sequence()); 27604 | } 27605 | else if (details::imatch(symbol,"[*]")) 27606 | { 27607 | return check_block_statement_closure(parse_multi_switch_statement()); 27608 | } 27609 | else if (details::imatch(symbol, "avg" )) opt_type = details::e_avg ; 27610 | else if (details::imatch(symbol, "mand")) opt_type = details::e_mand; 27611 | else if (details::imatch(symbol, "max" )) opt_type = details::e_max ; 27612 | else if (details::imatch(symbol, "min" )) opt_type = details::e_min ; 27613 | else if (details::imatch(symbol, "mor" )) opt_type = details::e_mor ; 27614 | else if (details::imatch(symbol, "mul" )) opt_type = details::e_prod; 27615 | else if (details::imatch(symbol, "sum" )) opt_type = details::e_sum ; 27616 | else 27617 | { 27618 | set_error(make_error( 27619 | parser_error::e_syntax, 27620 | current_token(), 27621 | "ERR104 - Unsupported built-in vararg function: " + symbol, 27622 | exprtk_error_location)); 27623 | 27624 | return error_node(); 27625 | } 27626 | 27627 | scoped_vec_delete<expression_node_t> svd((*this), arg_list); 27628 | 27629 | lodge_symbol(symbol, e_st_function); 27630 | 27631 | next_token(); 27632 | 27633 | if (!token_is(token_t::e_lbracket)) 27634 | { 27635 | set_error(make_error( 27636 | parser_error::e_syntax, 27637 | current_token(), 27638 | "ERR105 - Expected '(' for call to vararg function: " + symbol, 27639 | exprtk_error_location)); 27640 | 27641 | return error_node(); 27642 | } 27643 | 27644 | if (token_is(token_t::e_rbracket)) 27645 | { 27646 | set_error(make_error( 27647 | parser_error::e_syntax, 27648 | current_token(), 27649 | "ERR106 - vararg function: " + symbol + 27650 | " requires at least one input parameter", 27651 | exprtk_error_location)); 27652 | 27653 | return error_node(); 27654 | } 27655 | 27656 | for ( ; ; ) 27657 | { 27658 | expression_node_ptr arg = parse_expression(); 27659 | 27660 | if (0 == arg) 27661 | return error_node(); 27662 | else 27663 | arg_list.push_back(arg); 27664 | 27665 | if (token_is(token_t::e_rbracket)) 27666 | break; 27667 | else if (!token_is(token_t::e_comma)) 27668 | { 27669 | set_error(make_error( 27670 | parser_error::e_syntax, 27671 | current_token(), 27672 | "ERR107 - Expected ',' for call to vararg function: " + symbol, 27673 | exprtk_error_location)); 27674 | 27675 | return error_node(); 27676 | } 27677 | } 27678 | 27679 | const expression_node_ptr result = expression_generator_.vararg_function(opt_type,arg_list); 27680 | 27681 | svd.delete_ptr = (0 == result); 27682 | return result; 27683 | } 27684 | 27685 | #ifndef exprtk_disable_string_capabilities 27686 | inline expression_node_ptr parse_string_range_statement(expression_node_ptr& expression) 27687 | { 27688 | if (!token_is(token_t::e_lsqrbracket)) 27689 | { 27690 | set_error(make_error( 27691 | parser_error::e_syntax, 27692 | current_token(), 27693 | "ERR108 - Expected '[' as start of string range definition", 27694 | exprtk_error_location)); 27695 | 27696 | free_node(node_allocator_, expression); 27697 | 27698 | return error_node(); 27699 | } 27700 | else if (token_is(token_t::e_rsqrbracket)) 27701 | { 27702 | return node_allocator_.allocate<details::string_size_node<T> >(expression); 27703 | } 27704 | 27705 | range_t rp; 27706 | 27707 | if (!parse_range(rp,true)) 27708 | { 27709 | free_node(node_allocator_, expression); 27710 | 27711 | return error_node(); 27712 | } 27713 | 27714 | expression_node_ptr result = expression_generator_(expression,rp); 27715 | 27716 | if (0 == result) 27717 | { 27718 | set_error(make_error( 27719 | parser_error::e_syntax, 27720 | current_token(), 27721 | "ERR109 - Failed to generate string range node", 27722 | exprtk_error_location)); 27723 | 27724 | free_node(node_allocator_, expression); 27725 | rp.free(); 27726 | } 27727 | 27728 | rp.clear(); 27729 | 27730 | if (result && result->valid()) 27731 | { 27732 | return result; 27733 | } 27734 | 27735 | set_error(make_error( 27736 | parser_error::e_synthesis, 27737 | current_token(), 27738 | "ERR110 - Failed to synthesize node: string_range_node", 27739 | exprtk_error_location)); 27740 | 27741 | free_node(node_allocator_, result); 27742 | rp.free(); 27743 | return error_node(); 27744 | } 27745 | #else 27746 | inline expression_node_ptr parse_string_range_statement(expression_node_ptr&) 27747 | { 27748 | return error_node(); 27749 | } 27750 | #endif 27751 | 27752 | inline bool parse_pending_string_rangesize(expression_node_ptr& expression) 27753 | { 27754 | // Allow no more than 100 range calls, eg: s[][][]...[][] 27755 | const std::size_t max_rangesize_parses = 100; 27756 | 27757 | std::size_t i = 0; 27758 | 27759 | while 27760 | ( 27761 | (0 != expression) && 27762 | (i++ < max_rangesize_parses) && 27763 | error_list_.empty() && 27764 | is_generally_string_node(expression) && 27765 | token_is(token_t::e_lsqrbracket,prsrhlpr_t::e_hold) 27766 | ) 27767 | { 27768 | expression = parse_string_range_statement(expression); 27769 | } 27770 | 27771 | return (i > 1); 27772 | } 27773 | 27774 | inline void parse_pending_vector_index_operator(expression_node_ptr& expression) 27775 | { 27776 | if 27777 | ( 27778 | (0 != expression) && 27779 | error_list_.empty() && 27780 | is_ivector_node(expression) 27781 | ) 27782 | { 27783 | if ( 27784 | settings_.commutative_check_enabled() && 27785 | token_is(token_t::e_mul,prsrhlpr_t::e_hold) && 27786 | peek_token_is(token_t::e_lsqrbracket) 27787 | ) 27788 | { 27789 | token_is(token_t::e_mul); 27790 | token_is(token_t::e_lsqrbracket); 27791 | } 27792 | else if (token_is(token_t::e_lsqrbracket,prsrhlpr_t::e_hold)) 27793 | { 27794 | token_is(token_t::e_lsqrbracket); 27795 | } 27796 | else if ( 27797 | token_is(token_t::e_rbracket,prsrhlpr_t::e_hold) && 27798 | peek_token_is(token_t::e_lsqrbracket) 27799 | ) 27800 | { 27801 | token_is(token_t::e_rbracket ); 27802 | token_is(token_t::e_lsqrbracket); 27803 | } 27804 | else 27805 | return; 27806 | 27807 | details::vector_interface<T>* vi = dynamic_cast<details::vector_interface<T>*>(expression); 27808 | 27809 | if (vi) 27810 | { 27811 | details::vector_holder<T>& vec = vi->vec()->vec_holder(); 27812 | const std::string vector_name = sem_.get_vector_name(vec.data()); 27813 | expression_node_ptr index = parse_vector_index(vector_name); 27814 | 27815 | if (index) 27816 | { 27817 | expression = synthesize_vector_element(vector_name, &vec, expression, index); 27818 | return; 27819 | } 27820 | } 27821 | 27822 | free_node(node_allocator_, expression); 27823 | expression = error_node(); 27824 | } 27825 | } 27826 | 27827 | template <typename Allocator1, 27828 | typename Allocator2, 27829 | template <typename, typename> class Sequence> 27830 | inline expression_node_ptr simplify(Sequence<expression_node_ptr,Allocator1>& expression_list, 27831 | Sequence<bool,Allocator2>& side_effect_list, 27832 | const bool specialise_on_final_type = false) 27833 | { 27834 | if (expression_list.empty()) 27835 | return error_node(); 27836 | else if (1 == expression_list.size()) 27837 | return expression_list[0]; 27838 | 27839 | Sequence<expression_node_ptr,Allocator1> tmp_expression_list; 27840 | 27841 | exprtk_debug(("simplify() - expression_list.size: %d side_effect_list.size(): %d\n", 27842 | static_cast<int>(expression_list .size()), 27843 | static_cast<int>(side_effect_list.size()))); 27844 | 27845 | bool return_node_present = false; 27846 | 27847 | for (std::size_t i = 0; i < (expression_list.size() - 1); ++i) 27848 | { 27849 | if (is_variable_node(expression_list[i])) 27850 | continue; 27851 | else if ( 27852 | is_return_node (expression_list[i]) || 27853 | is_break_node (expression_list[i]) || 27854 | is_continue_node(expression_list[i]) 27855 | ) 27856 | { 27857 | tmp_expression_list.push_back(expression_list[i]); 27858 | 27859 | // Remove all subexpressions after first short-circuit 27860 | // node has been encountered. 27861 | 27862 | for (std::size_t j = i + 1; j < expression_list.size(); ++j) 27863 | { 27864 | free_node(node_allocator_, expression_list[j]); 27865 | } 27866 | 27867 | return_node_present = true; 27868 | 27869 | break; 27870 | } 27871 | else if ( 27872 | is_constant_node(expression_list[i]) || 27873 | is_null_node (expression_list[i]) || 27874 | !side_effect_list[i] 27875 | ) 27876 | { 27877 | free_node(node_allocator_, expression_list[i]); 27878 | continue; 27879 | } 27880 | else 27881 | tmp_expression_list.push_back(expression_list[i]); 27882 | } 27883 | 27884 | if (!return_node_present) 27885 | { 27886 | tmp_expression_list.push_back(expression_list.back()); 27887 | } 27888 | 27889 | expression_list.swap(tmp_expression_list); 27890 | 27891 | if (tmp_expression_list.size() > expression_list.size()) 27892 | { 27893 | exprtk_debug(("simplify() - Reduced subexpressions from %d to %d\n", 27894 | static_cast<int>(tmp_expression_list.size()), 27895 | static_cast<int>(expression_list .size()))); 27896 | } 27897 | 27898 | if ( 27899 | return_node_present || 27900 | side_effect_list.back() || 27901 | (expression_list.size() > 1) 27902 | ) 27903 | state_.activate_side_effect("simplify()"); 27904 | 27905 | if (1 == expression_list.size()) 27906 | return expression_list[0]; 27907 | else if (specialise_on_final_type && is_generally_string_node(expression_list.back())) 27908 | return expression_generator_.vararg_function(details::e_smulti,expression_list); 27909 | else 27910 | return expression_generator_.vararg_function(details::e_multi,expression_list); 27911 | } 27912 | 27913 | inline expression_node_ptr parse_multi_sequence(const std::string& source = "", 27914 | const bool enforce_crlbrackets = false) 27915 | { 27916 | token_t::token_type open_bracket = token_t::e_lcrlbracket; 27917 | token_t::token_type close_bracket = token_t::e_rcrlbracket; 27918 | token_t::token_type separator = token_t::e_eof; 27919 | 27920 | if (!token_is(open_bracket)) 27921 | { 27922 | if (!enforce_crlbrackets && token_is(token_t::e_lbracket)) 27923 | { 27924 | open_bracket = token_t::e_lbracket; 27925 | close_bracket = token_t::e_rbracket; 27926 | separator = token_t::e_comma; 27927 | } 27928 | else 27929 | { 27930 | set_error(make_error( 27931 | parser_error::e_syntax, 27932 | current_token(), 27933 | "ERR111 - Expected '" + token_t::to_str(open_bracket) + "' for call to multi-sequence" + 27934 | ((!source.empty()) ? std::string(" section of " + source): ""), 27935 | exprtk_error_location)); 27936 | 27937 | return error_node(); 27938 | } 27939 | } 27940 | else if (token_is(close_bracket)) 27941 | { 27942 | return node_allocator_.allocate<details::null_node<T> >(); 27943 | } 27944 | 27945 | std::vector<expression_node_ptr> arg_list; 27946 | std::vector<bool> side_effect_list; 27947 | 27948 | scoped_vec_delete<expression_node_t> svd((*this), arg_list); 27949 | 27950 | scope_handler sh(*this); 27951 | 27952 | scoped_bool_or_restorer sbr(state_.side_effect_present); 27953 | 27954 | for ( ; ; ) 27955 | { 27956 | state_.side_effect_present = false; 27957 | 27958 | expression_node_ptr arg = parse_expression(); 27959 | 27960 | if (0 == arg) 27961 | return error_node(); 27962 | else 27963 | { 27964 | arg_list.push_back(arg); 27965 | side_effect_list.push_back(state_.side_effect_present); 27966 | } 27967 | 27968 | if (token_is(close_bracket)) 27969 | break; 27970 | 27971 | const bool is_next_close = peek_token_is(close_bracket); 27972 | 27973 | if (!token_is(separator) && is_next_close) 27974 | { 27975 | set_error(make_error( 27976 | parser_error::e_syntax, 27977 | current_token(), 27978 | "ERR112 - Expected '" + lexer::token::seperator_to_str(separator) + "' for call to multi-sequence section of " + source, 27979 | exprtk_error_location)); 27980 | 27981 | return error_node(); 27982 | } 27983 | 27984 | if (token_is(close_bracket)) 27985 | break; 27986 | } 27987 | 27988 | expression_node_ptr result = simplify(arg_list, side_effect_list, source.empty()); 27989 | 27990 | svd.delete_ptr = (0 == result); 27991 | return result; 27992 | } 27993 | 27994 | inline bool parse_range(range_t& rp, const bool skip_lsqr = false) 27995 | { 27996 | // Examples of valid ranges: 27997 | // 1. [1:5] -> [1,5) 27998 | // 2. [ :5] -> [0,5) 27999 | // 3. [1: ] -> [1,end) 28000 | // 4. [x:y] -> [x,y) where x <= y 28001 | // 5. [x+1:y/2] -> [x+1,y/2) where x+1 <= y/2 28002 | // 6. [ :y] -> [0,y) where 0 <= y 28003 | // 7. [x: ] -> [x,end) where x <= end 28004 | 28005 | rp.clear(); 28006 | 28007 | if (!skip_lsqr && !token_is(token_t::e_lsqrbracket)) 28008 | { 28009 | set_error(make_error( 28010 | parser_error::e_syntax, 28011 | current_token(), 28012 | "ERR113 - Expected '[' for start of range", 28013 | exprtk_error_location)); 28014 | 28015 | return false; 28016 | } 28017 | 28018 | if (token_is(token_t::e_colon)) 28019 | { 28020 | rp.n0_c.first = true; 28021 | rp.n0_c.second = 0; 28022 | rp.cache.first = 0; 28023 | } 28024 | else 28025 | { 28026 | expression_node_ptr r0 = parse_expression(); 28027 | 28028 | if (0 == r0) 28029 | { 28030 | set_error(make_error( 28031 | parser_error::e_syntax, 28032 | current_token(), 28033 | "ERR114 - Failed parse begin section of range", 28034 | exprtk_error_location)); 28035 | 28036 | return false; 28037 | } 28038 | else if (is_constant_node(r0)) 28039 | { 28040 | const T r0_value = r0->value(); 28041 | 28042 | if (r0_value >= T(0)) 28043 | { 28044 | rp.n0_c.first = true; 28045 | rp.n0_c.second = static_cast<std::size_t>(details::numeric::to_int64(r0_value)); 28046 | rp.cache.first = rp.n0_c.second; 28047 | } 28048 | 28049 | free_node(node_allocator_, r0); 28050 | 28051 | if (r0_value < T(0)) 28052 | { 28053 | set_error(make_error( 28054 | parser_error::e_syntax, 28055 | current_token(), 28056 | "ERR115 - Range lower bound less than zero! Constraint: r0 >= 0", 28057 | exprtk_error_location)); 28058 | 28059 | return false; 28060 | } 28061 | } 28062 | else 28063 | { 28064 | rp.n0_e.first = true; 28065 | rp.n0_e.second = r0; 28066 | } 28067 | 28068 | if (!token_is(token_t::e_colon)) 28069 | { 28070 | set_error(make_error( 28071 | parser_error::e_syntax, 28072 | current_token(), 28073 | "ERR116 - Expected ':' for break in range", 28074 | exprtk_error_location)); 28075 | 28076 | rp.free(); 28077 | 28078 | return false; 28079 | } 28080 | } 28081 | 28082 | if (token_is(token_t::e_rsqrbracket)) 28083 | { 28084 | rp.n1_c.first = true; 28085 | rp.n1_c.second = std::numeric_limits<std::size_t>::max(); 28086 | } 28087 | else 28088 | { 28089 | expression_node_ptr r1 = parse_expression(); 28090 | 28091 | if (0 == r1) 28092 | { 28093 | set_error(make_error( 28094 | parser_error::e_syntax, 28095 | current_token(), 28096 | "ERR117 - Failed parse end section of range", 28097 | exprtk_error_location)); 28098 | 28099 | rp.free(); 28100 | 28101 | return false; 28102 | } 28103 | else if (is_constant_node(r1)) 28104 | { 28105 | const T r1_value = r1->value(); 28106 | 28107 | if (r1_value >= T(0)) 28108 | { 28109 | rp.n1_c.first = true; 28110 | rp.n1_c.second = static_cast<std::size_t>(details::numeric::to_int64(r1_value)); 28111 | rp.cache.second = rp.n1_c.second; 28112 | } 28113 | 28114 | free_node(node_allocator_, r1); 28115 | 28116 | if (r1_value < T(0)) 28117 | { 28118 | set_error(make_error( 28119 | parser_error::e_syntax, 28120 | current_token(), 28121 | "ERR118 - Range upper bound less than zero! Constraint: r1 >= 0", 28122 | exprtk_error_location)); 28123 | 28124 | rp.free(); 28125 | 28126 | return false; 28127 | } 28128 | } 28129 | else 28130 | { 28131 | rp.n1_e.first = true; 28132 | rp.n1_e.second = r1; 28133 | } 28134 | 28135 | if (!token_is(token_t::e_rsqrbracket)) 28136 | { 28137 | set_error(make_error( 28138 | parser_error::e_syntax, 28139 | current_token(), 28140 | "ERR119 - Expected ']' for start of range", 28141 | exprtk_error_location)); 28142 | 28143 | rp.free(); 28144 | 28145 | return false; 28146 | } 28147 | } 28148 | 28149 | if (rp.const_range()) 28150 | { 28151 | std::size_t r0 = 0; 28152 | std::size_t r1 = 0; 28153 | 28154 | bool rp_result = false; 28155 | 28156 | try 28157 | { 28158 | rp_result = rp(r0, r1); 28159 | } 28160 | catch (std::runtime_error&) 28161 | {} 28162 | 28163 | if (!rp_result || (r0 > r1)) 28164 | { 28165 | set_error(make_error( 28166 | parser_error::e_syntax, 28167 | current_token(), 28168 | "ERR120 - Invalid range, Constraint: r0 <= r1", 28169 | exprtk_error_location)); 28170 | 28171 | return false; 28172 | } 28173 | } 28174 | 28175 | return true; 28176 | } 28177 | 28178 | inline void lodge_symbol(const std::string& symbol, 28179 | const symbol_type st) 28180 | { 28181 | dec_.add_symbol(symbol,st); 28182 | } 28183 | 28184 | #ifndef exprtk_disable_string_capabilities 28185 | inline expression_node_ptr parse_string() 28186 | { 28187 | const std::string symbol = current_token().value; 28188 | 28189 | typedef details::stringvar_node<T>* strvar_node_t; 28190 | 28191 | expression_node_ptr result = error_node(); 28192 | strvar_node_t const_str_node = static_cast<strvar_node_t>(0); 28193 | 28194 | scope_element& se = sem_.get_active_element(symbol); 28195 | 28196 | if (scope_element::e_string == se.type) 28197 | { 28198 | se.active = true; 28199 | result = se.str_node; 28200 | lodge_symbol(symbol, e_st_local_string); 28201 | } 28202 | else 28203 | { 28204 | typedef typename symtab_store::string_context str_ctxt_t; 28205 | str_ctxt_t str_ctx = symtab_store_.get_string_context(symbol); 28206 | 28207 | if ((0 == str_ctx.str_var) || !symtab_store_.is_conststr_stringvar(symbol)) 28208 | { 28209 | set_error(make_error( 28210 | parser_error::e_syntax, 28211 | current_token(), 28212 | "ERR121 - Unknown string symbol", 28213 | exprtk_error_location)); 28214 | 28215 | return error_node(); 28216 | } 28217 | 28218 | assert(str_ctx.str_var != 0); 28219 | assert(str_ctx.symbol_table != 0); 28220 | 28221 | result = str_ctx.str_var; 28222 | 28223 | if (symtab_store_.is_constant_string(symbol)) 28224 | { 28225 | const_str_node = static_cast<strvar_node_t>(result); 28226 | result = expression_generator_(const_str_node->str()); 28227 | } 28228 | else if (symbol_table_t::e_immutable == str_ctx.symbol_table->mutability()) 28229 | { 28230 | lodge_immutable_symbol( 28231 | current_token(), 28232 | make_memory_range(str_ctx.str_var->base(), str_ctx.str_var->size())); 28233 | } 28234 | 28235 | lodge_symbol(symbol, e_st_string); 28236 | } 28237 | 28238 | if (peek_token_is(token_t::e_lsqrbracket)) 28239 | { 28240 | next_token(); 28241 | 28242 | if (peek_token_is(token_t::e_rsqrbracket)) 28243 | { 28244 | next_token(); 28245 | next_token(); 28246 | 28247 | if (const_str_node) 28248 | { 28249 | free_node(node_allocator_, result); 28250 | 28251 | return expression_generator_(T(const_str_node->size())); 28252 | } 28253 | else 28254 | return node_allocator_.allocate<details::stringvar_size_node<T> > 28255 | (static_cast<details::stringvar_node<T>*>(result)->ref()); 28256 | } 28257 | 28258 | range_t rp; 28259 | 28260 | if (!parse_range(rp)) 28261 | { 28262 | free_node(node_allocator_, result); 28263 | 28264 | return error_node(); 28265 | } 28266 | else if (const_str_node) 28267 | { 28268 | free_node(node_allocator_, result); 28269 | result = expression_generator_(const_str_node->ref(),rp); 28270 | } 28271 | else 28272 | result = expression_generator_(static_cast<details::stringvar_node<T>*> 28273 | (result)->ref(), rp); 28274 | 28275 | if (result) 28276 | rp.clear(); 28277 | } 28278 | else 28279 | next_token(); 28280 | 28281 | return result; 28282 | } 28283 | #else 28284 | inline expression_node_ptr parse_string() 28285 | { 28286 | return error_node(); 28287 | } 28288 | #endif 28289 | 28290 | #ifndef exprtk_disable_string_capabilities 28291 | inline expression_node_ptr parse_const_string() 28292 | { 28293 | const std::string const_str = current_token().value; 28294 | expression_node_ptr result = expression_generator_(const_str); 28295 | 28296 | if (peek_token_is(token_t::e_lsqrbracket)) 28297 | { 28298 | next_token(); 28299 | 28300 | if (peek_token_is(token_t::e_rsqrbracket)) 28301 | { 28302 | next_token(); 28303 | next_token(); 28304 | 28305 | free_node(node_allocator_, result); 28306 | 28307 | return expression_generator_(T(const_str.size())); 28308 | } 28309 | 28310 | range_t rp; 28311 | 28312 | if (!parse_range(rp)) 28313 | { 28314 | free_node(node_allocator_, result); 28315 | rp.free(); 28316 | 28317 | return error_node(); 28318 | } 28319 | 28320 | free_node(node_allocator_, result); 28321 | 28322 | if (rp.n1_c.first && (rp.n1_c.second == std::numeric_limits<std::size_t>::max())) 28323 | { 28324 | rp.n1_c.second = const_str.size() - 1; 28325 | rp.cache.second = rp.n1_c.second; 28326 | } 28327 | 28328 | if ( 28329 | (rp.n0_c.first && (rp.n0_c.second >= const_str.size())) || 28330 | (rp.n1_c.first && (rp.n1_c.second >= const_str.size())) 28331 | ) 28332 | { 28333 | set_error(make_error( 28334 | parser_error::e_syntax, 28335 | current_token(), 28336 | "ERR122 - Overflow in range for string: '" + const_str + "'[" + 28337 | (rp.n0_c.first ? details::to_str(static_cast<int>(rp.n0_c.second)) : "?") + ":" + 28338 | (rp.n1_c.first ? details::to_str(static_cast<int>(rp.n1_c.second)) : "?") + "]", 28339 | exprtk_error_location)); 28340 | 28341 | rp.free(); 28342 | 28343 | return error_node(); 28344 | } 28345 | 28346 | result = expression_generator_(const_str,rp); 28347 | 28348 | if (result) 28349 | rp.clear(); 28350 | } 28351 | else 28352 | next_token(); 28353 | 28354 | return result; 28355 | } 28356 | #else 28357 | inline expression_node_ptr parse_const_string() 28358 | { 28359 | return error_node(); 28360 | } 28361 | #endif 28362 | 28363 | inline expression_node_ptr parse_vector_index(const std::string& vector_name = "") 28364 | { 28365 | expression_node_ptr index_expr = error_node(); 28366 | 28367 | if (0 == (index_expr = parse_expression())) 28368 | { 28369 | set_error(make_error( 28370 | parser_error::e_syntax, 28371 | current_token(), 28372 | "ERR123 - Failed to parse index for vector: '" + vector_name + "'", 28373 | exprtk_error_location)); 28374 | 28375 | return error_node(); 28376 | } 28377 | else if (!token_is(token_t::e_rsqrbracket)) 28378 | { 28379 | set_error(make_error( 28380 | parser_error::e_syntax, 28381 | current_token(), 28382 | "ERR124 - Expected ']' for index of vector: '" + vector_name + "'", 28383 | exprtk_error_location)); 28384 | 28385 | free_node(node_allocator_, index_expr); 28386 | 28387 | return error_node(); 28388 | } 28389 | 28390 | return index_expr; 28391 | } 28392 | 28393 | inline expression_node_ptr parse_vector() 28394 | { 28395 | const std::string vector_name = current_token().value; 28396 | 28397 | vector_holder_ptr vec = vector_holder_ptr(0); 28398 | 28399 | const scope_element& se = sem_.get_active_element(vector_name); 28400 | 28401 | if ( 28402 | !details::imatch(se.name, vector_name) || 28403 | (se.depth > state_.scope_depth) || 28404 | (scope_element::e_vector != se.type) 28405 | ) 28406 | { 28407 | typedef typename symtab_store::vector_context vec_ctxt_t; 28408 | vec_ctxt_t vec_ctx = symtab_store_.get_vector_context(vector_name); 28409 | 28410 | if (0 == vec_ctx.vector_holder) 28411 | { 28412 | set_error(make_error( 28413 | parser_error::e_syntax, 28414 | current_token(), 28415 | "ERR125 - Symbol '" + vector_name + " not a vector", 28416 | exprtk_error_location)); 28417 | 28418 | return error_node(); 28419 | } 28420 | 28421 | assert(0 != vec_ctx.vector_holder); 28422 | assert(0 != vec_ctx.symbol_table ); 28423 | 28424 | vec = vec_ctx.vector_holder; 28425 | 28426 | if (symbol_table_t::e_immutable == vec_ctx.symbol_table->mutability()) 28427 | { 28428 | lodge_immutable_symbol( 28429 | current_token(), 28430 | make_memory_range(vec->data(), vec->size())); 28431 | } 28432 | } 28433 | else 28434 | { 28435 | vec = se.vec_node; 28436 | } 28437 | 28438 | assert(0 != vec); 28439 | 28440 | next_token(); 28441 | 28442 | if (!token_is(token_t::e_lsqrbracket)) 28443 | { 28444 | return node_allocator_.allocate<vector_node_t>(vec); 28445 | } 28446 | else if (token_is(token_t::e_rsqrbracket)) 28447 | { 28448 | return (vec->rebaseable()) ? 28449 | node_allocator_.allocate<vector_size_node_t>(vec) : 28450 | expression_generator_(T(vec->size())); 28451 | } 28452 | 28453 | expression_node_ptr index_expr = parse_vector_index(vector_name); 28454 | 28455 | if (index_expr) 28456 | { 28457 | expression_node_ptr vec_node = node_allocator_.allocate<vector_node_t>(vec); 28458 | 28459 | return synthesize_vector_element(vector_name, vec, vec_node, index_expr); 28460 | } 28461 | 28462 | return error_node(); 28463 | } 28464 | 28465 | inline expression_node_ptr synthesize_vector_element(const std::string& vector_name, 28466 | vector_holder_ptr vec, 28467 | expression_node_ptr vec_node, 28468 | expression_node_ptr index_expr) 28469 | { 28470 | // Perform compile-time range check 28471 | if (details::is_constant_node(index_expr)) 28472 | { 28473 | const std::size_t index = static_cast<std::size_t>(details::numeric::to_int32(index_expr->value())); 28474 | const std::size_t vec_size = vec->size(); 28475 | 28476 | if (index >= vec_size) 28477 | { 28478 | set_error(make_error( 28479 | parser_error::e_syntax, 28480 | current_token(), 28481 | "ERR126 - Index of " + details::to_str(index) + " out of range for " 28482 | "vector '" + vector_name + "' of size " + details::to_str(vec_size), 28483 | exprtk_error_location)); 28484 | 28485 | free_node(node_allocator_, vec_node ); 28486 | free_node(node_allocator_, index_expr); 28487 | 28488 | return error_node(); 28489 | } 28490 | } 28491 | 28492 | return expression_generator_.vector_element(vector_name, vec, vec_node, index_expr); 28493 | } 28494 | 28495 | inline expression_node_ptr parse_vararg_function_call(ivararg_function<T>* vararg_function, const std::string& vararg_function_name) 28496 | { 28497 | std::vector<expression_node_ptr> arg_list; 28498 | 28499 | scoped_vec_delete<expression_node_t> svd((*this), arg_list); 28500 | 28501 | next_token(); 28502 | 28503 | if (token_is(token_t::e_lbracket)) 28504 | { 28505 | if (token_is(token_t::e_rbracket)) 28506 | { 28507 | if (!vararg_function->allow_zero_parameters()) 28508 | { 28509 | set_error(make_error( 28510 | parser_error::e_syntax, 28511 | current_token(), 28512 | "ERR127 - Zero parameter call to vararg function: " 28513 | + vararg_function_name + " not allowed", 28514 | exprtk_error_location)); 28515 | 28516 | return error_node(); 28517 | } 28518 | } 28519 | else 28520 | { 28521 | for ( ; ; ) 28522 | { 28523 | expression_node_ptr arg = parse_expression(); 28524 | 28525 | if (0 == arg) 28526 | return error_node(); 28527 | else 28528 | arg_list.push_back(arg); 28529 | 28530 | if (token_is(token_t::e_rbracket)) 28531 | break; 28532 | else if (!token_is(token_t::e_comma)) 28533 | { 28534 | set_error(make_error( 28535 | parser_error::e_syntax, 28536 | current_token(), 28537 | "ERR128 - Expected ',' for call to vararg function: " 28538 | + vararg_function_name, 28539 | exprtk_error_location)); 28540 | 28541 | return error_node(); 28542 | } 28543 | } 28544 | } 28545 | } 28546 | else if (!vararg_function->allow_zero_parameters()) 28547 | { 28548 | set_error(make_error( 28549 | parser_error::e_syntax, 28550 | current_token(), 28551 | "ERR129 - Zero parameter call to vararg function: " 28552 | + vararg_function_name + " not allowed", 28553 | exprtk_error_location)); 28554 | 28555 | return error_node(); 28556 | } 28557 | 28558 | if (arg_list.size() < vararg_function->min_num_args()) 28559 | { 28560 | set_error(make_error( 28561 | parser_error::e_syntax, 28562 | current_token(), 28563 | "ERR130 - Invalid number of parameters to call to vararg function: " 28564 | + vararg_function_name + ", require at least " 28565 | + details::to_str(static_cast<int>(vararg_function->min_num_args())) + " parameters", 28566 | exprtk_error_location)); 28567 | 28568 | return error_node(); 28569 | } 28570 | else if (arg_list.size() > vararg_function->max_num_args()) 28571 | { 28572 | set_error(make_error( 28573 | parser_error::e_syntax, 28574 | current_token(), 28575 | "ERR131 - Invalid number of parameters to call to vararg function: " 28576 | + vararg_function_name + ", require no more than " 28577 | + details::to_str(static_cast<int>(vararg_function->max_num_args())) + " parameters", 28578 | exprtk_error_location)); 28579 | 28580 | return error_node(); 28581 | } 28582 | 28583 | expression_node_ptr result = expression_generator_.vararg_function_call(vararg_function,arg_list); 28584 | 28585 | svd.delete_ptr = (0 == result); 28586 | 28587 | return result; 28588 | } 28589 | 28590 | class type_checker 28591 | { 28592 | public: 28593 | 28594 | enum return_type_t 28595 | { 28596 | e_overload = ' ', 28597 | e_numeric = 'T', 28598 | e_string = 'S' 28599 | }; 28600 | 28601 | struct function_prototype_t 28602 | { 28603 | return_type_t return_type; 28604 | std::string param_seq; 28605 | }; 28606 | 28607 | typedef parser<T> parser_t; 28608 | typedef std::vector<function_prototype_t> function_definition_list_t; 28609 | 28610 | type_checker(parser_t& p, 28611 | const std::string& func_name, 28612 | const std::string& func_prototypes, 28613 | const return_type_t default_return_type) 28614 | : invalid_state_(true) 28615 | , parser_(p) 28616 | , function_name_(func_name) 28617 | , default_return_type_(default_return_type) 28618 | { 28619 | parse_function_prototypes(func_prototypes); 28620 | } 28621 | 28622 | bool verify(const std::string& param_seq, std::size_t& pseq_index) 28623 | { 28624 | if (function_definition_list_.empty()) 28625 | return true; 28626 | 28627 | std::vector<std::pair<std::size_t,char> > error_list; 28628 | 28629 | for (std::size_t i = 0; i < function_definition_list_.size(); ++i) 28630 | { 28631 | details::char_t diff_value = 0; 28632 | std::size_t diff_index = 0; 28633 | 28634 | const bool result = details::sequence_match(function_definition_list_[i].param_seq, 28635 | param_seq, 28636 | diff_index, diff_value); 28637 | 28638 | if (result) 28639 | { 28640 | pseq_index = i; 28641 | return true; 28642 | } 28643 | else 28644 | error_list.push_back(std::make_pair(diff_index, diff_value)); 28645 | } 28646 | 28647 | if (1 == error_list.size()) 28648 | { 28649 | parser_.set_error(make_error( 28650 | parser_error::e_syntax, 28651 | parser_.current_token(), 28652 | "ERR132 - Failed parameter type check for function '" + function_name_ + "', " 28653 | "Expected '" + function_definition_list_[0].param_seq + 28654 | "' call set: '" + param_seq + "'", 28655 | exprtk_error_location)); 28656 | } 28657 | else 28658 | { 28659 | // find first with largest diff_index; 28660 | std::size_t max_diff_index = 0; 28661 | 28662 | for (std::size_t i = 1; i < error_list.size(); ++i) 28663 | { 28664 | if (error_list[i].first > error_list[max_diff_index].first) 28665 | { 28666 | max_diff_index = i; 28667 | } 28668 | } 28669 | 28670 | parser_.set_error(make_error( 28671 | parser_error::e_syntax, 28672 | parser_.current_token(), 28673 | "ERR133 - Failed parameter type check for function '" + function_name_ + "', " 28674 | "Best match: '" + function_definition_list_[max_diff_index].param_seq + 28675 | "' call set: '" + param_seq + "'", 28676 | exprtk_error_location)); 28677 | } 28678 | 28679 | return false; 28680 | } 28681 | 28682 | std::size_t paramseq_count() const 28683 | { 28684 | return function_definition_list_.size(); 28685 | } 28686 | 28687 | std::string paramseq(const std::size_t& index) const 28688 | { 28689 | return function_definition_list_[index].param_seq; 28690 | } 28691 | 28692 | return_type_t return_type(const std::size_t& index) const 28693 | { 28694 | return function_definition_list_[index].return_type; 28695 | } 28696 | 28697 | bool invalid() const 28698 | { 28699 | return !invalid_state_; 28700 | } 28701 | 28702 | bool allow_zero_parameters() const 28703 | { 28704 | 28705 | for (std::size_t i = 0; i < function_definition_list_.size(); ++i) 28706 | { 28707 | if (std::string::npos != function_definition_list_[i].param_seq.find("Z")) 28708 | { 28709 | return true; 28710 | } 28711 | } 28712 | 28713 | return false; 28714 | } 28715 | 28716 | private: 28717 | 28718 | std::vector<std::string> split_param_seq(const std::string& param_seq, const details::char_t delimiter = '|') const 28719 | { 28720 | std::string::const_iterator current_begin = param_seq.begin(); 28721 | std::string::const_iterator iter = param_seq.begin(); 28722 | 28723 | std::vector<std::string> result; 28724 | 28725 | while (iter != param_seq.end()) 28726 | { 28727 | if (*iter == delimiter) 28728 | { 28729 | result.push_back(std::string(current_begin, iter)); 28730 | current_begin = ++iter; 28731 | } 28732 | else 28733 | ++iter; 28734 | } 28735 | 28736 | if (current_begin != iter) 28737 | { 28738 | result.push_back(std::string(current_begin, iter)); 28739 | } 28740 | 28741 | return result; 28742 | } 28743 | 28744 | inline bool is_valid_token(std::string param_seq, 28745 | function_prototype_t& funcproto) const 28746 | { 28747 | // Determine return type 28748 | funcproto.return_type = default_return_type_; 28749 | 28750 | if (param_seq.size() > 2) 28751 | { 28752 | if (':' == param_seq[1]) 28753 | { 28754 | // Note: Only overloaded igeneric functions can have return 28755 | // type definitions. 28756 | if (type_checker::e_overload != default_return_type_) 28757 | return false; 28758 | 28759 | switch (param_seq[0]) 28760 | { 28761 | case 'T' : funcproto.return_type = type_checker::e_numeric; 28762 | break; 28763 | 28764 | case 'S' : funcproto.return_type = type_checker::e_string; 28765 | break; 28766 | 28767 | default : return false; 28768 | } 28769 | 28770 | param_seq.erase(0,2); 28771 | } 28772 | } 28773 | 28774 | if ( 28775 | (std::string::npos != param_seq.find("?*")) || 28776 | (std::string::npos != param_seq.find("**")) 28777 | ) 28778 | { 28779 | return false; 28780 | } 28781 | else if ( 28782 | (std::string::npos == param_seq.find_first_not_of("STV*?|")) || 28783 | ("Z" == param_seq) 28784 | ) 28785 | { 28786 | funcproto.param_seq = param_seq; 28787 | return true; 28788 | } 28789 | 28790 | return false; 28791 | } 28792 | 28793 | void parse_function_prototypes(const std::string& func_prototypes) 28794 | { 28795 | if (func_prototypes.empty()) 28796 | return; 28797 | 28798 | std::vector<std::string> param_seq_list = split_param_seq(func_prototypes); 28799 | 28800 | typedef std::map<std::string,std::size_t> param_seq_map_t; 28801 | param_seq_map_t param_seq_map; 28802 | 28803 | for (std::size_t i = 0; i < param_seq_list.size(); ++i) 28804 | { 28805 | function_prototype_t func_proto; 28806 | 28807 | if (!is_valid_token(param_seq_list[i], func_proto)) 28808 | { 28809 | invalid_state_ = false; 28810 | 28811 | parser_.set_error(make_error( 28812 | parser_error::e_syntax, 28813 | parser_.current_token(), 28814 | "ERR134 - Invalid parameter sequence of '" + param_seq_list[i] + 28815 | "' for function: " + function_name_, 28816 | exprtk_error_location)); 28817 | return; 28818 | } 28819 | 28820 | param_seq_map_t::const_iterator seq_itr = param_seq_map.find(param_seq_list[i]); 28821 | 28822 | if (param_seq_map.end() != seq_itr) 28823 | { 28824 | invalid_state_ = false; 28825 | 28826 | parser_.set_error(make_error( 28827 | parser_error::e_syntax, 28828 | parser_.current_token(), 28829 | "ERR135 - Function '" + function_name_ + "' has a parameter sequence conflict between " + 28830 | "pseq_idx[" + details::to_str(seq_itr->second) + "] and" + 28831 | "pseq_idx[" + details::to_str(i) + "] " + 28832 | "param seq: " + param_seq_list[i], 28833 | exprtk_error_location)); 28834 | return; 28835 | } 28836 | 28837 | function_definition_list_.push_back(func_proto); 28838 | } 28839 | } 28840 | 28841 | type_checker(const type_checker&) exprtk_delete; 28842 | type_checker& operator=(const type_checker&) exprtk_delete; 28843 | 28844 | bool invalid_state_; 28845 | parser_t& parser_; 28846 | std::string function_name_; 28847 | const return_type_t default_return_type_; 28848 | function_definition_list_t function_definition_list_; 28849 | }; 28850 | 28851 | inline expression_node_ptr parse_generic_function_call(igeneric_function<T>* function, const std::string& function_name) 28852 | { 28853 | std::vector<expression_node_ptr> arg_list; 28854 | 28855 | scoped_vec_delete<expression_node_t> svd((*this), arg_list); 28856 | 28857 | next_token(); 28858 | 28859 | std::string param_type_list; 28860 | 28861 | type_checker tc( 28862 | (*this), 28863 | function_name, 28864 | function->parameter_sequence, 28865 | type_checker::e_string); 28866 | 28867 | if (tc.invalid()) 28868 | { 28869 | set_error(make_error( 28870 | parser_error::e_syntax, 28871 | current_token(), 28872 | "ERR136 - Type checker instantiation failure for generic function: " + function_name, 28873 | exprtk_error_location)); 28874 | 28875 | return error_node(); 28876 | } 28877 | 28878 | if (token_is(token_t::e_lbracket)) 28879 | { 28880 | if (token_is(token_t::e_rbracket)) 28881 | { 28882 | if ( 28883 | !function->allow_zero_parameters() && 28884 | !tc .allow_zero_parameters() 28885 | ) 28886 | { 28887 | set_error(make_error( 28888 | parser_error::e_syntax, 28889 | current_token(), 28890 | "ERR137 - Zero parameter call to generic function: " 28891 | + function_name + " not allowed", 28892 | exprtk_error_location)); 28893 | 28894 | return error_node(); 28895 | } 28896 | } 28897 | else 28898 | { 28899 | for ( ; ; ) 28900 | { 28901 | expression_node_ptr arg = parse_expression(); 28902 | 28903 | if (0 == arg) 28904 | return error_node(); 28905 | 28906 | if (is_ivector_node(arg)) 28907 | param_type_list += 'V'; 28908 | else if (is_generally_string_node(arg)) 28909 | param_type_list += 'S'; 28910 | else // Everything else is assumed to be a scalar returning expression 28911 | param_type_list += 'T'; 28912 | 28913 | arg_list.push_back(arg); 28914 | 28915 | if (token_is(token_t::e_rbracket)) 28916 | break; 28917 | else if (!token_is(token_t::e_comma)) 28918 | { 28919 | set_error(make_error( 28920 | parser_error::e_syntax, 28921 | current_token(), 28922 | "ERR138 - Expected ',' for call to generic function: " + function_name, 28923 | exprtk_error_location)); 28924 | 28925 | return error_node(); 28926 | } 28927 | } 28928 | } 28929 | } 28930 | else if ( 28931 | !function->parameter_sequence.empty() && 28932 | function->allow_zero_parameters () && 28933 | !tc .allow_zero_parameters () 28934 | ) 28935 | { 28936 | set_error(make_error( 28937 | parser_error::e_syntax, 28938 | current_token(), 28939 | "ERR139 - Zero parameter call to generic function: " 28940 | + function_name + " not allowed", 28941 | exprtk_error_location)); 28942 | 28943 | return error_node(); 28944 | } 28945 | 28946 | std::size_t param_seq_index = 0; 28947 | 28948 | if ( 28949 | state_.type_check_enabled && 28950 | !tc.verify(param_type_list, param_seq_index) 28951 | ) 28952 | { 28953 | set_error(make_error( 28954 | parser_error::e_syntax, 28955 | current_token(), 28956 | "ERR140 - Invalid input parameter sequence for call to generic function: " + function_name, 28957 | exprtk_error_location)); 28958 | 28959 | return error_node(); 28960 | } 28961 | 28962 | expression_node_ptr result = 28963 | (tc.paramseq_count() <= 1) ? 28964 | expression_generator_ 28965 | .generic_function_call(function, arg_list) : 28966 | expression_generator_ 28967 | .generic_function_call(function, arg_list, param_seq_index); 28968 | 28969 | svd.delete_ptr = (0 == result); 28970 | 28971 | return result; 28972 | } 28973 | 28974 | inline bool parse_igeneric_function_params(std::string& param_type_list, 28975 | std::vector<expression_node_ptr>& arg_list, 28976 | const std::string& function_name, 28977 | igeneric_function<T>* function, 28978 | const type_checker& tc) 28979 | { 28980 | if (token_is(token_t::e_lbracket)) 28981 | { 28982 | if (token_is(token_t::e_rbracket)) 28983 | { 28984 | if ( 28985 | !function->allow_zero_parameters() && 28986 | !tc .allow_zero_parameters() 28987 | ) 28988 | { 28989 | set_error(make_error( 28990 | parser_error::e_syntax, 28991 | current_token(), 28992 | "ERR141 - Zero parameter call to generic function: " 28993 | + function_name + " not allowed", 28994 | exprtk_error_location)); 28995 | 28996 | return false; 28997 | } 28998 | } 28999 | else 29000 | { 29001 | for ( ; ; ) 29002 | { 29003 | expression_node_ptr arg = parse_expression(); 29004 | 29005 | if (0 == arg) 29006 | return false; 29007 | 29008 | if (is_ivector_node(arg)) 29009 | param_type_list += 'V'; 29010 | else if (is_generally_string_node(arg)) 29011 | param_type_list += 'S'; 29012 | else // Everything else is a scalar returning expression 29013 | param_type_list += 'T'; 29014 | 29015 | arg_list.push_back(arg); 29016 | 29017 | if (token_is(token_t::e_rbracket)) 29018 | break; 29019 | else if (!token_is(token_t::e_comma)) 29020 | { 29021 | set_error(make_error( 29022 | parser_error::e_syntax, 29023 | current_token(), 29024 | "ERR142 - Expected ',' for call to string function: " + function_name, 29025 | exprtk_error_location)); 29026 | 29027 | return false; 29028 | } 29029 | } 29030 | } 29031 | 29032 | return true; 29033 | } 29034 | else 29035 | return false; 29036 | } 29037 | 29038 | #ifndef exprtk_disable_string_capabilities 29039 | inline expression_node_ptr parse_string_function_call(igeneric_function<T>* function, const std::string& function_name) 29040 | { 29041 | // Move pass the function name 29042 | next_token(); 29043 | 29044 | std::string param_type_list; 29045 | 29046 | type_checker tc((*this), function_name, function->parameter_sequence, type_checker::e_string); 29047 | 29048 | if ( 29049 | (!function->parameter_sequence.empty()) && 29050 | (0 == tc.paramseq_count()) 29051 | ) 29052 | { 29053 | return error_node(); 29054 | } 29055 | 29056 | std::vector<expression_node_ptr> arg_list; 29057 | scoped_vec_delete<expression_node_t> svd((*this), arg_list); 29058 | 29059 | if (!parse_igeneric_function_params(param_type_list, arg_list, function_name, function, tc)) 29060 | { 29061 | return error_node(); 29062 | } 29063 | 29064 | std::size_t param_seq_index = 0; 29065 | 29066 | if (!tc.verify(param_type_list, param_seq_index)) 29067 | { 29068 | set_error(make_error( 29069 | parser_error::e_syntax, 29070 | current_token(), 29071 | "ERR143 - Invalid input parameter sequence for call to string function: " + function_name, 29072 | exprtk_error_location)); 29073 | 29074 | return error_node(); 29075 | } 29076 | 29077 | expression_node_ptr result = 29078 | (tc.paramseq_count() <= 1) ? 29079 | expression_generator_ 29080 | .string_function_call(function, arg_list) : 29081 | expression_generator_ 29082 | .string_function_call(function, arg_list, param_seq_index); 29083 | 29084 | svd.delete_ptr = (0 == result); 29085 | 29086 | return result; 29087 | } 29088 | 29089 | inline expression_node_ptr parse_overload_function_call(igeneric_function<T>* function, const std::string& function_name) 29090 | { 29091 | // Move pass the function name 29092 | next_token(); 29093 | 29094 | std::string param_type_list; 29095 | 29096 | type_checker tc((*this), function_name, function->parameter_sequence, type_checker::e_overload); 29097 | 29098 | if ( 29099 | (!function->parameter_sequence.empty()) && 29100 | (0 == tc.paramseq_count()) 29101 | ) 29102 | { 29103 | return error_node(); 29104 | } 29105 | 29106 | std::vector<expression_node_ptr> arg_list; 29107 | scoped_vec_delete<expression_node_t> svd((*this), arg_list); 29108 | 29109 | if (!parse_igeneric_function_params(param_type_list, arg_list, function_name, function, tc)) 29110 | { 29111 | return error_node(); 29112 | } 29113 | 29114 | std::size_t param_seq_index = 0; 29115 | 29116 | if (!tc.verify(param_type_list, param_seq_index)) 29117 | { 29118 | set_error(make_error( 29119 | parser_error::e_syntax, 29120 | current_token(), 29121 | "ERR144 - Invalid input parameter sequence for call to overloaded function: " + function_name, 29122 | exprtk_error_location)); 29123 | 29124 | return error_node(); 29125 | } 29126 | 29127 | expression_node_ptr result = error_node(); 29128 | 29129 | if (type_checker::e_numeric == tc.return_type(param_seq_index)) 29130 | { 29131 | if (tc.paramseq_count() <= 1) 29132 | result = expression_generator_ 29133 | .generic_function_call(function, arg_list); 29134 | else 29135 | result = expression_generator_ 29136 | .generic_function_call(function, arg_list, param_seq_index); 29137 | } 29138 | else if (type_checker::e_string == tc.return_type(param_seq_index)) 29139 | { 29140 | if (tc.paramseq_count() <= 1) 29141 | result = expression_generator_ 29142 | .string_function_call(function, arg_list); 29143 | else 29144 | result = expression_generator_ 29145 | .string_function_call(function, arg_list, param_seq_index); 29146 | } 29147 | else 29148 | { 29149 | set_error(make_error( 29150 | parser_error::e_syntax, 29151 | current_token(), 29152 | "ERR145 - Invalid return type for call to overloaded function: " + function_name, 29153 | exprtk_error_location)); 29154 | } 29155 | 29156 | svd.delete_ptr = (0 == result); 29157 | return result; 29158 | } 29159 | #endif 29160 | 29161 | template <typename Type, std::size_t NumberOfParameters> 29162 | struct parse_special_function_impl 29163 | { 29164 | static inline expression_node_ptr process(parser<Type>& p, const details::operator_type opt_type, const std::string& sf_name) 29165 | { 29166 | expression_node_ptr branch[NumberOfParameters]; 29167 | expression_node_ptr result = error_node(); 29168 | 29169 | std::fill_n(branch, NumberOfParameters, reinterpret_cast<expression_node_ptr>(0)); 29170 | 29171 | scoped_delete<expression_node_t,NumberOfParameters> sd(p,branch); 29172 | 29173 | p.next_token(); 29174 | 29175 | if (!p.token_is(token_t::e_lbracket)) 29176 | { 29177 | p.set_error(make_error( 29178 | parser_error::e_syntax, 29179 | p.current_token(), 29180 | "ERR146 - Expected '(' for special function '" + sf_name + "'", 29181 | exprtk_error_location)); 29182 | 29183 | return error_node(); 29184 | } 29185 | 29186 | for (std::size_t i = 0; i < NumberOfParameters; ++i) 29187 | { 29188 | branch[i] = p.parse_expression(); 29189 | 29190 | if (0 == branch[i]) 29191 | { 29192 | return p.error_node(); 29193 | } 29194 | else if (i < (NumberOfParameters - 1)) 29195 | { 29196 | if (!p.token_is(token_t::e_comma)) 29197 | { 29198 | p.set_error(make_error( 29199 | parser_error::e_syntax, 29200 | p.current_token(), 29201 | "ERR147 - Expected ',' before next parameter of special function '" + sf_name + "'", 29202 | exprtk_error_location)); 29203 | 29204 | return p.error_node(); 29205 | } 29206 | } 29207 | } 29208 | 29209 | if (!p.token_is(token_t::e_rbracket)) 29210 | { 29211 | p.set_error(make_error( 29212 | parser_error::e_syntax, 29213 | p.current_token(), 29214 | "ERR148 - Invalid number of parameters for special function '" + sf_name + "'", 29215 | exprtk_error_location)); 29216 | 29217 | return p.error_node(); 29218 | } 29219 | else 29220 | result = p.expression_generator_.special_function(opt_type,branch); 29221 | 29222 | sd.delete_ptr = (0 == result); 29223 | 29224 | return result; 29225 | } 29226 | }; 29227 | 29228 | inline expression_node_ptr parse_special_function() 29229 | { 29230 | const std::string sf_name = current_token().value; 29231 | 29232 | // Expect: $fDD(expr0,expr1,expr2) or $fDD(expr0,expr1,expr2,expr3) 29233 | if ( 29234 | !details::is_digit(sf_name[2]) || 29235 | !details::is_digit(sf_name[3]) 29236 | ) 29237 | { 29238 | set_error(make_error( 29239 | parser_error::e_token, 29240 | current_token(), 29241 | "ERR149 - Invalid special function[1]: " + sf_name, 29242 | exprtk_error_location)); 29243 | 29244 | return error_node(); 29245 | } 29246 | 29247 | const int id = (sf_name[2] - '0') * 10 + 29248 | (sf_name[3] - '0'); 29249 | 29250 | if (id >= details::e_sffinal) 29251 | { 29252 | set_error(make_error( 29253 | parser_error::e_token, 29254 | current_token(), 29255 | "ERR150 - Invalid special function[2]: " + sf_name, 29256 | exprtk_error_location)); 29257 | 29258 | return error_node(); 29259 | } 29260 | 29261 | const int sf_3_to_4 = details::e_sf48; 29262 | const details::operator_type opt_type = details::operator_type(id + 1000); 29263 | const std::size_t NumberOfParameters = (id < (sf_3_to_4 - 1000)) ? 3U : 4U; 29264 | 29265 | switch (NumberOfParameters) 29266 | { 29267 | case 3 : return parse_special_function_impl<T,3>::process((*this), opt_type, sf_name); 29268 | case 4 : return parse_special_function_impl<T,4>::process((*this), opt_type, sf_name); 29269 | default : return error_node(); 29270 | } 29271 | } 29272 | 29273 | inline expression_node_ptr parse_null_statement() 29274 | { 29275 | next_token(); 29276 | return node_allocator_.allocate<details::null_node<T> >(); 29277 | } 29278 | 29279 | #ifndef exprtk_disable_break_continue 29280 | inline expression_node_ptr parse_break_statement() 29281 | { 29282 | if (state_.parsing_break_stmt) 29283 | { 29284 | set_error(make_error( 29285 | parser_error::e_syntax, 29286 | current_token(), 29287 | "ERR151 - Invoking 'break' within a break call is not allowed", 29288 | exprtk_error_location)); 29289 | 29290 | return error_node(); 29291 | } 29292 | else if (0 == state_.parsing_loop_stmt_count) 29293 | { 29294 | set_error(make_error( 29295 | parser_error::e_syntax, 29296 | current_token(), 29297 | "ERR152 - Invalid use of 'break', allowed only in the scope of a loop", 29298 | exprtk_error_location)); 29299 | 29300 | return error_node(); 29301 | } 29302 | 29303 | scoped_bool_negator sbn(state_.parsing_break_stmt); 29304 | 29305 | if (!brkcnt_list_.empty()) 29306 | { 29307 | next_token(); 29308 | 29309 | brkcnt_list_.front() = true; 29310 | 29311 | expression_node_ptr return_expr = error_node(); 29312 | 29313 | if (token_is(token_t::e_lsqrbracket)) 29314 | { 29315 | if (0 == (return_expr = parse_expression())) 29316 | { 29317 | set_error(make_error( 29318 | parser_error::e_syntax, 29319 | current_token(), 29320 | "ERR153 - Failed to parse return expression for 'break' statement", 29321 | exprtk_error_location)); 29322 | 29323 | return error_node(); 29324 | } 29325 | else if (!token_is(token_t::e_rsqrbracket)) 29326 | { 29327 | set_error(make_error( 29328 | parser_error::e_syntax, 29329 | current_token(), 29330 | "ERR154 - Expected ']' at the completion of break's return expression", 29331 | exprtk_error_location)); 29332 | 29333 | free_node(node_allocator_, return_expr); 29334 | 29335 | return error_node(); 29336 | } 29337 | } 29338 | 29339 | state_.activate_side_effect("parse_break_statement()"); 29340 | 29341 | return node_allocator_.allocate<details::break_node<T> >(return_expr); 29342 | } 29343 | else 29344 | { 29345 | set_error(make_error( 29346 | parser_error::e_syntax, 29347 | current_token(), 29348 | "ERR155 - Invalid use of 'break', allowed only in the scope of a loop", 29349 | exprtk_error_location)); 29350 | } 29351 | 29352 | return error_node(); 29353 | } 29354 | 29355 | inline expression_node_ptr parse_continue_statement() 29356 | { 29357 | if (0 == state_.parsing_loop_stmt_count) 29358 | { 29359 | set_error(make_error( 29360 | parser_error::e_syntax, 29361 | current_token(), 29362 | "ERR156 - Invalid use of 'continue', allowed only in the scope of a loop", 29363 | exprtk_error_location)); 29364 | 29365 | return error_node(); 29366 | } 29367 | else 29368 | { 29369 | next_token(); 29370 | 29371 | brkcnt_list_.front() = true; 29372 | state_.activate_side_effect("parse_continue_statement()"); 29373 | 29374 | return node_allocator_.allocate<details::continue_node<T> >(); 29375 | } 29376 | } 29377 | #endif 29378 | 29379 | inline expression_node_ptr parse_define_vector_statement(const std::string& vec_name) 29380 | { 29381 | expression_node_ptr size_expression_node = error_node(); 29382 | 29383 | if (!token_is(token_t::e_lsqrbracket)) 29384 | { 29385 | set_error(make_error( 29386 | parser_error::e_syntax, 29387 | current_token(), 29388 | "ERR157 - Expected '[' as part of vector size definition", 29389 | exprtk_error_location)); 29390 | 29391 | return error_node(); 29392 | } 29393 | else if (0 == (size_expression_node = parse_expression())) 29394 | { 29395 | set_error(make_error( 29396 | parser_error::e_syntax, 29397 | current_token(), 29398 | "ERR158 - Failed to determine size of vector '" + vec_name + "'", 29399 | exprtk_error_location)); 29400 | 29401 | return error_node(); 29402 | } 29403 | else if (!is_constant_node(size_expression_node)) 29404 | { 29405 | const bool is_rebaseble_vector = 29406 | (size_expression_node->type() == details::expression_node<T>::e_vecsize) && 29407 | static_cast<details::vector_size_node<T>*>(size_expression_node)->vec_holder()->rebaseable(); 29408 | 29409 | free_node(node_allocator_, size_expression_node); 29410 | 29411 | const std::string error_msg = (is_rebaseble_vector) ? 29412 | std::string("Rebasable/Resizable vector cannot be used to define the size of vector") : 29413 | std::string("Expected a constant literal number as size of vector"); 29414 | set_error(make_error( 29415 | parser_error::e_syntax, 29416 | current_token(), 29417 | "ERR159 - " + error_msg + " '" + vec_name + "'", 29418 | exprtk_error_location)); 29419 | 29420 | return error_node(); 29421 | } 29422 | 29423 | const T vector_size = size_expression_node->value(); 29424 | 29425 | free_node(node_allocator_, size_expression_node); 29426 | 29427 | const std::size_t max_vector_size = settings_.max_local_vector_size(); 29428 | 29429 | if ( 29430 | (vector_size <= T(0)) || 29431 | std::not_equal_to<T>() 29432 | (T(0),vector_size - details::numeric::trunc(vector_size)) || 29433 | (static_cast<std::size_t>(vector_size) > max_vector_size) 29434 | ) 29435 | { 29436 | set_error(make_error( 29437 | parser_error::e_syntax, 29438 | current_token(), 29439 | "ERR160 - Invalid vector size. Must be an integer in the " 29440 | "range [0," + details::to_str(static_cast<std::size_t>(max_vector_size)) + "], size: " + 29441 | details::to_str(details::numeric::to_int32(vector_size)), 29442 | exprtk_error_location)); 29443 | 29444 | return error_node(); 29445 | } 29446 | 29447 | typename symbol_table_t::vector_holder_ptr vec_holder = typename symbol_table_t::vector_holder_ptr(0); 29448 | 29449 | const std::size_t vec_size = static_cast<std::size_t>(details::numeric::to_int32(vector_size)); 29450 | const std::size_t predicted_total_lclsymb_size = sizeof(T) * vec_size + sem_.total_local_symb_size_bytes(); 29451 | 29452 | if (predicted_total_lclsymb_size > settings().max_total_local_symbol_size_bytes()) 29453 | { 29454 | set_error(make_error( 29455 | parser_error::e_syntax, 29456 | current_token(), 29457 | "ERR161 - Adding vector '" + vec_name + "' of size " + details::to_str(vec_size) + " bytes " 29458 | "will exceed max total local symbol size of: " + details::to_str(settings().max_total_local_symbol_size_bytes()) + " bytes, " 29459 | "current total size: " + details::to_str(sem_.total_local_symb_size_bytes()) + " bytes", 29460 | exprtk_error_location)); 29461 | 29462 | return error_node(); 29463 | } 29464 | 29465 | scope_element& se = sem_.get_element(vec_name); 29466 | 29467 | if (se.name == vec_name) 29468 | { 29469 | if (se.active) 29470 | { 29471 | set_error(make_error( 29472 | parser_error::e_syntax, 29473 | current_token(), 29474 | "ERR162 - Illegal redefinition of local vector: '" + vec_name + "'", 29475 | exprtk_error_location)); 29476 | 29477 | return error_node(); 29478 | } 29479 | else if ( 29480 | (se.size == vec_size) && 29481 | (scope_element::e_vector == se.type) 29482 | ) 29483 | { 29484 | vec_holder = se.vec_node; 29485 | se.active = true; 29486 | se.depth = state_.scope_depth; 29487 | se.ref_count++; 29488 | } 29489 | } 29490 | 29491 | if (0 == vec_holder) 29492 | { 29493 | scope_element nse; 29494 | nse.name = vec_name; 29495 | nse.active = true; 29496 | nse.ref_count = 1; 29497 | nse.type = scope_element::e_vector; 29498 | nse.depth = state_.scope_depth; 29499 | nse.size = vec_size; 29500 | nse.data = new T[vec_size]; 29501 | nse.vec_node = new typename scope_element::vector_holder_t(reinterpret_cast<T*>(nse.data),nse.size); 29502 | 29503 | details::set_zero_value(reinterpret_cast<T*>(nse.data),vec_size); 29504 | 29505 | if (!sem_.add_element(nse)) 29506 | { 29507 | set_error(make_error( 29508 | parser_error::e_syntax, 29509 | current_token(), 29510 | "ERR163 - Failed to add new local vector '" + vec_name + "' to SEM", 29511 | exprtk_error_location)); 29512 | 29513 | sem_.free_element(nse); 29514 | 29515 | return error_node(); 29516 | } 29517 | 29518 | assert(sem_.total_local_symb_size_bytes() <= settings().max_total_local_symbol_size_bytes()); 29519 | 29520 | vec_holder = nse.vec_node; 29521 | 29522 | exprtk_debug(("parse_define_vector_statement() - INFO - Added new local vector: %s[%d]\n", 29523 | nse.name.c_str(), 29524 | static_cast<int>(nse.size))); 29525 | } 29526 | 29527 | state_.activate_side_effect("parse_define_vector_statement()"); 29528 | 29529 | lodge_symbol(vec_name, e_st_local_vector); 29530 | 29531 | std::vector<expression_node_ptr> vec_initilizer_list; 29532 | 29533 | scoped_vec_delete<expression_node_t> svd((*this), vec_initilizer_list); 29534 | 29535 | bool single_value_initialiser = false; 29536 | bool range_value_initialiser = false; 29537 | bool vec_to_vec_initialiser = false; 29538 | bool null_initialisation = false; 29539 | 29540 | if (!token_is(token_t::e_rsqrbracket)) 29541 | { 29542 | set_error(make_error( 29543 | parser_error::e_syntax, 29544 | current_token(), 29545 | "ERR164 - Expected ']' as part of vector size definition", 29546 | exprtk_error_location)); 29547 | 29548 | return error_node(); 29549 | } 29550 | else if (!token_is(token_t::e_eof, prsrhlpr_t::e_hold)) 29551 | { 29552 | if (!token_is(token_t::e_assign)) 29553 | { 29554 | set_error(make_error( 29555 | parser_error::e_syntax, 29556 | current_token(), 29557 | "ERR165 - Expected ':=' as part of vector definition", 29558 | exprtk_error_location)); 29559 | 29560 | return error_node(); 29561 | } 29562 | else if (token_is(token_t::e_lsqrbracket)) 29563 | { 29564 | expression_node_ptr initialiser_component = parse_expression(); 29565 | 29566 | if (0 == initialiser_component) 29567 | { 29568 | set_error(make_error( 29569 | parser_error::e_syntax, 29570 | current_token(), 29571 | "ERR166 - Failed to parse first component of vector initialiser for vector: " + vec_name, 29572 | exprtk_error_location)); 29573 | 29574 | return error_node(); 29575 | } 29576 | 29577 | vec_initilizer_list.push_back(initialiser_component); 29578 | 29579 | if (token_is(token_t::e_colon)) 29580 | { 29581 | initialiser_component = parse_expression(); 29582 | 29583 | if (0 == initialiser_component) 29584 | { 29585 | set_error(make_error( 29586 | parser_error::e_syntax, 29587 | current_token(), 29588 | "ERR167 - Failed to parse second component of vector initialiser for vector: " + vec_name, 29589 | exprtk_error_location)); 29590 | 29591 | return error_node(); 29592 | } 29593 | 29594 | vec_initilizer_list.push_back(initialiser_component); 29595 | } 29596 | 29597 | if (!token_is(token_t::e_rsqrbracket)) 29598 | { 29599 | set_error(make_error( 29600 | parser_error::e_syntax, 29601 | current_token(), 29602 | "ERR168 - Expected ']' to close single value vector initialiser", 29603 | exprtk_error_location)); 29604 | 29605 | return error_node(); 29606 | } 29607 | 29608 | switch (vec_initilizer_list.size()) 29609 | { 29610 | case 1 : single_value_initialiser = true; break; 29611 | case 2 : range_value_initialiser = true; break; 29612 | } 29613 | } 29614 | else if (!token_is(token_t::e_lcrlbracket)) 29615 | { 29616 | expression_node_ptr initialiser = error_node(); 29617 | 29618 | // Is this a vector to vector assignment and initialisation? 29619 | if (token_t::e_symbol == current_token().type) 29620 | { 29621 | // Is it a locally defined vector? 29622 | const scope_element& lcl_se = sem_.get_active_element(current_token().value); 29623 | 29624 | if (scope_element::e_vector == lcl_se.type) 29625 | { 29626 | if (0 != (initialiser = parse_expression())) 29627 | vec_initilizer_list.push_back(initialiser); 29628 | else 29629 | return error_node(); 29630 | } 29631 | // Are we dealing with a user defined vector? 29632 | else if (symtab_store_.is_vector(current_token().value)) 29633 | { 29634 | lodge_symbol(current_token().value, e_st_vector); 29635 | 29636 | if (0 != (initialiser = parse_expression())) 29637 | vec_initilizer_list.push_back(initialiser); 29638 | else 29639 | return error_node(); 29640 | } 29641 | // Are we dealing with a null initialisation vector definition? 29642 | else if (token_is(token_t::e_symbol,"null")) 29643 | null_initialisation = true; 29644 | } 29645 | 29646 | if (!null_initialisation) 29647 | { 29648 | if (0 == initialiser) 29649 | { 29650 | set_error(make_error( 29651 | parser_error::e_syntax, 29652 | current_token(), 29653 | "ERR169 - Expected '{' as part of vector initialiser list", 29654 | exprtk_error_location)); 29655 | 29656 | return error_node(); 29657 | } 29658 | else 29659 | vec_to_vec_initialiser = true; 29660 | } 29661 | } 29662 | else if (!token_is(token_t::e_rcrlbracket)) 29663 | { 29664 | for ( ; ; ) 29665 | { 29666 | expression_node_ptr initialiser = parse_expression(); 29667 | 29668 | if (0 == initialiser) 29669 | { 29670 | set_error(make_error( 29671 | parser_error::e_syntax, 29672 | current_token(), 29673 | "ERR170 - Expected '{' as part of vector initialiser list", 29674 | exprtk_error_location)); 29675 | 29676 | return error_node(); 29677 | } 29678 | else 29679 | vec_initilizer_list.push_back(initialiser); 29680 | 29681 | if (token_is(token_t::e_rcrlbracket)) 29682 | break; 29683 | 29684 | const bool is_next_close = peek_token_is(token_t::e_rcrlbracket); 29685 | 29686 | if (!token_is(token_t::e_comma) && is_next_close) 29687 | { 29688 | set_error(make_error( 29689 | parser_error::e_syntax, 29690 | current_token(), 29691 | "ERR171 - Expected ',' between vector initialisers", 29692 | exprtk_error_location)); 29693 | 29694 | return error_node(); 29695 | } 29696 | 29697 | if (token_is(token_t::e_rcrlbracket)) 29698 | break; 29699 | } 29700 | } 29701 | 29702 | if ( 29703 | !token_is(token_t::e_rbracket , prsrhlpr_t::e_hold) && 29704 | !token_is(token_t::e_rcrlbracket, prsrhlpr_t::e_hold) && 29705 | !token_is(token_t::e_rsqrbracket, prsrhlpr_t::e_hold) 29706 | ) 29707 | { 29708 | if (!token_is(token_t::e_eof,prsrhlpr_t::e_hold)) 29709 | { 29710 | set_error(make_error( 29711 | parser_error::e_syntax, 29712 | current_token(), 29713 | "ERR172 - Expected ';' at end of vector definition", 29714 | exprtk_error_location)); 29715 | 29716 | return error_node(); 29717 | } 29718 | } 29719 | 29720 | if ( 29721 | !single_value_initialiser && 29722 | !range_value_initialiser && 29723 | (T(vec_initilizer_list.size()) > vector_size) 29724 | ) 29725 | { 29726 | set_error(make_error( 29727 | parser_error::e_syntax, 29728 | current_token(), 29729 | "ERR173 - Initialiser list larger than the number of elements in the vector: '" + vec_name + "'", 29730 | exprtk_error_location)); 29731 | 29732 | return error_node(); 29733 | } 29734 | } 29735 | 29736 | expression_node_ptr result = error_node(); 29737 | 29738 | if ( 29739 | (vec_initilizer_list.size() == 1) && 29740 | single_value_initialiser 29741 | ) 29742 | { 29743 | if (details::is_constant_node(vec_initilizer_list[0])) 29744 | { 29745 | // vector_init_zero_value_node var v[10] := [0] 29746 | if (T(0) == vec_initilizer_list[0]->value()) 29747 | { 29748 | result = node_allocator_ 29749 | .allocate<details::vector_init_zero_value_node<T> >( 29750 | (*vec_holder)[0], 29751 | vec_size, 29752 | vec_initilizer_list); 29753 | } 29754 | else 29755 | { 29756 | // vector_init_single_constvalue_node var v[10] := [123] 29757 | result = node_allocator_ 29758 | .allocate<details::vector_init_single_constvalue_node<T> >( 29759 | (*vec_holder)[0], 29760 | vec_size, 29761 | vec_initilizer_list); 29762 | } 29763 | } 29764 | else 29765 | { 29766 | // vector_init_single_value_node var v[10] := [123 + (x / y)] 29767 | result = node_allocator_ 29768 | .allocate<details::vector_init_single_value_node<T> >( 29769 | (*vec_holder)[0], 29770 | vec_size, 29771 | vec_initilizer_list); 29772 | } 29773 | } 29774 | else if ( 29775 | (vec_initilizer_list.size() == 2) && 29776 | range_value_initialiser 29777 | ) 29778 | { 29779 | bool base_const = details::is_constant_node(vec_initilizer_list[0]); 29780 | bool inc_const = details::is_constant_node(vec_initilizer_list[1]); 29781 | 29782 | if (base_const && inc_const) 29783 | { 29784 | // vector_init_single_value_node var v[10] := [1 : 3.5] 29785 | result = node_allocator_ 29786 | .allocate<details::vector_init_iota_constconst_node<T> >( 29787 | (*vec_holder)[0], 29788 | vec_size, 29789 | vec_initilizer_list); 29790 | } 29791 | else if (base_const && !inc_const) 29792 | { 29793 | // vector_init_single_value_node var v[10] := [1 : x + y] 29794 | result = node_allocator_ 29795 | .allocate<details::vector_init_iota_constnconst_node<T> >( 29796 | (*vec_holder)[0], 29797 | vec_size, 29798 | vec_initilizer_list); 29799 | } 29800 | else if (!base_const && inc_const) 29801 | { 29802 | // vector_init_single_value_node var v[10] := [x + y : 3] 29803 | result = node_allocator_ 29804 | .allocate<details::vector_init_iota_nconstconst_node<T> >( 29805 | (*vec_holder)[0], 29806 | vec_size, 29807 | vec_initilizer_list); 29808 | } 29809 | else if (!base_const && !inc_const) 29810 | { 29811 | // vector_init_single_value_node var v[10] := [x + y : z / w] 29812 | result = node_allocator_ 29813 | .allocate<details::vector_init_iota_nconstnconst_node<T> >( 29814 | (*vec_holder)[0], 29815 | vec_size, 29816 | vec_initilizer_list); 29817 | } 29818 | } 29819 | else if (null_initialisation) 29820 | result = expression_generator_(T(0.0)); 29821 | else if (vec_to_vec_initialiser) 29822 | { 29823 | expression_node_ptr vec_node = node_allocator_.allocate<vector_node_t>(vec_holder); 29824 | 29825 | result = expression_generator_( 29826 | details::e_assign, 29827 | vec_node, 29828 | vec_initilizer_list[0]); 29829 | } 29830 | else 29831 | { 29832 | result = node_allocator_ 29833 | .allocate<details::vector_initialisation_node<T> >( 29834 | (*vec_holder)[0], 29835 | vec_size, 29836 | vec_initilizer_list, 29837 | single_value_initialiser); 29838 | } 29839 | 29840 | svd.delete_ptr = false; 29841 | 29842 | if (result && result->valid()) 29843 | { 29844 | return result; 29845 | } 29846 | 29847 | details::free_node(node_allocator_, result); 29848 | 29849 | set_error(make_error( 29850 | parser_error::e_synthesis, 29851 | current_token(), 29852 | "ERR174 - Failed to generate initialisation node for vector: " + vec_name, 29853 | exprtk_error_location)); 29854 | 29855 | return error_node(); 29856 | } 29857 | 29858 | #ifndef exprtk_disable_string_capabilities 29859 | inline expression_node_ptr parse_define_string_statement(const std::string& str_name, expression_node_ptr initialisation_expression) 29860 | { 29861 | stringvar_node_t* str_node = reinterpret_cast<stringvar_node_t*>(0); 29862 | 29863 | scope_element& se = sem_.get_element(str_name); 29864 | 29865 | if (se.name == str_name) 29866 | { 29867 | if (se.active) 29868 | { 29869 | set_error(make_error( 29870 | parser_error::e_syntax, 29871 | current_token(), 29872 | "ERR175 - Illegal redefinition of local variable: '" + str_name + "'", 29873 | exprtk_error_location)); 29874 | 29875 | free_node(node_allocator_, initialisation_expression); 29876 | 29877 | return error_node(); 29878 | } 29879 | else if (scope_element::e_string == se.type) 29880 | { 29881 | str_node = se.str_node; 29882 | se.active = true; 29883 | se.depth = state_.scope_depth; 29884 | se.ref_count++; 29885 | } 29886 | } 29887 | 29888 | if (0 == str_node) 29889 | { 29890 | scope_element nse; 29891 | nse.name = str_name; 29892 | nse.active = true; 29893 | nse.ref_count = 1; 29894 | nse.type = scope_element::e_string; 29895 | nse.depth = state_.scope_depth; 29896 | nse.data = new std::string; 29897 | nse.str_node = new stringvar_node_t(*reinterpret_cast<std::string*>(nse.data)); 29898 | 29899 | if (!sem_.add_element(nse)) 29900 | { 29901 | set_error(make_error( 29902 | parser_error::e_syntax, 29903 | current_token(), 29904 | "ERR176 - Failed to add new local string variable '" + str_name + "' to SEM", 29905 | exprtk_error_location)); 29906 | 29907 | free_node(node_allocator_, initialisation_expression); 29908 | 29909 | sem_.free_element(nse); 29910 | 29911 | return error_node(); 29912 | } 29913 | 29914 | assert(sem_.total_local_symb_size_bytes() <= settings().max_total_local_symbol_size_bytes()); 29915 | 29916 | str_node = nse.str_node; 29917 | 29918 | exprtk_debug(("parse_define_string_statement() - INFO - Added new local string variable: %s\n", nse.name.c_str())); 29919 | } 29920 | 29921 | lodge_symbol(str_name, e_st_local_string); 29922 | 29923 | state_.activate_side_effect("parse_define_string_statement()"); 29924 | 29925 | expression_node_ptr branch[2] = {0}; 29926 | 29927 | branch[0] = str_node; 29928 | branch[1] = initialisation_expression; 29929 | 29930 | return expression_generator_(details::e_assign,branch); 29931 | } 29932 | #else 29933 | inline expression_node_ptr parse_define_string_statement(const std::string&, expression_node_ptr) 29934 | { 29935 | return error_node(); 29936 | } 29937 | #endif 29938 | 29939 | inline bool local_variable_is_shadowed(const std::string& symbol) 29940 | { 29941 | const scope_element& se = sem_.get_element(symbol); 29942 | return (se.name == symbol) && se.active; 29943 | } 29944 | 29945 | inline expression_node_ptr parse_define_var_statement() 29946 | { 29947 | if (settings_.vardef_disabled()) 29948 | { 29949 | set_error(make_error( 29950 | parser_error::e_syntax, 29951 | current_token(), 29952 | "ERR177 - Illegal variable definition", 29953 | exprtk_error_location)); 29954 | 29955 | return error_node(); 29956 | } 29957 | else if (!details::imatch(current_token().value,"var")) 29958 | { 29959 | return error_node(); 29960 | } 29961 | else 29962 | next_token(); 29963 | 29964 | const std::string var_name = current_token().value; 29965 | 29966 | expression_node_ptr initialisation_expression = error_node(); 29967 | 29968 | if (!token_is(token_t::e_symbol)) 29969 | { 29970 | set_error(make_error( 29971 | parser_error::e_syntax, 29972 | current_token(), 29973 | "ERR178 - Expected a symbol for variable definition", 29974 | exprtk_error_location)); 29975 | 29976 | return error_node(); 29977 | } 29978 | else if (details::is_reserved_symbol(var_name)) 29979 | { 29980 | set_error(make_error( 29981 | parser_error::e_syntax, 29982 | current_token(), 29983 | "ERR179 - Illegal redefinition of reserved keyword: '" + var_name + "'", 29984 | exprtk_error_location)); 29985 | 29986 | return error_node(); 29987 | } 29988 | else if (symtab_store_.symbol_exists(var_name)) 29989 | { 29990 | set_error(make_error( 29991 | parser_error::e_syntax, 29992 | current_token(), 29993 | "ERR180 - Illegal redefinition of variable '" + var_name + "'", 29994 | exprtk_error_location)); 29995 | 29996 | return error_node(); 29997 | } 29998 | else if (local_variable_is_shadowed(var_name)) 29999 | { 30000 | set_error(make_error( 30001 | parser_error::e_syntax, 30002 | current_token(), 30003 | "ERR181 - Illegal redefinition of local variable: '" + var_name + "'", 30004 | exprtk_error_location)); 30005 | 30006 | return error_node(); 30007 | } 30008 | else if (token_is(token_t::e_lsqrbracket,prsrhlpr_t::e_hold)) 30009 | { 30010 | return parse_define_vector_statement(var_name); 30011 | } 30012 | else if (token_is(token_t::e_lcrlbracket,prsrhlpr_t::e_hold)) 30013 | { 30014 | return parse_uninitialised_var_statement(var_name); 30015 | } 30016 | else if (token_is(token_t::e_assign)) 30017 | { 30018 | if (0 == (initialisation_expression = parse_expression())) 30019 | { 30020 | set_error(make_error( 30021 | parser_error::e_syntax, 30022 | current_token(), 30023 | "ERR182 - Failed to parse initialisation expression for variable '" + var_name + "'", 30024 | exprtk_error_location)); 30025 | 30026 | return error_node(); 30027 | } 30028 | } 30029 | 30030 | if ( 30031 | !token_is(token_t::e_rbracket , prsrhlpr_t::e_hold) && 30032 | !token_is(token_t::e_rcrlbracket, prsrhlpr_t::e_hold) && 30033 | !token_is(token_t::e_rsqrbracket, prsrhlpr_t::e_hold) 30034 | ) 30035 | { 30036 | if (!token_is(token_t::e_eof,prsrhlpr_t::e_hold)) 30037 | { 30038 | set_error(make_error( 30039 | parser_error::e_syntax, 30040 | current_token(), 30041 | "ERR183 - Expected ';' after variable '" + var_name + "' definition", 30042 | exprtk_error_location)); 30043 | 30044 | free_node(node_allocator_, initialisation_expression); 30045 | 30046 | return error_node(); 30047 | } 30048 | } 30049 | 30050 | if ( 30051 | (0 != initialisation_expression) && 30052 | details::is_generally_string_node(initialisation_expression) 30053 | ) 30054 | { 30055 | return parse_define_string_statement(var_name,initialisation_expression); 30056 | } 30057 | 30058 | expression_node_ptr var_node = reinterpret_cast<expression_node_ptr>(0); 30059 | 30060 | scope_element& se = sem_.get_element(var_name); 30061 | 30062 | if (se.name == var_name) 30063 | { 30064 | if (se.active) 30065 | { 30066 | set_error(make_error( 30067 | parser_error::e_syntax, 30068 | current_token(), 30069 | "ERR184 - Illegal redefinition of local variable: '" + var_name + "'", 30070 | exprtk_error_location)); 30071 | 30072 | free_node(node_allocator_, initialisation_expression); 30073 | 30074 | return error_node(); 30075 | } 30076 | else if (scope_element::e_variable == se.type) 30077 | { 30078 | var_node = se.var_node; 30079 | se.active = true; 30080 | se.depth = state_.scope_depth; 30081 | se.ref_count++; 30082 | } 30083 | } 30084 | 30085 | if (0 == var_node) 30086 | { 30087 | const std::size_t predicted_total_lclsymb_size = sizeof(T) + sem_.total_local_symb_size_bytes(); 30088 | 30089 | if (predicted_total_lclsymb_size > settings().max_total_local_symbol_size_bytes()) 30090 | { 30091 | set_error(make_error( 30092 | parser_error::e_syntax, 30093 | current_token(), 30094 | "ERR185 - Adding variable '" + var_name + "' " 30095 | "will exceed max total local symbol size of: " + details::to_str(settings().max_total_local_symbol_size_bytes()) + " bytes, " 30096 | "current total size: " + details::to_str(sem_.total_local_symb_size_bytes()) + " bytes", 30097 | exprtk_error_location)); 30098 | 30099 | free_node(node_allocator_, initialisation_expression); 30100 | 30101 | return error_node(); 30102 | } 30103 | 30104 | scope_element nse; 30105 | nse.name = var_name; 30106 | nse.active = true; 30107 | nse.ref_count = 1; 30108 | nse.type = scope_element::e_variable; 30109 | nse.depth = state_.scope_depth; 30110 | nse.data = new T(T(0)); 30111 | nse.var_node = node_allocator_.allocate<variable_node_t>(*reinterpret_cast<T*>(nse.data)); 30112 | 30113 | if (!sem_.add_element(nse)) 30114 | { 30115 | set_error(make_error( 30116 | parser_error::e_syntax, 30117 | current_token(), 30118 | "ERR186 - Failed to add new local variable '" + var_name + "' to SEM", 30119 | exprtk_error_location)); 30120 | 30121 | free_node(node_allocator_, initialisation_expression); 30122 | 30123 | sem_.free_element(nse); 30124 | 30125 | return error_node(); 30126 | } 30127 | 30128 | assert(sem_.total_local_symb_size_bytes() <= settings().max_total_local_symbol_size_bytes()); 30129 | 30130 | var_node = nse.var_node; 30131 | 30132 | exprtk_debug(("parse_define_var_statement() - INFO - Added new local variable: %s\n", nse.name.c_str())); 30133 | } 30134 | 30135 | state_.activate_side_effect("parse_define_var_statement()"); 30136 | 30137 | lodge_symbol(var_name, e_st_local_variable); 30138 | 30139 | expression_node_ptr branch[2] = {0}; 30140 | 30141 | branch[0] = var_node; 30142 | branch[1] = initialisation_expression ? initialisation_expression : expression_generator_(T(0)); 30143 | 30144 | return expression_generator_(details::e_assign,branch); 30145 | } 30146 | 30147 | inline expression_node_ptr parse_define_constvar_statement() 30148 | { 30149 | if (settings_.vardef_disabled()) 30150 | { 30151 | set_error(make_error( 30152 | parser_error::e_syntax, 30153 | current_token(), 30154 | "ERR187 - Illegal const variable definition", 30155 | exprtk_error_location)); 30156 | 30157 | return error_node(); 30158 | } 30159 | else if (!token_is("const")) 30160 | { 30161 | set_error(make_error( 30162 | parser_error::e_syntax, 30163 | current_token(), 30164 | "ERR188 - Expected 'const' keyword for const-variable definition", 30165 | exprtk_error_location)); 30166 | 30167 | return error_node(); 30168 | } 30169 | else if (!token_is("var")) 30170 | { 30171 | set_error(make_error( 30172 | parser_error::e_syntax, 30173 | current_token(), 30174 | "ERR189 - Expected 'var' keyword for const-variable definition", 30175 | exprtk_error_location)); 30176 | 30177 | return error_node(); 30178 | } 30179 | 30180 | const std::string var_name = current_token().value; 30181 | 30182 | expression_node_ptr initialisation_expression = error_node(); 30183 | 30184 | if (!token_is(token_t::e_symbol)) 30185 | { 30186 | set_error(make_error( 30187 | parser_error::e_syntax, 30188 | current_token(), 30189 | "ERR190 - Expected a symbol for const-variable definition", 30190 | exprtk_error_location)); 30191 | 30192 | return error_node(); 30193 | } 30194 | else if (details::is_reserved_symbol(var_name)) 30195 | { 30196 | set_error(make_error( 30197 | parser_error::e_syntax, 30198 | current_token(), 30199 | "ERR191 - Illegal redefinition of reserved keyword: '" + var_name + "'", 30200 | exprtk_error_location)); 30201 | 30202 | return error_node(); 30203 | } 30204 | else if (symtab_store_.symbol_exists(var_name)) 30205 | { 30206 | set_error(make_error( 30207 | parser_error::e_syntax, 30208 | current_token(), 30209 | "ERR192 - Illegal redefinition of variable '" + var_name + "'", 30210 | exprtk_error_location)); 30211 | 30212 | return error_node(); 30213 | } 30214 | else if (local_variable_is_shadowed(var_name)) 30215 | { 30216 | set_error(make_error( 30217 | parser_error::e_syntax, 30218 | current_token(), 30219 | "ERR193 - Illegal redefinition of local variable: '" + var_name + "'", 30220 | exprtk_error_location)); 30221 | 30222 | return error_node(); 30223 | } 30224 | else if (!token_is(token_t::e_assign)) 30225 | { 30226 | set_error(make_error( 30227 | parser_error::e_syntax, 30228 | current_token(), 30229 | "ERR194 - Expected assignment operator after const-variable: '" + var_name + "' definition", 30230 | exprtk_error_location)); 30231 | 30232 | return error_node(); 30233 | } 30234 | else if (0 == (initialisation_expression = parse_expression())) 30235 | { 30236 | set_error(make_error( 30237 | parser_error::e_syntax, 30238 | current_token(), 30239 | "ERR195 - Failed to parse initialisation expression for const-variable: '" + var_name + "'", 30240 | exprtk_error_location)); 30241 | 30242 | return error_node(); 30243 | } 30244 | 30245 | if (!details::is_literal_node(initialisation_expression)) 30246 | { 30247 | set_error(make_error( 30248 | parser_error::e_syntax, 30249 | current_token(), 30250 | "ERR196 - initialisation expression for const-variable: '" + var_name + "' must be a constant/literal", 30251 | exprtk_error_location)); 30252 | 30253 | free_node(node_allocator_, initialisation_expression); 30254 | 30255 | return error_node(); 30256 | } 30257 | 30258 | assert(initialisation_expression); 30259 | 30260 | const T init_value = initialisation_expression->value(); 30261 | 30262 | free_node(node_allocator_, initialisation_expression); 30263 | 30264 | expression_node_ptr var_node = reinterpret_cast<expression_node_ptr>(0); 30265 | 30266 | scope_element& se = sem_.get_element(var_name); 30267 | 30268 | if (se.name == var_name) 30269 | { 30270 | if (se.active) 30271 | { 30272 | set_error(make_error( 30273 | parser_error::e_syntax, 30274 | current_token(), 30275 | "ERR197 - Illegal redefinition of local variable: '" + var_name + "'", 30276 | exprtk_error_location)); 30277 | 30278 | return error_node(); 30279 | } 30280 | else if (scope_element::e_literal == se.type) 30281 | { 30282 | var_node = se.var_node; 30283 | se.active = true; 30284 | se.depth = state_.scope_depth; 30285 | se.ref_count++; 30286 | } 30287 | } 30288 | 30289 | if (0 == var_node) 30290 | { 30291 | const std::size_t predicted_total_lclsymb_size = sizeof(T) + sem_.total_local_symb_size_bytes(); 30292 | 30293 | if (predicted_total_lclsymb_size > settings().max_total_local_symbol_size_bytes()) 30294 | { 30295 | set_error(make_error( 30296 | parser_error::e_syntax, 30297 | current_token(), 30298 | "ERR198 - Adding variable '" + var_name + "' " 30299 | "will exceed max total local symbol size of: " + details::to_str(settings().max_total_local_symbol_size_bytes()) + " bytes, " 30300 | "current total size: " + details::to_str(sem_.total_local_symb_size_bytes()) + " bytes", 30301 | exprtk_error_location)); 30302 | 30303 | return error_node(); 30304 | } 30305 | 30306 | scope_element nse; 30307 | nse.name = var_name; 30308 | nse.active = true; 30309 | nse.ref_count = 1; 30310 | nse.type = scope_element::e_literal; 30311 | nse.depth = state_.scope_depth; 30312 | nse.data = 0; 30313 | nse.var_node = node_allocator_.allocate<literal_node_t>(init_value); 30314 | 30315 | if (!sem_.add_element(nse)) 30316 | { 30317 | set_error(make_error( 30318 | parser_error::e_syntax, 30319 | current_token(), 30320 | "ERR199 - Failed to add new local const-variable '" + var_name + "' to SEM", 30321 | exprtk_error_location)); 30322 | 30323 | sem_.free_element(nse); 30324 | 30325 | return error_node(); 30326 | } 30327 | 30328 | assert(sem_.total_local_symb_size_bytes() <= settings().max_total_local_symbol_size_bytes()); 30329 | 30330 | var_node = nse.var_node; 30331 | 30332 | exprtk_debug(("parse_define_constvar_statement() - INFO - Added new local const-variable: %s\n", nse.name.c_str())); 30333 | } 30334 | 30335 | state_.activate_side_effect("parse_define_constvar_statement()"); 30336 | 30337 | lodge_symbol(var_name, e_st_local_variable); 30338 | 30339 | return expression_generator_(var_node->value()); 30340 | } 30341 | 30342 | inline expression_node_ptr parse_uninitialised_var_statement(const std::string& var_name) 30343 | { 30344 | if ( 30345 | !token_is(token_t::e_lcrlbracket) || 30346 | !token_is(token_t::e_rcrlbracket) 30347 | ) 30348 | { 30349 | set_error(make_error( 30350 | parser_error::e_syntax, 30351 | current_token(), 30352 | "ERR200 - Expected a '{}' for uninitialised var definition", 30353 | exprtk_error_location)); 30354 | 30355 | return error_node(); 30356 | } 30357 | else if (!token_is(token_t::e_eof,prsrhlpr_t::e_hold)) 30358 | { 30359 | set_error(make_error( 30360 | parser_error::e_syntax, 30361 | current_token(), 30362 | "ERR201 - Expected ';' after uninitialised variable definition", 30363 | exprtk_error_location)); 30364 | 30365 | return error_node(); 30366 | } 30367 | 30368 | expression_node_ptr var_node = reinterpret_cast<expression_node_ptr>(0); 30369 | 30370 | scope_element& se = sem_.get_element(var_name); 30371 | 30372 | if (se.name == var_name) 30373 | { 30374 | if (se.active) 30375 | { 30376 | set_error(make_error( 30377 | parser_error::e_syntax, 30378 | current_token(), 30379 | "ERR202 - Illegal redefinition of local variable: '" + var_name + "'", 30380 | exprtk_error_location)); 30381 | 30382 | return error_node(); 30383 | } 30384 | else if (scope_element::e_variable == se.type) 30385 | { 30386 | var_node = se.var_node; 30387 | se.active = true; 30388 | se.ref_count++; 30389 | } 30390 | } 30391 | 30392 | if (0 == var_node) 30393 | { 30394 | const std::size_t predicted_total_lclsymb_size = sizeof(T) + sem_.total_local_symb_size_bytes(); 30395 | 30396 | if (predicted_total_lclsymb_size > settings().max_total_local_symbol_size_bytes()) 30397 | { 30398 | set_error(make_error( 30399 | parser_error::e_syntax, 30400 | current_token(), 30401 | "ERR203 - Adding variable '" + var_name + "' " 30402 | "will exceed max total local symbol size of: " + details::to_str(settings().max_total_local_symbol_size_bytes()) + " bytes, " 30403 | "current total size: " + details::to_str(sem_.total_local_symb_size_bytes()) + " bytes", 30404 | exprtk_error_location)); 30405 | 30406 | return error_node(); 30407 | } 30408 | 30409 | scope_element nse; 30410 | nse.name = var_name; 30411 | nse.active = true; 30412 | nse.ref_count = 1; 30413 | nse.type = scope_element::e_variable; 30414 | nse.depth = state_.scope_depth; 30415 | nse.ip_index = sem_.next_ip_index(); 30416 | nse.data = new T(T(0)); 30417 | nse.var_node = node_allocator_.allocate<variable_node_t>(*reinterpret_cast<T*>(nse.data)); 30418 | 30419 | if (!sem_.add_element(nse)) 30420 | { 30421 | set_error(make_error( 30422 | parser_error::e_syntax, 30423 | current_token(), 30424 | "ERR204 - Failed to add new local variable '" + var_name + "' to SEM", 30425 | exprtk_error_location)); 30426 | 30427 | sem_.free_element(nse); 30428 | 30429 | return error_node(); 30430 | } 30431 | 30432 | assert(sem_.total_local_symb_size_bytes() <= settings().max_total_local_symbol_size_bytes()); 30433 | 30434 | exprtk_debug(("parse_uninitialised_var_statement() - INFO - Added new local variable: %s\n", 30435 | nse.name.c_str())); 30436 | } 30437 | 30438 | lodge_symbol(var_name, e_st_local_variable); 30439 | 30440 | state_.activate_side_effect("parse_uninitialised_var_statement()"); 30441 | 30442 | return expression_generator_(T(0)); 30443 | } 30444 | 30445 | inline expression_node_ptr parse_swap_statement() 30446 | { 30447 | if (!details::imatch(current_token().value,"swap")) 30448 | { 30449 | return error_node(); 30450 | } 30451 | else 30452 | next_token(); 30453 | 30454 | if (!token_is(token_t::e_lbracket)) 30455 | { 30456 | set_error(make_error( 30457 | parser_error::e_syntax, 30458 | current_token(), 30459 | "ERR205 - Expected '(' at start of swap statement", 30460 | exprtk_error_location)); 30461 | 30462 | return error_node(); 30463 | } 30464 | 30465 | expression_node_ptr variable0 = error_node(); 30466 | expression_node_ptr variable1 = error_node(); 30467 | 30468 | bool variable0_generated = false; 30469 | bool variable1_generated = false; 30470 | 30471 | const std::string var0_name = current_token().value; 30472 | 30473 | if (!token_is(token_t::e_symbol,prsrhlpr_t::e_hold)) 30474 | { 30475 | set_error(make_error( 30476 | parser_error::e_syntax, 30477 | current_token(), 30478 | "ERR206 - Expected a symbol for variable or vector element definition", 30479 | exprtk_error_location)); 30480 | 30481 | return error_node(); 30482 | } 30483 | else if (peek_token_is(token_t::e_lsqrbracket)) 30484 | { 30485 | if (0 == (variable0 = parse_vector())) 30486 | { 30487 | set_error(make_error( 30488 | parser_error::e_syntax, 30489 | current_token(), 30490 | "ERR207 - First parameter to swap is an invalid vector element: '" + var0_name + "'", 30491 | exprtk_error_location)); 30492 | 30493 | return error_node(); 30494 | } 30495 | 30496 | variable0_generated = true; 30497 | } 30498 | else 30499 | { 30500 | if (symtab_store_.is_variable(var0_name)) 30501 | { 30502 | variable0 = symtab_store_.get_variable(var0_name); 30503 | } 30504 | 30505 | const scope_element& se = sem_.get_element(var0_name); 30506 | 30507 | if ( 30508 | (se.active) && 30509 | (se.name == var0_name) && 30510 | (scope_element::e_variable == se.type) 30511 | ) 30512 | { 30513 | variable0 = se.var_node; 30514 | } 30515 | 30516 | lodge_symbol(var0_name, e_st_variable); 30517 | 30518 | if (0 == variable0) 30519 | { 30520 | set_error(make_error( 30521 | parser_error::e_syntax, 30522 | current_token(), 30523 | "ERR208 - First parameter to swap is an invalid variable: '" + var0_name + "'", 30524 | exprtk_error_location)); 30525 | 30526 | return error_node(); 30527 | } 30528 | else 30529 | next_token(); 30530 | } 30531 | 30532 | if (!token_is(token_t::e_comma)) 30533 | { 30534 | set_error(make_error( 30535 | parser_error::e_syntax, 30536 | current_token(), 30537 | "ERR209 - Expected ',' between parameters to swap", 30538 | exprtk_error_location)); 30539 | 30540 | if (variable0_generated) 30541 | { 30542 | free_node(node_allocator_, variable0); 30543 | } 30544 | 30545 | return error_node(); 30546 | } 30547 | 30548 | const std::string var1_name = current_token().value; 30549 | 30550 | if (!token_is(token_t::e_symbol,prsrhlpr_t::e_hold)) 30551 | { 30552 | set_error(make_error( 30553 | parser_error::e_syntax, 30554 | current_token(), 30555 | "ERR210 - Expected a symbol for variable or vector element definition", 30556 | exprtk_error_location)); 30557 | 30558 | if (variable0_generated) 30559 | { 30560 | free_node(node_allocator_, variable0); 30561 | } 30562 | 30563 | return error_node(); 30564 | } 30565 | else if (peek_token_is(token_t::e_lsqrbracket)) 30566 | { 30567 | if (0 == (variable1 = parse_vector())) 30568 | { 30569 | set_error(make_error( 30570 | parser_error::e_syntax, 30571 | current_token(), 30572 | "ERR211 - Second parameter to swap is an invalid vector element: '" + var1_name + "'", 30573 | exprtk_error_location)); 30574 | 30575 | if (variable0_generated) 30576 | { 30577 | free_node(node_allocator_, variable0); 30578 | } 30579 | 30580 | return error_node(); 30581 | } 30582 | 30583 | variable1_generated = true; 30584 | } 30585 | else 30586 | { 30587 | if (symtab_store_.is_variable(var1_name)) 30588 | { 30589 | variable1 = symtab_store_.get_variable(var1_name); 30590 | } 30591 | 30592 | const scope_element& se = sem_.get_element(var1_name); 30593 | 30594 | if ( 30595 | (se.active) && 30596 | (se.name == var1_name) && 30597 | (scope_element::e_variable == se.type) 30598 | ) 30599 | { 30600 | variable1 = se.var_node; 30601 | } 30602 | 30603 | lodge_symbol(var1_name, e_st_variable); 30604 | 30605 | if (0 == variable1) 30606 | { 30607 | set_error(make_error( 30608 | parser_error::e_syntax, 30609 | current_token(), 30610 | "ERR212 - Second parameter to swap is an invalid variable: '" + var1_name + "'", 30611 | exprtk_error_location)); 30612 | 30613 | if (variable0_generated) 30614 | { 30615 | free_node(node_allocator_, variable0); 30616 | } 30617 | 30618 | return error_node(); 30619 | } 30620 | else 30621 | next_token(); 30622 | } 30623 | 30624 | if (!token_is(token_t::e_rbracket)) 30625 | { 30626 | set_error(make_error( 30627 | parser_error::e_syntax, 30628 | current_token(), 30629 | "ERR213 - Expected ')' at end of swap statement", 30630 | exprtk_error_location)); 30631 | 30632 | if (variable0_generated) 30633 | { 30634 | free_node(node_allocator_, variable0); 30635 | } 30636 | 30637 | if (variable1_generated) 30638 | { 30639 | free_node(node_allocator_, variable1); 30640 | } 30641 | 30642 | return error_node(); 30643 | } 30644 | 30645 | typedef details::variable_node<T>* variable_node_ptr; 30646 | 30647 | variable_node_ptr v0 = variable_node_ptr(0); 30648 | variable_node_ptr v1 = variable_node_ptr(0); 30649 | 30650 | expression_node_ptr result = error_node(); 30651 | 30652 | if ( 30653 | (0 != (v0 = dynamic_cast<variable_node_ptr>(variable0))) && 30654 | (0 != (v1 = dynamic_cast<variable_node_ptr>(variable1))) 30655 | ) 30656 | { 30657 | result = node_allocator_.allocate<details::swap_node<T> >(v0, v1); 30658 | 30659 | if (variable0_generated) 30660 | { 30661 | free_node(node_allocator_, variable0); 30662 | } 30663 | 30664 | if (variable1_generated) 30665 | { 30666 | free_node(node_allocator_, variable1); 30667 | } 30668 | } 30669 | else 30670 | result = node_allocator_.allocate<details::swap_generic_node<T> > 30671 | (variable0, variable1); 30672 | 30673 | state_.activate_side_effect("parse_swap_statement()"); 30674 | 30675 | return result; 30676 | } 30677 | 30678 | #ifndef exprtk_disable_return_statement 30679 | inline expression_node_ptr parse_return_statement() 30680 | { 30681 | if (state_.parsing_return_stmt) 30682 | { 30683 | set_error(make_error( 30684 | parser_error::e_syntax, 30685 | current_token(), 30686 | "ERR214 - Return call within a return call is not allowed", 30687 | exprtk_error_location)); 30688 | 30689 | return error_node(); 30690 | } 30691 | 30692 | scoped_bool_negator sbn(state_.parsing_return_stmt); 30693 | 30694 | std::vector<expression_node_ptr> arg_list; 30695 | 30696 | scoped_vec_delete<expression_node_t> svd((*this), arg_list); 30697 | 30698 | if (!details::imatch(current_token().value,"return")) 30699 | { 30700 | return error_node(); 30701 | } 30702 | else 30703 | next_token(); 30704 | 30705 | if (!token_is(token_t::e_lsqrbracket)) 30706 | { 30707 | set_error(make_error( 30708 | parser_error::e_syntax, 30709 | current_token(), 30710 | "ERR215 - Expected '[' at start of return statement", 30711 | exprtk_error_location)); 30712 | 30713 | return error_node(); 30714 | } 30715 | else if (!token_is(token_t::e_rsqrbracket)) 30716 | { 30717 | for ( ; ; ) 30718 | { 30719 | expression_node_ptr arg = parse_expression(); 30720 | 30721 | if (0 == arg) 30722 | return error_node(); 30723 | 30724 | arg_list.push_back(arg); 30725 | 30726 | if (token_is(token_t::e_rsqrbracket)) 30727 | break; 30728 | else if (!token_is(token_t::e_comma)) 30729 | { 30730 | set_error(make_error( 30731 | parser_error::e_syntax, 30732 | current_token(), 30733 | "ERR216 - Expected ',' between values during call to return", 30734 | exprtk_error_location)); 30735 | 30736 | return error_node(); 30737 | } 30738 | } 30739 | } 30740 | else if (settings_.zero_return_disabled()) 30741 | { 30742 | set_error(make_error( 30743 | parser_error::e_syntax, 30744 | current_token(), 30745 | "ERR217 - Zero parameter return statement not allowed", 30746 | exprtk_error_location)); 30747 | 30748 | return error_node(); 30749 | } 30750 | 30751 | const lexer::token prev_token = current_token(); 30752 | 30753 | if (token_is(token_t::e_rsqrbracket)) 30754 | { 30755 | if (!arg_list.empty()) 30756 | { 30757 | set_error(make_error( 30758 | parser_error::e_syntax, 30759 | prev_token, 30760 | "ERR218 - Invalid ']' found during return call", 30761 | exprtk_error_location)); 30762 | 30763 | return error_node(); 30764 | } 30765 | } 30766 | 30767 | std::string ret_param_type_list; 30768 | 30769 | for (std::size_t i = 0; i < arg_list.size(); ++i) 30770 | { 30771 | if (0 == arg_list[i]) 30772 | return error_node(); 30773 | else if (is_ivector_node(arg_list[i])) 30774 | ret_param_type_list += 'V'; 30775 | else if (is_generally_string_node(arg_list[i])) 30776 | ret_param_type_list += 'S'; 30777 | else 30778 | ret_param_type_list += 'T'; 30779 | } 30780 | 30781 | dec_.retparam_list_.push_back(ret_param_type_list); 30782 | 30783 | expression_node_ptr result = expression_generator_.return_call(arg_list); 30784 | 30785 | svd.delete_ptr = (0 == result); 30786 | 30787 | state_.return_stmt_present = true; 30788 | 30789 | state_.activate_side_effect("parse_return_statement()"); 30790 | 30791 | return result; 30792 | } 30793 | #else 30794 | inline expression_node_ptr parse_return_statement() 30795 | { 30796 | return error_node(); 30797 | } 30798 | #endif 30799 | 30800 | inline expression_node_ptr parse_assert_statement() 30801 | { 30802 | assert(details::imatch(current_token().value, "assert")); 30803 | 30804 | if (state_.parsing_assert_stmt) 30805 | { 30806 | set_error(make_error( 30807 | parser_error::e_syntax, 30808 | current_token(), 30809 | "ERR219 - Assert statement within an assert statement is not allowed", 30810 | exprtk_error_location)); 30811 | 30812 | return error_node(); 30813 | } 30814 | 30815 | scoped_bool_negator sbn(state_.parsing_assert_stmt); 30816 | 30817 | next_token(); 30818 | 30819 | std::vector<expression_node_ptr> assert_arg_list(3, error_node()); 30820 | scoped_vec_delete<expression_node_t> svd((*this), assert_arg_list); 30821 | 30822 | expression_node_ptr& assert_condition = assert_arg_list[0]; 30823 | expression_node_ptr& assert_message = assert_arg_list[1]; 30824 | expression_node_ptr& assert_id = assert_arg_list[2]; 30825 | 30826 | if (!token_is(token_t::e_lbracket)) 30827 | { 30828 | set_error(make_error( 30829 | parser_error::e_syntax, 30830 | current_token(), 30831 | "ERR220 - Expected '(' at start of assert statement", 30832 | exprtk_error_location)); 30833 | 30834 | return error_node(); 30835 | } 30836 | 30837 | const token_t start_token = current_token(); 30838 | 30839 | // Parse the assert condition 30840 | if (0 == (assert_condition = parse_expression())) 30841 | { 30842 | set_error(make_error( 30843 | parser_error::e_syntax, 30844 | current_token(), 30845 | "ERR221 - Failed to parse condition for assert statement", 30846 | exprtk_error_location)); 30847 | 30848 | return error_node(); 30849 | } 30850 | 30851 | const token_t end_token = current_token(); 30852 | 30853 | if (!token_is(token_t::e_rbracket)) 30854 | { 30855 | if (!token_is(token_t::e_comma)) 30856 | { 30857 | set_error(make_error( 30858 | parser_error::e_syntax, 30859 | current_token(), 30860 | "ERR222 - Expected ',' between condition and message for assert statement", 30861 | exprtk_error_location)); 30862 | 30863 | return error_node(); 30864 | } 30865 | // Parse the assert message 30866 | else if ( 30867 | (0 == (assert_message = parse_expression())) || 30868 | !details::is_generally_string_node(assert_message) 30869 | ) 30870 | { 30871 | set_error(make_error( 30872 | parser_error::e_syntax, 30873 | current_token(), 30874 | "ERR223 - " + 30875 | (assert_message ? 30876 | std::string("Expected string for assert message") : 30877 | std::string("Failed to parse message for assert statement")), 30878 | exprtk_error_location)); 30879 | 30880 | return error_node(); 30881 | } 30882 | else if (!token_is(token_t::e_rbracket)) 30883 | { 30884 | if (!token_is(token_t::e_comma)) 30885 | { 30886 | set_error(make_error( 30887 | parser_error::e_syntax, 30888 | current_token(), 30889 | "ERR224 - Expected ',' between message and ID for assert statement", 30890 | exprtk_error_location)); 30891 | 30892 | return error_node(); 30893 | } 30894 | // Parse assert ID 30895 | else if ( 30896 | (0 == (assert_id = parse_expression())) || 30897 | !details::is_const_string_node(assert_id) 30898 | ) 30899 | { 30900 | set_error(make_error( 30901 | parser_error::e_syntax, 30902 | current_token(), 30903 | "ERR225 - " + 30904 | (assert_id ? 30905 | std::string("Expected literal string for assert ID") : 30906 | std::string("Failed to parse string for assert ID")), 30907 | exprtk_error_location)); 30908 | 30909 | return error_node(); 30910 | } 30911 | else if (!token_is(token_t::e_rbracket)) 30912 | { 30913 | set_error(make_error( 30914 | parser_error::e_syntax, 30915 | current_token(), 30916 | "ERR226 - Expected ')' at start of assert statement", 30917 | exprtk_error_location)); 30918 | 30919 | return error_node(); 30920 | } 30921 | } 30922 | } 30923 | 30924 | exprtk::assert_check::assert_context context; 30925 | context.condition = lexer().substr(start_token.position, end_token.position); 30926 | context.offet = start_token.position; 30927 | 30928 | if (0 == assert_check_) 30929 | { 30930 | exprtk_debug(("parse_assert_statement() - assert functionality is disabled. assert condition: %s\n", 30931 | context.condition.c_str())); 30932 | 30933 | return new details::null_node<T>(); 30934 | } 30935 | 30936 | #ifndef exprtk_disable_string_capabilities 30937 | if (assert_message && details::is_const_string_node(assert_message)) 30938 | { 30939 | context.message = dynamic_cast<details::string_base_node<T>*>(assert_message)->str(); 30940 | } 30941 | 30942 | if (assert_id && details::is_const_string_node(assert_id)) 30943 | { 30944 | context.id = dynamic_cast<details::string_base_node<T>*>(assert_id)->str(); 30945 | 30946 | if (assert_ids_.end() != assert_ids_.find(context.id)) 30947 | { 30948 | set_error(make_error( 30949 | parser_error::e_syntax, 30950 | current_token(), 30951 | "ERR227 - Duplicate assert ID: " + context.id, 30952 | exprtk_error_location)); 30953 | 30954 | return error_node(); 30955 | } 30956 | 30957 | assert_ids_.insert(context.id); 30958 | free_node(node_allocator_, assert_id); 30959 | } 30960 | #endif 30961 | 30962 | expression_node_ptr result_node = 30963 | expression_generator_.assert_call( 30964 | assert_condition, 30965 | assert_message, 30966 | context); 30967 | 30968 | exprtk_debug(("parse_assert_statement() - assert condition: [%s]\n", context.condition.c_str() )); 30969 | exprtk_debug(("parse_assert_statement() - assert message: [%s]\n", context.message .c_str() )); 30970 | exprtk_debug(("parse_assert_statement() - assert id: [%s]\n", context.id .c_str() )); 30971 | exprtk_debug(("parse_assert_statement() - assert offset: [%d]\n", static_cast<int>(context.offet))); 30972 | 30973 | if (0 == result_node) 30974 | { 30975 | set_error(make_error( 30976 | parser_error::e_syntax, 30977 | current_token(), 30978 | "ERR228 - Failed to synthesize assert", 30979 | exprtk_error_location)); 30980 | 30981 | return error_node(); 30982 | } 30983 | 30984 | svd.delete_ptr = false; 30985 | return result_node; 30986 | } 30987 | 30988 | inline bool post_variable_process(const std::string& symbol) 30989 | { 30990 | if ( 30991 | peek_token_is(token_t::e_lbracket ) || 30992 | peek_token_is(token_t::e_lcrlbracket) || 30993 | peek_token_is(token_t::e_lsqrbracket) 30994 | ) 30995 | { 30996 | if (!settings_.commutative_check_enabled()) 30997 | { 30998 | set_error(make_error( 30999 | parser_error::e_syntax, 31000 | current_token(), 31001 | "ERR229 - Invalid sequence of variable '" + symbol + "' and bracket", 31002 | exprtk_error_location)); 31003 | 31004 | return false; 31005 | } 31006 | 31007 | lexer().insert_front(token_t::e_mul); 31008 | } 31009 | 31010 | return true; 31011 | } 31012 | 31013 | inline bool post_bracket_process(const typename token_t::token_type& token, expression_node_ptr& branch) 31014 | { 31015 | bool implied_mul = false; 31016 | 31017 | if (details::is_generally_string_node(branch)) 31018 | return true; 31019 | 31020 | if (details::is_ivector_node(branch)) 31021 | return true; 31022 | 31023 | const lexer::parser_helper::token_advance_mode hold = prsrhlpr_t::e_hold; 31024 | 31025 | switch (token) 31026 | { 31027 | case token_t::e_lcrlbracket : implied_mul = token_is(token_t::e_lbracket , hold) || 31028 | token_is(token_t::e_lcrlbracket, hold) || 31029 | token_is(token_t::e_lsqrbracket, hold) ; 31030 | break; 31031 | 31032 | case token_t::e_lbracket : implied_mul = token_is(token_t::e_lbracket , hold) || 31033 | token_is(token_t::e_lcrlbracket, hold) || 31034 | token_is(token_t::e_lsqrbracket, hold) ; 31035 | break; 31036 | 31037 | case token_t::e_lsqrbracket : implied_mul = token_is(token_t::e_lbracket , hold) || 31038 | token_is(token_t::e_lcrlbracket, hold) || 31039 | token_is(token_t::e_lsqrbracket, hold) ; 31040 | break; 31041 | 31042 | default : return true; 31043 | } 31044 | 31045 | if (implied_mul) 31046 | { 31047 | if (!settings_.commutative_check_enabled()) 31048 | { 31049 | set_error(make_error( 31050 | parser_error::e_syntax, 31051 | current_token(), 31052 | "ERR230 - Invalid sequence of brackets", 31053 | exprtk_error_location)); 31054 | 31055 | return false; 31056 | } 31057 | else if (token_t::e_eof != current_token().type) 31058 | { 31059 | lexer().insert_front(current_token().type); 31060 | lexer().insert_front(token_t::e_mul); 31061 | next_token(); 31062 | } 31063 | } 31064 | 31065 | return true; 31066 | } 31067 | 31068 | typedef typename interval_container_t<const void*>::interval_t interval_t; 31069 | typedef interval_container_t<const void*> immutable_memory_map_t; 31070 | typedef std::map<interval_t,token_t> immutable_symtok_map_t; 31071 | 31072 | inline interval_t make_memory_range(const T& t) 31073 | { 31074 | const T* begin = reinterpret_cast<const T*>(&t); 31075 | const T* end = begin + 1; 31076 | return interval_t(begin, end); 31077 | } 31078 | 31079 | inline interval_t make_memory_range(const T* begin, const std::size_t size) 31080 | { 31081 | return interval_t(begin, begin + size); 31082 | } 31083 | 31084 | inline interval_t make_memory_range(details::char_cptr begin, const std::size_t size) 31085 | { 31086 | return interval_t(begin, begin + size); 31087 | } 31088 | 31089 | void lodge_immutable_symbol(const lexer::token& token, const interval_t interval) 31090 | { 31091 | immutable_memory_map_.add_interval(interval); 31092 | immutable_symtok_map_[interval] = token; 31093 | } 31094 | 31095 | inline expression_node_ptr parse_symtab_symbol() 31096 | { 31097 | const std::string symbol = current_token().value; 31098 | 31099 | // Are we dealing with a variable or a special constant? 31100 | typedef typename symtab_store::variable_context var_ctxt_t; 31101 | var_ctxt_t var_ctx = symtab_store_.get_variable_context(symbol); 31102 | 31103 | if (var_ctx.variable) 31104 | { 31105 | assert(var_ctx.symbol_table); 31106 | 31107 | expression_node_ptr result_variable = var_ctx.variable; 31108 | 31109 | if (symtab_store_.is_constant_node(symbol)) 31110 | { 31111 | result_variable = expression_generator_(var_ctx.variable->value()); 31112 | } 31113 | else if (symbol_table_t::e_immutable == var_ctx.symbol_table->mutability()) 31114 | { 31115 | lodge_immutable_symbol(current_token(), make_memory_range(var_ctx.variable->ref())); 31116 | result_variable = var_ctx.variable; 31117 | } 31118 | 31119 | if (!post_variable_process(symbol)) 31120 | return error_node(); 31121 | 31122 | lodge_symbol(symbol, e_st_variable); 31123 | 31124 | next_token(); 31125 | 31126 | return result_variable; 31127 | } 31128 | 31129 | // Are we dealing with a locally defined variable, vector or string? 31130 | if (!sem_.empty()) 31131 | { 31132 | scope_element& se = sem_.get_active_element(symbol); 31133 | 31134 | if (se.active && details::imatch(se.name, symbol)) 31135 | { 31136 | if ( 31137 | (scope_element::e_variable == se.type) || 31138 | (scope_element::e_literal == se.type) 31139 | ) 31140 | { 31141 | se.active = true; 31142 | lodge_symbol(symbol, e_st_local_variable); 31143 | 31144 | if (!post_variable_process(symbol)) 31145 | return error_node(); 31146 | 31147 | next_token(); 31148 | 31149 | return (scope_element::e_variable == se.type) ? 31150 | se.var_node : 31151 | expression_generator_(se.var_node->value()); 31152 | } 31153 | else if (scope_element::e_vector == se.type) 31154 | { 31155 | return parse_vector(); 31156 | } 31157 | #ifndef exprtk_disable_string_capabilities 31158 | else if (scope_element::e_string == se.type) 31159 | { 31160 | return parse_string(); 31161 | } 31162 | #endif 31163 | } 31164 | } 31165 | 31166 | #ifndef exprtk_disable_string_capabilities 31167 | // Are we dealing with a string variable? 31168 | if (symtab_store_.is_stringvar(symbol)) 31169 | { 31170 | return parse_string(); 31171 | } 31172 | #endif 31173 | 31174 | { 31175 | // Are we dealing with a function? 31176 | ifunction<T>* function = symtab_store_.get_function(symbol); 31177 | 31178 | if (function) 31179 | { 31180 | lodge_symbol(symbol, e_st_function); 31181 | 31182 | expression_node_ptr func_node = 31183 | parse_function_invocation(function,symbol); 31184 | 31185 | if (func_node) 31186 | return func_node; 31187 | else 31188 | { 31189 | set_error(make_error( 31190 | parser_error::e_syntax, 31191 | current_token(), 31192 | "ERR231 - Failed to generate node for function: '" + symbol + "'", 31193 | exprtk_error_location)); 31194 | 31195 | return error_node(); 31196 | } 31197 | } 31198 | } 31199 | 31200 | { 31201 | // Are we dealing with a vararg function? 31202 | ivararg_function<T>* vararg_function = symtab_store_.get_vararg_function(symbol); 31203 | 31204 | if (vararg_function) 31205 | { 31206 | lodge_symbol(symbol, e_st_function); 31207 | 31208 | expression_node_ptr vararg_func_node = 31209 | parse_vararg_function_call(vararg_function, symbol); 31210 | 31211 | if (vararg_func_node) 31212 | return vararg_func_node; 31213 | else 31214 | { 31215 | set_error(make_error( 31216 | parser_error::e_syntax, 31217 | current_token(), 31218 | "ERR232 - Failed to generate node for vararg function: '" + symbol + "'", 31219 | exprtk_error_location)); 31220 | 31221 | return error_node(); 31222 | } 31223 | } 31224 | } 31225 | 31226 | { 31227 | // Are we dealing with a vararg generic function? 31228 | igeneric_function<T>* generic_function = symtab_store_.get_generic_function(symbol); 31229 | 31230 | if (generic_function) 31231 | { 31232 | lodge_symbol(symbol, e_st_function); 31233 | 31234 | expression_node_ptr genericfunc_node = 31235 | parse_generic_function_call(generic_function, symbol); 31236 | 31237 | if (genericfunc_node) 31238 | return genericfunc_node; 31239 | else 31240 | { 31241 | set_error(make_error( 31242 | parser_error::e_syntax, 31243 | current_token(), 31244 | "ERR233 - Failed to generate node for generic function: '" + symbol + "'", 31245 | exprtk_error_location)); 31246 | 31247 | return error_node(); 31248 | } 31249 | } 31250 | } 31251 | 31252 | #ifndef exprtk_disable_string_capabilities 31253 | { 31254 | // Are we dealing with a vararg string returning function? 31255 | igeneric_function<T>* string_function = symtab_store_.get_string_function(symbol); 31256 | 31257 | if (string_function) 31258 | { 31259 | lodge_symbol(symbol, e_st_function); 31260 | 31261 | expression_node_ptr stringfunc_node = 31262 | parse_string_function_call(string_function, symbol); 31263 | 31264 | if (stringfunc_node) 31265 | return stringfunc_node; 31266 | else 31267 | { 31268 | set_error(make_error( 31269 | parser_error::e_syntax, 31270 | current_token(), 31271 | "ERR234 - Failed to generate node for string function: '" + symbol + "'", 31272 | exprtk_error_location)); 31273 | 31274 | return error_node(); 31275 | } 31276 | } 31277 | } 31278 | 31279 | { 31280 | // Are we dealing with a vararg overloaded scalar/string returning function? 31281 | igeneric_function<T>* overload_function = symtab_store_.get_overload_function(symbol); 31282 | 31283 | if (overload_function) 31284 | { 31285 | lodge_symbol(symbol, e_st_function); 31286 | 31287 | expression_node_ptr overloadfunc_node = 31288 | parse_overload_function_call(overload_function, symbol); 31289 | 31290 | if (overloadfunc_node) 31291 | return overloadfunc_node; 31292 | else 31293 | { 31294 | set_error(make_error( 31295 | parser_error::e_syntax, 31296 | current_token(), 31297 | "ERR235 - Failed to generate node for overload function: '" + symbol + "'", 31298 | exprtk_error_location)); 31299 | 31300 | return error_node(); 31301 | } 31302 | } 31303 | } 31304 | #endif 31305 | 31306 | // Are we dealing with a vector? 31307 | if (symtab_store_.is_vector(symbol)) 31308 | { 31309 | lodge_symbol(symbol, e_st_vector); 31310 | return parse_vector(); 31311 | } 31312 | 31313 | if (details::is_reserved_symbol(symbol)) 31314 | { 31315 | if ( 31316 | settings_.function_enabled(symbol) || 31317 | !details::is_base_function(symbol) 31318 | ) 31319 | { 31320 | set_error(make_error( 31321 | parser_error::e_syntax, 31322 | current_token(), 31323 | "ERR236 - Invalid use of reserved symbol '" + symbol + "'", 31324 | exprtk_error_location)); 31325 | 31326 | return error_node(); 31327 | } 31328 | } 31329 | 31330 | // Should we handle unknown symbols? 31331 | if (resolve_unknown_symbol_ && unknown_symbol_resolver_) 31332 | { 31333 | if (!(settings_.rsrvd_sym_usr_disabled() && details::is_reserved_symbol(symbol))) 31334 | { 31335 | symbol_table_t& symtab = symtab_store_.get_symbol_table(); 31336 | 31337 | std::string error_message; 31338 | 31339 | if (unknown_symbol_resolver::e_usrmode_default == unknown_symbol_resolver_->mode) 31340 | { 31341 | T default_value = T(0); 31342 | 31343 | typename unknown_symbol_resolver::usr_symbol_type usr_symbol_type = unknown_symbol_resolver::e_usr_unknown_type; 31344 | 31345 | if (unknown_symbol_resolver_->process(symbol, usr_symbol_type, default_value, error_message)) 31346 | { 31347 | bool create_result = false; 31348 | 31349 | switch (usr_symbol_type) 31350 | { 31351 | case unknown_symbol_resolver::e_usr_variable_type : 31352 | create_result = symtab.create_variable(symbol, default_value); 31353 | break; 31354 | 31355 | case unknown_symbol_resolver::e_usr_constant_type : 31356 | create_result = symtab.add_constant(symbol, default_value); 31357 | break; 31358 | 31359 | default : create_result = false; 31360 | } 31361 | 31362 | if (create_result) 31363 | { 31364 | expression_node_ptr var = symtab_store_.get_variable(symbol); 31365 | 31366 | if (var) 31367 | { 31368 | if (symtab_store_.is_constant_node(symbol)) 31369 | { 31370 | var = expression_generator_(var->value()); 31371 | } 31372 | 31373 | lodge_symbol(symbol, e_st_variable); 31374 | 31375 | if (!post_variable_process(symbol)) 31376 | return error_node(); 31377 | 31378 | next_token(); 31379 | 31380 | return var; 31381 | } 31382 | } 31383 | } 31384 | 31385 | set_error(make_error( 31386 | parser_error::e_symtab, 31387 | current_token(), 31388 | "ERR237 - Failed to create variable: '" + symbol + "'" + 31389 | (error_message.empty() ? "" : " - " + error_message), 31390 | exprtk_error_location)); 31391 | 31392 | } 31393 | else if (unknown_symbol_resolver::e_usrmode_extended == unknown_symbol_resolver_->mode) 31394 | { 31395 | if (unknown_symbol_resolver_->process(symbol, symtab, error_message)) 31396 | { 31397 | expression_node_ptr result = parse_symtab_symbol(); 31398 | 31399 | if (result) 31400 | { 31401 | return result; 31402 | } 31403 | } 31404 | 31405 | set_error(make_error( 31406 | parser_error::e_symtab, 31407 | current_token(), 31408 | "ERR238 - Failed to resolve symbol: '" + symbol + "'" + 31409 | (error_message.empty() ? "" : " - " + error_message), 31410 | exprtk_error_location)); 31411 | } 31412 | 31413 | return error_node(); 31414 | } 31415 | } 31416 | 31417 | set_error(make_error( 31418 | parser_error::e_syntax, 31419 | current_token(), 31420 | "ERR239 - Undefined symbol: '" + symbol + "'", 31421 | exprtk_error_location)); 31422 | 31423 | return error_node(); 31424 | } 31425 | 31426 | inline expression_node_ptr check_block_statement_closure(expression_node_ptr expression) 31427 | { 31428 | if ( 31429 | expression && 31430 | ( 31431 | (current_token().type == token_t::e_symbol) || 31432 | (current_token().type == token_t::e_number) 31433 | ) 31434 | ) 31435 | { 31436 | free_node(node_allocator_, expression); 31437 | 31438 | set_error(make_error( 31439 | parser_error::e_syntax, 31440 | current_token(), 31441 | "ERR240 - Invalid syntax '" + current_token().value + "' possible missing operator or context", 31442 | exprtk_error_location)); 31443 | 31444 | return error_node(); 31445 | } 31446 | 31447 | return expression; 31448 | } 31449 | 31450 | inline expression_node_ptr parse_symbol() 31451 | { 31452 | static const std::string symbol_if = "if" ; 31453 | static const std::string symbol_while = "while" ; 31454 | static const std::string symbol_repeat = "repeat" ; 31455 | static const std::string symbol_for = "for" ; 31456 | static const std::string symbol_switch = "switch" ; 31457 | static const std::string symbol_null = "null" ; 31458 | static const std::string symbol_break = "break" ; 31459 | static const std::string symbol_continue = "continue" 31460 | static const std::string symbol_var = "var" ; 31461 | static const std::string symbol_const = "const" ; 31462 | static const std::string symbol_swap = "swap" ; 31463 | static const std::string symbol_return = "return" ; 31464 | static const std::string symbol_not = "not" ; 31465 | static const std::string symbol_assert = "assert" ; 31466 | 31467 | const std::string symbol = current_token().value; 31468 | 31469 | if (valid_vararg_operation(symbol)) 31470 | { 31471 | return parse_vararg_function(); 31472 | } 31473 | else if (details::imatch(symbol, symbol_not)) 31474 | { 31475 | return parse_not_statement(); 31476 | } 31477 | else if (valid_base_operation(symbol)) 31478 | { 31479 | return parse_base_operation(); 31480 | } 31481 | else if ( 31482 | details::imatch(symbol, symbol_if) && 31483 | settings_.control_struct_enabled(symbol) 31484 | ) 31485 | { 31486 | return parse_conditional_statement(); 31487 | } 31488 | else if ( 31489 | details::imatch(symbol, symbol_while) && 31490 | settings_.control_struct_enabled(symbol) 31491 | ) 31492 | { 31493 | return check_block_statement_closure(parse_while_loop()); 31494 | } 31495 | else if ( 31496 | details::imatch(symbol, symbol_repeat) && 31497 | settings_.control_struct_enabled(symbol) 31498 | ) 31499 | { 31500 | return check_block_statement_closure(parse_repeat_until_loop()); 31501 | } 31502 | else if ( 31503 | details::imatch(symbol, symbol_for) && 31504 | settings_.control_struct_enabled(symbol) 31505 | ) 31506 | { 31507 | return check_block_statement_closure(parse_for_loop()); 31508 | } 31509 | else if ( 31510 | details::imatch(symbol, symbol_switch) && 31511 | settings_.control_struct_enabled(symbol) 31512 | ) 31513 | { 31514 | return check_block_statement_closure(parse_switch_statement()); 31515 | } 31516 | else if (details::is_valid_sf_symbol(symbol)) 31517 | { 31518 | return parse_special_function(); 31519 | } 31520 | else if (details::imatch(symbol, symbol_null)) 31521 | { 31522 | return parse_null_statement(); 31523 | } 31524 | #ifndef exprtk_disable_break_continue 31525 | else if (details::imatch(symbol, symbol_break)) 31526 | { 31527 | return parse_break_statement(); 31528 | } 31529 | else if (details::imatch(symbol, symbol_continue)) 31530 | { 31531 | return parse_continue_statement(); 31532 | } 31533 | #endif 31534 | else if (details::imatch(symbol, symbol_var)) 31535 | { 31536 | return parse_define_var_statement(); 31537 | } 31538 | else if (details::imatch(symbol, symbol_const)) 31539 | { 31540 | return parse_define_constvar_statement(); 31541 | } 31542 | else if (details::imatch(symbol, symbol_swap)) 31543 | { 31544 | return parse_swap_statement(); 31545 | } 31546 | #ifndef exprtk_disable_return_statement 31547 | else if ( 31548 | details::imatch(symbol, symbol_return) && 31549 | settings_.control_struct_enabled(symbol) 31550 | ) 31551 | { 31552 | return check_block_statement_closure(parse_return_statement()); 31553 | } 31554 | #endif 31555 | else if (details::imatch(symbol, symbol_assert)) 31556 | { 31557 | return parse_assert_statement(); 31558 | } 31559 | else if (symtab_store_.valid() || !sem_.empty()) 31560 | { 31561 | return parse_symtab_symbol(); 31562 | } 31563 | else 31564 | { 31565 | set_error(make_error( 31566 | parser_error::e_symtab, 31567 | current_token(), 31568 | "ERR241 - Unknown variable or function encountered. Symbol table(s) " 31569 | "is either invalid or does not contain symbol: '" + symbol + "'", 31570 | exprtk_error_location)); 31571 | 31572 | return error_node(); 31573 | } 31574 | } 31575 | 31576 | inline expression_node_ptr parse_branch(precedence_level precedence = e_level00) 31577 | { 31578 | stack_limit_handler slh(*this); 31579 | 31580 | if (!slh) 31581 | { 31582 | return error_node(); 31583 | } 31584 | 31585 | expression_node_ptr branch = error_node(); 31586 | 31587 | if (token_t::e_number == current_token().type) 31588 | { 31589 | T numeric_value = T(0); 31590 | 31591 | if (details::string_to_real(current_token().value, numeric_value)) 31592 | { 31593 | expression_node_ptr literal_exp = expression_generator_(numeric_value); 31594 | 31595 | if (0 == literal_exp) 31596 | { 31597 | set_error(make_error( 31598 | parser_error::e_numeric, 31599 | current_token(), 31600 | "ERR242 - Failed generate node for scalar: '" + current_token().value + "'", 31601 | exprtk_error_location)); 31602 | 31603 | return error_node(); 31604 | } 31605 | 31606 | next_token(); 31607 | branch = literal_exp; 31608 | } 31609 | else 31610 | { 31611 | set_error(make_error( 31612 | parser_error::e_numeric, 31613 | current_token(), 31614 | "ERR243 - Failed to convert '" + current_token().value + "' to a number", 31615 | exprtk_error_location)); 31616 | 31617 | return error_node(); 31618 | } 31619 | } 31620 | else if (token_t::e_symbol == current_token().type) 31621 | { 31622 | branch = parse_symbol(); 31623 | } 31624 | #ifndef exprtk_disable_string_capabilities 31625 | else if (token_t::e_string == current_token().type) 31626 | { 31627 | branch = parse_const_string(); 31628 | } 31629 | #endif 31630 | else if (token_t::e_lbracket == current_token().type) 31631 | { 31632 | next_token(); 31633 | 31634 | if (0 == (branch = parse_expression())) 31635 | { 31636 | return error_node(); 31637 | } 31638 | 31639 | token_is(token_t::e_eof); 31640 | 31641 | if (!token_is(token_t::e_rbracket)) 31642 | { 31643 | set_error(make_error( 31644 | parser_error::e_syntax, 31645 | current_token(), 31646 | "ERR244 - Expected ')' instead of: '" + current_token().value + "'", 31647 | exprtk_error_location)); 31648 | 31649 | details::free_node(node_allocator_, branch); 31650 | 31651 | return error_node(); 31652 | } 31653 | else if (!post_bracket_process(token_t::e_lbracket,branch)) 31654 | { 31655 | details::free_node(node_allocator_, branch); 31656 | 31657 | return error_node(); 31658 | } 31659 | 31660 | parse_pending_vector_index_operator(branch); 31661 | } 31662 | else if (token_t::e_lsqrbracket == current_token().type) 31663 | { 31664 | next_token(); 31665 | 31666 | if (0 == (branch = parse_expression())) 31667 | return error_node(); 31668 | else if (!token_is(token_t::e_rsqrbracket)) 31669 | { 31670 | set_error(make_error( 31671 | parser_error::e_syntax, 31672 | current_token(), 31673 | "ERR245 - Expected ']' instead of: '" + current_token().value + "'", 31674 | exprtk_error_location)); 31675 | 31676 | details::free_node(node_allocator_, branch); 31677 | 31678 | return error_node(); 31679 | } 31680 | else if (!post_bracket_process(token_t::e_lsqrbracket,branch)) 31681 | { 31682 | details::free_node(node_allocator_, branch); 31683 | 31684 | return error_node(); 31685 | } 31686 | } 31687 | else if (token_t::e_lcrlbracket == current_token().type) 31688 | { 31689 | next_token(); 31690 | 31691 | if (0 == (branch = parse_expression())) 31692 | return error_node(); 31693 | else if (!token_is(token_t::e_rcrlbracket)) 31694 | { 31695 | set_error(make_error( 31696 | parser_error::e_syntax, 31697 | current_token(), 31698 | "ERR246 - Expected '}' instead of: '" + current_token().value + "'", 31699 | exprtk_error_location)); 31700 | 31701 | details::free_node(node_allocator_, branch); 31702 | 31703 | return error_node(); 31704 | } 31705 | else if (!post_bracket_process(token_t::e_lcrlbracket,branch)) 31706 | { 31707 | details::free_node(node_allocator_, branch); 31708 | 31709 | return error_node(); 31710 | } 31711 | } 31712 | else if (token_t::e_sub == current_token().type) 31713 | { 31714 | next_token(); 31715 | branch = parse_expression(e_level11); 31716 | 31717 | if ( 31718 | branch && 31719 | !( 31720 | details::is_neg_unary_node (branch) && 31721 | simplify_unary_negation_branch(branch) 31722 | ) 31723 | ) 31724 | { 31725 | expression_node_ptr result = expression_generator_(details::e_neg,branch); 31726 | 31727 | if (0 == result) 31728 | { 31729 | details::free_node(node_allocator_, branch); 31730 | 31731 | return error_node(); 31732 | } 31733 | else 31734 | branch = result; 31735 | } 31736 | } 31737 | else if (token_t::e_add == current_token().type) 31738 | { 31739 | next_token(); 31740 | branch = parse_expression(e_level13); 31741 | } 31742 | else if (token_t::e_eof == current_token().type) 31743 | { 31744 | set_error(make_error( 31745 | parser_error::e_syntax, 31746 | current_token(), 31747 | "ERR247 - Premature end of expression[1]", 31748 | exprtk_error_location)); 31749 | 31750 | return error_node(); 31751 | } 31752 | else 31753 | { 31754 | set_error(make_error( 31755 | parser_error::e_syntax, 31756 | current_token(), 31757 | "ERR248 - Premature end of expression[2]", 31758 | exprtk_error_location)); 31759 | 31760 | return error_node(); 31761 | } 31762 | 31763 | if ( 31764 | branch && 31765 | (e_level00 == precedence) && 31766 | token_is(token_t::e_ternary,prsrhlpr_t::e_hold) 31767 | ) 31768 | { 31769 | branch = parse_ternary_conditional_statement(branch); 31770 | } 31771 | 31772 | parse_pending_string_rangesize(branch); 31773 | 31774 | return branch; 31775 | } 31776 | 31777 | template <typename Type> 31778 | class expression_generator 31779 | { 31780 | public: 31781 | 31782 | typedef details::expression_node<Type>* expression_node_ptr; 31783 | typedef expression_node_ptr (*synthesize_functor_t)(expression_generator<T>&, const details::operator_type& operation, expression_node_ptr (&branch)[2]); 31784 | typedef std::map<std::string,synthesize_functor_t> synthesize_map_t; 31785 | typedef typename exprtk::parser<Type> parser_t; 31786 | typedef const Type& vtype; 31787 | typedef const Type ctype; 31788 | 31789 | inline void init_synthesize_map() 31790 | { 31791 | #ifndef exprtk_disable_enhanced_features 31792 | synthesize_map_["(v)o(v)"] = synthesize_vov_expression::process; 31793 | synthesize_map_["(c)o(v)"] = synthesize_cov_expression::process; 31794 | synthesize_map_["(v)o(c)"] = synthesize_voc_expression::process; 31795 | 31796 | #define register_synthezier(S) \ 31797 | synthesize_map_[S ::node_type::id()] = S ::process; \ 31798 | 31799 | register_synthezier(synthesize_vovov_expression0) 31800 | register_synthezier(synthesize_vovov_expression1) 31801 | register_synthezier(synthesize_vovoc_expression0) 31802 | register_synthezier(synthesize_vovoc_expression1) 31803 | register_synthezier(synthesize_vocov_expression0) 31804 | register_synthezier(synthesize_vocov_expression1) 31805 | register_synthezier(synthesize_covov_expression0) 31806 | register_synthezier(synthesize_covov_expression1) 31807 | register_synthezier(synthesize_covoc_expression0) 31808 | register_synthezier(synthesize_covoc_expression1) 31809 | register_synthezier(synthesize_cocov_expression1) 31810 | register_synthezier(synthesize_vococ_expression0) 31811 | 31812 | register_synthezier(synthesize_vovovov_expression0) 31813 | register_synthezier(synthesize_vovovoc_expression0) 31814 | register_synthezier(synthesize_vovocov_expression0) 31815 | register_synthezier(synthesize_vocovov_expression0) 31816 | register_synthezier(synthesize_covovov_expression0) 31817 | register_synthezier(synthesize_covocov_expression0) 31818 | register_synthezier(synthesize_vocovoc_expression0) 31819 | register_synthezier(synthesize_covovoc_expression0) 31820 | register_synthezier(synthesize_vococov_expression0) 31821 | 31822 | register_synthezier(synthesize_vovovov_expression1) 31823 | register_synthezier(synthesize_vovovoc_expression1) 31824 | register_synthezier(synthesize_vovocov_expression1) 31825 | register_synthezier(synthesize_vocovov_expression1) 31826 | register_synthezier(synthesize_covovov_expression1) 31827 | register_synthezier(synthesize_covocov_expression1) 31828 | register_synthezier(synthesize_vocovoc_expression1) 31829 | register_synthezier(synthesize_covovoc_expression1) 31830 | register_synthezier(synthesize_vococov_expression1) 31831 | 31832 | register_synthezier(synthesize_vovovov_expression2) 31833 | register_synthezier(synthesize_vovovoc_expression2) 31834 | register_synthezier(synthesize_vovocov_expression2) 31835 | register_synthezier(synthesize_vocovov_expression2) 31836 | register_synthezier(synthesize_covovov_expression2) 31837 | register_synthezier(synthesize_covocov_expression2) 31838 | register_synthezier(synthesize_vocovoc_expression2) 31839 | register_synthezier(synthesize_covovoc_expression2) 31840 | 31841 | register_synthezier(synthesize_vovovov_expression3) 31842 | register_synthezier(synthesize_vovovoc_expression3) 31843 | register_synthezier(synthesize_vovocov_expression3) 31844 | register_synthezier(synthesize_vocovov_expression3) 31845 | register_synthezier(synthesize_covovov_expression3) 31846 | register_synthezier(synthesize_covocov_expression3) 31847 | register_synthezier(synthesize_vocovoc_expression3) 31848 | register_synthezier(synthesize_covovoc_expression3) 31849 | register_synthezier(synthesize_vococov_expression3) 31850 | 31851 | register_synthezier(synthesize_vovovov_expression4) 31852 | register_synthezier(synthesize_vovovoc_expression4) 31853 | register_synthezier(synthesize_vovocov_expression4) 31854 | register_synthezier(synthesize_vocovov_expression4) 31855 | register_synthezier(synthesize_covovov_expression4) 31856 | register_synthezier(synthesize_covocov_expression4) 31857 | register_synthezier(synthesize_vocovoc_expression4) 31858 | register_synthezier(synthesize_covovoc_expression4) 31859 | 31860 | #undef register_synthezier 31861 | #endif 31862 | } 31863 | 31864 | inline void set_parser(parser_t& p) 31865 | { 31866 | parser_ = &p; 31867 | } 31868 | 31869 | inline void set_uom(unary_op_map_t& unary_op_map) 31870 | { 31871 | unary_op_map_ = &unary_op_map; 31872 | } 31873 | 31874 | inline void set_bom(binary_op_map_t& binary_op_map) 31875 | { 31876 | binary_op_map_ = &binary_op_map; 31877 | } 31878 | 31879 | inline void set_ibom(inv_binary_op_map_t& inv_binary_op_map) 31880 | { 31881 | inv_binary_op_map_ = &inv_binary_op_map; 31882 | } 31883 | 31884 | inline void set_sf3m(sf3_map_t& sf3_map) 31885 | { 31886 | sf3_map_ = &sf3_map; 31887 | } 31888 | 31889 | inline void set_sf4m(sf4_map_t& sf4_map) 31890 | { 31891 | sf4_map_ = &sf4_map; 31892 | } 31893 | 31894 | inline void set_allocator(details::node_allocator& na) 31895 | { 31896 | node_allocator_ = &na; 31897 | } 31898 | 31899 | inline void set_strength_reduction_state(const bool enabled) 31900 | { 31901 | strength_reduction_enabled_ = enabled; 31902 | } 31903 | 31904 | inline bool strength_reduction_enabled() const 31905 | { 31906 | return strength_reduction_enabled_; 31907 | } 31908 | 31909 | inline bool valid_operator(const details::operator_type& operation, binary_functor_t& bop) 31910 | { 31911 | typename binary_op_map_t::iterator bop_itr = binary_op_map_->find(operation); 31912 | 31913 | if (binary_op_map_->end() == bop_itr) 31914 | return false; 31915 | 31916 | bop = bop_itr->second; 31917 | 31918 | return true; 31919 | } 31920 | 31921 | inline bool valid_operator(const details::operator_type& operation, unary_functor_t& uop) 31922 | { 31923 | typename unary_op_map_t::iterator uop_itr = unary_op_map_->find(operation); 31924 | 31925 | if ((*unary_op_map_).end() == uop_itr) 31926 | return false; 31927 | 31928 | uop = uop_itr->second; 31929 | 31930 | return true; 31931 | } 31932 | 31933 | inline details::operator_type get_operator(const binary_functor_t& bop) const 31934 | { 31935 | return (*inv_binary_op_map_).find(bop)->second; 31936 | } 31937 | 31938 | inline expression_node_ptr operator() (const Type& v) const 31939 | { 31940 | return node_allocator_->allocate<literal_node_t>(v); 31941 | } 31942 | 31943 | #ifndef exprtk_disable_string_capabilities 31944 | inline expression_node_ptr operator() (const std::string& s) const 31945 | { 31946 | return node_allocator_->allocate<string_literal_node_t>(s); 31947 | } 31948 | 31949 | inline expression_node_ptr operator() (std::string& s, range_t& rp) const 31950 | { 31951 | return node_allocator_->allocate_rr<string_range_node_t>(s,rp); 31952 | } 31953 | 31954 | inline expression_node_ptr operator() (const std::string& s, range_t& rp) const 31955 | { 31956 | return node_allocator_->allocate_tt<const_string_range_node_t>(s,rp); 31957 | } 31958 | 31959 | inline expression_node_ptr operator() (expression_node_ptr branch, range_t& rp) const 31960 | { 31961 | if (is_generally_string_node(branch)) 31962 | return node_allocator_->allocate_tt<generic_string_range_node_t>(branch,rp); 31963 | else 31964 | return error_node(); 31965 | } 31966 | #endif 31967 | 31968 | inline bool unary_optimisable(const details::operator_type& operation) const 31969 | { 31970 | return (details::e_abs == operation) || (details::e_acos == operation) || 31971 | (details::e_acosh == operation) || (details::e_asin == operation) || 31972 | (details::e_asinh == operation) || (details::e_atan == operation) || 31973 | (details::e_atanh == operation) || (details::e_ceil == operation) || 31974 | (details::e_cos == operation) || (details::e_cosh == operation) || 31975 | (details::e_exp == operation) || (details::e_expm1 == operation) || 31976 | (details::e_floor == operation) || (details::e_log == operation) || 31977 | (details::e_log10 == operation) || (details::e_log2 == operation) || 31978 | (details::e_log1p == operation) || (details::e_neg == operation) || 31979 | (details::e_pos == operation) || (details::e_round == operation) || 31980 | (details::e_sin == operation) || (details::e_sinc == operation) || 31981 | (details::e_sinh == operation) || (details::e_sqrt == operation) || 31982 | (details::e_tan == operation) || (details::e_tanh == operation) || 31983 | (details::e_cot == operation) || (details::e_sec == operation) || 31984 | (details::e_csc == operation) || (details::e_r2d == operation) || 31985 | (details::e_d2r == operation) || (details::e_d2g == operation) || 31986 | (details::e_g2d == operation) || (details::e_notl == operation) || 31987 | (details::e_sgn == operation) || (details::e_erf == operation) || 31988 | (details::e_erfc == operation) || (details::e_ncdf == operation) || 31989 | (details::e_frac == operation) || (details::e_trunc == operation) ; 31990 | } 31991 | 31992 | inline bool sf3_optimisable(const std::string& sf3id, trinary_functor_t& tfunc) const 31993 | { 31994 | typename sf3_map_t::const_iterator itr = sf3_map_->find(sf3id); 31995 | 31996 | if (sf3_map_->end() == itr) 31997 | return false; 31998 | else 31999 | tfunc = itr->second.first; 32000 | 32001 | return true; 32002 | } 32003 | 32004 | inline bool sf4_optimisable(const std::string& sf4id, quaternary_functor_t& qfunc) const 32005 | { 32006 | typename sf4_map_t::const_iterator itr = sf4_map_->find(sf4id); 32007 | 32008 | if (sf4_map_->end() == itr) 32009 | return false; 32010 | else 32011 | qfunc = itr->second.first; 32012 | 32013 | return true; 32014 | } 32015 | 32016 | inline bool sf3_optimisable(const std::string& sf3id, details::operator_type& operation) const 32017 | { 32018 | typename sf3_map_t::const_iterator itr = sf3_map_->find(sf3id); 32019 | 32020 | if (sf3_map_->end() == itr) 32021 | return false; 32022 | else 32023 | operation = itr->second.second; 32024 | 32025 | return true; 32026 | } 32027 | 32028 | inline bool sf4_optimisable(const std::string& sf4id, details::operator_type& operation) const 32029 | { 32030 | typename sf4_map_t::const_iterator itr = sf4_map_->find(sf4id); 32031 | 32032 | if (sf4_map_->end() == itr) 32033 | return false; 32034 | else 32035 | operation = itr->second.second; 32036 | 32037 | return true; 32038 | } 32039 | 32040 | inline expression_node_ptr operator() (const details::operator_type& operation, expression_node_ptr (&branch)[1]) 32041 | { 32042 | if (0 == branch[0]) 32043 | { 32044 | return error_node(); 32045 | } 32046 | else if (details::is_null_node(branch[0])) 32047 | { 32048 | return branch[0]; 32049 | } 32050 | else if (details::is_break_node(branch[0])) 32051 | { 32052 | return error_node(); 32053 | } 32054 | else if (details::is_continue_node(branch[0])) 32055 | { 32056 | return error_node(); 32057 | } 32058 | else if (details::is_constant_node(branch[0])) 32059 | { 32060 | return synthesize_expression<unary_node_t,1>(operation,branch); 32061 | } 32062 | else if (unary_optimisable(operation) && details::is_variable_node(branch[0])) 32063 | { 32064 | return synthesize_uv_expression(operation,branch); 32065 | } 32066 | else if (unary_optimisable(operation) && details::is_ivector_node(branch[0])) 32067 | { 32068 | return synthesize_uvec_expression(operation,branch); 32069 | } 32070 | else 32071 | return synthesize_unary_expression(operation,branch); 32072 | } 32073 | 32074 | inline bool is_assignment_operation(const details::operator_type& operation) const 32075 | { 32076 | return ( 32077 | (details::e_addass == operation) || 32078 | (details::e_subass == operation) || 32079 | (details::e_mulass == operation) || 32080 | (details::e_divass == operation) || 32081 | (details::e_modass == operation) 32082 | ) && 32083 | parser_->settings_.assignment_enabled(operation); 32084 | } 32085 | 32086 | #ifndef exprtk_disable_string_capabilities 32087 | inline bool valid_string_operation(const details::operator_type& operation) const 32088 | { 32089 | return (details::e_add == operation) || 32090 | (details::e_lt == operation) || 32091 | (details::e_lte == operation) || 32092 | (details::e_gt == operation) || 32093 | (details::e_gte == operation) || 32094 | (details::e_eq == operation) || 32095 | (details::e_ne == operation) || 32096 | (details::e_in == operation) || 32097 | (details::e_like == operation) || 32098 | (details::e_ilike == operation) || 32099 | (details::e_assign == operation) || 32100 | (details::e_addass == operation) || 32101 | (details::e_swap == operation) ; 32102 | } 32103 | #else 32104 | inline bool valid_string_operation(const details::operator_type&) const 32105 | { 32106 | return false; 32107 | } 32108 | #endif 32109 | 32110 | inline std::string to_str(const details::operator_type& operation) const 32111 | { 32112 | switch (operation) 32113 | { 32114 | case details::e_add : return "+" ; 32115 | case details::e_sub : return "-" ; 32116 | case details::e_mul : return "*" ; 32117 | case details::e_div : return "/" ; 32118 | case details::e_mod : return "%" ; 32119 | case details::e_pow : return "^" ; 32120 | case details::e_lt : return "<" ; 32121 | case details::e_lte : return "<=" ; 32122 | case details::e_gt : return ">" ; 32123 | case details::e_gte : return ">=" ; 32124 | case details::e_eq : return "==" ; 32125 | case details::e_ne : return "!=" ; 32126 | case details::e_and : return "and" ; 32127 | case details::e_nand : return "nand" ; 32128 | case details::e_or : return "or" ; 32129 | case details::e_nor : return "nor" ; 32130 | case details::e_xor : return "xor" ; 32131 | case details::e_xnor : return "xnor" ; 32132 | default : return "UNKNOWN" 32133 | } 32134 | } 32135 | 32136 | inline bool operation_optimisable(const details::operator_type& operation) const 32137 | { 32138 | return (details::e_add == operation) || 32139 | (details::e_sub == operation) || 32140 | (details::e_mul == operation) || 32141 | (details::e_div == operation) || 32142 | (details::e_mod == operation) || 32143 | (details::e_pow == operation) || 32144 | (details::e_lt == operation) || 32145 | (details::e_lte == operation) || 32146 | (details::e_gt == operation) || 32147 | (details::e_gte == operation) || 32148 | (details::e_eq == operation) || 32149 | (details::e_ne == operation) || 32150 | (details::e_and == operation) || 32151 | (details::e_nand == operation) || 32152 | (details::e_or == operation) || 32153 | (details::e_nor == operation) || 32154 | (details::e_xor == operation) || 32155 | (details::e_xnor == operation) ; 32156 | } 32157 | 32158 | inline std::string branch_to_id(expression_node_ptr branch) const 32159 | { 32160 | static const std::string null_str ("(null)" ); 32161 | static const std::string const_str ("(c)" ); 32162 | static const std::string var_str ("(v)" ); 32163 | static const std::string vov_str ("(vov)" ); 32164 | static const std::string cov_str ("(cov)" ); 32165 | static const std::string voc_str ("(voc)" ); 32166 | static const std::string str_str ("(s)" ); 32167 | static const std::string strrng_str ("(rngs)" ); 32168 | static const std::string cs_str ("(cs)" ); 32169 | static const std::string cstrrng_str("(crngs)"); 32170 | 32171 | if (details::is_null_node(branch)) 32172 | return null_str; 32173 | else if (details::is_constant_node(branch)) 32174 | return const_str; 32175 | else if (details::is_variable_node(branch)) 32176 | return var_str; 32177 | else if (details::is_vov_node(branch)) 32178 | return vov_str; 32179 | else if (details::is_cov_node(branch)) 32180 | return cov_str; 32181 | else if (details::is_voc_node(branch)) 32182 | return voc_str; 32183 | else if (details::is_string_node(branch)) 32184 | return str_str; 32185 | else if (details::is_const_string_node(branch)) 32186 | return cs_str; 32187 | else if (details::is_string_range_node(branch)) 32188 | return strrng_str; 32189 | else if (details::is_const_string_range_node(branch)) 32190 | return cstrrng_str; 32191 | else if (details::is_t0ot1ot2_node(branch)) 32192 | return "(" + dynamic_cast<details::T0oT1oT2_base_node<T>*>(branch)->type_id() + ")" 32193 | else if (details::is_t0ot1ot2ot3_node(branch)) 32194 | return "(" + dynamic_cast<details::T0oT1oT2oT3_base_node<T>*>(branch)->type_id() + ")" 32195 | else 32196 | return "ERROR" 32197 | } 32198 | 32199 | inline std::string branch_to_id(expression_node_ptr (&branch)[2]) const 32200 | { 32201 | return branch_to_id(branch[0]) + std::string("o") + branch_to_id(branch[1]); 32202 | } 32203 | 32204 | inline bool cov_optimisable(const details::operator_type& operation, expression_node_ptr (&branch)[2]) const 32205 | { 32206 | if (!operation_optimisable(operation)) 32207 | return false; 32208 | else 32209 | return details::is_constant_node(branch[0]) && 32210 | details::is_variable_node(branch[1]) ; 32211 | } 32212 | 32213 | inline bool voc_optimisable(const details::operator_type& operation, expression_node_ptr (&branch)[2]) const 32214 | { 32215 | if (!operation_optimisable(operation)) 32216 | return false; 32217 | else 32218 | return details::is_variable_node(branch[0]) && 32219 | details::is_constant_node(branch[1]) ; 32220 | } 32221 | 32222 | inline bool vov_optimisable(const details::operator_type& operation, expression_node_ptr (&branch)[2]) const 32223 | { 32224 | if (!operation_optimisable(operation)) 32225 | return false; 32226 | else 32227 | return details::is_variable_node(branch[0]) && 32228 | details::is_variable_node(branch[1]) ; 32229 | } 32230 | 32231 | inline bool cob_optimisable(const details::operator_type& operation, expression_node_ptr (&branch)[2]) const 32232 | { 32233 | if (!operation_optimisable(operation)) 32234 | return false; 32235 | else 32236 | return details::is_constant_node(branch[0]) && 32237 | !details::is_constant_node(branch[1]) ; 32238 | } 32239 | 32240 | inline bool boc_optimisable(const details::operator_type& operation, expression_node_ptr (&branch)[2]) const 32241 | { 32242 | if (!operation_optimisable(operation)) 32243 | return false; 32244 | else 32245 | return !details::is_constant_node(branch[0]) && 32246 | details::is_constant_node(branch[1]) ; 32247 | } 32248 | 32249 | inline bool cocob_optimisable(const details::operator_type& operation, expression_node_ptr (&branch)[2]) const 32250 | { 32251 | if ( 32252 | (details::e_add == operation) || 32253 | (details::e_sub == operation) || 32254 | (details::e_mul == operation) || 32255 | (details::e_div == operation) 32256 | ) 32257 | { 32258 | return (details::is_constant_node(branch[0]) && details::is_cob_node(branch[1])) || 32259 | (details::is_constant_node(branch[1]) && details::is_cob_node(branch[0])) ; 32260 | } 32261 | else 32262 | return false; 32263 | } 32264 | 32265 | inline bool coboc_optimisable(const details::operator_type& operation, expression_node_ptr (&branch)[2]) const 32266 | { 32267 | if ( 32268 | (details::e_add == operation) || 32269 | (details::e_sub == operation) || 32270 | (details::e_mul == operation) || 32271 | (details::e_div == operation) 32272 | ) 32273 | { 32274 | return (details::is_constant_node(branch[0]) && details::is_boc_node(branch[1])) || 32275 | (details::is_constant_node(branch[1]) && details::is_boc_node(branch[0])) ; 32276 | } 32277 | else 32278 | return false; 32279 | } 32280 | 32281 | inline bool uvouv_optimisable(const details::operator_type& operation, expression_node_ptr (&branch)[2]) const 32282 | { 32283 | if (!operation_optimisable(operation)) 32284 | return false; 32285 | else 32286 | return details::is_uv_node(branch[0]) && 32287 | details::is_uv_node(branch[1]) ; 32288 | } 32289 | 32290 | inline bool vob_optimisable(const details::operator_type& operation, expression_node_ptr (&branch)[2]) const 32291 | { 32292 | if (!operation_optimisable(operation)) 32293 | return false; 32294 | else 32295 | return details::is_variable_node(branch[0]) && 32296 | !details::is_variable_node(branch[1]) ; 32297 | } 32298 | 32299 | inline bool bov_optimisable(const details::operator_type& operation, expression_node_ptr (&branch)[2]) const 32300 | { 32301 | if (!operation_optimisable(operation)) 32302 | return false; 32303 | else 32304 | return !details::is_variable_node(branch[0]) && 32305 | details::is_variable_node(branch[1]) ; 32306 | } 32307 | 32308 | inline bool binext_optimisable(const details::operator_type& operation, expression_node_ptr (&branch)[2]) const 32309 | { 32310 | if (!operation_optimisable(operation)) 32311 | return false; 32312 | else 32313 | return !details::is_constant_node(branch[0]) || 32314 | !details::is_constant_node(branch[1]) ; 32315 | } 32316 | 32317 | inline bool is_invalid_assignment_op(const details::operator_type& operation, expression_node_ptr (&branch)[2]) const 32318 | { 32319 | if (is_assignment_operation(operation)) 32320 | { 32321 | const bool b1_is_genstring = details::is_generally_string_node(branch[1]); 32322 | 32323 | if (details::is_string_node(branch[0])) 32324 | return !b1_is_genstring; 32325 | else if (details::is_literal_node(branch[0])) 32326 | return true; 32327 | else 32328 | return ( 32329 | !details::is_variable_node (branch[0]) && 32330 | !details::is_vector_elem_node (branch[0]) && 32331 | !details::is_vector_celem_node (branch[0]) && 32332 | !details::is_vector_elem_rtc_node (branch[0]) && 32333 | !details::is_vector_celem_rtc_node (branch[0]) && 32334 | !details::is_rebasevector_elem_node (branch[0]) && 32335 | !details::is_rebasevector_celem_node (branch[0]) && 32336 | !details::is_rebasevector_elem_rtc_node (branch[0]) && 32337 | !details::is_rebasevector_celem_rtc_node(branch[0]) && 32338 | !details::is_vector_node (branch[0]) 32339 | ) 32340 | || b1_is_genstring; 32341 | } 32342 | else 32343 | return false; 32344 | } 32345 | 32346 | inline bool is_constpow_operation(const details::operator_type& operation, expression_node_ptr(&branch)[2]) const 32347 | { 32348 | if ( 32349 | !details::is_constant_node(branch[1]) || 32350 | details::is_constant_node(branch[0]) || 32351 | details::is_variable_node(branch[0]) || 32352 | details::is_vector_node (branch[0]) || 32353 | details::is_generally_string_node(branch[0]) 32354 | ) 32355 | return false; 32356 | 32357 | const Type c = static_cast<details::literal_node<Type>*>(branch[1])->value(); 32358 | 32359 | return cardinal_pow_optimisable(operation, c); 32360 | } 32361 | 32362 | inline bool is_invalid_break_continue_op(expression_node_ptr (&branch)[2]) const 32363 | { 32364 | return ( 32365 | details::is_break_node (branch[0]) || 32366 | details::is_break_node (branch[1]) || 32367 | details::is_continue_node(branch[0]) || 32368 | details::is_continue_node(branch[1]) 32369 | ); 32370 | } 32371 | 32372 | inline bool is_invalid_string_op(const details::operator_type& operation, expression_node_ptr (&branch)[2]) const 32373 | { 32374 | const bool b0_string = is_generally_string_node(branch[0]); 32375 | const bool b1_string = is_generally_string_node(branch[1]); 32376 | 32377 | bool result = false; 32378 | 32379 | if (b0_string != b1_string) 32380 | result = true; 32381 | else if (!valid_string_operation(operation) && b0_string && b1_string) 32382 | result = true; 32383 | 32384 | if (result) 32385 | { 32386 | parser_->set_synthesis_error("Invalid string operation"); 32387 | } 32388 | 32389 | return result; 32390 | } 32391 | 32392 | inline bool is_invalid_string_op(const details::operator_type& operation, expression_node_ptr (&branch)[3]) const 32393 | { 32394 | const bool b0_string = is_generally_string_node(branch[0]); 32395 | const bool b1_string = is_generally_string_node(branch[1]); 32396 | const bool b2_string = is_generally_string_node(branch[2]); 32397 | 32398 | bool result = false; 32399 | 32400 | if ((b0_string != b1_string) || (b1_string != b2_string)) 32401 | result = true; 32402 | else if ((details::e_inrange != operation) && b0_string && b1_string && b2_string) 32403 | result = true; 32404 | 32405 | if (result) 32406 | { 32407 | parser_->set_synthesis_error("Invalid string operation"); 32408 | } 32409 | 32410 | return result; 32411 | } 32412 | 32413 | inline bool is_string_operation(const details::operator_type& operation, expression_node_ptr (&branch)[2]) const 32414 | { 32415 | const bool b0_string = is_generally_string_node(branch[0]); 32416 | const bool b1_string = is_generally_string_node(branch[1]); 32417 | 32418 | return (b0_string && b1_string && valid_string_operation(operation)); 32419 | } 32420 | 32421 | inline bool is_string_operation(const details::operator_type& operation, expression_node_ptr (&branch)[3]) const 32422 | { 32423 | const bool b0_string = is_generally_string_node(branch[0]); 32424 | const bool b1_string = is_generally_string_node(branch[1]); 32425 | const bool b2_string = is_generally_string_node(branch[2]); 32426 | 32427 | return (b0_string && b1_string && b2_string && (details::e_inrange == operation)); 32428 | } 32429 | 32430 | #ifndef exprtk_disable_sc_andor 32431 | inline bool is_shortcircuit_expression(const details::operator_type& operation) const 32432 | { 32433 | return ( 32434 | (details::e_scand == operation) || 32435 | (details::e_scor == operation) 32436 | ); 32437 | } 32438 | #else 32439 | inline bool is_shortcircuit_expression(const details::operator_type&) const 32440 | { 32441 | return false; 32442 | } 32443 | #endif 32444 | 32445 | inline bool is_null_present(expression_node_ptr (&branch)[2]) const 32446 | { 32447 | return ( 32448 | details::is_null_node(branch[0]) || 32449 | details::is_null_node(branch[1]) 32450 | ); 32451 | } 32452 | 32453 | inline bool is_vector_eqineq_logic_operation(const details::operator_type& operation, expression_node_ptr (&branch)[2]) const 32454 | { 32455 | if (!is_ivector_node(branch[0]) && !is_ivector_node(branch[1])) 32456 | return false; 32457 | else 32458 | return ( 32459 | (details::e_lt == operation) || 32460 | (details::e_lte == operation) || 32461 | (details::e_gt == operation) || 32462 | (details::e_gte == operation) || 32463 | (details::e_eq == operation) || 32464 | (details::e_ne == operation) || 32465 | (details::e_equal == operation) || 32466 | (details::e_and == operation) || 32467 | (details::e_nand == operation) || 32468 | (details::e_or == operation) || 32469 | (details::e_nor == operation) || 32470 | (details::e_xor == operation) || 32471 | (details::e_xnor == operation) 32472 | ); 32473 | } 32474 | 32475 | inline bool is_vector_arithmetic_operation(const details::operator_type& operation, expression_node_ptr (&branch)[2]) const 32476 | { 32477 | if (!is_ivector_node(branch[0]) && !is_ivector_node(branch[1])) 32478 | return false; 32479 | else 32480 | return ( 32481 | (details::e_add == operation) || 32482 | (details::e_sub == operation) || 32483 | (details::e_mul == operation) || 32484 | (details::e_div == operation) || 32485 | (details::e_pow == operation) 32486 | ); 32487 | } 32488 | 32489 | inline expression_node_ptr operator() (const details::operator_type& operation, expression_node_ptr (&branch)[2]) 32490 | { 32491 | if ((0 == branch[0]) || (0 == branch[1])) 32492 | { 32493 | parser_->set_error(parser_error::make_error( 32494 | parser_error::e_syntax, 32495 | parser_->current_state().token, 32496 | "ERR249 - Invalid branches received for operator '" + details::to_str(operation) + "'", 32497 | exprtk_error_location)); 32498 | 32499 | return error_node(); 32500 | } 32501 | else if (is_invalid_string_op(operation,branch)) 32502 | { 32503 | parser_->set_error(parser_error::make_error( 32504 | parser_error::e_syntax, 32505 | parser_->current_state().token, 32506 | "ERR250 - Invalid branch pair for string operator '" + details::to_str(operation) + "'", 32507 | exprtk_error_location)); 32508 | 32509 | return error_node(); 32510 | } 32511 | else if (is_invalid_assignment_op(operation,branch)) 32512 | { 32513 | parser_->set_error(parser_error::make_error( 32514 | parser_error::e_syntax, 32515 | parser_->current_state().token, 32516 | "ERR251 - Invalid branch pair for assignment operator '" + details::to_str(operation) + "'", 32517 | exprtk_error_location)); 32518 | 32519 | return error_node(); 32520 | } 32521 | else if (is_invalid_break_continue_op(branch)) 32522 | { 32523 | parser_->set_error(parser_error::make_error( 32524 | parser_error::e_syntax, 32525 | parser_->current_state().token, 32526 | "ERR252 - Invalid branch pair for break/continue operator '" + details::to_str(operation) + "'", 32527 | exprtk_error_location)); 32528 | 32529 | return error_node(); 32530 | } 32531 | else if (details::e_assign == operation) 32532 | { 32533 | return synthesize_assignment_expression(operation, branch); 32534 | } 32535 | else if (details::e_swap == operation) 32536 | { 32537 | return synthesize_swap_expression(branch); 32538 | } 32539 | else if (is_assignment_operation(operation)) 32540 | { 32541 | return synthesize_assignment_operation_expression(operation, branch); 32542 | } 32543 | else if (is_vector_eqineq_logic_operation(operation, branch)) 32544 | { 32545 | return synthesize_veceqineqlogic_operation_expression(operation, branch); 32546 | } 32547 | else if (is_vector_arithmetic_operation(operation, branch)) 32548 | { 32549 | return synthesize_vecarithmetic_operation_expression(operation, branch); 32550 | } 32551 | else if (is_shortcircuit_expression(operation)) 32552 | { 32553 | return synthesize_shortcircuit_expression(operation, branch); 32554 | } 32555 | else if (is_string_operation(operation, branch)) 32556 | { 32557 | return synthesize_string_expression(operation, branch); 32558 | } 32559 | else if (is_null_present(branch)) 32560 | { 32561 | return synthesize_null_expression(operation, branch); 32562 | } 32563 | #ifndef exprtk_disable_cardinal_pow_optimisation 32564 | else if (is_constpow_operation(operation, branch)) 32565 | { 32566 | return cardinal_pow_optimisation(branch); 32567 | } 32568 | #endif 32569 | 32570 | expression_node_ptr result = error_node(); 32571 | 32572 | #ifndef exprtk_disable_enhanced_features 32573 | if (synthesize_expression(operation, branch, result)) 32574 | { 32575 | return result; 32576 | } 32577 | else 32578 | #endif 32579 | 32580 | { 32581 | /* 32582 | Possible reductions: 32583 | 1. c o cob -> cob 32584 | 2. cob o c -> cob 32585 | 3. c o boc -> boc 32586 | 4. boc o c -> boc 32587 | */ 32588 | result = error_node(); 32589 | 32590 | if (cocob_optimisable(operation, branch)) 32591 | { 32592 | result = synthesize_cocob_expression::process((*this), operation, branch); 32593 | } 32594 | else if (coboc_optimisable(operation, branch) && (0 == result)) 32595 | { 32596 | result = synthesize_coboc_expression::process((*this), operation, branch); 32597 | } 32598 | 32599 | if (result) 32600 | return result; 32601 | } 32602 | 32603 | if (uvouv_optimisable(operation, branch)) 32604 | { 32605 | return synthesize_uvouv_expression(operation, branch); 32606 | } 32607 | else if (vob_optimisable(operation, branch)) 32608 | { 32609 | return synthesize_vob_expression::process((*this), operation, branch); 32610 | } 32611 | else if (bov_optimisable(operation, branch)) 32612 | { 32613 | return synthesize_bov_expression::process((*this), operation, branch); 32614 | } 32615 | else if (cob_optimisable(operation, branch)) 32616 | { 32617 | return synthesize_cob_expression::process((*this), operation, branch); 32618 | } 32619 | else if (boc_optimisable(operation, branch)) 32620 | { 32621 | return synthesize_boc_expression::process((*this), operation, branch); 32622 | } 32623 | #ifndef exprtk_disable_enhanced_features 32624 | else if (cov_optimisable(operation, branch)) 32625 | { 32626 | return synthesize_cov_expression::process((*this), operation, branch); 32627 | } 32628 | #endif 32629 | else if (binext_optimisable(operation, branch)) 32630 | { 32631 | return synthesize_binary_ext_expression::process((*this), operation, branch); 32632 | } 32633 | else 32634 | return synthesize_expression<binary_node_t,2>(operation, branch); 32635 | } 32636 | 32637 | inline expression_node_ptr operator() (const details::operator_type& operation, expression_node_ptr (&branch)[3]) 32638 | { 32639 | if ( 32640 | (0 == branch[0]) || 32641 | (0 == branch[1]) || 32642 | (0 == branch[2]) 32643 | ) 32644 | { 32645 | details::free_all_nodes(*node_allocator_,branch); 32646 | 32647 | parser_->set_error(parser_error::make_error( 32648 | parser_error::e_syntax, 32649 | parser_->current_state().token, 32650 | "ERR253 - Invalid branches operator '" + details::to_str(operation) + "'", 32651 | exprtk_error_location)); 32652 | 32653 | return error_node(); 32654 | } 32655 | else if (is_invalid_string_op(operation, branch)) 32656 | { 32657 | parser_->set_error(parser_error::make_error( 32658 | parser_error::e_syntax, 32659 | parser_->current_state().token, 32660 | "ERR254 - Invalid branches for string operator '" + details::to_str(operation) + "'", 32661 | exprtk_error_location)); 32662 | 32663 | return error_node(); 32664 | } 32665 | else if (is_string_operation(operation, branch)) 32666 | { 32667 | return synthesize_string_expression(operation, branch); 32668 | } 32669 | else 32670 | return synthesize_expression<trinary_node_t,3>(operation, branch); 32671 | } 32672 | 32673 | inline expression_node_ptr operator() (const details::operator_type& operation, expression_node_ptr (&branch)[4]) 32674 | { 32675 | return synthesize_expression<quaternary_node_t,4>(operation,branch); 32676 | } 32677 | 32678 | inline expression_node_ptr operator() (const details::operator_type& operation, expression_node_ptr b0) 32679 | { 32680 | expression_node_ptr branch[1] = { b0 }; 32681 | return (*this)(operation,branch); 32682 | } 32683 | 32684 | inline expression_node_ptr operator() (const details::operator_type& operation, expression_node_ptr& b0, expression_node_ptr& b1) 32685 | { 32686 | expression_node_ptr result = error_node(); 32687 | 32688 | if ((0 != b0) && (0 != b1)) 32689 | { 32690 | expression_node_ptr branch[2] = { b0, b1 }; 32691 | result = expression_generator<Type>::operator()(operation, branch); 32692 | b0 = branch[0]; 32693 | b1 = branch[1]; 32694 | } 32695 | 32696 | return result; 32697 | } 32698 | 32699 | inline expression_node_ptr conditional(expression_node_ptr condition, 32700 | expression_node_ptr consequent, 32701 | expression_node_ptr alternative) const 32702 | { 32703 | if ((0 == condition) || (0 == consequent)) 32704 | { 32705 | details::free_node(*node_allocator_, condition ); 32706 | details::free_node(*node_allocator_, consequent ); 32707 | details::free_node(*node_allocator_, alternative); 32708 | 32709 | const std::string invalid_branches = 32710 | ((0 == condition ) ? std::string("condition ") : "") + 32711 | ((0 == consequent) ? std::string("consequent") : "") ; 32712 | 32713 | parser_->set_error(parser_error::make_error( 32714 | parser_error::e_parser, 32715 | parser_->current_state().token, 32716 | "ERR255 - Invalid " + invalid_branches + " for conditional statement", 32717 | exprtk_error_location)); 32718 | 32719 | return error_node(); 32720 | } 32721 | // Can the condition be immediately evaluated? if so optimise. 32722 | else if (details::is_constant_node(condition)) 32723 | { 32724 | // True branch 32725 | if (details::is_true(condition)) 32726 | { 32727 | details::free_node(*node_allocator_, condition ); 32728 | details::free_node(*node_allocator_, alternative); 32729 | 32730 | return consequent; 32731 | } 32732 | // False branch 32733 | else 32734 | { 32735 | details::free_node(*node_allocator_, condition ); 32736 | details::free_node(*node_allocator_, consequent); 32737 | 32738 | if (alternative) 32739 | return alternative; 32740 | else 32741 | return node_allocator_->allocate<details::null_node<T> >(); 32742 | } 32743 | } 32744 | 32745 | expression_node_ptr result = error_node(); 32746 | std::string node_name = "Unknown!" 32747 | 32748 | if ((0 != consequent) && (0 != alternative)) 32749 | { 32750 | result = node_allocator_->allocate<conditional_node_t>(condition, consequent, alternative); 32751 | node_name = "conditional_node_t" 32752 | } 32753 | else 32754 | { 32755 | result = node_allocator_->allocate<cons_conditional_node_t>(condition, consequent); 32756 | node_name = "cons_conditional_node_t" 32757 | } 32758 | 32759 | if (result && result->valid()) 32760 | { 32761 | return result; 32762 | } 32763 | 32764 | parser_->set_error(parser_error::make_error( 32765 | parser_error::e_parser, 32766 | token_t(), 32767 | "ERR256 - Failed to synthesize node: " + node_name, 32768 | exprtk_error_location)); 32769 | 32770 | details::free_node(*node_allocator_, result); 32771 | return error_node(); 32772 | } 32773 | 32774 | #ifndef exprtk_disable_string_capabilities 32775 | inline expression_node_ptr conditional_string(expression_node_ptr condition, 32776 | expression_node_ptr consequent, 32777 | expression_node_ptr alternative) const 32778 | { 32779 | if ((0 == condition) || (0 == consequent)) 32780 | { 32781 | details::free_node(*node_allocator_, condition ); 32782 | details::free_node(*node_allocator_, consequent ); 32783 | details::free_node(*node_allocator_, alternative); 32784 | 32785 | const std::string invalid_branches = 32786 | ((0 == condition ) ? std::string("condition ") : "") + 32787 | ((0 == consequent) ? std::string("consequent") : "") ; 32788 | 32789 | parser_->set_error(parser_error::make_error( 32790 | parser_error::e_parser, 32791 | parser_->current_state().token, 32792 | "ERR257 - Invalid " + invalid_branches + " for string conditional statement", 32793 | exprtk_error_location)); 32794 | 32795 | return error_node(); 32796 | } 32797 | // Can the condition be immediately evaluated? if so optimise. 32798 | else if (details::is_constant_node(condition)) 32799 | { 32800 | // True branch 32801 | if (details::is_true(condition)) 32802 | { 32803 | details::free_node(*node_allocator_, condition ); 32804 | details::free_node(*node_allocator_, alternative); 32805 | 32806 | return consequent; 32807 | } 32808 | // False branch 32809 | else 32810 | { 32811 | details::free_node(*node_allocator_, condition ); 32812 | details::free_node(*node_allocator_, consequent); 32813 | 32814 | if (alternative) 32815 | return alternative; 32816 | else 32817 | return node_allocator_-> 32818 | allocate_c<details::string_literal_node<Type> >(""); 32819 | } 32820 | } 32821 | else if ((0 != consequent) && (0 != alternative)) 32822 | { 32823 | expression_node_ptr result = 32824 | node_allocator_->allocate<conditional_string_node_t>(condition, consequent, alternative); 32825 | 32826 | if (result && result->valid()) 32827 | { 32828 | return result; 32829 | } 32830 | 32831 | parser_->set_error(parser_error::make_error( 32832 | parser_error::e_parser, 32833 | token_t(), 32834 | "ERR258 - Failed to synthesize node: conditional_string_node_t", 32835 | exprtk_error_location)); 32836 | 32837 | details::free_node(*node_allocator_, result); 32838 | } 32839 | 32840 | return error_node(); 32841 | } 32842 | #else 32843 | inline expression_node_ptr conditional_string(expression_node_ptr, 32844 | expression_node_ptr, 32845 | expression_node_ptr) const 32846 | { 32847 | return error_node(); 32848 | } 32849 | #endif 32850 | 32851 | inline expression_node_ptr conditional_vector(expression_node_ptr condition, 32852 | expression_node_ptr consequent, 32853 | expression_node_ptr alternative) const 32854 | { 32855 | if ((0 == condition) || (0 == consequent)) 32856 | { 32857 | details::free_node(*node_allocator_, condition ); 32858 | details::free_node(*node_allocator_, consequent ); 32859 | details::free_node(*node_allocator_, alternative); 32860 | 32861 | const std::string invalid_branches = 32862 | ((0 == condition ) ? std::string("condition ") : "") + 32863 | ((0 == consequent) ? std::string("consequent") : "") ; 32864 | 32865 | parser_->set_error(parser_error::make_error( 32866 | parser_error::e_parser, 32867 | parser_->current_state().token, 32868 | "ERR259 - Invalid " + invalid_branches + " for vector conditional statement", 32869 | exprtk_error_location)); 32870 | 32871 | return error_node(); 32872 | } 32873 | // Can the condition be immediately evaluated? if so optimise. 32874 | else if (details::is_constant_node(condition)) 32875 | { 32876 | // True branch 32877 | if (details::is_true(condition)) 32878 | { 32879 | details::free_node(*node_allocator_, condition ); 32880 | details::free_node(*node_allocator_, alternative); 32881 | 32882 | return consequent; 32883 | } 32884 | // False branch 32885 | else 32886 | { 32887 | details::free_node(*node_allocator_, condition ); 32888 | details::free_node(*node_allocator_, consequent); 32889 | 32890 | if (alternative) 32891 | return alternative; 32892 | else 32893 | return node_allocator_->allocate<details::null_node<T> >(); 32894 | 32895 | } 32896 | } 32897 | else if ((0 != consequent) && (0 != alternative)) 32898 | { 32899 | return node_allocator_-> 32900 | allocate<conditional_vector_node_t>(condition, consequent, alternative); 32901 | } 32902 | else 32903 | return error_node(); 32904 | } 32905 | 32906 | inline loop_runtime_check_ptr get_loop_runtime_check(const loop_runtime_check::loop_types loop_type) const 32907 | { 32908 | if ( 32909 | parser_->loop_runtime_check_ && 32910 | (loop_type == (parser_->loop_runtime_check_->loop_set & loop_type)) 32911 | ) 32912 | { 32913 | return parser_->loop_runtime_check_; 32914 | } 32915 | 32916 | return loop_runtime_check_ptr(0); 32917 | } 32918 | 32919 | inline vector_access_runtime_check_ptr get_vector_access_runtime_check() const 32920 | { 32921 | return parser_->vector_access_runtime_check_; 32922 | } 32923 | 32924 | inline expression_node_ptr while_loop(expression_node_ptr& condition, 32925 | expression_node_ptr& branch, 32926 | const bool break_continue_present = false) const 32927 | { 32928 | if ( 32929 | !break_continue_present && 32930 | !parser_->state_.return_stmt_present && 32931 | details::is_constant_node(condition) 32932 | ) 32933 | { 32934 | expression_node_ptr result = error_node(); 32935 | if (details::is_true(condition)) 32936 | { 32937 | // Infinite loops are not allowed. 32938 | 32939 | parser_->set_error(parser_error::make_error( 32940 | parser_error::e_parser, 32941 | parser_->current_state().token, 32942 | "ERR260 - Infinite loop condition without 'break' or 'return' not allowed in while-loops", 32943 | exprtk_error_location)); 32944 | 32945 | result = error_node(); 32946 | } 32947 | else 32948 | result = node_allocator_->allocate<details::null_node<Type> >(); 32949 | 32950 | details::free_node(*node_allocator_, condition); 32951 | details::free_node(*node_allocator_, branch ); 32952 | 32953 | return result; 32954 | } 32955 | else if (details::is_null_node(condition)) 32956 | { 32957 | details::free_node(*node_allocator_,condition); 32958 | 32959 | return branch; 32960 | } 32961 | 32962 | loop_runtime_check_ptr rtc = get_loop_runtime_check(loop_runtime_check::e_while_loop); 32963 | 32964 | if (!break_continue_present) 32965 | { 32966 | if (rtc) 32967 | return node_allocator_->allocate<while_loop_rtc_node_t> 32968 | (condition, branch, rtc); 32969 | else 32970 | return node_allocator_->allocate<while_loop_node_t> 32971 | (condition, branch); 32972 | } 32973 | #ifndef exprtk_disable_break_continue 32974 | else 32975 | { 32976 | if (rtc) 32977 | return node_allocator_->allocate<while_loop_bc_rtc_node_t> 32978 | (condition, branch, rtc); 32979 | else 32980 | return node_allocator_->allocate<while_loop_bc_node_t> 32981 | (condition, branch); 32982 | } 32983 | #else 32984 | return error_node(); 32985 | #endif 32986 | } 32987 | 32988 | inline expression_node_ptr repeat_until_loop(expression_node_ptr& condition, 32989 | expression_node_ptr& branch, 32990 | const bool break_continue_present = false) const 32991 | { 32992 | if (!break_continue_present && details::is_constant_node(condition)) 32993 | { 32994 | if ( 32995 | details::is_true(condition) && 32996 | details::is_constant_node(branch) 32997 | ) 32998 | { 32999 | free_node(*node_allocator_,condition); 33000 | 33001 | return branch; 33002 | } 33003 | 33004 | details::free_node(*node_allocator_, condition); 33005 | details::free_node(*node_allocator_, branch ); 33006 | 33007 | return error_node(); 33008 | } 33009 | else if (details::is_null_node(condition)) 33010 | { 33011 | details::free_node(*node_allocator_,condition); 33012 | 33013 | return branch; 33014 | } 33015 | 33016 | loop_runtime_check_ptr rtc = get_loop_runtime_check(loop_runtime_check::e_repeat_until_loop); 33017 | 33018 | if (!break_continue_present) 33019 | { 33020 | if (rtc) 33021 | return node_allocator_->allocate<repeat_until_loop_rtc_node_t> 33022 | (condition, branch, rtc); 33023 | else 33024 | return node_allocator_->allocate<repeat_until_loop_node_t> 33025 | (condition, branch); 33026 | } 33027 | #ifndef exprtk_disable_break_continue 33028 | else 33029 | { 33030 | if (rtc) 33031 | return node_allocator_->allocate<repeat_until_loop_bc_rtc_node_t> 33032 | (condition, branch, rtc); 33033 | else 33034 | return node_allocator_->allocate<repeat_until_loop_bc_node_t> 33035 | (condition, branch); 33036 | } 33037 | #else 33038 | return error_node(); 33039 | #endif 33040 | } 33041 | 33042 | inline expression_node_ptr for_loop(expression_node_ptr& initialiser, 33043 | expression_node_ptr& condition, 33044 | expression_node_ptr& incrementor, 33045 | expression_node_ptr& loop_body, 33046 | bool break_continue_present = false) const 33047 | { 33048 | if ( 33049 | !break_continue_present && 33050 | !parser_->state_.return_stmt_present && 33051 | details::is_constant_node(condition) 33052 | ) 33053 | { 33054 | expression_node_ptr result = error_node(); 33055 | 33056 | if (details::is_true(condition)) 33057 | { 33058 | // Infinite loops are not allowed. 33059 | 33060 | parser_->set_error(parser_error::make_error( 33061 | parser_error::e_parser, 33062 | parser_->current_state().token, 33063 | "ERR261 - Infinite loop condition without 'break' or 'return' not allowed in for-loop", 33064 | exprtk_error_location)); 33065 | 33066 | result = error_node(); 33067 | } 33068 | else 33069 | result = node_allocator_->allocate<details::null_node<Type> >(); 33070 | 33071 | details::free_node(*node_allocator_, initialiser); 33072 | details::free_node(*node_allocator_, condition ); 33073 | details::free_node(*node_allocator_, incrementor); 33074 | details::free_node(*node_allocator_, loop_body ); 33075 | 33076 | return result; 33077 | } 33078 | else if (details::is_null_node(condition) || (0 == condition)) 33079 | { 33080 | details::free_node(*node_allocator_, initialiser); 33081 | details::free_node(*node_allocator_, condition ); 33082 | details::free_node(*node_allocator_, incrementor); 33083 | 33084 | return loop_body; 33085 | } 33086 | 33087 | loop_runtime_check_ptr rtc = get_loop_runtime_check(loop_runtime_check::e_for_loop); 33088 | 33089 | if (!break_continue_present) 33090 | { 33091 | if (rtc) 33092 | return node_allocator_->allocate<for_loop_rtc_node_t> 33093 | ( 33094 | initialiser, 33095 | condition, 33096 | incrementor, 33097 | loop_body, 33098 | rtc 33099 | ); 33100 | else 33101 | return node_allocator_->allocate<for_loop_node_t> 33102 | ( 33103 | initialiser, 33104 | condition, 33105 | incrementor, 33106 | loop_body 33107 | ); 33108 | } 33109 | #ifndef exprtk_disable_break_continue 33110 | else 33111 | { 33112 | if (rtc) 33113 | return node_allocator_->allocate<for_loop_bc_rtc_node_t> 33114 | ( 33115 | initialiser, 33116 | condition, 33117 | incrementor, 33118 | loop_body, 33119 | rtc 33120 | ); 33121 | else 33122 | return node_allocator_->allocate<for_loop_bc_node_t> 33123 | ( 33124 | initialiser, 33125 | condition, 33126 | incrementor, 33127 | loop_body 33128 | ); 33129 | } 33130 | #else 33131 | return error_node(); 33132 | #endif 33133 | } 33134 | 33135 | template <typename Allocator, 33136 | template <typename, typename> class Sequence> 33137 | inline expression_node_ptr const_optimise_switch(Sequence<expression_node_ptr,Allocator>& arg_list) 33138 | { 33139 | expression_node_ptr result = error_node(); 33140 | 33141 | for (std::size_t i = 0; i < (arg_list.size() / 2); ++i) 33142 | { 33143 | expression_node_ptr condition = arg_list[(2 * i) ]; 33144 | expression_node_ptr consequent = arg_list[(2 * i) + 1]; 33145 | 33146 | if ((0 == result) && details::is_true(condition)) 33147 | { 33148 | result = consequent; 33149 | break; 33150 | } 33151 | } 33152 | 33153 | if (0 == result) 33154 | { 33155 | result = arg_list.back(); 33156 | } 33157 | 33158 | for (std::size_t i = 0; i < arg_list.size(); ++i) 33159 | { 33160 | expression_node_ptr current_expr = arg_list[i]; 33161 | 33162 | if (current_expr && (current_expr != result)) 33163 | { 33164 | free_node(*node_allocator_,current_expr); 33165 | } 33166 | } 33167 | 33168 | return result; 33169 | } 33170 | 33171 | template <typename Allocator, 33172 | template <typename, typename> class Sequence> 33173 | inline expression_node_ptr const_optimise_mswitch(Sequence<expression_node_ptr,Allocator>& arg_list) 33174 | { 33175 | expression_node_ptr result = error_node(); 33176 | 33177 | for (std::size_t i = 0; i < (arg_list.size() / 2); ++i) 33178 | { 33179 | expression_node_ptr condition = arg_list[(2 * i) ]; 33180 | expression_node_ptr consequent = arg_list[(2 * i) + 1]; 33181 | 33182 | if (details::is_true(condition)) 33183 | { 33184 | result = consequent; 33185 | } 33186 | } 33187 | 33188 | if (0 == result) 33189 | { 33190 | const T zero = T(0); 33191 | result = node_allocator_->allocate<literal_node_t>(zero); 33192 | } 33193 | 33194 | for (std::size_t i = 0; i < arg_list.size(); ++i) 33195 | { 33196 | expression_node_ptr& current_expr = arg_list[i]; 33197 | 33198 | if (current_expr && (current_expr != result)) 33199 | { 33200 | details::free_node(*node_allocator_,current_expr); 33201 | } 33202 | } 33203 | 33204 | return result; 33205 | } 33206 | 33207 | struct switch_nodes 33208 | { 33209 | typedef std::vector<std::pair<expression_node_ptr,bool> > arg_list_t; 33210 | 33211 | #define case_stmt(N) \ 33212 | if (is_true(arg[(2 * N)].first)) { return arg[(2 * N) + 1].first->value(); } \ 33213 | 33214 | struct switch_impl_1 33215 | { 33216 | static inline T process(const arg_list_t& arg) 33217 | { 33218 | case_stmt(0) 33219 | 33220 | assert(arg.size() == ((2 * 1) + 1)); 33221 | 33222 | return arg.back().first->value(); 33223 | } 33224 | }; 33225 | 33226 | struct switch_impl_2 33227 | { 33228 | static inline T process(const arg_list_t& arg) 33229 | { 33230 | case_stmt(0) case_stmt(1) 33231 | 33232 | assert(arg.size() == ((2 * 2) + 1)); 33233 | 33234 | return arg.back().first->value(); 33235 | } 33236 | }; 33237 | 33238 | struct switch_impl_3 33239 | { 33240 | static inline T process(const arg_list_t& arg) 33241 | { 33242 | case_stmt(0) case_stmt(1) 33243 | case_stmt(2) 33244 | 33245 | assert(arg.size() == ((2 * 3) + 1)); 33246 | 33247 | return arg.back().first->value(); 33248 | } 33249 | }; 33250 | 33251 | struct switch_impl_4 33252 | { 33253 | static inline T process(const arg_list_t& arg) 33254 | { 33255 | case_stmt(0) case_stmt(1) 33256 | case_stmt(2) case_stmt(3) 33257 | 33258 | assert(arg.size() == ((2 * 4) + 1)); 33259 | 33260 | return arg.back().first->value(); 33261 | } 33262 | }; 33263 | 33264 | struct switch_impl_5 33265 | { 33266 | static inline T process(const arg_list_t& arg) 33267 | { 33268 | case_stmt(0) case_stmt(1) 33269 | case_stmt(2) case_stmt(3) 33270 | case_stmt(4) 33271 | 33272 | assert(arg.size() == ((2 * 5) + 1)); 33273 | 33274 | return arg.back().first->value(); 33275 | } 33276 | }; 33277 | 33278 | struct switch_impl_6 33279 | { 33280 | static inline T process(const arg_list_t& arg) 33281 | { 33282 | case_stmt(0) case_stmt(1) 33283 | case_stmt(2) case_stmt(3) 33284 | case_stmt(4) case_stmt(5) 33285 | 33286 | assert(arg.size() == ((2 * 6) + 1)); 33287 | 33288 | return arg.back().first->value(); 33289 | } 33290 | }; 33291 | 33292 | struct switch_impl_7 33293 | { 33294 | static inline T process(const arg_list_t& arg) 33295 | { 33296 | case_stmt(0) case_stmt(1) 33297 | case_stmt(2) case_stmt(3) 33298 | case_stmt(4) case_stmt(5) 33299 | case_stmt(6) 33300 | 33301 | assert(arg.size() == ((2 * 7) + 1)); 33302 | 33303 | return arg.back().first->value(); 33304 | } 33305 | }; 33306 | 33307 | #undef case_stmt 33308 | }; 33309 | 33310 | template <typename Allocator, 33311 | template <typename, typename> class Sequence> 33312 | inline expression_node_ptr switch_statement(Sequence<expression_node_ptr,Allocator>& arg_list, const bool default_statement_present) 33313 | { 33314 | if (arg_list.empty()) 33315 | return error_node(); 33316 | else if ( 33317 | !all_nodes_valid(arg_list) || 33318 | (!default_statement_present && (arg_list.size() < 2)) 33319 | ) 33320 | { 33321 | details::free_all_nodes(*node_allocator_,arg_list); 33322 | 33323 | return error_node(); 33324 | } 33325 | else if (is_constant_foldable(arg_list)) 33326 | return const_optimise_switch(arg_list); 33327 | 33328 | switch ((arg_list.size() - 1) / 2) 33329 | { 33330 | #define case_stmt(N) \ 33331 | case N : \ 33332 | return node_allocator_-> \ 33333 | allocate<details::switch_n_node \ 33334 | <Type,typename switch_nodes::switch_impl_##N > >(arg_list); \ 33335 | 33336 | case_stmt(1) 33337 | case_stmt(2) 33338 | case_stmt(3) 33339 | case_stmt(4) 33340 | case_stmt(5) 33341 | case_stmt(6) 33342 | case_stmt(7) 33343 | #undef case_stmt 33344 | 33345 | default : return node_allocator_->allocate<details::switch_node<Type> >(arg_list); 33346 | } 33347 | } 33348 | 33349 | template <typename Allocator, 33350 | template <typename, typename> class Sequence> 33351 | inline expression_node_ptr multi_switch_statement(Sequence<expression_node_ptr,Allocator>& arg_list) 33352 | { 33353 | if (!all_nodes_valid(arg_list)) 33354 | { 33355 | details::free_all_nodes(*node_allocator_,arg_list); 33356 | 33357 | return error_node(); 33358 | } 33359 | else if (is_constant_foldable(arg_list)) 33360 | return const_optimise_mswitch(arg_list); 33361 | else 33362 | return node_allocator_->allocate<details::multi_switch_node<Type> >(arg_list); 33363 | } 33364 | 33365 | inline expression_node_ptr assert_call(expression_node_ptr& assert_condition, 33366 | expression_node_ptr& assert_message, 33367 | const assert_check::assert_context& context) 33368 | { 33369 | typedef details::assert_node<Type> alloc_type; 33370 | 33371 | expression_node_ptr result = node_allocator_->allocate_rrrr<alloc_type> 33372 | (assert_condition, assert_message, parser_->assert_check_, context); 33373 | 33374 | if (result && result->valid()) 33375 | { 33376 | parser_->state_.activate_side_effect("assert_call()"); 33377 | return result; 33378 | } 33379 | 33380 | details::free_node(*node_allocator_, result ); 33381 | details::free_node(*node_allocator_, assert_condition); 33382 | details::free_node(*node_allocator_, assert_message ); 33383 | 33384 | return error_node(); 33385 | } 33386 | 33387 | #define unary_opr_switch_statements \ 33388 | case_stmt(details::e_abs , details::abs_op ) \ 33389 | case_stmt(details::e_acos , details::acos_op ) \ 33390 | case_stmt(details::e_acosh , details::acosh_op) \ 33391 | case_stmt(details::e_asin , details::asin_op ) \ 33392 | case_stmt(details::e_asinh , details::asinh_op) \ 33393 | case_stmt(details::e_atan , details::atan_op ) \ 33394 | case_stmt(details::e_atanh , details::atanh_op) \ 33395 | case_stmt(details::e_ceil , details::ceil_op ) \ 33396 | case_stmt(details::e_cos , details::cos_op ) \ 33397 | case_stmt(details::e_cosh , details::cosh_op ) \ 33398 | case_stmt(details::e_exp , details::exp_op ) \ 33399 | case_stmt(details::e_expm1 , details::expm1_op) \ 33400 | case_stmt(details::e_floor , details::floor_op) \ 33401 | case_stmt(details::e_log , details::log_op ) \ 33402 | case_stmt(details::e_log10 , details::log10_op) \ 33403 | case_stmt(details::e_log2 , details::log2_op ) \ 33404 | case_stmt(details::e_log1p , details::log1p_op) \ 33405 | case_stmt(details::e_neg , details::neg_op ) \ 33406 | case_stmt(details::e_pos , details::pos_op ) \ 33407 | case_stmt(details::e_round , details::round_op) \ 33408 | case_stmt(details::e_sin , details::sin_op ) \ 33409 | case_stmt(details::e_sinc , details::sinc_op ) \ 33410 | case_stmt(details::e_sinh , details::sinh_op ) \ 33411 | case_stmt(details::e_sqrt , details::sqrt_op ) \ 33412 | case_stmt(details::e_tan , details::tan_op ) \ 33413 | case_stmt(details::e_tanh , details::tanh_op ) \ 33414 | case_stmt(details::e_cot , details::cot_op ) \ 33415 | case_stmt(details::e_sec , details::sec_op ) \ 33416 | case_stmt(details::e_csc , details::csc_op ) \ 33417 | case_stmt(details::e_r2d , details::r2d_op ) \ 33418 | case_stmt(details::e_d2r , details::d2r_op ) \ 33419 | case_stmt(details::e_d2g , details::d2g_op ) \ 33420 | case_stmt(details::e_g2d , details::g2d_op ) \ 33421 | case_stmt(details::e_notl , details::notl_op ) \ 33422 | case_stmt(details::e_sgn , details::sgn_op ) \ 33423 | case_stmt(details::e_erf , details::erf_op ) \ 33424 | case_stmt(details::e_erfc , details::erfc_op ) \ 33425 | case_stmt(details::e_ncdf , details::ncdf_op ) \ 33426 | case_stmt(details::e_frac , details::frac_op ) \ 33427 | case_stmt(details::e_trunc , details::trunc_op) \ 33428 | 33429 | inline expression_node_ptr synthesize_uv_expression(const details::operator_type& operation, 33430 | expression_node_ptr (&branch)[1]) 33431 | { 33432 | T& v = static_cast<details::variable_node<T>*>(branch[0])->ref(); 33433 | 33434 | switch (operation) 33435 | { 33436 | #define case_stmt(op0, op1) \ 33437 | case op0 : return node_allocator_-> \ 33438 | allocate<typename details::unary_variable_node<Type,op1<Type> > >(v); \ 33439 | 33440 | unary_opr_switch_statements 33441 | #undef case_stmt 33442 | default : return error_node(); 33443 | } 33444 | } 33445 | 33446 | inline expression_node_ptr synthesize_uvec_expression(const details::operator_type& operation, 33447 | expression_node_ptr (&branch)[1]) 33448 | { 33449 | switch (operation) 33450 | { 33451 | #define case_stmt(op0, op1) \ 33452 | case op0 : return node_allocator_-> \ 33453 | allocate<typename details::unary_vector_node<Type,op1<Type> > > \ 33454 | (operation, branch[0]); \ 33455 | 33456 | unary_opr_switch_statements 33457 | #undef case_stmt 33458 | default : return error_node(); 33459 | } 33460 | } 33461 | 33462 | inline expression_node_ptr synthesize_unary_expression(const details::operator_type& operation, 33463 | expression_node_ptr (&branch)[1]) 33464 | { 33465 | switch (operation) 33466 | { 33467 | #define case_stmt(op0, op1) \ 33468 | case op0 : return node_allocator_-> \ 33469 | allocate<typename details::unary_branch_node<Type,op1<Type> > >(branch[0]); \ 33470 | 33471 | unary_opr_switch_statements 33472 | #undef case_stmt 33473 | default : return error_node(); 33474 | } 33475 | } 33476 | 33477 | inline expression_node_ptr const_optimise_sf3(const details::operator_type& operation, 33478 | expression_node_ptr (&branch)[3]) 33479 | { 33480 | expression_node_ptr temp_node = error_node(); 33481 | 33482 | switch (operation) 33483 | { 33484 | #define case_stmt(op) \ 33485 | case details::e_sf##op : temp_node = node_allocator_-> \ 33486 | allocate<details::sf3_node<Type,details::sf##op##_op<Type> > > \ 33487 | (operation, branch); \ 33488 | break; \ 33489 | 33490 | case_stmt(00) case_stmt(01) case_stmt(02) case_stmt(03) 33491 | case_stmt(04) case_stmt(05) case_stmt(06) case_stmt(07) 33492 | case_stmt(08) case_stmt(09) case_stmt(10) case_stmt(11) 33493 | case_stmt(12) case_stmt(13) case_stmt(14) case_stmt(15) 33494 | case_stmt(16) case_stmt(17) case_stmt(18) case_stmt(19) 33495 | case_stmt(20) case_stmt(21) case_stmt(22) case_stmt(23) 33496 | case_stmt(24) case_stmt(25) case_stmt(26) case_stmt(27) 33497 | case_stmt(28) case_stmt(29) case_stmt(30) case_stmt(31) 33498 | case_stmt(32) case_stmt(33) case_stmt(34) case_stmt(35) 33499 | case_stmt(36) case_stmt(37) case_stmt(38) case_stmt(39) 33500 | case_stmt(40) case_stmt(41) case_stmt(42) case_stmt(43) 33501 | case_stmt(44) case_stmt(45) case_stmt(46) case_stmt(47) 33502 | #undef case_stmt 33503 | default : return error_node(); 33504 | } 33505 | 33506 | assert(temp_node); 33507 | 33508 | const T v = temp_node->value(); 33509 | 33510 | details::free_node(*node_allocator_,temp_node); 33511 | 33512 | return node_allocator_->allocate<literal_node_t>(v); 33513 | } 33514 | 33515 | inline expression_node_ptr varnode_optimise_sf3(const details::operator_type& operation, expression_node_ptr (&branch)[3]) 33516 | { 33517 | typedef details::variable_node<Type>* variable_ptr; 33518 | 33519 | const Type& v0 = static_cast<variable_ptr>(branch[0])->ref(); 33520 | const Type& v1 = static_cast<variable_ptr>(branch[1])->ref(); 33521 | const Type& v2 = static_cast<variable_ptr>(branch[2])->ref(); 33522 | 33523 | switch (operation) 33524 | { 33525 | #define case_stmt(op) \ 33526 | case details::e_sf##op : return node_allocator_-> \ 33527 | allocate_rrr<details::sf3_var_node<Type,details::sf##op##_op<Type> > > \ 33528 | (v0, v1, v2); \ 33529 | 33530 | case_stmt(00) case_stmt(01) case_stmt(02) case_stmt(03) 33531 | case_stmt(04) case_stmt(05) case_stmt(06) case_stmt(07) 33532 | case_stmt(08) case_stmt(09) case_stmt(10) case_stmt(11) 33533 | case_stmt(12) case_stmt(13) case_stmt(14) case_stmt(15) 33534 | case_stmt(16) case_stmt(17) case_stmt(18) case_stmt(19) 33535 | case_stmt(20) case_stmt(21) case_stmt(22) case_stmt(23) 33536 | case_stmt(24) case_stmt(25) case_stmt(26) case_stmt(27) 33537 | case_stmt(28) case_stmt(29) case_stmt(30) case_stmt(31) 33538 | case_stmt(32) case_stmt(33) case_stmt(34) case_stmt(35) 33539 | case_stmt(36) case_stmt(37) case_stmt(38) case_stmt(39) 33540 | case_stmt(40) case_stmt(41) case_stmt(42) case_stmt(43) 33541 | case_stmt(44) case_stmt(45) case_stmt(46) case_stmt(47) 33542 | #undef case_stmt 33543 | default : return error_node(); 33544 | } 33545 | } 33546 | 33547 | inline expression_node_ptr special_function(const details::operator_type& operation, expression_node_ptr (&branch)[3]) 33548 | { 33549 | if (!all_nodes_valid(branch)) 33550 | return error_node(); 33551 | else if (is_constant_foldable(branch)) 33552 | return const_optimise_sf3(operation,branch); 33553 | else if (all_nodes_variables(branch)) 33554 | return varnode_optimise_sf3(operation,branch); 33555 | else 33556 | { 33557 | switch (operation) 33558 | { 33559 | #define case_stmt(op) \ 33560 | case details::e_sf##op : return node_allocator_-> \ 33561 | allocate<details::sf3_node<Type,details::sf##op##_op<Type> > > \ 33562 | (operation, branch); \ 33563 | 33564 | case_stmt(00) case_stmt(01) case_stmt(02) case_stmt(03) 33565 | case_stmt(04) case_stmt(05) case_stmt(06) case_stmt(07) 33566 | case_stmt(08) case_stmt(09) case_stmt(10) case_stmt(11) 33567 | case_stmt(12) case_stmt(13) case_stmt(14) case_stmt(15) 33568 | case_stmt(16) case_stmt(17) case_stmt(18) case_stmt(19) 33569 | case_stmt(20) case_stmt(21) case_stmt(22) case_stmt(23) 33570 | case_stmt(24) case_stmt(25) case_stmt(26) case_stmt(27) 33571 | case_stmt(28) case_stmt(29) case_stmt(30) case_stmt(31) 33572 | case_stmt(32) case_stmt(33) case_stmt(34) case_stmt(35) 33573 | case_stmt(36) case_stmt(37) case_stmt(38) case_stmt(39) 33574 | case_stmt(40) case_stmt(41) case_stmt(42) case_stmt(43) 33575 | case_stmt(44) case_stmt(45) case_stmt(46) case_stmt(47) 33576 | #undef case_stmt 33577 | default : return error_node(); 33578 | } 33579 | } 33580 | } 33581 | 33582 | inline expression_node_ptr const_optimise_sf4(const details::operator_type& operation, expression_node_ptr (&branch)[4]) 33583 | { 33584 | expression_node_ptr temp_node = error_node(); 33585 | 33586 | switch (operation) 33587 | { 33588 | #define case_stmt(op) \ 33589 | case details::e_sf##op : temp_node = node_allocator_-> \ 33590 | allocate<details::sf4_node<Type,details::sf##op##_op<Type> > > \ 33591 | (operation, branch); \ 33592 | break; \ 33593 | 33594 | case_stmt(48) case_stmt(49) case_stmt(50) case_stmt(51) 33595 | case_stmt(52) case_stmt(53) case_stmt(54) case_stmt(55) 33596 | case_stmt(56) case_stmt(57) case_stmt(58) case_stmt(59) 33597 | case_stmt(60) case_stmt(61) case_stmt(62) case_stmt(63) 33598 | case_stmt(64) case_stmt(65) case_stmt(66) case_stmt(67) 33599 | case_stmt(68) case_stmt(69) case_stmt(70) case_stmt(71) 33600 | case_stmt(72) case_stmt(73) case_stmt(74) case_stmt(75) 33601 | case_stmt(76) case_stmt(77) case_stmt(78) case_stmt(79) 33602 | case_stmt(80) case_stmt(81) case_stmt(82) case_stmt(83) 33603 | case_stmt(84) case_stmt(85) case_stmt(86) case_stmt(87) 33604 | case_stmt(88) case_stmt(89) case_stmt(90) case_stmt(91) 33605 | case_stmt(92) case_stmt(93) case_stmt(94) case_stmt(95) 33606 | case_stmt(96) case_stmt(97) case_stmt(98) case_stmt(99) 33607 | #undef case_stmt 33608 | default : return error_node(); 33609 | } 33610 | 33611 | assert(temp_node); 33612 | 33613 | const T v = temp_node->value(); 33614 | 33615 | details::free_node(*node_allocator_,temp_node); 33616 | 33617 | return node_allocator_->allocate<literal_node_t>(v); 33618 | } 33619 | 33620 | inline expression_node_ptr varnode_optimise_sf4(const details::operator_type& operation, expression_node_ptr (&branch)[4]) 33621 | { 33622 | typedef details::variable_node<Type>* variable_ptr; 33623 | 33624 | const Type& v0 = static_cast<variable_ptr>(branch[0])->ref(); 33625 | const Type& v1 = static_cast<variable_ptr>(branch[1])->ref(); 33626 | const Type& v2 = static_cast<variable_ptr>(branch[2])->ref(); 33627 | const Type& v3 = static_cast<variable_ptr>(branch[3])->ref(); 33628 | 33629 | switch (operation) 33630 | { 33631 | #define case_stmt(op) \ 33632 | case details::e_sf##op : return node_allocator_-> \ 33633 | allocate_rrrr<details::sf4_var_node<Type,details::sf##op##_op<Type> > > \ 33634 | (v0, v1, v2, v3); \ 33635 | 33636 | case_stmt(48) case_stmt(49) case_stmt(50) case_stmt(51) 33637 | case_stmt(52) case_stmt(53) case_stmt(54) case_stmt(55) 33638 | case_stmt(56) case_stmt(57) case_stmt(58) case_stmt(59) 33639 | case_stmt(60) case_stmt(61) case_stmt(62) case_stmt(63) 33640 | case_stmt(64) case_stmt(65) case_stmt(66) case_stmt(67) 33641 | case_stmt(68) case_stmt(69) case_stmt(70) case_stmt(71) 33642 | case_stmt(72) case_stmt(73) case_stmt(74) case_stmt(75) 33643 | case_stmt(76) case_stmt(77) case_stmt(78) case_stmt(79) 33644 | case_stmt(80) case_stmt(81) case_stmt(82) case_stmt(83) 33645 | case_stmt(84) case_stmt(85) case_stmt(86) case_stmt(87) 33646 | case_stmt(88) case_stmt(89) case_stmt(90) case_stmt(91) 33647 | case_stmt(92) case_stmt(93) case_stmt(94) case_stmt(95) 33648 | case_stmt(96) case_stmt(97) case_stmt(98) case_stmt(99) 33649 | #undef case_stmt 33650 | default : return error_node(); 33651 | } 33652 | } 33653 | 33654 | inline expression_node_ptr special_function(const details::operator_type& operation, expression_node_ptr (&branch)[4]) 33655 | { 33656 | if (!all_nodes_valid(branch)) 33657 | return error_node(); 33658 | else if (is_constant_foldable(branch)) 33659 | return const_optimise_sf4(operation,branch); 33660 | else if (all_nodes_variables(branch)) 33661 | return varnode_optimise_sf4(operation,branch); 33662 | switch (operation) 33663 | { 33664 | #define case_stmt(op) \ 33665 | case details::e_sf##op : return node_allocator_-> \ 33666 | allocate<details::sf4_node<Type,details::sf##op##_op<Type> > > \ 33667 | (operation, branch); \ 33668 | 33669 | case_stmt(48) case_stmt(49) case_stmt(50) case_stmt(51) 33670 | case_stmt(52) case_stmt(53) case_stmt(54) case_stmt(55) 33671 | case_stmt(56) case_stmt(57) case_stmt(58) case_stmt(59) 33672 | case_stmt(60) case_stmt(61) case_stmt(62) case_stmt(63) 33673 | case_stmt(64) case_stmt(65) case_stmt(66) case_stmt(67) 33674 | case_stmt(68) case_stmt(69) case_stmt(70) case_stmt(71) 33675 | case_stmt(72) case_stmt(73) case_stmt(74) case_stmt(75) 33676 | case_stmt(76) case_stmt(77) case_stmt(78) case_stmt(79) 33677 | case_stmt(80) case_stmt(81) case_stmt(82) case_stmt(83) 33678 | case_stmt(84) case_stmt(85) case_stmt(86) case_stmt(87) 33679 | case_stmt(88) case_stmt(89) case_stmt(90) case_stmt(91) 33680 | case_stmt(92) case_stmt(93) case_stmt(94) case_stmt(95) 33681 | case_stmt(96) case_stmt(97) case_stmt(98) case_stmt(99) 33682 | #undef case_stmt 33683 | default : return error_node(); 33684 | } 33685 | } 33686 | 33687 | template <typename Allocator, 33688 | template <typename, typename> class Sequence> 33689 | inline expression_node_ptr const_optimise_varargfunc(const details::operator_type& operation, Sequence<expression_node_ptr,Allocator>& arg_list) 33690 | { 33691 | expression_node_ptr temp_node = error_node(); 33692 | 33693 | switch (operation) 33694 | { 33695 | #define case_stmt(op0, op1) \ 33696 | case op0 : temp_node = node_allocator_-> \ 33697 | allocate<details::vararg_node<Type,op1<Type> > > \ 33698 | (arg_list); \ 33699 | break; \ 33700 | 33701 | case_stmt(details::e_sum , details::vararg_add_op ) 33702 | case_stmt(details::e_prod , details::vararg_mul_op ) 33703 | case_stmt(details::e_avg , details::vararg_avg_op ) 33704 | case_stmt(details::e_min , details::vararg_min_op ) 33705 | case_stmt(details::e_max , details::vararg_max_op ) 33706 | case_stmt(details::e_mand , details::vararg_mand_op ) 33707 | case_stmt(details::e_mor , details::vararg_mor_op ) 33708 | case_stmt(details::e_multi , details::vararg_multi_op) 33709 | #undef case_stmt 33710 | default : return error_node(); 33711 | } 33712 | 33713 | const T v = temp_node->value(); 33714 | 33715 | details::free_node(*node_allocator_,temp_node); 33716 | 33717 | return node_allocator_->allocate<literal_node_t>(v); 33718 | } 33719 | 33720 | inline bool special_one_parameter_vararg(const details::operator_type& operation) const 33721 | { 33722 | return ( 33723 | (details::e_sum == operation) || 33724 | (details::e_prod == operation) || 33725 | (details::e_avg == operation) || 33726 | (details::e_min == operation) || 33727 | (details::e_max == operation) 33728 | ); 33729 | } 33730 | 33731 | template <typename Allocator, 33732 | template <typename, typename> class Sequence> 33733 | inline expression_node_ptr varnode_optimise_varargfunc(const details::operator_type& operation, 33734 | Sequence<expression_node_ptr,Allocator>& arg_list) 33735 | { 33736 | switch (operation) 33737 | { 33738 | #define case_stmt(op0, op1) \ 33739 | case op0 : return node_allocator_-> \ 33740 | allocate<details::vararg_varnode<Type,op1<Type> > >(arg_list); \ 33741 | 33742 | case_stmt(details::e_sum , details::vararg_add_op ) 33743 | case_stmt(details::e_prod , details::vararg_mul_op ) 33744 | case_stmt(details::e_avg , details::vararg_avg_op ) 33745 | case_stmt(details::e_min , details::vararg_min_op ) 33746 | case_stmt(details::e_max , details::vararg_max_op ) 33747 | case_stmt(details::e_mand , details::vararg_mand_op ) 33748 | case_stmt(details::e_mor , details::vararg_mor_op ) 33749 | case_stmt(details::e_multi , details::vararg_multi_op) 33750 | #undef case_stmt 33751 | default : return error_node(); 33752 | } 33753 | } 33754 | 33755 | template <typename Allocator, 33756 | template <typename, typename> class Sequence> 33757 | inline expression_node_ptr vectorize_func(const details::operator_type& operation, 33758 | Sequence<expression_node_ptr,Allocator>& arg_list) 33759 | { 33760 | if (1 == arg_list.size()) 33761 | { 33762 | switch (operation) 33763 | { 33764 | #define case_stmt(op0, op1) \ 33765 | case op0 : return node_allocator_-> \ 33766 | allocate<details::vectorize_node<Type,op1<Type> > >(arg_list[0]); \ 33767 | 33768 | case_stmt(details::e_sum , details::vec_add_op) 33769 | case_stmt(details::e_prod , details::vec_mul_op) 33770 | case_stmt(details::e_avg , details::vec_avg_op) 33771 | case_stmt(details::e_min , details::vec_min_op) 33772 | case_stmt(details::e_max , details::vec_max_op) 33773 | #undef case_stmt 33774 | default : return error_node(); 33775 | } 33776 | } 33777 | else 33778 | return error_node(); 33779 | } 33780 | 33781 | template <typename Allocator, 33782 | template <typename, typename> class Sequence> 33783 | inline expression_node_ptr vararg_function(const details::operator_type& operation, 33784 | Sequence<expression_node_ptr,Allocator>& arg_list) 33785 | { 33786 | if (!all_nodes_valid(arg_list)) 33787 | { 33788 | details::free_all_nodes(*node_allocator_,arg_list); 33789 | 33790 | return error_node(); 33791 | } 33792 | else if (is_constant_foldable(arg_list)) 33793 | return const_optimise_varargfunc(operation,arg_list); 33794 | else if ((1 == arg_list.size()) && details::is_ivector_node(arg_list[0])) 33795 | return vectorize_func(operation,arg_list); 33796 | else if ((1 == arg_list.size()) && special_one_parameter_vararg(operation)) 33797 | return arg_list[0]; 33798 | else if (all_nodes_variables(arg_list)) 33799 | return varnode_optimise_varargfunc(operation,arg_list); 33800 | 33801 | #ifndef exprtk_disable_string_capabilities 33802 | if (details::e_smulti == operation) 33803 | { 33804 | expression_node_ptr result = node_allocator_-> 33805 | allocate<details::str_vararg_node<Type,details::vararg_multi_op<Type> > >(arg_list); 33806 | if (result && result->valid()) 33807 | { 33808 | return result; 33809 | } 33810 | 33811 | parser_->set_error(parser_error::make_error( 33812 | parser_error::e_synthesis, 33813 | token_t(), 33814 | "ERR262 - Failed to synthesize node: str_vararg_node<vararg_multi_op>", 33815 | exprtk_error_location)); 33816 | 33817 | details::free_node(*node_allocator_, result); 33818 | } 33819 | else 33820 | #endif 33821 | { 33822 | expression_node_ptr result = error_node(); 33823 | 33824 | switch (operation) 33825 | { 33826 | #define case_stmt(op0, op1) \ 33827 | case op0 : result = node_allocator_-> \ 33828 | allocate<details::vararg_node<Type,op1<Type> > >(arg_list); \ 33829 | break; \ 33830 | 33831 | case_stmt(details::e_sum , details::vararg_add_op ) 33832 | case_stmt(details::e_prod , details::vararg_mul_op ) 33833 | case_stmt(details::e_avg , details::vararg_avg_op ) 33834 | case_stmt(details::e_min , details::vararg_min_op ) 33835 | case_stmt(details::e_max , details::vararg_max_op ) 33836 | case_stmt(details::e_mand , details::vararg_mand_op ) 33837 | case_stmt(details::e_mor , details::vararg_mor_op ) 33838 | case_stmt(details::e_multi , details::vararg_multi_op) 33839 | #undef case_stmt 33840 | default : return error_node(); 33841 | } 33842 | 33843 | if (result && result->valid()) 33844 | { 33845 | return result; 33846 | } 33847 | 33848 | parser_->set_error(parser_error::make_error( 33849 | parser_error::e_synthesis, 33850 | token_t(), 33851 | "ERR263 - Failed to synthesize node: vararg_node", 33852 | exprtk_error_location)); 33853 | 33854 | details::free_node(*node_allocator_, result); 33855 | } 33856 | 33857 | return error_node(); 33858 | } 33859 | 33860 | template <std::size_t N> 33861 | inline expression_node_ptr function(ifunction_t* f, expression_node_ptr (&b)[N]) 33862 | { 33863 | typedef typename details::function_N_node<T,ifunction_t,N> function_N_node_t; 33864 | expression_node_ptr result = synthesize_expression<function_N_node_t,N>(f,b); 33865 | 33866 | if (0 == result) 33867 | return error_node(); 33868 | else 33869 | { 33870 | // Can the function call be completely optimised? 33871 | if (details::is_constant_node(result)) 33872 | return result; 33873 | else if (!all_nodes_valid(b)) 33874 | { 33875 | details::free_node(*node_allocator_,result); 33876 | std::fill_n(b, N, reinterpret_cast<expression_node_ptr>(0)); 33877 | 33878 | return error_node(); 33879 | } 33880 | else if (N != f->param_count) 33881 | { 33882 | details::free_node(*node_allocator_,result); 33883 | std::fill_n(b, N, reinterpret_cast<expression_node_ptr>(0)); 33884 | 33885 | return error_node(); 33886 | } 33887 | 33888 | function_N_node_t* func_node_ptr = reinterpret_cast<function_N_node_t*>(result); 33889 | 33890 | if (!func_node_ptr->init_branches(b)) 33891 | { 33892 | details::free_node(*node_allocator_,result); 33893 | std::fill_n(b, N, reinterpret_cast<expression_node_ptr>(0)); 33894 | 33895 | return error_node(); 33896 | } 33897 | 33898 | if (result && result->valid()) 33899 | { 33900 | return result; 33901 | } 33902 | 33903 | parser_->set_error(parser_error::make_error( 33904 | parser_error::e_synthesis, 33905 | token_t(), 33906 | "ERR264 - Failed to synthesize node: function_N_node_t", 33907 | exprtk_error_location)); 33908 | 33909 | details::free_node(*node_allocator_, result); 33910 | return error_node(); 33911 | } 33912 | } 33913 | 33914 | inline expression_node_ptr function(ifunction_t* f) 33915 | { 33916 | typedef typename details::function_N_node<Type,ifunction_t,0> function_N_node_t; 33917 | return node_allocator_->allocate<function_N_node_t>(f); 33918 | } 33919 | 33920 | inline expression_node_ptr vararg_function_call(ivararg_function_t* vaf, 33921 | std::vector<expression_node_ptr>& arg_list) 33922 | { 33923 | if (!all_nodes_valid(arg_list)) 33924 | { 33925 | details::free_all_nodes(*node_allocator_,arg_list); 33926 | 33927 | return error_node(); 33928 | } 33929 | 33930 | typedef details::vararg_function_node<Type,ivararg_function_t> alloc_type; 33931 | 33932 | expression_node_ptr result = node_allocator_->allocate<alloc_type>(vaf,arg_list); 33933 | 33934 | if ( 33935 | !arg_list.empty() && 33936 | !vaf->has_side_effects() && 33937 | is_constant_foldable(arg_list) 33938 | ) 33939 | { 33940 | const Type v = result->value(); 33941 | details::free_node(*node_allocator_,result); 33942 | result = node_allocator_->allocate<literal_node_t>(v); 33943 | } 33944 | 33945 | parser_->state_.activate_side_effect("vararg_function_call()"); 33946 | 33947 | if (result && result->valid()) 33948 | { 33949 | return result; 33950 | } 33951 | 33952 | parser_->set_error(parser_error::make_error( 33953 | parser_error::e_synthesis, 33954 | token_t(), 33955 | "ERR265 - Failed to synthesize node: vararg_function_node<ivararg_function_t>", 33956 | exprtk_error_location)); 33957 | 33958 | details::free_node(*node_allocator_, result); 33959 | return error_node(); 33960 | } 33961 | 33962 | inline expression_node_ptr generic_function_call(igeneric_function_t* gf, 33963 | std::vector<expression_node_ptr>& arg_list, 33964 | const std::size_t& param_seq_index = std::numeric_limits<std::size_t>::max()) 33965 | { 33966 | if (!all_nodes_valid(arg_list)) 33967 | { 33968 | details::free_all_nodes(*node_allocator_,arg_list); 33969 | return error_node(); 33970 | } 33971 | 33972 | typedef details::generic_function_node <Type,igeneric_function_t> alloc_type1; 33973 | typedef details::multimode_genfunction_node<Type,igeneric_function_t> alloc_type2; 33974 | 33975 | const std::size_t no_psi = std::numeric_limits<std::size_t>::max(); 33976 | 33977 | expression_node_ptr result = error_node(); 33978 | std::string node_name = "Unknown" 33979 | 33980 | if (no_psi == param_seq_index) 33981 | { 33982 | result = node_allocator_->allocate<alloc_type1>(arg_list,gf); 33983 | node_name = "generic_function_node<igeneric_function_t>" 33984 | } 33985 | else 33986 | { 33987 | result = node_allocator_->allocate<alloc_type2>(gf, param_seq_index, arg_list); 33988 | node_name = "multimode_genfunction_node<igeneric_function_t>" 33989 | } 33990 | 33991 | alloc_type1* genfunc_node_ptr = static_cast<alloc_type1*>(result); 33992 | 33993 | assert(genfunc_node_ptr); 33994 | 33995 | if ( 33996 | !arg_list.empty() && 33997 | !gf->has_side_effects() && 33998 | parser_->state_.type_check_enabled && 33999 | is_constant_foldable(arg_list) 34000 | ) 34001 | { 34002 | genfunc_node_ptr->init_branches(); 34003 | 34004 | const Type v = result->value(); 34005 | 34006 | details::free_node(*node_allocator_,result); 34007 | 34008 | return node_allocator_->allocate<literal_node_t>(v); 34009 | } 34010 | else if (genfunc_node_ptr->init_branches()) 34011 | { 34012 | if (result && result->valid()) 34013 | { 34014 | parser_->state_.activate_side_effect("generic_function_call()"); 34015 | return result; 34016 | } 34017 | 34018 | parser_->set_error(parser_error::make_error( 34019 | parser_error::e_synthesis, 34020 | token_t(), 34021 | "ERR266 - Failed to synthesize node: " + node_name, 34022 | exprtk_error_location)); 34023 | 34024 | details::free_node(*node_allocator_, result); 34025 | return error_node(); 34026 | } 34027 | else 34028 | { 34029 | details::free_node(*node_allocator_, result); 34030 | details::free_all_nodes(*node_allocator_, arg_list); 34031 | 34032 | return error_node(); 34033 | } 34034 | } 34035 | 34036 | #ifndef exprtk_disable_string_capabilities 34037 | inline expression_node_ptr string_function_call(igeneric_function_t* gf, 34038 | std::vector<expression_node_ptr>& arg_list, 34039 | const std::size_t& param_seq_index = std::numeric_limits<std::size_t>::max()) 34040 | { 34041 | if (!all_nodes_valid(arg_list)) 34042 | { 34043 | details::free_all_nodes(*node_allocator_,arg_list); 34044 | return error_node(); 34045 | } 34046 | 34047 | typedef details::string_function_node <Type,igeneric_function_t> alloc_type1; 34048 | typedef details::multimode_strfunction_node<Type,igeneric_function_t> alloc_type2; 34049 | 34050 | const std::size_t no_psi = std::numeric_limits<std::size_t>::max(); 34051 | 34052 | expression_node_ptr result = error_node(); 34053 | std::string node_name = "Unknown" 34054 | 34055 | if (no_psi == param_seq_index) 34056 | { 34057 | result = node_allocator_->allocate<alloc_type1>(gf,arg_list); 34058 | node_name = "string_function_node<igeneric_function_t>" 34059 | } 34060 | else 34061 | { 34062 | result = node_allocator_->allocate<alloc_type2>(gf, param_seq_index, arg_list); 34063 | node_name = "multimode_strfunction_node<igeneric_function_t>" 34064 | } 34065 | 34066 | alloc_type1* strfunc_node_ptr = static_cast<alloc_type1*>(result); 34067 | 34068 | assert(strfunc_node_ptr); 34069 | 34070 | if ( 34071 | !arg_list.empty() && 34072 | !gf->has_side_effects() && 34073 | is_constant_foldable(arg_list) 34074 | ) 34075 | { 34076 | strfunc_node_ptr->init_branches(); 34077 | 34078 | const Type v = result->value(); 34079 | 34080 | details::free_node(*node_allocator_,result); 34081 | 34082 | return node_allocator_->allocate<literal_node_t>(v); 34083 | } 34084 | else if (strfunc_node_ptr->init_branches()) 34085 | { 34086 | if (result && result->valid()) 34087 | { 34088 | parser_->state_.activate_side_effect("string_function_call()"); 34089 | return result; 34090 | } 34091 | 34092 | parser_->set_error(parser_error::make_error( 34093 | parser_error::e_synthesis, 34094 | token_t(), 34095 | "ERR267 - Failed to synthesize node: " + node_name, 34096 | exprtk_error_location)); 34097 | 34098 | details::free_node(*node_allocator_, result); 34099 | return error_node(); 34100 | } 34101 | else 34102 | { 34103 | details::free_node (*node_allocator_,result ); 34104 | details::free_all_nodes(*node_allocator_,arg_list); 34105 | 34106 | return error_node(); 34107 | } 34108 | } 34109 | #endif 34110 | 34111 | #ifndef exprtk_disable_return_statement 34112 | inline expression_node_ptr return_call(std::vector<expression_node_ptr>& arg_list) 34113 | { 34114 | if (!all_nodes_valid(arg_list)) 34115 | { 34116 | details::free_all_nodes(*node_allocator_,arg_list); 34117 | return error_node(); 34118 | } 34119 | 34120 | typedef details::return_node<Type> alloc_type; 34121 | 34122 | expression_node_ptr result = node_allocator_-> 34123 | allocate_rr<alloc_type>(arg_list,parser_->results_ctx()); 34124 | 34125 | alloc_type* return_node_ptr = static_cast<alloc_type*>(result); 34126 | 34127 | assert(return_node_ptr); 34128 | 34129 | if (return_node_ptr->init_branches()) 34130 | { 34131 | if (result && result->valid()) 34132 | { 34133 | parser_->state_.activate_side_effect("return_call()"); 34134 | return result; 34135 | } 34136 | 34137 | parser_->set_error(parser_error::make_error( 34138 | parser_error::e_synthesis, 34139 | token_t(), 34140 | "ERR268 - Failed to synthesize node: return_node", 34141 | exprtk_error_location)); 34142 | 34143 | details::free_node(*node_allocator_, result); 34144 | return error_node(); 34145 | } 34146 | else 34147 | { 34148 | details::free_node (*node_allocator_, result ); 34149 | details::free_all_nodes(*node_allocator_, arg_list); 34150 | 34151 | return error_node(); 34152 | } 34153 | } 34154 | 34155 | inline expression_node_ptr return_envelope(expression_node_ptr body, 34156 | results_context_t* rc, 34157 | bool*& return_invoked) 34158 | { 34159 | typedef details::return_envelope_node<Type> alloc_type; 34160 | 34161 | expression_node_ptr result = node_allocator_-> 34162 | allocate_cr<alloc_type>(body,(*rc)); 34163 | 34164 | return_invoked = static_cast<alloc_type*>(result)->retinvk_ptr(); 34165 | 34166 | return result; 34167 | } 34168 | #else 34169 | inline expression_node_ptr return_call(std::vector<expression_node_ptr>&) 34170 | { 34171 | return error_node(); 34172 | } 34173 | 34174 | inline expression_node_ptr return_envelope(expression_node_ptr, 34175 | results_context_t*, 34176 | bool*&) 34177 | { 34178 | return error_node(); 34179 | } 34180 | #endif 34181 | 34182 | inline expression_node_ptr vector_element(const std::string& symbol, 34183 | vector_holder_ptr vector_base, 34184 | expression_node_ptr vec_node, 34185 | expression_node_ptr index) 34186 | { 34187 | expression_node_ptr result = error_node(); 34188 | std::string node_name = "Unknown" 34189 | 34190 | if (details::is_constant_node(index)) 34191 | { 34192 | const std::size_t vec_index = static_cast<std::size_t>(details::numeric::to_int64(index->value())); 34193 | 34194 | details::free_node(*node_allocator_,index); 34195 | 34196 | if (vec_index >= vector_base->size()) 34197 | { 34198 | parser_->set_error(parser_error::make_error( 34199 | parser_error::e_parser, 34200 | token_t(), 34201 | "ERR269 - Index of " + details::to_str(vec_index) + " out of range for " 34202 | "vector '" + symbol + "' of size " + details::to_str(vector_base->size()), 34203 | exprtk_error_location)); 34204 | 34205 | details::free_node(*node_allocator_,vec_node); 34206 | 34207 | return error_node(); 34208 | } 34209 | 34210 | if (vector_base->rebaseable()) 34211 | { 34212 | vector_access_runtime_check_ptr rtc = get_vector_access_runtime_check(); 34213 | 34214 | result = (rtc) ? 34215 | node_allocator_->allocate<rebasevector_celem_rtc_node_t>(vec_node, vec_index, vector_base, rtc) : 34216 | node_allocator_->allocate<rebasevector_celem_node_t >(vec_node, vec_index, vector_base ) ; 34217 | 34218 | node_name = (rtc) ? 34219 | "rebasevector_elem_rtc_node_t" : 34220 | "rebasevector_elem_node_t" ; 34221 | 34222 | if (result && result->valid()) 34223 | { 34224 | return result; 34225 | } 34226 | 34227 | parser_->set_error(parser_error::make_error( 34228 | parser_error::e_synthesis, 34229 | token_t(), 34230 | "ERR270 - Failed to synthesize node: " + node_name + " for vector: " + symbol, 34231 | exprtk_error_location)); 34232 | 34233 | details::free_node(*node_allocator_, result); 34234 | return error_node(); 34235 | } 34236 | else if (details::is_ivector_node(vec_node) && !details::is_vector_node(vec_node)) 34237 | { 34238 | vector_access_runtime_check_ptr rtc = get_vector_access_runtime_check(); 34239 | 34240 | result = (rtc) ? 34241 | node_allocator_->allocate<vector_celem_rtc_node_t>(vec_node, vec_index, vector_base, rtc) : 34242 | node_allocator_->allocate<vector_celem_node_t >(vec_node, vec_index, vector_base ) ; 34243 | 34244 | node_name = (rtc) ? 34245 | "vector_elem_rtc_node_t" : 34246 | "vector_elem_node_t" ; 34247 | 34248 | if (result && result->valid()) 34249 | { 34250 | return result; 34251 | } 34252 | 34253 | parser_->set_error(parser_error::make_error( 34254 | parser_error::e_synthesis, 34255 | token_t(), 34256 | "ERR271 - Failed to synthesize node: " + node_name + " for vector: " + symbol, 34257 | exprtk_error_location)); 34258 | 34259 | details::free_node(*node_allocator_, result); 34260 | return error_node(); 34261 | } 34262 | 34263 | const scope_element& se = parser_->sem_.get_element(symbol,vec_index); 34264 | 34265 | if (se.index == vec_index) 34266 | { 34267 | result = se.var_node; 34268 | details::free_node(*node_allocator_,vec_node); 34269 | } 34270 | else 34271 | { 34272 | scope_element nse; 34273 | nse.name = symbol; 34274 | nse.active = true; 34275 | nse.ref_count = 1; 34276 | nse.type = scope_element::e_vecelem; 34277 | nse.index = vec_index; 34278 | nse.depth = parser_->state_.scope_depth; 34279 | nse.data = 0; 34280 | nse.var_node = node_allocator_->allocate<variable_node_t>((*(*vector_base)[vec_index])); 34281 | 34282 | if (!parser_->sem_.add_element(nse)) 34283 | { 34284 | parser_->set_synthesis_error("Failed to add new local vector element to SEM [1]"); 34285 | 34286 | parser_->sem_.free_element(nse); 34287 | 34288 | result = error_node(); 34289 | } 34290 | 34291 | assert(parser_->sem_.total_local_symb_size_bytes() <= parser_->settings().max_total_local_symbol_size_bytes()); 34292 | 34293 | details::free_node(*node_allocator_,vec_node); 34294 | 34295 | exprtk_debug(("vector_element() - INFO - Added new local vector element: %s\n", nse.name.c_str())); 34296 | 34297 | parser_->state_.activate_side_effect("vector_element()"); 34298 | 34299 | result = nse.var_node; 34300 | node_name = "variable_node_t" 34301 | } 34302 | } 34303 | else 34304 | { 34305 | vector_access_runtime_check_ptr rtc = get_vector_access_runtime_check(); 34306 | 34307 | if (vector_base->rebaseable()) 34308 | { 34309 | result = (rtc) ? 34310 | node_allocator_->allocate<rebasevector_elem_rtc_node_t>(vec_node, index, vector_base, rtc) : 34311 | node_allocator_->allocate<rebasevector_elem_node_t >(vec_node, index, vector_base ) ; 34312 | 34313 | node_name = (rtc) ? 34314 | "rebasevector_elem_rtc_node_t" : 34315 | "rebasevector_elem_node_t" ; 34316 | } 34317 | else 34318 | { 34319 | result = rtc ? 34320 | node_allocator_->allocate<vector_elem_rtc_node_t>(vec_node, index, vector_base, rtc) : 34321 | node_allocator_->allocate<vector_elem_node_t >(vec_node, index, vector_base ) ; 34322 | 34323 | node_name = (rtc) ? 34324 | "vector_elem_rtc_node_t" : 34325 | "vector_elem_node_t" ; 34326 | } 34327 | } 34328 | 34329 | if (result && result->valid()) 34330 | { 34331 | return result; 34332 | } 34333 | 34334 | parser_->set_error(parser_error::make_error( 34335 | parser_error::e_synthesis, 34336 | token_t(), 34337 | "ERR272 - Failed to synthesize node: " + node_name, 34338 | exprtk_error_location)); 34339 | 34340 | details::free_node(*node_allocator_, result); 34341 | return error_node(); 34342 | } 34343 | 34344 | private: 34345 | 34346 | template <std::size_t N, typename NodePtr> 34347 | inline bool is_constant_foldable(NodePtr (&b)[N]) const 34348 | { 34349 | for (std::size_t i = 0; i < N; ++i) 34350 | { 34351 | if (0 == b[i]) 34352 | return false; 34353 | else if (!details::is_constant_node(b[i])) 34354 | return false; 34355 | } 34356 | 34357 | return true; 34358 | } 34359 | 34360 | template <typename NodePtr, 34361 | typename Allocator, 34362 | template <typename, typename> class Sequence> 34363 | inline bool is_constant_foldable(const Sequence<NodePtr,Allocator>& b) const 34364 | { 34365 | for (std::size_t i = 0; i < b.size(); ++i) 34366 | { 34367 | if (0 == b[i]) 34368 | return false; 34369 | else if (!details::is_constant_node(b[i])) 34370 | return false; 34371 | } 34372 | 34373 | return true; 34374 | } 34375 | 34376 | void lodge_assignment(symbol_type cst, expression_node_ptr node) 34377 | { 34378 | parser_->state_.activate_side_effect("lodge_assignment()"); 34379 | 34380 | if (!parser_->dec_.collect_assignments()) 34381 | return; 34382 | 34383 | std::string symbol_name; 34384 | 34385 | switch (cst) 34386 | { 34387 | case e_st_variable : symbol_name = parser_->symtab_store_ 34388 | .get_variable_name(node); 34389 | break; 34390 | 34391 | #ifndef exprtk_disable_string_capabilities 34392 | case e_st_string : symbol_name = parser_->symtab_store_ 34393 | .get_stringvar_name(node); 34394 | break; 34395 | #endif 34396 | 34397 | case e_st_vector : { 34398 | typedef details::vector_holder<T> vector_holder_t; 34399 | 34400 | vector_holder_t& vh = static_cast<vector_node_t*>(node)->vec_holder(); 34401 | 34402 | symbol_name = parser_->symtab_store_.get_vector_name(&vh); 34403 | } 34404 | break; 34405 | 34406 | case e_st_vecelem : { 34407 | typedef details::vector_holder<T> vector_holder_t; 34408 | 34409 | vector_holder_t& vh = static_cast<vector_elem_node_t*>(node)->vec_holder(); 34410 | 34411 | symbol_name = parser_->symtab_store_.get_vector_name(&vh); 34412 | 34413 | cst = e_st_vector; 34414 | } 34415 | break; 34416 | 34417 | default : return; 34418 | } 34419 | 34420 | if (!symbol_name.empty()) 34421 | { 34422 | parser_->dec_.add_assignment(symbol_name,cst); 34423 | } 34424 | } 34425 | 34426 | const void* base_ptr(expression_node_ptr node) 34427 | { 34428 | if (node) 34429 | { 34430 | switch (node->type()) 34431 | { 34432 | case details::expression_node<T>::e_variable: 34433 | return reinterpret_cast<const void*>(&static_cast<variable_node_t*>(node)->ref()); 34434 | 34435 | case details::expression_node<T>::e_vecelem: 34436 | return reinterpret_cast<const void*>(&static_cast<vector_elem_node_t*>(node)->ref()); 34437 | 34438 | case details::expression_node<T>::e_veccelem: 34439 | return reinterpret_cast<const void*>(&static_cast<vector_celem_node_t*>(node)->ref()); 34440 | 34441 | case details::expression_node<T>::e_vecelemrtc: 34442 | return reinterpret_cast<const void*>(&static_cast<vector_elem_rtc_node_t*>(node)->ref()); 34443 | 34444 | case details::expression_node<T>::e_veccelemrtc: 34445 | return reinterpret_cast<const void*>(&static_cast<vector_celem_rtc_node_t*>(node)->ref()); 34446 | 34447 | case details::expression_node<T>::e_rbvecelem: 34448 | return reinterpret_cast<const void*>(&static_cast<rebasevector_elem_node_t*>(node)->ref()); 34449 | 34450 | case details::expression_node<T>::e_rbvecelemrtc: 34451 | return reinterpret_cast<const void*>(&static_cast<rebasevector_elem_rtc_node_t*>(node)->ref()); 34452 | 34453 | case details::expression_node<T>::e_rbveccelem: 34454 | return reinterpret_cast<const void*>(&static_cast<rebasevector_celem_node_t*>(node)->ref()); 34455 | 34456 | case details::expression_node<T>::e_rbveccelemrtc: 34457 | return reinterpret_cast<const void*>(&static_cast<rebasevector_celem_rtc_node_t*>(node)->ref()); 34458 | 34459 | case details::expression_node<T>::e_vector: 34460 | return reinterpret_cast<const void*>(static_cast<vector_node_t*>(node)->vec_holder().data()); 34461 | 34462 | #ifndef exprtk_disable_string_capabilities 34463 | case details::expression_node<T>::e_stringvar: 34464 | return reinterpret_cast<const void*>((static_cast<stringvar_node_t*>(node)->base())); 34465 | 34466 | case details::expression_node<T>::e_stringvarrng: 34467 | return reinterpret_cast<const void*>((static_cast<string_range_node_t*>(node)->base())); 34468 | #endif 34469 | default : return reinterpret_cast<const void*>(0); 34470 | } 34471 | } 34472 | 34473 | return reinterpret_cast<const void*>(0); 34474 | } 34475 | 34476 | bool assign_immutable_symbol(expression_node_ptr node) 34477 | { 34478 | interval_t interval; 34479 | const void* baseptr_addr = base_ptr(node); 34480 | 34481 | exprtk_debug(("assign_immutable_symbol - base ptr addr: %p\n", baseptr_addr)); 34482 | 34483 | if (parser_->immutable_memory_map_.in_interval(baseptr_addr,interval)) 34484 | { 34485 | typename immutable_symtok_map_t::iterator itr = parser_->immutable_symtok_map_.find(interval); 34486 | 34487 | if (parser_->immutable_symtok_map_.end() != itr) 34488 | { 34489 | token_t& token = itr->second; 34490 | parser_->set_error(parser_error::make_error( 34491 | parser_error::e_parser, 34492 | token, 34493 | "ERR273 - Symbol '" + token.value + "' cannot be assigned-to as it is immutable.", 34494 | exprtk_error_location)); 34495 | } 34496 | else 34497 | parser_->set_synthesis_error("Unable to assign symbol is immutable."); 34498 | 34499 | return true; 34500 | } 34501 | 34502 | return false; 34503 | } 34504 | 34505 | inline expression_node_ptr synthesize_assignment_expression(const details::operator_type& operation, expression_node_ptr (&branch)[2]) 34506 | { 34507 | if (assign_immutable_symbol(branch[0])) 34508 | { 34509 | return error_node(); 34510 | } 34511 | else if (details::is_variable_node(branch[0])) 34512 | { 34513 | lodge_assignment(e_st_variable,branch[0]); 34514 | return synthesize_expression<assignment_node_t,2>(operation,branch); 34515 | } 34516 | else if (details::is_vector_elem_node(branch[0]) || details::is_vector_celem_node(branch[0])) 34517 | { 34518 | lodge_assignment(e_st_vecelem,branch[0]); 34519 | return synthesize_expression<assignment_vec_elem_node_t, 2>(operation, branch); 34520 | } 34521 | else if (details::is_vector_elem_rtc_node(branch[0]) || details::is_vector_celem_rtc_node(branch[0])) 34522 | { 34523 | lodge_assignment(e_st_vecelem,branch[0]); 34524 | return synthesize_expression<assignment_vec_elem_rtc_node_t, 2>(operation, branch); 34525 | } 34526 | else if (details::is_rebasevector_elem_node(branch[0])) 34527 | { 34528 | lodge_assignment(e_st_vecelem,branch[0]); 34529 | return synthesize_expression<assignment_rebasevec_elem_node_t, 2>(operation, branch); 34530 | } 34531 | else if (details::is_rebasevector_elem_rtc_node(branch[0])) 34532 | { 34533 | lodge_assignment(e_st_vecelem,branch[0]); 34534 | return synthesize_expression<assignment_rebasevec_elem_rtc_node_t, 2>(operation, branch); 34535 | } 34536 | else if (details::is_rebasevector_celem_node(branch[0])) 34537 | { 34538 | lodge_assignment(e_st_vecelem,branch[0]); 34539 | return synthesize_expression<assignment_rebasevec_celem_node_t, 2>(operation, branch); 34540 | } 34541 | #ifndef exprtk_disable_string_capabilities 34542 | else if (details::is_string_node(branch[0])) 34543 | { 34544 | lodge_assignment(e_st_string,branch[0]); 34545 | return synthesize_expression<assignment_string_node_t,2>(operation, branch); 34546 | } 34547 | else if (details::is_string_range_node(branch[0])) 34548 | { 34549 | lodge_assignment(e_st_string,branch[0]); 34550 | return synthesize_expression<assignment_string_range_node_t,2>(operation, branch); 34551 | } 34552 | #endif 34553 | else if (details::is_vector_node(branch[0])) 34554 | { 34555 | lodge_assignment(e_st_vector,branch[0]); 34556 | 34557 | if (details::is_ivector_node(branch[1])) 34558 | return synthesize_expression<assignment_vecvec_node_t,2>(operation, branch); 34559 | else 34560 | return synthesize_expression<assignment_vec_node_t,2>(operation, branch); 34561 | } 34562 | else if (details::is_literal_node(branch[0])) 34563 | { 34564 | parser_->set_error(parser_error::make_error( 34565 | parser_error::e_syntax, 34566 | parser_->current_state().token, 34567 | "ERR274 - Cannot assign value to const variable", 34568 | exprtk_error_location)); 34569 | 34570 | return error_node(); 34571 | } 34572 | else 34573 | { 34574 | parser_->set_error(parser_error::make_error( 34575 | parser_error::e_syntax, 34576 | parser_->current_state().token, 34577 | "ERR275 - Invalid branches for assignment operator '" + details::to_str(operation) + "'", 34578 | exprtk_error_location)); 34579 | 34580 | return error_node(); 34581 | } 34582 | } 34583 | 34584 | inline expression_node_ptr synthesize_assignment_operation_expression(const details::operator_type& operation, 34585 | expression_node_ptr (&branch)[2]) 34586 | { 34587 | if (assign_immutable_symbol(branch[0])) 34588 | { 34589 | return error_node(); 34590 | } 34591 | 34592 | expression_node_ptr result = error_node(); 34593 | std::string node_name = "Unknown" 34594 | 34595 | if (details::is_variable_node(branch[0])) 34596 | { 34597 | lodge_assignment(e_st_variable,branch[0]); 34598 | 34599 | switch (operation) 34600 | { 34601 | #define case_stmt(op0, op1) \ 34602 | case op0 : result = node_allocator_-> \ 34603 | template allocate_rrr<typename details::assignment_op_node<Type,op1<Type> > > \ 34604 | (operation, branch[0], branch[1]); \ 34605 | node_name = "assignment_op_node" \ 34606 | break; \ 34607 | 34608 | case_stmt(details::e_addass , details::add_op) 34609 | case_stmt(details::e_subass , details::sub_op) 34610 | case_stmt(details::e_mulass , details::mul_op) 34611 | case_stmt(details::e_divass , details::div_op) 34612 | case_stmt(details::e_modass , details::mod_op) 34613 | #undef case_stmt 34614 | default : return error_node(); 34615 | } 34616 | } 34617 | else if (details::is_vector_elem_node(branch[0])) 34618 | { 34619 | lodge_assignment(e_st_vecelem,branch[0]); 34620 | 34621 | switch (operation) 34622 | { 34623 | #define case_stmt(op0, op1) \ 34624 | case op0 : result = node_allocator_-> \ 34625 | template allocate_rrr<typename details::assignment_vec_elem_op_node<Type,op1<Type> > > \ 34626 | (operation, branch[0], branch[1]); \ 34627 | node_name = "assignment_vec_elem_op_node" \ 34628 | break; \ 34629 | 34630 | case_stmt(details::e_addass , details::add_op) 34631 | case_stmt(details::e_subass , details::sub_op) 34632 | case_stmt(details::e_mulass , details::mul_op) 34633 | case_stmt(details::e_divass , details::div_op) 34634 | case_stmt(details::e_modass , details::mod_op) 34635 | #undef case_stmt 34636 | default : return error_node(); 34637 | } 34638 | } 34639 | else if (details::is_vector_elem_rtc_node(branch[0])) 34640 | { 34641 | lodge_assignment(e_st_vecelem,branch[0]); 34642 | 34643 | switch (operation) 34644 | { 34645 | #define case_stmt(op0, op1) \ 34646 | case op0 : result = node_allocator_-> \ 34647 | template allocate_rrr<typename details::assignment_vec_elem_op_rtc_node<Type,op1<Type> > > \ 34648 | (operation, branch[0], branch[1]); \ 34649 | node_name = "assignment_vec_elem_op_rtc_node" \ 34650 | break; \ 34651 | 34652 | case_stmt(details::e_addass , details::add_op) 34653 | case_stmt(details::e_subass , details::sub_op) 34654 | case_stmt(details::e_mulass , details::mul_op) 34655 | case_stmt(details::e_divass , details::div_op) 34656 | case_stmt(details::e_modass , details::mod_op) 34657 | #undef case_stmt 34658 | default : return error_node(); 34659 | } 34660 | } 34661 | else if (details::is_vector_celem_rtc_node(branch[0])) 34662 | { 34663 | lodge_assignment(e_st_vecelem,branch[0]); 34664 | 34665 | switch (operation) 34666 | { 34667 | #define case_stmt(op0, op1) \ 34668 | case op0 : result = node_allocator_-> \ 34669 | template allocate_rrr<typename details::assignment_vec_celem_op_rtc_node<Type,op1<Type> > > \ 34670 | (operation, branch[0], branch[1]); \ 34671 | node_name = "assignment_vec_celem_op_rtc_node" \ 34672 | break; \ 34673 | 34674 | case_stmt(details::e_addass , details::add_op) 34675 | case_stmt(details::e_subass , details::sub_op) 34676 | case_stmt(details::e_mulass , details::mul_op) 34677 | case_stmt(details::e_divass , details::div_op) 34678 | case_stmt(details::e_modass , details::mod_op) 34679 | #undef case_stmt 34680 | default : return error_node(); 34681 | } 34682 | } 34683 | else if (details::is_rebasevector_elem_node(branch[0])) 34684 | { 34685 | lodge_assignment(e_st_vecelem,branch[0]); 34686 | 34687 | switch (operation) 34688 | { 34689 | #define case_stmt(op0, op1) \ 34690 | case op0 : result = node_allocator_-> \ 34691 | template allocate_rrr<typename details::assignment_rebasevec_elem_op_node<Type,op1<Type> > > \ 34692 | (operation, branch[0], branch[1]); \ 34693 | node_name = "assignment_rebasevec_elem_op_node" \ 34694 | break; \ 34695 | 34696 | case_stmt(details::e_addass , details::add_op) 34697 | case_stmt(details::e_subass , details::sub_op) 34698 | case_stmt(details::e_mulass , details::mul_op) 34699 | case_stmt(details::e_divass , details::div_op) 34700 | case_stmt(details::e_modass , details::mod_op) 34701 | #undef case_stmt 34702 | default : return error_node(); 34703 | } 34704 | } 34705 | else if (details::is_rebasevector_celem_node(branch[0])) 34706 | { 34707 | lodge_assignment(e_st_vecelem,branch[0]); 34708 | 34709 | switch (operation) 34710 | { 34711 | #define case_stmt(op0, op1) \ 34712 | case op0 : result = node_allocator_-> \ 34713 | template allocate_rrr<typename details::assignment_rebasevec_celem_op_node<Type,op1<Type> > > \ 34714 | (operation, branch[0], branch[1]); \ 34715 | node_name = "assignment_rebasevec_celem_op_node" \ 34716 | break; \ 34717 | 34718 | case_stmt(details::e_addass , details::add_op) 34719 | case_stmt(details::e_subass , details::sub_op) 34720 | case_stmt(details::e_mulass , details::mul_op) 34721 | case_stmt(details::e_divass , details::div_op) 34722 | case_stmt(details::e_modass , details::mod_op) 34723 | #undef case_stmt 34724 | default : return error_node(); 34725 | } 34726 | } 34727 | else if (details::is_rebasevector_elem_rtc_node(branch[0])) 34728 | { 34729 | lodge_assignment(e_st_vecelem,branch[0]); 34730 | 34731 | switch (operation) 34732 | { 34733 | #define case_stmt(op0, op1) \ 34734 | case op0 : result = node_allocator_-> \ 34735 | template allocate_rrr<typename details::assignment_rebasevec_elem_op_rtc_node<Type,op1<Type> > > \ 34736 | (operation, branch[0], branch[1]); \ 34737 | node_name = "assignment_rebasevec_elem_op_rtc_node" \ 34738 | break; \ 34739 | 34740 | case_stmt(details::e_addass , details::add_op) 34741 | case_stmt(details::e_subass , details::sub_op) 34742 | case_stmt(details::e_mulass , details::mul_op) 34743 | case_stmt(details::e_divass , details::div_op) 34744 | case_stmt(details::e_modass , details::mod_op) 34745 | #undef case_stmt 34746 | default : return error_node(); 34747 | } 34748 | } 34749 | else if (details::is_rebasevector_celem_rtc_node(branch[0])) 34750 | { 34751 | lodge_assignment(e_st_vecelem,branch[0]); 34752 | 34753 | switch (operation) 34754 | { 34755 | #define case_stmt(op0, op1) \ 34756 | case op0 : result = node_allocator_-> \ 34757 | template allocate_rrr<typename details::assignment_rebasevec_celem_op_rtc_node<Type,op1<Type> > > \ 34758 | (operation, branch[0], branch[1]); \ 34759 | node_name = "assignment_rebasevec_celem_op_rtc_node" \ 34760 | break; \ 34761 | 34762 | case_stmt(details::e_addass , details::add_op) 34763 | case_stmt(details::e_subass , details::sub_op) 34764 | case_stmt(details::e_mulass , details::mul_op) 34765 | case_stmt(details::e_divass , details::div_op) 34766 | case_stmt(details::e_modass , details::mod_op) 34767 | #undef case_stmt 34768 | default : return error_node(); 34769 | } 34770 | } 34771 | else if (details::is_vector_node(branch[0])) 34772 | { 34773 | lodge_assignment(e_st_vector,branch[0]); 34774 | 34775 | if (details::is_ivector_node(branch[1])) 34776 | { 34777 | switch (operation) 34778 | { 34779 | #define case_stmt(op0, op1) \ 34780 | case op0 : result = node_allocator_-> \ 34781 | template allocate_rrr<typename details::assignment_vecvec_op_node<Type,op1<Type> > > \ 34782 | (operation, branch[0], branch[1]); \ 34783 | node_name = "assignment_rebasevec_celem_op_node" \ 34784 | break; \ 34785 | 34786 | case_stmt(details::e_addass , details::add_op) 34787 | case_stmt(details::e_subass , details::sub_op) 34788 | case_stmt(details::e_mulass , details::mul_op) 34789 | case_stmt(details::e_divass , details::div_op) 34790 | case_stmt(details::e_modass , details::mod_op) 34791 | #undef case_stmt 34792 | default : return error_node(); 34793 | } 34794 | } 34795 | else 34796 | { 34797 | switch (operation) 34798 | { 34799 | #define case_stmt(op0, op1) \ 34800 | case op0 : result = node_allocator_-> \ 34801 | template allocate_rrr<typename details::assignment_vec_op_node<Type,op1<Type> > > \ 34802 | (operation, branch[0], branch[1]); \ 34803 | node_name = "assignment_vec_op_node" \ 34804 | break; \ 34805 | 34806 | case_stmt(details::e_addass , details::add_op) 34807 | case_stmt(details::e_subass , details::sub_op) 34808 | case_stmt(details::e_mulass , details::mul_op) 34809 | case_stmt(details::e_divass , details::div_op) 34810 | case_stmt(details::e_modass , details::mod_op) 34811 | #undef case_stmt 34812 | default : return error_node(); 34813 | } 34814 | } 34815 | } 34816 | #ifndef exprtk_disable_string_capabilities 34817 | else if ( 34818 | (details::e_addass == operation) && 34819 | details::is_string_node(branch[0]) 34820 | ) 34821 | { 34822 | typedef details::assignment_string_node<T,details::asn_addassignment> addass_t; 34823 | 34824 | lodge_assignment(e_st_string,branch[0]); 34825 | 34826 | result = synthesize_expression<addass_t,2>(operation,branch); 34827 | node_name = "assignment_string_node<T,details::asn_addassignment>" 34828 | } 34829 | #endif 34830 | else 34831 | { 34832 | parser_->set_error(parser_error::make_error( 34833 | parser_error::e_syntax, 34834 | parser_->current_state().token, 34835 | "ERR276 - Invalid branches for assignment operator '" + details::to_str(operation) + "'", 34836 | exprtk_error_location)); 34837 | 34838 | return error_node(); 34839 | } 34840 | 34841 | if (result && result->valid()) 34842 | { 34843 | return result; 34844 | } 34845 | 34846 | parser_->set_error(parser_error::make_error( 34847 | parser_error::e_synthesis, 34848 | token_t(), 34849 | "ERR277 - Failed to synthesize node: " + node_name, 34850 | exprtk_error_location)); 34851 | 34852 | details::free_node(*node_allocator_, result); 34853 | return error_node(); 34854 | } 34855 | 34856 | inline expression_node_ptr synthesize_veceqineqlogic_operation_expression(const details::operator_type& operation, 34857 | expression_node_ptr (&branch)[2]) 34858 | { 34859 | const bool is_b0_ivec = details::is_ivector_node(branch[0]); 34860 | const bool is_b1_ivec = details::is_ivector_node(branch[1]); 34861 | 34862 | #define batch_eqineq_logic_case \ 34863 | case_stmt(details::e_lt , details::lt_op ) \ 34864 | case_stmt(details::e_lte , details::lte_op ) \ 34865 | case_stmt(details::e_gt , details::gt_op ) \ 34866 | case_stmt(details::e_gte , details::gte_op ) \ 34867 | case_stmt(details::e_eq , details::eq_op ) \ 34868 | case_stmt(details::e_ne , details::ne_op ) \ 34869 | case_stmt(details::e_equal , details::equal_op) \ 34870 | case_stmt(details::e_and , details::and_op ) \ 34871 | case_stmt(details::e_nand , details::nand_op ) \ 34872 | case_stmt(details::e_or , details::or_op ) \ 34873 | case_stmt(details::e_nor , details::nor_op ) \ 34874 | case_stmt(details::e_xor , details::xor_op ) \ 34875 | case_stmt(details::e_xnor , details::xnor_op ) \ 34876 | 34877 | expression_node_ptr result = error_node(); 34878 | std::string node_name = "Unknown" 34879 | 34880 | if (is_b0_ivec && is_b1_ivec) 34881 | { 34882 | switch (operation) 34883 | { 34884 | #define case_stmt(op0, op1) \ 34885 | case op0 : result = node_allocator_-> \ 34886 | template allocate_rrr<typename details::vec_binop_vecvec_node<Type,op1<Type> > > \ 34887 | (operation, branch[0], branch[1]); \ 34888 | node_name = "vec_binop_vecvec_node" \ 34889 | break; \ 34890 | 34891 | batch_eqineq_logic_case 34892 | #undef case_stmt 34893 | default : return error_node(); 34894 | } 34895 | } 34896 | else if (is_b0_ivec && !is_b1_ivec) 34897 | { 34898 | switch (operation) 34899 | { 34900 | #define case_stmt(op0, op1) \ 34901 | case op0 : result = node_allocator_-> \ 34902 | template allocate_rrr<typename details::vec_binop_vecval_node<Type,op1<Type> > > \ 34903 | (operation, branch[0], branch[1]); \ 34904 | node_name = "vec_binop_vecval_node" \ 34905 | break; \ 34906 | 34907 | batch_eqineq_logic_case 34908 | #undef case_stmt 34909 | default : return error_node(); 34910 | } 34911 | } 34912 | else if (!is_b0_ivec && is_b1_ivec) 34913 | { 34914 | switch (operation) 34915 | { 34916 | #define case_stmt(op0, op1) \ 34917 | case op0 : result = node_allocator_-> \ 34918 | template allocate_rrr<typename details::vec_binop_valvec_node<Type,op1<Type> > > \ 34919 | (operation, branch[0], branch[1]); \ 34920 | node_name = "vec_binop_valvec_node" \ 34921 | break; \ 34922 | 34923 | batch_eqineq_logic_case 34924 | #undef case_stmt 34925 | default : return error_node(); 34926 | } 34927 | } 34928 | else 34929 | return error_node(); 34930 | 34931 | if (result && result->valid()) 34932 | { 34933 | return result; 34934 | } 34935 | 34936 | parser_->set_error(parser_error::make_error( 34937 | parser_error::e_synthesis, 34938 | token_t(), 34939 | "ERR278 - Failed to synthesize node: " + node_name, 34940 | exprtk_error_location)); 34941 | 34942 | details::free_node(*node_allocator_, result); 34943 | return error_node(); 34944 | 34945 | #undef batch_eqineq_logic_case 34946 | } 34947 | 34948 | inline expression_node_ptr synthesize_vecarithmetic_operation_expression(const details::operator_type& operation, 34949 | expression_node_ptr (&branch)[2]) 34950 | { 34951 | const bool is_b0_ivec = details::is_ivector_node(branch[0]); 34952 | const bool is_b1_ivec = details::is_ivector_node(branch[1]); 34953 | 34954 | #define vector_ops \ 34955 | case_stmt(details::e_add , details::add_op) \ 34956 | case_stmt(details::e_sub , details::sub_op) \ 34957 | case_stmt(details::e_mul , details::mul_op) \ 34958 | case_stmt(details::e_div , details::div_op) \ 34959 | case_stmt(details::e_mod , details::mod_op) \ 34960 | 34961 | expression_node_ptr result = error_node(); 34962 | std::string node_name = "Unknown" 34963 | 34964 | if (is_b0_ivec && is_b1_ivec) 34965 | { 34966 | switch (operation) 34967 | { 34968 | #define case_stmt(op0, op1) \ 34969 | case op0 : result = node_allocator_-> \ 34970 | template allocate_rrr<typename details::vec_binop_vecvec_node<Type,op1<Type> > > \ 34971 | (operation, branch[0], branch[1]); \ 34972 | node_name = "vec_binop_vecvec_node" \ 34973 | break; \ 34974 | 34975 | vector_ops 34976 | case_stmt(details::e_pow,details:: pow_op) 34977 | #undef case_stmt 34978 | default : return error_node(); 34979 | } 34980 | } 34981 | else if (is_b0_ivec && !is_b1_ivec) 34982 | { 34983 | switch (operation) 34984 | { 34985 | #define case_stmt(op0, op1) \ 34986 | case op0 : result = node_allocator_-> \ 34987 | template allocate_rrr<typename details::vec_binop_vecval_node<Type,op1<Type> > > \ 34988 | (operation, branch[0], branch[1]); \ 34989 | node_name = "vec_binop_vecval_node(b0ivec,!b1ivec)" \ 34990 | break; \ 34991 | 34992 | vector_ops 34993 | case_stmt(details::e_pow,details:: pow_op) 34994 | #undef case_stmt 34995 | default : return error_node(); 34996 | } 34997 | } 34998 | else if (!is_b0_ivec && is_b1_ivec) 34999 | { 35000 | switch (operation) 35001 | { 35002 | #define case_stmt(op0, op1) \ 35003 | case op0 : result = node_allocator_-> \ 35004 | template allocate_rrr<typename details::vec_binop_valvec_node<Type,op1<Type> > > \ 35005 | (operation, branch[0], branch[1]); \ 35006 | node_name = "vec_binop_vecval_node(!b0ivec,b1ivec)" \ 35007 | break; \ 35008 | 35009 | vector_ops 35010 | #undef case_stmt 35011 | default : return error_node(); 35012 | } 35013 | } 35014 | else 35015 | return error_node(); 35016 | 35017 | if (result && result->valid()) 35018 | { 35019 | return result; 35020 | } 35021 | 35022 | parser_->set_error(parser_error::make_error( 35023 | parser_error::e_synthesis, 35024 | token_t(), 35025 | "ERR279 - Failed to synthesize node: " + node_name, 35026 | exprtk_error_location)); 35027 | 35028 | details::free_node(*node_allocator_, result); 35029 | return error_node(); 35030 | 35031 | #undef vector_ops 35032 | } 35033 | 35034 | inline expression_node_ptr synthesize_swap_expression(expression_node_ptr (&branch)[2]) 35035 | { 35036 | const bool v0_is_ivar = details::is_ivariable_node(branch[0]); 35037 | const bool v1_is_ivar = details::is_ivariable_node(branch[1]); 35038 | 35039 | const bool v0_is_ivec = details::is_ivector_node (branch[0]); 35040 | const bool v1_is_ivec = details::is_ivector_node (branch[1]); 35041 | 35042 | #ifndef exprtk_disable_string_capabilities 35043 | const bool v0_is_str = details::is_generally_string_node(branch[0]); 35044 | const bool v1_is_str = details::is_generally_string_node(branch[1]); 35045 | #endif 35046 | 35047 | expression_node_ptr result = error_node(); 35048 | std::string node_name = "Unknown" 35049 | 35050 | if (v0_is_ivar && v1_is_ivar) 35051 | { 35052 | typedef details::variable_node<T>* variable_node_ptr; 35053 | 35054 | variable_node_ptr v0 = variable_node_ptr(0); 35055 | variable_node_ptr v1 = variable_node_ptr(0); 35056 | 35057 | if ( 35058 | (0 != (v0 = dynamic_cast<variable_node_ptr>(branch[0]))) && 35059 | (0 != (v1 = dynamic_cast<variable_node_ptr>(branch[1]))) 35060 | ) 35061 | { 35062 | result = node_allocator_->allocate<details::swap_node<T> >(v0,v1); 35063 | node_name = "swap_node" 35064 | } 35065 | else 35066 | { 35067 | result = node_allocator_->allocate<details::swap_generic_node<T> >(branch[0],branch[1]); 35068 | node_name = "swap_generic_node" 35069 | } 35070 | } 35071 | else if (v0_is_ivec && v1_is_ivec) 35072 | { 35073 | result = node_allocator_->allocate<details::swap_vecvec_node<T> >(branch[0],branch[1]); 35074 | node_name = "swap_vecvec_node" 35075 | } 35076 | #ifndef exprtk_disable_string_capabilities 35077 | else if (v0_is_str && v1_is_str) 35078 | { 35079 | if (is_string_node(branch[0]) && is_string_node(branch[1])) 35080 | { 35081 | result = node_allocator_->allocate<details::swap_string_node<T> > 35082 | (branch[0], branch[1]); 35083 | node_name = "swap_string_node" 35084 | } 35085 | else 35086 | { 35087 | result = node_allocator_->allocate<details::swap_genstrings_node<T> > 35088 | (branch[0], branch[1]); 35089 | node_name = "swap_genstrings_node" 35090 | } 35091 | } 35092 | #endif 35093 | else 35094 | { 35095 | parser_->set_synthesis_error("Only variables, strings, vectors or vector elements can be swapped"); 35096 | return error_node(); 35097 | } 35098 | 35099 | if (result && result->valid()) 35100 | { 35101 | parser_->state_.activate_side_effect("synthesize_swap_expression()"); 35102 | return result; 35103 | } 35104 | 35105 | parser_->set_error(parser_error::make_error( 35106 | parser_error::e_synthesis, 35107 | token_t(), 35108 | "ERR280 - Failed to synthesize node: " + node_name, 35109 | exprtk_error_location)); 35110 | 35111 | details::free_node(*node_allocator_, result); 35112 | return error_node(); 35113 | } 35114 | 35115 | #ifndef exprtk_disable_sc_andor 35116 | inline expression_node_ptr synthesize_shortcircuit_expression(const details::operator_type& operation, expression_node_ptr (&branch)[2]) 35117 | { 35118 | expression_node_ptr result = error_node(); 35119 | 35120 | if (details::is_constant_node(branch[0])) 35121 | { 35122 | if ( 35123 | (details::e_scand == operation) && 35124 | std::equal_to<T>()(T(0),branch[0]->value()) 35125 | ) 35126 | result = node_allocator_->allocate_c<literal_node_t>(T(0)); 35127 | else if ( 35128 | (details::e_scor == operation) && 35129 | std::not_equal_to<T>()(T(0),branch[0]->value()) 35130 | ) 35131 | result = node_allocator_->allocate_c<literal_node_t>(T(1)); 35132 | } 35133 | 35134 | if (details::is_constant_node(branch[1]) && (0 == result)) 35135 | { 35136 | if ( 35137 | (details::e_scand == operation) && 35138 | std::equal_to<T>()(T(0),branch[1]->value()) 35139 | ) 35140 | result = node_allocator_->allocate_c<literal_node_t>(T(0)); 35141 | else if ( 35142 | (details::e_scor == operation) && 35143 | std::not_equal_to<T>()(T(0),branch[1]->value()) 35144 | ) 35145 | result = node_allocator_->allocate_c<literal_node_t>(T(1)); 35146 | } 35147 | 35148 | if (result) 35149 | { 35150 | details::free_node(*node_allocator_, branch[0]); 35151 | details::free_node(*node_allocator_, branch[1]); 35152 | 35153 | return result; 35154 | } 35155 | else if (details::e_scand == operation) 35156 | { 35157 | return synthesize_expression<scand_node_t,2>(operation, branch); 35158 | } 35159 | else if (details::e_scor == operation) 35160 | { 35161 | return synthesize_expression<scor_node_t,2>(operation, branch); 35162 | } 35163 | else 35164 | return error_node(); 35165 | } 35166 | #else 35167 | inline expression_node_ptr synthesize_shortcircuit_expression(const details::operator_type&, expression_node_ptr (&)[2]) 35168 | { 35169 | return error_node(); 35170 | } 35171 | #endif 35172 | 35173 | #define basic_opr_switch_statements \ 35174 | case_stmt(details::e_add , details::add_op) \ 35175 | case_stmt(details::e_sub , details::sub_op) \ 35176 | case_stmt(details::e_mul , details::mul_op) \ 35177 | case_stmt(details::e_div , details::div_op) \ 35178 | case_stmt(details::e_mod , details::mod_op) \ 35179 | case_stmt(details::e_pow , details::pow_op) \ 35180 | 35181 | #define extended_opr_switch_statements \ 35182 | case_stmt(details::e_lt , details::lt_op ) \ 35183 | case_stmt(details::e_lte , details::lte_op ) \ 35184 | case_stmt(details::e_gt , details::gt_op ) \ 35185 | case_stmt(details::e_gte , details::gte_op ) \ 35186 | case_stmt(details::e_eq , details::eq_op ) \ 35187 | case_stmt(details::e_ne , details::ne_op ) \ 35188 | case_stmt(details::e_and , details::and_op ) \ 35189 | case_stmt(details::e_nand , details::nand_op) \ 35190 | case_stmt(details::e_or , details::or_op ) \ 35191 | case_stmt(details::e_nor , details::nor_op ) \ 35192 | case_stmt(details::e_xor , details::xor_op ) \ 35193 | case_stmt(details::e_xnor , details::xnor_op) \ 35194 | 35195 | #ifndef exprtk_disable_cardinal_pow_optimisation 35196 | template <typename TType, template <typename, typename> class IPowNode> 35197 | inline expression_node_ptr cardinal_pow_optimisation_impl(const TType& v, const unsigned int& p) 35198 | { 35199 | switch (p) 35200 | { 35201 | #define case_stmt(cp) \ 35202 | case cp : return node_allocator_-> \ 35203 | allocate<IPowNode<T,details::numeric::fast_exp<T,cp> > >(v); \ 35204 | 35205 | case_stmt( 1) case_stmt( 2) case_stmt( 3) case_stmt( 4) 35206 | case_stmt( 5) case_stmt( 6) case_stmt( 7) case_stmt( 8) 35207 | case_stmt( 9) case_stmt(10) case_stmt(11) case_stmt(12) 35208 | case_stmt(13) case_stmt(14) case_stmt(15) case_stmt(16) 35209 | case_stmt(17) case_stmt(18) case_stmt(19) case_stmt(20) 35210 | case_stmt(21) case_stmt(22) case_stmt(23) case_stmt(24) 35211 | case_stmt(25) case_stmt(26) case_stmt(27) case_stmt(28) 35212 | case_stmt(29) case_stmt(30) case_stmt(31) case_stmt(32) 35213 | case_stmt(33) case_stmt(34) case_stmt(35) case_stmt(36) 35214 | case_stmt(37) case_stmt(38) case_stmt(39) case_stmt(40) 35215 | case_stmt(41) case_stmt(42) case_stmt(43) case_stmt(44) 35216 | case_stmt(45) case_stmt(46) case_stmt(47) case_stmt(48) 35217 | case_stmt(49) case_stmt(50) case_stmt(51) case_stmt(52) 35218 | case_stmt(53) case_stmt(54) case_stmt(55) case_stmt(56) 35219 | case_stmt(57) case_stmt(58) case_stmt(59) case_stmt(60) 35220 | #undef case_stmt 35221 | default : return error_node(); 35222 | } 35223 | } 35224 | 35225 | inline expression_node_ptr cardinal_pow_optimisation(const T& v, const T& c) 35226 | { 35227 | const bool not_recipricol = (c >= T(0)); 35228 | const unsigned int p = static_cast<unsigned int>(details::numeric::to_int32(details::numeric::abs(c))); 35229 | 35230 | if (0 == p) 35231 | return node_allocator_->allocate_c<literal_node_t>(T(1)); 35232 | else if (std::equal_to<T>()(T(2),c)) 35233 | { 35234 | return node_allocator_-> 35235 | template allocate_rr<typename details::vov_node<Type,details::mul_op<Type> > >(v,v); 35236 | } 35237 | else 35238 | { 35239 | if (not_recipricol) 35240 | return cardinal_pow_optimisation_impl<T,details::ipow_node>(v,p); 35241 | else 35242 | return cardinal_pow_optimisation_impl<T,details::ipowinv_node>(v,p); 35243 | } 35244 | } 35245 | 35246 | inline bool cardinal_pow_optimisable(const details::operator_type& operation, const T& c) const 35247 | { 35248 | return (details::e_pow == operation) && (details::numeric::abs(c) <= T(60)) && details::numeric::is_integer(c); 35249 | } 35250 | 35251 | inline expression_node_ptr cardinal_pow_optimisation(expression_node_ptr (&branch)[2]) 35252 | { 35253 | const Type c = static_cast<details::literal_node<Type>*>(branch[1])->value(); 35254 | const bool not_recipricol = (c >= T(0)); 35255 | const unsigned int p = static_cast<unsigned int>(details::numeric::to_int32(details::numeric::abs(c))); 35256 | 35257 | node_allocator_->free(branch[1]); 35258 | 35259 | if (0 == p) 35260 | { 35261 | details::free_all_nodes(*node_allocator_, branch); 35262 | 35263 | return node_allocator_->allocate_c<literal_node_t>(T(1)); 35264 | } 35265 | else if (not_recipricol) 35266 | return cardinal_pow_optimisation_impl<expression_node_ptr,details::bipow_node>(branch[0],p); 35267 | else 35268 | return cardinal_pow_optimisation_impl<expression_node_ptr,details::bipowinv_node>(branch[0],p); 35269 | } 35270 | #else 35271 | inline expression_node_ptr cardinal_pow_optimisation(T&, const T&) 35272 | { 35273 | return error_node(); 35274 | } 35275 | 35276 | inline bool cardinal_pow_optimisable(const details::operator_type&, const T&) 35277 | { 35278 | return false; 35279 | } 35280 | 35281 | inline expression_node_ptr cardinal_pow_optimisation(expression_node_ptr(&)[2]) 35282 | { 35283 | return error_node(); 35284 | } 35285 | #endif 35286 | 35287 | struct synthesize_binary_ext_expression 35288 | { 35289 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 35290 | const details::operator_type& operation, 35291 | expression_node_ptr (&branch)[2]) 35292 | { 35293 | const bool left_neg = is_neg_unary_node(branch[0]); 35294 | const bool right_neg = is_neg_unary_node(branch[1]); 35295 | 35296 | if (left_neg && right_neg) 35297 | { 35298 | if ( 35299 | (details::e_add == operation) || 35300 | (details::e_sub == operation) || 35301 | (details::e_mul == operation) || 35302 | (details::e_div == operation) 35303 | ) 35304 | { 35305 | if ( 35306 | !expr_gen.parser_->simplify_unary_negation_branch(branch[0]) || 35307 | !expr_gen.parser_->simplify_unary_negation_branch(branch[1]) 35308 | ) 35309 | { 35310 | details::free_all_nodes(*expr_gen.node_allocator_,branch); 35311 | 35312 | return error_node(); 35313 | } 35314 | } 35315 | 35316 | switch (operation) 35317 | { 35318 | // -f(x + 1) + -g(y + 1) --> -(f(x + 1) + g(y + 1)) 35319 | case details::e_add : return expr_gen(details::e_neg, 35320 | expr_gen.node_allocator_-> 35321 | template allocate<typename details::binary_ext_node<Type,details::add_op<Type> > > 35322 | (branch[0],branch[1])); 35323 | 35324 | // -f(x + 1) - -g(y + 1) --> g(y + 1) - f(x + 1) 35325 | case details::e_sub : return expr_gen.node_allocator_-> 35326 | template allocate<typename details::binary_ext_node<Type,details::sub_op<Type> > > 35327 | (branch[1],branch[0]); 35328 | 35329 | default : break; 35330 | } 35331 | } 35332 | else if (left_neg && !right_neg) 35333 | { 35334 | if ( 35335 | (details::e_add == operation) || 35336 | (details::e_sub == operation) || 35337 | (details::e_mul == operation) || 35338 | (details::e_div == operation) 35339 | ) 35340 | { 35341 | if (!expr_gen.parser_->simplify_unary_negation_branch(branch[0])) 35342 | { 35343 | details::free_all_nodes(*expr_gen.node_allocator_,branch); 35344 | 35345 | return error_node(); 35346 | } 35347 | 35348 | switch (operation) 35349 | { 35350 | // -f(x + 1) + g(y + 1) --> g(y + 1) - f(x + 1) 35351 | case details::e_add : return expr_gen.node_allocator_-> 35352 | template allocate<typename details::binary_ext_node<Type,details::sub_op<Type> > > 35353 | (branch[1], branch[0]); 35354 | 35355 | // -f(x + 1) - g(y + 1) --> -(f(x + 1) + g(y + 1)) 35356 | case details::e_sub : return expr_gen(details::e_neg, 35357 | expr_gen.node_allocator_-> 35358 | template allocate<typename details::binary_ext_node<Type,details::add_op<Type> > > 35359 | (branch[0], branch[1])); 35360 | 35361 | // -f(x + 1) * g(y + 1) --> -(f(x + 1) * g(y + 1)) 35362 | case details::e_mul : return expr_gen(details::e_neg, 35363 | expr_gen.node_allocator_-> 35364 | template allocate<typename details::binary_ext_node<Type,details::mul_op<Type> > > 35365 | (branch[0], branch[1])); 35366 | 35367 | // -f(x + 1) / g(y + 1) --> -(f(x + 1) / g(y + 1)) 35368 | case details::e_div : return expr_gen(details::e_neg, 35369 | expr_gen.node_allocator_-> 35370 | template allocate<typename details::binary_ext_node<Type,details::div_op<Type> > > 35371 | (branch[0], branch[1])); 35372 | 35373 | default : return error_node(); 35374 | } 35375 | } 35376 | } 35377 | else if (!left_neg && right_neg) 35378 | { 35379 | if ( 35380 | (details::e_add == operation) || 35381 | (details::e_sub == operation) || 35382 | (details::e_mul == operation) || 35383 | (details::e_div == operation) 35384 | ) 35385 | { 35386 | if (!expr_gen.parser_->simplify_unary_negation_branch(branch[1])) 35387 | { 35388 | details::free_all_nodes(*expr_gen.node_allocator_,branch); 35389 | 35390 | return error_node(); 35391 | } 35392 | 35393 | switch (operation) 35394 | { 35395 | // f(x + 1) + -g(y + 1) --> f(x + 1) - g(y + 1) 35396 | case details::e_add : return expr_gen.node_allocator_-> 35397 | template allocate<typename details::binary_ext_node<Type,details::sub_op<Type> > > 35398 | (branch[0], branch[1]); 35399 | 35400 | // f(x + 1) - - g(y + 1) --> f(x + 1) + g(y + 1) 35401 | case details::e_sub : return expr_gen.node_allocator_-> 35402 | template allocate<typename details::binary_ext_node<Type,details::add_op<Type> > > 35403 | (branch[0], branch[1]); 35404 | 35405 | // f(x + 1) * -g(y + 1) --> -(f(x + 1) * g(y + 1)) 35406 | case details::e_mul : return expr_gen(details::e_neg, 35407 | expr_gen.node_allocator_-> 35408 | template allocate<typename details::binary_ext_node<Type,details::mul_op<Type> > > 35409 | (branch[0], branch[1])); 35410 | 35411 | // f(x + 1) / -g(y + 1) --> -(f(x + 1) / g(y + 1)) 35412 | case details::e_div : return expr_gen(details::e_neg, 35413 | expr_gen.node_allocator_-> 35414 | template allocate<typename details::binary_ext_node<Type,details::div_op<Type> > > 35415 | (branch[0], branch[1])); 35416 | 35417 | default : return error_node(); 35418 | } 35419 | } 35420 | } 35421 | 35422 | switch (operation) 35423 | { 35424 | #define case_stmt(op0, op1) \ 35425 | case op0 : return expr_gen.node_allocator_-> \ 35426 | template allocate<typename details::binary_ext_node<Type,op1<Type> > > \ 35427 | (branch[0], branch[1]); \ 35428 | 35429 | basic_opr_switch_statements 35430 | extended_opr_switch_statements 35431 | #undef case_stmt 35432 | default : return error_node(); 35433 | } 35434 | } 35435 | }; 35436 | 35437 | struct synthesize_vob_expression 35438 | { 35439 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 35440 | const details::operator_type& operation, 35441 | expression_node_ptr (&branch)[2]) 35442 | { 35443 | const Type& v = static_cast<details::variable_node<Type>*>(branch[0])->ref(); 35444 | 35445 | #ifndef exprtk_disable_enhanced_features 35446 | if (details::is_sf3ext_node(branch[1])) 35447 | { 35448 | expression_node_ptr result = error_node(); 35449 | 35450 | const bool synthesis_result = 35451 | synthesize_sf4ext_expression::template compile_right<vtype> 35452 | (expr_gen, v, operation, branch[1], result); 35453 | 35454 | if (synthesis_result) 35455 | { 35456 | details::free_node(*expr_gen.node_allocator_,branch[1]); 35457 | return result; 35458 | } 35459 | } 35460 | #endif 35461 | 35462 | if ( 35463 | (details::e_mul == operation) || 35464 | (details::e_div == operation) 35465 | ) 35466 | { 35467 | if (details::is_uv_node(branch[1])) 35468 | { 35469 | typedef details::uv_base_node<Type>* uvbn_ptr_t; 35470 | 35471 | details::operator_type o = static_cast<uvbn_ptr_t>(branch[1])->operation(); 35472 | 35473 | if (details::e_neg == o) 35474 | { 35475 | const Type& v1 = static_cast<uvbn_ptr_t>(branch[1])->v(); 35476 | 35477 | details::free_node(*expr_gen.node_allocator_,branch[1]); 35478 | 35479 | switch (operation) 35480 | { 35481 | case details::e_mul : return expr_gen(details::e_neg, 35482 | expr_gen.node_allocator_-> 35483 | template allocate_rr<typename details:: 35484 | vov_node<Type,details::mul_op<Type> > >(v,v1)); 35485 | 35486 | case details::e_div : return expr_gen(details::e_neg, 35487 | expr_gen.node_allocator_-> 35488 | template allocate_rr<typename details:: 35489 | vov_node<Type,details::div_op<Type> > >(v,v1)); 35490 | 35491 | default : break; 35492 | } 35493 | } 35494 | } 35495 | } 35496 | 35497 | switch (operation) 35498 | { 35499 | #define case_stmt(op0, op1) \ 35500 | case op0 : return expr_gen.node_allocator_-> \ 35501 | template allocate_rc<typename details::vob_node<Type,op1<Type> > > \ 35502 | (v, branch[1]); \ 35503 | 35504 | basic_opr_switch_statements 35505 | extended_opr_switch_statements 35506 | #undef case_stmt 35507 | default : return error_node(); 35508 | } 35509 | } 35510 | }; 35511 | 35512 | struct synthesize_bov_expression 35513 | { 35514 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 35515 | const details::operator_type& operation, 35516 | expression_node_ptr (&branch)[2]) 35517 | { 35518 | const Type& v = static_cast<details::variable_node<Type>*>(branch[1])->ref(); 35519 | 35520 | #ifndef exprtk_disable_enhanced_features 35521 | if (details::is_sf3ext_node(branch[0])) 35522 | { 35523 | expression_node_ptr result = error_node(); 35524 | 35525 | const bool synthesis_result = 35526 | synthesize_sf4ext_expression::template compile_left<vtype> 35527 | (expr_gen, v, operation, branch[0], result); 35528 | 35529 | if (synthesis_result) 35530 | { 35531 | details::free_node(*expr_gen.node_allocator_, branch[0]); 35532 | 35533 | return result; 35534 | } 35535 | } 35536 | #endif 35537 | 35538 | if ( 35539 | (details::e_add == operation) || 35540 | (details::e_sub == operation) || 35541 | (details::e_mul == operation) || 35542 | (details::e_div == operation) 35543 | ) 35544 | { 35545 | if (details::is_uv_node(branch[0])) 35546 | { 35547 | typedef details::uv_base_node<Type>* uvbn_ptr_t; 35548 | 35549 | details::operator_type o = static_cast<uvbn_ptr_t>(branch[0])->operation(); 35550 | 35551 | if (details::e_neg == o) 35552 | { 35553 | const Type& v0 = static_cast<uvbn_ptr_t>(branch[0])->v(); 35554 | 35555 | details::free_node(*expr_gen.node_allocator_,branch[0]); 35556 | 35557 | switch (operation) 35558 | { 35559 | case details::e_add : return expr_gen.node_allocator_-> 35560 | template allocate_rr<typename details:: 35561 | vov_node<Type,details::sub_op<Type> > >(v,v0); 35562 | 35563 | case details::e_sub : return expr_gen(details::e_neg, 35564 | expr_gen.node_allocator_-> 35565 | template allocate_rr<typename details:: 35566 | vov_node<Type,details::add_op<Type> > >(v0,v)); 35567 | 35568 | case details::e_mul : return expr_gen(details::e_neg, 35569 | expr_gen.node_allocator_-> 35570 | template allocate_rr<typename details:: 35571 | vov_node<Type,details::mul_op<Type> > >(v0,v)); 35572 | 35573 | case details::e_div : return expr_gen(details::e_neg, 35574 | expr_gen.node_allocator_-> 35575 | template allocate_rr<typename details:: 35576 | vov_node<Type,details::div_op<Type> > >(v0,v)); 35577 | default : break; 35578 | } 35579 | } 35580 | } 35581 | } 35582 | 35583 | switch (operation) 35584 | { 35585 | #define case_stmt(op0, op1) \ 35586 | case op0 : return expr_gen.node_allocator_-> \ 35587 | template allocate_cr<typename details::bov_node<Type,op1<Type> > > \ 35588 | (branch[0], v); \ 35589 | 35590 | basic_opr_switch_statements 35591 | extended_opr_switch_statements 35592 | #undef case_stmt 35593 | default : return error_node(); 35594 | } 35595 | } 35596 | }; 35597 | 35598 | struct synthesize_cob_expression 35599 | { 35600 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 35601 | const details::operator_type& operation, 35602 | expression_node_ptr (&branch)[2]) 35603 | { 35604 | const Type c = static_cast<details::literal_node<Type>*>(branch[0])->value(); 35605 | 35606 | details::free_node(*expr_gen.node_allocator_,branch[0]); 35607 | 35608 | if (std::equal_to<T>()(T(0),c) && (details::e_mul == operation)) 35609 | { 35610 | details::free_node(*expr_gen.node_allocator_,branch[1]); 35611 | 35612 | return expr_gen(T(0)); 35613 | } 35614 | else if (std::equal_to<T>()(T(0),c) && (details::e_div == operation)) 35615 | { 35616 | details::free_node(*expr_gen.node_allocator_, branch[1]); 35617 | 35618 | return expr_gen(T(0)); 35619 | } 35620 | else if (std::equal_to<T>()(T(0),c) && (details::e_add == operation)) 35621 | return branch[1]; 35622 | else if (std::equal_to<T>()(T(1),c) && (details::e_mul == operation)) 35623 | return branch[1]; 35624 | 35625 | if (details::is_cob_node(branch[1])) 35626 | { 35627 | // Simplify expressions of the form: 35628 | // 1. (1 * (2 * (3 * (4 * (5 * (6 * (7 * (8 * (9 + x))))))))) --> 40320 * (9 + x) 35629 | // 2. (1 + (2 + (3 + (4 + (5 + (6 + (7 + (8 + (9 + x))))))))) --> 45 + x 35630 | if ( 35631 | (details::e_mul == operation) || 35632 | (details::e_add == operation) 35633 | ) 35634 | { 35635 | details::cob_base_node<Type>* cobnode = static_cast<details::cob_base_node<Type>*>(branch[1]); 35636 | 35637 | if (operation == cobnode->operation()) 35638 | { 35639 | switch (operation) 35640 | { 35641 | case details::e_add : cobnode->set_c(c + cobnode->c()); break; 35642 | case details::e_mul : cobnode->set_c(c * cobnode->c()); break; 35643 | default : return error_node(); 35644 | } 35645 | 35646 | return cobnode; 35647 | } 35648 | } 35649 | 35650 | if (operation == details::e_mul) 35651 | { 35652 | details::cob_base_node<Type>* cobnode = static_cast<details::cob_base_node<Type>*>(branch[1]); 35653 | details::operator_type cob_opr = cobnode->operation(); 35654 | 35655 | if ( 35656 | (details::e_div == cob_opr) || 35657 | (details::e_mul == cob_opr) 35658 | ) 35659 | { 35660 | switch (cob_opr) 35661 | { 35662 | case details::e_div : cobnode->set_c(c * cobnode->c()); break; 35663 | case details::e_mul : cobnode->set_c(cobnode->c() / c); break; 35664 | default : return error_node(); 35665 | } 35666 | 35667 | return cobnode; 35668 | } 35669 | } 35670 | else if (operation == details::e_div) 35671 | { 35672 | details::cob_base_node<Type>* cobnode = static_cast<details::cob_base_node<Type>*>(branch[1]); 35673 | details::operator_type cob_opr = cobnode->operation(); 35674 | 35675 | if ( 35676 | (details::e_div == cob_opr) || 35677 | (details::e_mul == cob_opr) 35678 | ) 35679 | { 35680 | details::expression_node<Type>* new_cobnode = error_node(); 35681 | 35682 | switch (cob_opr) 35683 | { 35684 | case details::e_div : new_cobnode = expr_gen.node_allocator_-> 35685 | template allocate_tt<typename details::cob_node<Type,details::mul_op<Type> > > 35686 | (c / cobnode->c(), cobnode->move_branch(0)); 35687 | break; 35688 | 35689 | case details::e_mul : new_cobnode = expr_gen.node_allocator_-> 35690 | template allocate_tt<typename details::cob_node<Type,details::div_op<Type> > > 35691 | (c / cobnode->c(), cobnode->move_branch(0)); 35692 | break; 35693 | 35694 | default : return error_node(); 35695 | } 35696 | 35697 | details::free_node(*expr_gen.node_allocator_,branch[1]); 35698 | 35699 | return new_cobnode; 35700 | } 35701 | } 35702 | } 35703 | #ifndef exprtk_disable_enhanced_features 35704 | else if (details::is_sf3ext_node(branch[1])) 35705 | { 35706 | expression_node_ptr result = error_node(); 35707 | 35708 | const bool synthesis_result = 35709 | synthesize_sf4ext_expression::template compile_right<ctype> 35710 | (expr_gen, c, operation, branch[1], result); 35711 | 35712 | if (synthesis_result) 35713 | { 35714 | details::free_node(*expr_gen.node_allocator_,branch[1]); 35715 | 35716 | return result; 35717 | } 35718 | } 35719 | #endif 35720 | 35721 | switch (operation) 35722 | { 35723 | #define case_stmt(op0, op1) \ 35724 | case op0 : return expr_gen.node_allocator_-> \ 35725 | template allocate_tt<typename details::cob_node<Type,op1<Type> > > \ 35726 | (c, branch[1]); \ 35727 | 35728 | basic_opr_switch_statements 35729 | extended_opr_switch_statements 35730 | #undef case_stmt 35731 | default : return error_node(); 35732 | } 35733 | } 35734 | }; 35735 | 35736 | struct synthesize_boc_expression 35737 | { 35738 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 35739 | const details::operator_type& operation, 35740 | expression_node_ptr (&branch)[2]) 35741 | { 35742 | const Type c = static_cast<details::literal_node<Type>*>(branch[1])->value(); 35743 | 35744 | details::free_node(*(expr_gen.node_allocator_), branch[1]); 35745 | 35746 | if (std::equal_to<T>()(T(0),c) && (details::e_mul == operation)) 35747 | { 35748 | details::free_node(*expr_gen.node_allocator_, branch[0]); 35749 | 35750 | return expr_gen(T(0)); 35751 | } 35752 | else if (std::equal_to<T>()(T(0),c) && (details::e_div == operation)) 35753 | { 35754 | details::free_node(*expr_gen.node_allocator_, branch[0]); 35755 | 35756 | return expr_gen(std::numeric_limits<T>::quiet_NaN()); 35757 | } 35758 | else if (std::equal_to<T>()(T(0),c) && (details::e_add == operation)) 35759 | return branch[0]; 35760 | else if (std::equal_to<T>()(T(1),c) && (details::e_mul == operation)) 35761 | return branch[0]; 35762 | 35763 | if (details::is_boc_node(branch[0])) 35764 | { 35765 | // Simplify expressions of the form: 35766 | // 1. (((((((((x + 9) * 8) * 7) * 6) * 5) * 4) * 3) * 2) * 1) --> (x + 9) * 40320 35767 | // 2. (((((((((x + 9) + 8) + 7) + 6) + 5) + 4) + 3) + 2) + 1) --> x + 45 35768 | if ( 35769 | (details::e_mul == operation) || 35770 | (details::e_add == operation) 35771 | ) 35772 | { 35773 | details::boc_base_node<Type>* bocnode = static_cast<details::boc_base_node<Type>*>(branch[0]); 35774 | 35775 | if (operation == bocnode->operation()) 35776 | { 35777 | switch (operation) 35778 | { 35779 | case details::e_add : bocnode->set_c(c + bocnode->c()); break; 35780 | case details::e_mul : bocnode->set_c(c * bocnode->c()); break; 35781 | default : return error_node(); 35782 | } 35783 | 35784 | return bocnode; 35785 | } 35786 | } 35787 | else if (operation == details::e_div) 35788 | { 35789 | details::boc_base_node<Type>* bocnode = static_cast<details::boc_base_node<Type>*>(branch[0]); 35790 | details::operator_type boc_opr = bocnode->operation(); 35791 | 35792 | if ( 35793 | (details::e_div == boc_opr) || 35794 | (details::e_mul == boc_opr) 35795 | ) 35796 | { 35797 | switch (boc_opr) 35798 | { 35799 | case details::e_div : bocnode->set_c(c * bocnode->c()); break; 35800 | case details::e_mul : bocnode->set_c(bocnode->c() / c); break; 35801 | default : return error_node(); 35802 | } 35803 | 35804 | return bocnode; 35805 | } 35806 | } 35807 | else if (operation == details::e_pow) 35808 | { 35809 | // (v ^ c0) ^ c1 --> v ^(c0 * c1) 35810 | details::boc_base_node<Type>* bocnode = static_cast<details::boc_base_node<Type>*>(branch[0]); 35811 | details::operator_type boc_opr = bocnode->operation(); 35812 | 35813 | if (details::e_pow == boc_opr) 35814 | { 35815 | bocnode->set_c(bocnode->c() * c); 35816 | 35817 | return bocnode; 35818 | } 35819 | } 35820 | } 35821 | 35822 | #ifndef exprtk_disable_enhanced_features 35823 | if (details::is_sf3ext_node(branch[0])) 35824 | { 35825 | expression_node_ptr result = error_node(); 35826 | 35827 | const bool synthesis_result = 35828 | synthesize_sf4ext_expression::template compile_left<ctype> 35829 | (expr_gen, c, operation, branch[0], result); 35830 | 35831 | if (synthesis_result) 35832 | { 35833 | free_node(*expr_gen.node_allocator_, branch[0]); 35834 | 35835 | return result; 35836 | } 35837 | } 35838 | #endif 35839 | 35840 | switch (operation) 35841 | { 35842 | #define case_stmt(op0, op1) \ 35843 | case op0 : return expr_gen.node_allocator_-> \ 35844 | template allocate_cr<typename details::boc_node<Type,op1<Type> > > \ 35845 | (branch[0], c); \ 35846 | 35847 | basic_opr_switch_statements 35848 | extended_opr_switch_statements 35849 | #undef case_stmt 35850 | default : return error_node(); 35851 | } 35852 | } 35853 | }; 35854 | 35855 | struct synthesize_cocob_expression 35856 | { 35857 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 35858 | const details::operator_type& operation, 35859 | expression_node_ptr (&branch)[2]) 35860 | { 35861 | expression_node_ptr result = error_node(); 35862 | 35863 | // (cob) o c --> cob 35864 | if (details::is_cob_node(branch[0])) 35865 | { 35866 | details::cob_base_node<Type>* cobnode = static_cast<details::cob_base_node<Type>*>(branch[0]); 35867 | 35868 | const Type c = static_cast<details::literal_node<Type>*>(branch[1])->value(); 35869 | 35870 | if (std::equal_to<T>()(T(0),c) && (details::e_mul == operation)) 35871 | { 35872 | details::free_node(*expr_gen.node_allocator_, branch[0]); 35873 | details::free_node(*expr_gen.node_allocator_, branch[1]); 35874 | 35875 | return expr_gen(T(0)); 35876 | } 35877 | else if (std::equal_to<T>()(T(0),c) && (details::e_div == operation)) 35878 | { 35879 | details::free_node(*expr_gen.node_allocator_, branch[0]); 35880 | details::free_node(*expr_gen.node_allocator_, branch[1]); 35881 | 35882 | return expr_gen(T(std::numeric_limits<T>::quiet_NaN())); 35883 | } 35884 | else if (std::equal_to<T>()(T(0),c) && (details::e_add == operation)) 35885 | { 35886 | details::free_node(*expr_gen.node_allocator_, branch[1]); 35887 | 35888 | return branch[0]; 35889 | } 35890 | else if (std::equal_to<T>()(T(1),c) && (details::e_mul == operation)) 35891 | { 35892 | details::free_node(*expr_gen.node_allocator_, branch[1]); 35893 | 35894 | return branch[0]; 35895 | } 35896 | else if (std::equal_to<T>()(T(1),c) && (details::e_div == operation)) 35897 | { 35898 | details::free_node(*expr_gen.node_allocator_, branch[1]); 35899 | 35900 | return branch[0]; 35901 | } 35902 | 35903 | const bool op_addsub = (details::e_add == cobnode->operation()) || 35904 | (details::e_sub == cobnode->operation()) ; 35905 | 35906 | if (op_addsub) 35907 | { 35908 | switch (operation) 35909 | { 35910 | case details::e_add : cobnode->set_c(cobnode->c() + c); break; 35911 | case details::e_sub : cobnode->set_c(cobnode->c() - c); break; 35912 | default : return error_node(); 35913 | } 35914 | 35915 | result = cobnode; 35916 | } 35917 | else if (details::e_mul == cobnode->operation()) 35918 | { 35919 | switch (operation) 35920 | { 35921 | case details::e_mul : cobnode->set_c(cobnode->c() * c); break; 35922 | case details::e_div : cobnode->set_c(cobnode->c() / c); break; 35923 | default : return error_node(); 35924 | } 35925 | 35926 | result = cobnode; 35927 | } 35928 | else if (details::e_div == cobnode->operation()) 35929 | { 35930 | if (details::e_mul == operation) 35931 | { 35932 | cobnode->set_c(cobnode->c() * c); 35933 | result = cobnode; 35934 | } 35935 | else if (details::e_div == operation) 35936 | { 35937 | result = expr_gen.node_allocator_-> 35938 | template allocate_tt<typename details::cob_node<Type,details::div_op<Type> > > 35939 | (cobnode->c() / c, cobnode->move_branch(0)); 35940 | 35941 | details::free_node(*expr_gen.node_allocator_, branch[0]); 35942 | } 35943 | } 35944 | 35945 | if (result) 35946 | { 35947 | details::free_node(*expr_gen.node_allocator_,branch[1]); 35948 | } 35949 | } 35950 | 35951 | // c o (cob) --> cob 35952 | else if (details::is_cob_node(branch[1])) 35953 | { 35954 | details::cob_base_node<Type>* cobnode = static_cast<details::cob_base_node<Type>*>(branch[1]); 35955 | 35956 | const Type c = static_cast<details::literal_node<Type>*>(branch[0])->value(); 35957 | 35958 | if (std::equal_to<T>()(T(0),c) && (details::e_mul == operation)) 35959 | { 35960 | details::free_node(*expr_gen.node_allocator_, branch[0]); 35961 | details::free_node(*expr_gen.node_allocator_, branch[1]); 35962 | 35963 | return expr_gen(T(0)); 35964 | } 35965 | else if (std::equal_to<T>()(T(0),c) && (details::e_div == operation)) 35966 | { 35967 | details::free_node(*expr_gen.node_allocator_, branch[0]); 35968 | details::free_node(*expr_gen.node_allocator_, branch[1]); 35969 | 35970 | return expr_gen(T(0)); 35971 | } 35972 | else if (std::equal_to<T>()(T(0),c) && (details::e_add == operation)) 35973 | { 35974 | details::free_node(*expr_gen.node_allocator_, branch[0]); 35975 | 35976 | return branch[1]; 35977 | } 35978 | else if (std::equal_to<T>()(T(1),c) && (details::e_mul == operation)) 35979 | { 35980 | details::free_node(*expr_gen.node_allocator_, branch[0]); 35981 | 35982 | return branch[1]; 35983 | } 35984 | 35985 | if (details::e_add == cobnode->operation()) 35986 | { 35987 | if (details::e_add == operation) 35988 | { 35989 | cobnode->set_c(c + cobnode->c()); 35990 | result = cobnode; 35991 | } 35992 | else if (details::e_sub == operation) 35993 | { 35994 | result = expr_gen.node_allocator_-> 35995 | template allocate_tt<typename details::cob_node<Type,details::sub_op<Type> > > 35996 | (c - cobnode->c(), cobnode->move_branch(0)); 35997 | 35998 | details::free_node(*expr_gen.node_allocator_,branch[1]); 35999 | } 36000 | } 36001 | else if (details::e_sub == cobnode->operation()) 36002 | { 36003 | if (details::e_add == operation) 36004 | { 36005 | cobnode->set_c(c + cobnode->c()); 36006 | result = cobnode; 36007 | } 36008 | else if (details::e_sub == operation) 36009 | { 36010 | result = expr_gen.node_allocator_-> 36011 | template allocate_tt<typename details::cob_node<Type,details::add_op<Type> > > 36012 | (c - cobnode->c(), cobnode->move_branch(0)); 36013 | 36014 | details::free_node(*expr_gen.node_allocator_,branch[1]); 36015 | } 36016 | } 36017 | else if (details::e_mul == cobnode->operation()) 36018 | { 36019 | if (details::e_mul == operation) 36020 | { 36021 | cobnode->set_c(c * cobnode->c()); 36022 | result = cobnode; 36023 | } 36024 | else if (details::e_div == operation) 36025 | { 36026 | result = expr_gen.node_allocator_-> 36027 | template allocate_tt<typename details::cob_node<Type,details::div_op<Type> > > 36028 | (c / cobnode->c(), cobnode->move_branch(0)); 36029 | 36030 | details::free_node(*expr_gen.node_allocator_,branch[1]); 36031 | } 36032 | } 36033 | else if (details::e_div == cobnode->operation()) 36034 | { 36035 | if (details::e_mul == operation) 36036 | { 36037 | cobnode->set_c(c * cobnode->c()); 36038 | result = cobnode; 36039 | } 36040 | else if (details::e_div == operation) 36041 | { 36042 | result = expr_gen.node_allocator_-> 36043 | template allocate_tt<typename details::cob_node<Type,details::mul_op<Type> > > 36044 | (c / cobnode->c(), cobnode->move_branch(0)); 36045 | 36046 | details::free_node(*expr_gen.node_allocator_,branch[1]); 36047 | } 36048 | } 36049 | 36050 | if (result) 36051 | { 36052 | details::free_node(*expr_gen.node_allocator_,branch[0]); 36053 | } 36054 | } 36055 | 36056 | return result; 36057 | } 36058 | }; 36059 | 36060 | struct synthesize_coboc_expression 36061 | { 36062 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 36063 | const details::operator_type& operation, 36064 | expression_node_ptr (&branch)[2]) 36065 | { 36066 | expression_node_ptr result = error_node(); 36067 | 36068 | // (boc) o c --> boc 36069 | if (details::is_boc_node(branch[0])) 36070 | { 36071 | details::boc_base_node<Type>* bocnode = static_cast<details::boc_base_node<Type>*>(branch[0]); 36072 | 36073 | const Type c = static_cast<details::literal_node<Type>*>(branch[1])->value(); 36074 | 36075 | if (details::e_add == bocnode->operation()) 36076 | { 36077 | switch (operation) 36078 | { 36079 | case details::e_add : bocnode->set_c(bocnode->c() + c); break; 36080 | case details::e_sub : bocnode->set_c(bocnode->c() - c); break; 36081 | default : return error_node(); 36082 | } 36083 | 36084 | result = bocnode; 36085 | } 36086 | else if (details::e_mul == bocnode->operation()) 36087 | { 36088 | switch (operation) 36089 | { 36090 | case details::e_mul : bocnode->set_c(bocnode->c() * c); break; 36091 | case details::e_div : bocnode->set_c(bocnode->c() / c); break; 36092 | default : return error_node(); 36093 | } 36094 | 36095 | result = bocnode; 36096 | } 36097 | else if (details::e_sub == bocnode->operation()) 36098 | { 36099 | if (details::e_add == operation) 36100 | { 36101 | result = expr_gen.node_allocator_-> 36102 | template allocate_tt<typename details::boc_node<Type,details::add_op<Type> > > 36103 | (bocnode->move_branch(0), c - bocnode->c()); 36104 | 36105 | details::free_node(*expr_gen.node_allocator_,branch[0]); 36106 | } 36107 | else if (details::e_sub == operation) 36108 | { 36109 | bocnode->set_c(bocnode->c() + c); 36110 | result = bocnode; 36111 | } 36112 | } 36113 | else if (details::e_div == bocnode->operation()) 36114 | { 36115 | switch (operation) 36116 | { 36117 | case details::e_div : bocnode->set_c(bocnode->c() * c); break; 36118 | case details::e_mul : bocnode->set_c(bocnode->c() / c); break; 36119 | default : return error_node(); 36120 | } 36121 | 36122 | result = bocnode; 36123 | } 36124 | 36125 | if (result) 36126 | { 36127 | details::free_node(*expr_gen.node_allocator_, branch[1]); 36128 | } 36129 | } 36130 | 36131 | // c o (boc) --> boc 36132 | else if (details::is_boc_node(branch[1])) 36133 | { 36134 | details::boc_base_node<Type>* bocnode = static_cast<details::boc_base_node<Type>*>(branch[1]); 36135 | 36136 | const Type c = static_cast<details::literal_node<Type>*>(branch[0])->value(); 36137 | 36138 | if (details::e_add == bocnode->operation()) 36139 | { 36140 | if (details::e_add == operation) 36141 | { 36142 | bocnode->set_c(c + bocnode->c()); 36143 | result = bocnode; 36144 | } 36145 | else if (details::e_sub == operation) 36146 | { 36147 | result = expr_gen.node_allocator_-> 36148 | template allocate_tt<typename details::cob_node<Type,details::sub_op<Type> > > 36149 | (c - bocnode->c(), bocnode->move_branch(0)); 36150 | 36151 | details::free_node(*expr_gen.node_allocator_,branch[1]); 36152 | } 36153 | } 36154 | else if (details::e_sub == bocnode->operation()) 36155 | { 36156 | if (details::e_add == operation) 36157 | { 36158 | result = expr_gen.node_allocator_-> 36159 | template allocate_tt<typename details::boc_node<Type,details::add_op<Type> > > 36160 | (bocnode->move_branch(0), c - bocnode->c()); 36161 | 36162 | details::free_node(*expr_gen.node_allocator_,branch[1]); 36163 | } 36164 | else if (details::e_sub == operation) 36165 | { 36166 | result = expr_gen.node_allocator_-> 36167 | template allocate_tt<typename details::cob_node<Type,details::sub_op<Type> > > 36168 | (c + bocnode->c(), bocnode->move_branch(0)); 36169 | 36170 | details::free_node(*expr_gen.node_allocator_,branch[1]); 36171 | } 36172 | } 36173 | else if (details::e_mul == bocnode->operation()) 36174 | { 36175 | if (details::e_mul == operation) 36176 | { 36177 | bocnode->set_c(c * bocnode->c()); 36178 | result = bocnode; 36179 | } 36180 | else if (details::e_div == operation) 36181 | { 36182 | result = expr_gen.node_allocator_-> 36183 | template allocate_tt<typename details::cob_node<Type,details::div_op<Type> > > 36184 | (c / bocnode->c(), bocnode->move_branch(0)); 36185 | 36186 | details::free_node(*expr_gen.node_allocator_,branch[1]); 36187 | } 36188 | } 36189 | else if (details::e_div == bocnode->operation()) 36190 | { 36191 | if (details::e_mul == operation) 36192 | { 36193 | bocnode->set_c(bocnode->c() / c); 36194 | result = bocnode; 36195 | } 36196 | else if (details::e_div == operation) 36197 | { 36198 | result = expr_gen.node_allocator_-> 36199 | template allocate_tt<typename details::cob_node<Type,details::div_op<Type> > > 36200 | (c * bocnode->c(), bocnode->move_branch(0)); 36201 | 36202 | details::free_node(*expr_gen.node_allocator_,branch[1]); 36203 | } 36204 | } 36205 | 36206 | if (result) 36207 | { 36208 | details::free_node(*expr_gen.node_allocator_,branch[0]); 36209 | } 36210 | } 36211 | 36212 | return result; 36213 | } 36214 | }; 36215 | 36216 | #ifndef exprtk_disable_enhanced_features 36217 | inline bool synthesize_expression(const details::operator_type& operation, 36218 | expression_node_ptr (&branch)[2], 36219 | expression_node_ptr& result) 36220 | { 36221 | result = error_node(); 36222 | 36223 | if (!operation_optimisable(operation)) 36224 | return false; 36225 | 36226 | const std::string node_id = branch_to_id(branch); 36227 | 36228 | const typename synthesize_map_t::iterator itr = synthesize_map_.find(node_id); 36229 | 36230 | if (synthesize_map_.end() != itr) 36231 | { 36232 | result = itr->second((*this), operation, branch); 36233 | 36234 | return true; 36235 | } 36236 | else 36237 | return false; 36238 | } 36239 | 36240 | struct synthesize_vov_expression 36241 | { 36242 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 36243 | const details::operator_type& operation, 36244 | expression_node_ptr (&branch)[2]) 36245 | { 36246 | const Type& v1 = static_cast<details::variable_node<Type>*>(branch[0])->ref(); 36247 | const Type& v2 = static_cast<details::variable_node<Type>*>(branch[1])->ref(); 36248 | 36249 | switch (operation) 36250 | { 36251 | #define case_stmt(op0, op1) \ 36252 | case op0 : return expr_gen.node_allocator_-> \ 36253 | template allocate_rr<typename details::vov_node<Type,op1<Type> > > \ 36254 | (v1, v2); \ 36255 | 36256 | basic_opr_switch_statements 36257 | extended_opr_switch_statements 36258 | #undef case_stmt 36259 | default : return error_node(); 36260 | } 36261 | } 36262 | }; 36263 | 36264 | struct synthesize_cov_expression 36265 | { 36266 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 36267 | const details::operator_type& operation, 36268 | expression_node_ptr (&branch)[2]) 36269 | { 36270 | const Type c = static_cast<details::literal_node<Type>*> (branch[0])->value(); 36271 | const Type& v = static_cast<details::variable_node<Type>*>(branch[1])->ref (); 36272 | 36273 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 36274 | 36275 | if (std::equal_to<T>()(T(0),c) && (details::e_mul == operation)) 36276 | return expr_gen(T(0)); 36277 | else if (std::equal_to<T>()(T(0),c) && (details::e_div == operation)) 36278 | return expr_gen(T(0)); 36279 | else if (std::equal_to<T>()(T(0),c) && (details::e_add == operation)) 36280 | return static_cast<details::variable_node<Type>*>(branch[1]); 36281 | else if (std::equal_to<T>()(T(1),c) && (details::e_mul == operation)) 36282 | return static_cast<details::variable_node<Type>*>(branch[1]); 36283 | 36284 | switch (operation) 36285 | { 36286 | #define case_stmt(op0, op1) \ 36287 | case op0 : return expr_gen.node_allocator_-> \ 36288 | template allocate_cr<typename details::cov_node<Type,op1<Type> > > \ 36289 | (c, v); \ 36290 | 36291 | basic_opr_switch_statements 36292 | extended_opr_switch_statements 36293 | #undef case_stmt 36294 | default : return error_node(); 36295 | } 36296 | } 36297 | }; 36298 | 36299 | struct synthesize_voc_expression 36300 | { 36301 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 36302 | const details::operator_type& operation, 36303 | expression_node_ptr (&branch)[2]) 36304 | { 36305 | const Type& v = static_cast<details::variable_node<Type>*>(branch[0])->ref (); 36306 | const Type c = static_cast<details::literal_node<Type>*> (branch[1])->value(); 36307 | 36308 | details::free_node(*(expr_gen.node_allocator_), branch[1]); 36309 | 36310 | if (expr_gen.cardinal_pow_optimisable(operation,c)) 36311 | { 36312 | if (std::equal_to<T>()(T(1),c)) 36313 | return branch[0]; 36314 | else 36315 | return expr_gen.cardinal_pow_optimisation(v,c); 36316 | } 36317 | else if (std::equal_to<T>()(T(0),c) && (details::e_mul == operation)) 36318 | return expr_gen(T(0)); 36319 | else if (std::equal_to<T>()(T(0),c) && (details::e_div == operation)) 36320 | return expr_gen(std::numeric_limits<T>::quiet_NaN()); 36321 | else if (std::equal_to<T>()(T(0),c) && (details::e_add == operation)) 36322 | return static_cast<details::variable_node<Type>*>(branch[0]); 36323 | else if (std::equal_to<T>()(T(1),c) && (details::e_mul == operation)) 36324 | return static_cast<details::variable_node<Type>*>(branch[0]); 36325 | else if (std::equal_to<T>()(T(1),c) && (details::e_div == operation)) 36326 | return static_cast<details::variable_node<Type>*>(branch[0]); 36327 | 36328 | switch (operation) 36329 | { 36330 | #define case_stmt(op0, op1) \ 36331 | case op0 : return expr_gen.node_allocator_-> \ 36332 | template allocate_rc<typename details::voc_node<Type,op1<Type> > > \ 36333 | (v, c); \ 36334 | 36335 | basic_opr_switch_statements 36336 | extended_opr_switch_statements 36337 | #undef case_stmt 36338 | default : return error_node(); 36339 | } 36340 | } 36341 | }; 36342 | 36343 | struct synthesize_sf3ext_expression 36344 | { 36345 | template <typename T0, typename T1, typename T2> 36346 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 36347 | const details::operator_type& sf3opr, 36348 | T0 t0, T1 t1, T2 t2) 36349 | { 36350 | switch (sf3opr) 36351 | { 36352 | #define case_stmt(op) \ 36353 | case details::e_sf##op : return details::T0oT1oT2_sf3ext<T,T0,T1,T2,details::sf##op##_op<Type> >:: \ 36354 | allocate(*(expr_gen.node_allocator_), t0, t1, t2); \ 36355 | 36356 | case_stmt(00) case_stmt(01) case_stmt(02) case_stmt(03) 36357 | case_stmt(04) case_stmt(05) case_stmt(06) case_stmt(07) 36358 | case_stmt(08) case_stmt(09) case_stmt(10) case_stmt(11) 36359 | case_stmt(12) case_stmt(13) case_stmt(14) case_stmt(15) 36360 | case_stmt(16) case_stmt(17) case_stmt(18) case_stmt(19) 36361 | case_stmt(20) case_stmt(21) case_stmt(22) case_stmt(23) 36362 | case_stmt(24) case_stmt(25) case_stmt(26) case_stmt(27) 36363 | case_stmt(28) case_stmt(29) case_stmt(30) 36364 | #undef case_stmt 36365 | default : return error_node(); 36366 | } 36367 | } 36368 | 36369 | template <typename T0, typename T1, typename T2> 36370 | static inline bool compile(expression_generator<Type>& expr_gen, const std::string& id, 36371 | T0 t0, T1 t1, T2 t2, 36372 | expression_node_ptr& result) 36373 | { 36374 | details::operator_type sf3opr; 36375 | 36376 | if (!expr_gen.sf3_optimisable(id,sf3opr)) 36377 | return false; 36378 | else 36379 | result = synthesize_sf3ext_expression::template process<T0, T1, T2> 36380 | (expr_gen, sf3opr, t0, t1, t2); 36381 | 36382 | return true; 36383 | } 36384 | }; 36385 | 36386 | struct synthesize_sf4ext_expression 36387 | { 36388 | template <typename T0, typename T1, typename T2, typename T3> 36389 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 36390 | const details::operator_type& sf4opr, 36391 | T0 t0, T1 t1, T2 t2, T3 t3) 36392 | { 36393 | switch (sf4opr) 36394 | { 36395 | #define case_stmt0(op) \ 36396 | case details::e_sf##op : return details::T0oT1oT2oT3_sf4ext<Type,T0,T1,T2,T3,details::sf##op##_op<Type> >:: \ 36397 | allocate(*(expr_gen.node_allocator_), t0, t1, t2, t3); \ 36398 | 36399 | #define case_stmt1(op) \ 36400 | case details::e_sf4ext##op : return details::T0oT1oT2oT3_sf4ext<Type,T0,T1,T2,T3,details::sfext##op##_op<Type> >:: \ 36401 | allocate(*(expr_gen.node_allocator_), t0, t1, t2, t3); \ 36402 | 36403 | case_stmt0(48) case_stmt0(49) case_stmt0(50) case_stmt0(51) 36404 | case_stmt0(52) case_stmt0(53) case_stmt0(54) case_stmt0(55) 36405 | case_stmt0(56) case_stmt0(57) case_stmt0(58) case_stmt0(59) 36406 | case_stmt0(60) case_stmt0(61) case_stmt0(62) case_stmt0(63) 36407 | case_stmt0(64) case_stmt0(65) case_stmt0(66) case_stmt0(67) 36408 | case_stmt0(68) case_stmt0(69) case_stmt0(70) case_stmt0(71) 36409 | case_stmt0(72) case_stmt0(73) case_stmt0(74) case_stmt0(75) 36410 | case_stmt0(76) case_stmt0(77) case_stmt0(78) case_stmt0(79) 36411 | case_stmt0(80) case_stmt0(81) case_stmt0(82) case_stmt0(83) 36412 | 36413 | case_stmt1(00) case_stmt1(01) case_stmt1(02) case_stmt1(03) 36414 | case_stmt1(04) case_stmt1(05) case_stmt1(06) case_stmt1(07) 36415 | case_stmt1(08) case_stmt1(09) case_stmt1(10) case_stmt1(11) 36416 | case_stmt1(12) case_stmt1(13) case_stmt1(14) case_stmt1(15) 36417 | case_stmt1(16) case_stmt1(17) case_stmt1(18) case_stmt1(19) 36418 | case_stmt1(20) case_stmt1(21) case_stmt1(22) case_stmt1(23) 36419 | case_stmt1(24) case_stmt1(25) case_stmt1(26) case_stmt1(27) 36420 | case_stmt1(28) case_stmt1(29) case_stmt1(30) case_stmt1(31) 36421 | case_stmt1(32) case_stmt1(33) case_stmt1(34) case_stmt1(35) 36422 | case_stmt1(36) case_stmt1(37) case_stmt1(38) case_stmt1(39) 36423 | case_stmt1(40) case_stmt1(41) case_stmt1(42) case_stmt1(43) 36424 | case_stmt1(44) case_stmt1(45) case_stmt1(46) case_stmt1(47) 36425 | case_stmt1(48) case_stmt1(49) case_stmt1(50) case_stmt1(51) 36426 | case_stmt1(52) case_stmt1(53) case_stmt1(54) case_stmt1(55) 36427 | case_stmt1(56) case_stmt1(57) case_stmt1(58) case_stmt1(59) 36428 | case_stmt1(60) case_stmt1(61) 36429 | 36430 | #undef case_stmt0 36431 | #undef case_stmt1 36432 | default : return error_node(); 36433 | } 36434 | } 36435 | 36436 | template <typename T0, typename T1, typename T2, typename T3> 36437 | static inline bool compile(expression_generator<Type>& expr_gen, const std::string& id, 36438 | T0 t0, T1 t1, T2 t2, T3 t3, 36439 | expression_node_ptr& result) 36440 | { 36441 | details::operator_type sf4opr; 36442 | 36443 | if (!expr_gen.sf4_optimisable(id,sf4opr)) 36444 | return false; 36445 | else 36446 | result = synthesize_sf4ext_expression::template process<T0, T1, T2, T3> 36447 | (expr_gen, sf4opr, t0, t1, t2, t3); 36448 | 36449 | return true; 36450 | } 36451 | 36452 | // T o (sf3ext) 36453 | template <typename ExternalType> 36454 | static inline bool compile_right(expression_generator<Type>& expr_gen, 36455 | ExternalType t, 36456 | const details::operator_type& operation, 36457 | expression_node_ptr& sf3node, 36458 | expression_node_ptr& result) 36459 | { 36460 | if (!details::is_sf3ext_node(sf3node)) 36461 | return false; 36462 | 36463 | typedef details::T0oT1oT2_base_node<Type>* sf3ext_base_ptr; 36464 | 36465 | sf3ext_base_ptr n = static_cast<sf3ext_base_ptr>(sf3node); 36466 | const std::string id = "t" + expr_gen.to_str(operation) + "(" + n->type_id() + ")" 36467 | 36468 | switch (n->type()) 36469 | { 36470 | case details::expression_node<Type>::e_covoc : return compile_right_impl 36471 | <typename covoc_t::sf3_type_node,ExternalType, ctype, vtype, ctype> 36472 | (expr_gen, id, t, sf3node, result); 36473 | 36474 | case details::expression_node<Type>::e_covov : return compile_right_impl 36475 | <typename covov_t::sf3_type_node,ExternalType, ctype, vtype, vtype> 36476 | (expr_gen, id, t, sf3node, result); 36477 | 36478 | case details::expression_node<Type>::e_vocov : return compile_right_impl 36479 | <typename vocov_t::sf3_type_node,ExternalType, vtype, ctype, vtype> 36480 | (expr_gen, id, t, sf3node, result); 36481 | 36482 | case details::expression_node<Type>::e_vovoc : return compile_right_impl 36483 | <typename vovoc_t::sf3_type_node,ExternalType, vtype, vtype, ctype> 36484 | (expr_gen, id, t, sf3node, result); 36485 | 36486 | case details::expression_node<Type>::e_vovov : return compile_right_impl 36487 | <typename vovov_t::sf3_type_node,ExternalType, vtype, vtype, vtype> 36488 | (expr_gen, id, t, sf3node, result); 36489 | 36490 | default : return false; 36491 | } 36492 | } 36493 | 36494 | // (sf3ext) o T 36495 | template <typename ExternalType> 36496 | static inline bool compile_left(expression_generator<Type>& expr_gen, 36497 | ExternalType t, 36498 | const details::operator_type& operation, 36499 | expression_node_ptr& sf3node, 36500 | expression_node_ptr& result) 36501 | { 36502 | if (!details::is_sf3ext_node(sf3node)) 36503 | return false; 36504 | 36505 | typedef details::T0oT1oT2_base_node<Type>* sf3ext_base_ptr; 36506 | 36507 | sf3ext_base_ptr n = static_cast<sf3ext_base_ptr>(sf3node); 36508 | 36509 | const std::string id = "(" + n->type_id() + ")" + expr_gen.to_str(operation) + "t" 36510 | 36511 | switch (n->type()) 36512 | { 36513 | case details::expression_node<Type>::e_covoc : return compile_left_impl 36514 | <typename covoc_t::sf3_type_node,ExternalType, ctype, vtype, ctype> 36515 | (expr_gen, id, t, sf3node, result); 36516 | 36517 | case details::expression_node<Type>::e_covov : return compile_left_impl 36518 | <typename covov_t::sf3_type_node,ExternalType, ctype, vtype, vtype> 36519 | (expr_gen, id, t, sf3node, result); 36520 | 36521 | case details::expression_node<Type>::e_vocov : return compile_left_impl 36522 | <typename vocov_t::sf3_type_node,ExternalType, vtype, ctype, vtype> 36523 | (expr_gen, id, t, sf3node, result); 36524 | 36525 | case details::expression_node<Type>::e_vovoc : return compile_left_impl 36526 | <typename vovoc_t::sf3_type_node,ExternalType, vtype, vtype, ctype> 36527 | (expr_gen, id, t, sf3node, result); 36528 | 36529 | case details::expression_node<Type>::e_vovov : return compile_left_impl 36530 | <typename vovov_t::sf3_type_node,ExternalType, vtype, vtype, vtype> 36531 | (expr_gen, id, t, sf3node, result); 36532 | 36533 | default : return false; 36534 | } 36535 | } 36536 | 36537 | template <typename SF3TypeNode, typename ExternalType, typename T0, typename T1, typename T2> 36538 | static inline bool compile_right_impl(expression_generator<Type>& expr_gen, 36539 | const std::string& id, 36540 | ExternalType t, 36541 | expression_node_ptr& node, 36542 | expression_node_ptr& result) 36543 | { 36544 | SF3TypeNode* n = dynamic_cast<SF3TypeNode*>(node); 36545 | 36546 | if (n) 36547 | { 36548 | T0 t0 = n->t0(); 36549 | T1 t1 = n->t1(); 36550 | T2 t2 = n->t2(); 36551 | 36552 | return synthesize_sf4ext_expression::template compile<ExternalType, T0, T1, T2> 36553 | (expr_gen, id, t, t0, t1, t2, result); 36554 | } 36555 | else 36556 | return false; 36557 | } 36558 | 36559 | template <typename SF3TypeNode, typename ExternalType, typename T0, typename T1, typename T2> 36560 | static inline bool compile_left_impl(expression_generator<Type>& expr_gen, 36561 | const std::string& id, 36562 | ExternalType t, 36563 | expression_node_ptr& node, 36564 | expression_node_ptr& result) 36565 | { 36566 | SF3TypeNode* n = dynamic_cast<SF3TypeNode*>(node); 36567 | 36568 | if (n) 36569 | { 36570 | T0 t0 = n->t0(); 36571 | T1 t1 = n->t1(); 36572 | T2 t2 = n->t2(); 36573 | 36574 | return synthesize_sf4ext_expression::template compile<T0, T1, T2, ExternalType> 36575 | (expr_gen, id, t0, t1, t2, t, result); 36576 | } 36577 | else 36578 | return false; 36579 | } 36580 | }; 36581 | 36582 | struct synthesize_vovov_expression0 36583 | { 36584 | typedef typename vovov_t::type0 node_type; 36585 | typedef typename vovov_t::sf3_type sf3_type; 36586 | 36587 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 36588 | const details::operator_type& operation, 36589 | expression_node_ptr (&branch)[2]) 36590 | { 36591 | // (v0 o0 v1) o1 (v2) 36592 | const details::vov_base_node<Type>* vov = static_cast<details::vov_base_node<Type>*>(branch[0]); 36593 | const Type& v0 = vov->v0(); 36594 | const Type& v1 = vov->v1(); 36595 | const Type& v2 = static_cast<details::variable_node<Type>*>(branch[1])->ref(); 36596 | const details::operator_type o0 = vov->operation(); 36597 | const details::operator_type o1 = operation; 36598 | 36599 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 36600 | 36601 | expression_node_ptr result = error_node(); 36602 | 36603 | if (expr_gen.parser_->settings_.strength_reduction_enabled()) 36604 | { 36605 | // (v0 / v1) / v2 --> (vovov) v0 / (v1 * v2) 36606 | if ((details::e_div == o0) && (details::e_div == o1)) 36607 | { 36608 | const bool synthesis_result = 36609 | synthesize_sf3ext_expression:: 36610 | template compile<vtype, vtype, vtype>(expr_gen, "t/(t*t)", v0, v1, v2, result); 36611 | 36612 | exprtk_debug(("(v0 / v1) / v2 --> (vovov) v0 / (v1 * v2)\n")); 36613 | 36614 | return (synthesis_result) ? result : error_node(); 36615 | } 36616 | } 36617 | 36618 | const bool synthesis_result = 36619 | synthesize_sf3ext_expression::template compile<vtype, vtype, vtype> 36620 | (expr_gen, id(expr_gen, o0, o1), v0, v1, v2, result); 36621 | 36622 | if (synthesis_result) 36623 | return result; 36624 | 36625 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 36626 | binary_functor_t f1 = reinterpret_cast<binary_functor_t>(0); 36627 | 36628 | if (!expr_gen.valid_operator(o0,f0)) 36629 | return error_node(); 36630 | else if (!expr_gen.valid_operator(o1,f1)) 36631 | return error_node(); 36632 | else 36633 | return node_type::allocate(*(expr_gen.node_allocator_), v0, v1, v2, f0, f1); 36634 | } 36635 | 36636 | static inline std::string id(expression_generator<Type>& expr_gen, 36637 | const details::operator_type o0, 36638 | const details::operator_type o1) 36639 | { 36640 | return details::build_string() 36641 | << "(t" << expr_gen.to_str(o0) 36642 | << "t)" << expr_gen.to_str(o1) 36643 | << "t" 36644 | } 36645 | }; 36646 | 36647 | struct synthesize_vovov_expression1 36648 | { 36649 | typedef typename vovov_t::type1 node_type; 36650 | typedef typename vovov_t::sf3_type sf3_type; 36651 | 36652 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 36653 | const details::operator_type& operation, 36654 | expression_node_ptr (&branch)[2]) 36655 | { 36656 | // (v0) o0 (v1 o1 v2) 36657 | const details::vov_base_node<Type>* vov = static_cast<details::vov_base_node<Type>*>(branch[1]); 36658 | const Type& v0 = static_cast<details::variable_node<Type>*>(branch[0])->ref(); 36659 | const Type& v1 = vov->v0(); 36660 | const Type& v2 = vov->v1(); 36661 | const details::operator_type o0 = operation; 36662 | const details::operator_type o1 = vov->operation(); 36663 | 36664 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 36665 | 36666 | expression_node_ptr result = error_node(); 36667 | 36668 | if (expr_gen.parser_->settings_.strength_reduction_enabled()) 36669 | { 36670 | // v0 / (v1 / v2) --> (vovov) (v0 * v2) / v1 36671 | if ((details::e_div == o0) && (details::e_div == o1)) 36672 | { 36673 | const bool synthesis_result = 36674 | synthesize_sf3ext_expression:: 36675 | template compile<vtype, vtype, vtype>(expr_gen, "(t*t)/t", v0, v2, v1, result); 36676 | 36677 | exprtk_debug(("v0 / (v1 / v2) --> (vovov) (v0 * v2) / v1\n")); 36678 | 36679 | return (synthesis_result) ? result : error_node(); 36680 | } 36681 | } 36682 | 36683 | const bool synthesis_result = 36684 | synthesize_sf3ext_expression::template compile<vtype, vtype, vtype> 36685 | (expr_gen, id(expr_gen, o0, o1), v0, v1, v2, result); 36686 | 36687 | if (synthesis_result) 36688 | return result; 36689 | 36690 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 36691 | binary_functor_t f1 = reinterpret_cast<binary_functor_t>(0); 36692 | 36693 | if (!expr_gen.valid_operator(o0,f0)) 36694 | return error_node(); 36695 | else if (!expr_gen.valid_operator(o1,f1)) 36696 | return error_node(); 36697 | else 36698 | return node_type::allocate(*(expr_gen.node_allocator_), v0, v1, v2, f0, f1); 36699 | } 36700 | 36701 | static inline std::string id(expression_generator<Type>& expr_gen, 36702 | const details::operator_type o0, 36703 | const details::operator_type o1) 36704 | { 36705 | return details::build_string() 36706 | << "t" << expr_gen.to_str(o0) 36707 | << "(t" << expr_gen.to_str(o1) 36708 | << "t)" 36709 | } 36710 | }; 36711 | 36712 | struct synthesize_vovoc_expression0 36713 | { 36714 | typedef typename vovoc_t::type0 node_type; 36715 | typedef typename vovoc_t::sf3_type sf3_type; 36716 | 36717 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 36718 | const details::operator_type& operation, 36719 | expression_node_ptr (&branch)[2]) 36720 | { 36721 | // (v0 o0 v1) o1 (c) 36722 | const details::vov_base_node<Type>* vov = static_cast<details::vov_base_node<Type>*>(branch[0]); 36723 | const Type& v0 = vov->v0(); 36724 | const Type& v1 = vov->v1(); 36725 | const Type c = static_cast<details::literal_node<Type>*>(branch[1])->value(); 36726 | const details::operator_type o0 = vov->operation(); 36727 | const details::operator_type o1 = operation; 36728 | 36729 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 36730 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 36731 | 36732 | expression_node_ptr result = error_node(); 36733 | 36734 | if (expr_gen.parser_->settings_.strength_reduction_enabled()) 36735 | { 36736 | // (v0 / v1) / c --> (vovoc) v0 / (v1 * c) 36737 | if ((details::e_div == o0) && (details::e_div == o1)) 36738 | { 36739 | const bool synthesis_result = 36740 | synthesize_sf3ext_expression:: 36741 | template compile<vtype, vtype, ctype>(expr_gen, "t/(t*t)", v0, v1, c, result); 36742 | 36743 | exprtk_debug(("(v0 / v1) / c --> (vovoc) v0 / (v1 * c)\n")); 36744 | 36745 | return (synthesis_result) ? result : error_node(); 36746 | } 36747 | } 36748 | 36749 | const bool synthesis_result = 36750 | synthesize_sf3ext_expression::template compile<vtype, vtype, ctype> 36751 | (expr_gen, id(expr_gen, o0, o1), v0, v1, c, result); 36752 | 36753 | if (synthesis_result) 36754 | return result; 36755 | 36756 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 36757 | binary_functor_t f1 = reinterpret_cast<binary_functor_t>(0); 36758 | 36759 | if (!expr_gen.valid_operator(o0,f0)) 36760 | return error_node(); 36761 | else if (!expr_gen.valid_operator(o1,f1)) 36762 | return error_node(); 36763 | else 36764 | return node_type::allocate(*(expr_gen.node_allocator_), v0, v1, c, f0, f1); 36765 | } 36766 | 36767 | static inline std::string id(expression_generator<Type>& expr_gen, 36768 | const details::operator_type o0, 36769 | const details::operator_type o1) 36770 | { 36771 | return details::build_string() 36772 | << "(t" << expr_gen.to_str(o0) 36773 | << "t)" << expr_gen.to_str(o1) 36774 | << "t" 36775 | } 36776 | }; 36777 | 36778 | struct synthesize_vovoc_expression1 36779 | { 36780 | typedef typename vovoc_t::type1 node_type; 36781 | typedef typename vovoc_t::sf3_type sf3_type; 36782 | 36783 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 36784 | const details::operator_type& operation, 36785 | expression_node_ptr (&branch)[2]) 36786 | { 36787 | // (v0) o0 (v1 o1 c) 36788 | const details::voc_base_node<Type>* voc = static_cast<const details::voc_base_node<Type>*>(branch[1]); 36789 | const Type& v0 = static_cast<details::variable_node<Type>*>(branch[0])->ref(); 36790 | const Type& v1 = voc->v(); 36791 | const Type c = voc->c(); 36792 | const details::operator_type o0 = operation; 36793 | const details::operator_type o1 = voc->operation(); 36794 | 36795 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 36796 | 36797 | expression_node_ptr result = error_node(); 36798 | 36799 | if (expr_gen.parser_->settings_.strength_reduction_enabled()) 36800 | { 36801 | // v0 / (v1 / c) --> (vocov) (v0 * c) / v1 36802 | if ((details::e_div == o0) && (details::e_div == o1)) 36803 | { 36804 | const bool synthesis_result = 36805 | synthesize_sf3ext_expression:: 36806 | template compile<vtype, ctype, vtype>(expr_gen, "(t*t)/t", v0, c, v1, result); 36807 | 36808 | exprtk_debug(("v0 / (v1 / c) --> (vocov) (v0 * c) / v1\n")); 36809 | 36810 | return (synthesis_result) ? result : error_node(); 36811 | } 36812 | } 36813 | 36814 | const bool synthesis_result = 36815 | synthesize_sf3ext_expression::template compile<vtype, vtype, ctype> 36816 | (expr_gen, id(expr_gen, o0, o1), v0, v1, c, result); 36817 | 36818 | if (synthesis_result) 36819 | return result; 36820 | 36821 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 36822 | binary_functor_t f1 = reinterpret_cast<binary_functor_t>(0); 36823 | 36824 | if (!expr_gen.valid_operator(o0,f0)) 36825 | return error_node(); 36826 | else if (!expr_gen.valid_operator(o1,f1)) 36827 | return error_node(); 36828 | else 36829 | return node_type::allocate(*(expr_gen.node_allocator_), v0, v1, c, f0, f1); 36830 | } 36831 | 36832 | static inline std::string id(expression_generator<Type>& expr_gen, 36833 | const details::operator_type o0, 36834 | const details::operator_type o1) 36835 | { 36836 | return details::build_string() 36837 | << "t" << expr_gen.to_str(o0) 36838 | << "(t" << expr_gen.to_str(o1) 36839 | << "t)" 36840 | } 36841 | }; 36842 | 36843 | struct synthesize_vocov_expression0 36844 | { 36845 | typedef typename vocov_t::type0 node_type; 36846 | typedef typename vocov_t::sf3_type sf3_type; 36847 | 36848 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 36849 | const details::operator_type& operation, 36850 | expression_node_ptr (&branch)[2]) 36851 | { 36852 | // (v0 o0 c) o1 (v1) 36853 | const details::voc_base_node<Type>* voc = static_cast<details::voc_base_node<Type>*>(branch[0]); 36854 | const Type& v0 = voc->v(); 36855 | const Type c = voc->c(); 36856 | const Type& v1 = static_cast<details::variable_node<Type>*>(branch[1])->ref(); 36857 | const details::operator_type o0 = voc->operation(); 36858 | const details::operator_type o1 = operation; 36859 | 36860 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 36861 | 36862 | expression_node_ptr result = error_node(); 36863 | 36864 | if (expr_gen.parser_->settings_.strength_reduction_enabled()) 36865 | { 36866 | // (v0 / c) / v1 --> (vovoc) v0 / (v1 * c) 36867 | if ((details::e_div == o0) && (details::e_div == o1)) 36868 | { 36869 | const bool synthesis_result = 36870 | synthesize_sf3ext_expression:: 36871 | template compile<vtype, vtype, ctype>(expr_gen, "t/(t*t)", v0, v1, c, result); 36872 | 36873 | exprtk_debug(("(v0 / c) / v1 --> (vovoc) v0 / (v1 * c)\n")); 36874 | 36875 | return (synthesis_result) ? result : error_node(); 36876 | } 36877 | } 36878 | 36879 | const bool synthesis_result = 36880 | synthesize_sf3ext_expression::template compile<vtype, ctype, vtype> 36881 | (expr_gen, id(expr_gen, o0, o1), v0, c, v1, result); 36882 | 36883 | if (synthesis_result) 36884 | return result; 36885 | 36886 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 36887 | binary_functor_t f1 = reinterpret_cast<binary_functor_t>(0); 36888 | 36889 | if (!expr_gen.valid_operator(o0,f0)) 36890 | return error_node(); 36891 | else if (!expr_gen.valid_operator(o1,f1)) 36892 | return error_node(); 36893 | else 36894 | return node_type::allocate(*(expr_gen.node_allocator_), v0, c, v1, f0, f1); 36895 | } 36896 | 36897 | static inline std::string id(expression_generator<Type>& expr_gen, 36898 | const details::operator_type o0, 36899 | const details::operator_type o1) 36900 | { 36901 | return details::build_string() 36902 | << "(t" << expr_gen.to_str(o0) 36903 | << "t)" << expr_gen.to_str(o1) 36904 | << "t" 36905 | } 36906 | }; 36907 | 36908 | struct synthesize_vocov_expression1 36909 | { 36910 | typedef typename vocov_t::type1 node_type; 36911 | typedef typename vocov_t::sf3_type sf3_type; 36912 | 36913 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 36914 | const details::operator_type& operation, 36915 | expression_node_ptr (&branch)[2]) 36916 | { 36917 | // (v0) o0 (c o1 v1) 36918 | const details::cov_base_node<Type>* cov = static_cast<details::cov_base_node<Type>*>(branch[1]); 36919 | const Type& v0 = static_cast<details::variable_node<Type>*>(branch[0])->ref(); 36920 | const Type c = cov->c(); 36921 | const Type& v1 = cov->v(); 36922 | const details::operator_type o0 = operation; 36923 | const details::operator_type o1 = cov->operation(); 36924 | 36925 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 36926 | 36927 | expression_node_ptr result = error_node(); 36928 | 36929 | if (expr_gen.parser_->settings_.strength_reduction_enabled()) 36930 | { 36931 | // v0 / (c / v1) --> (vovoc) (v0 * v1) / c 36932 | if ((details::e_div == o0) && (details::e_div == o1)) 36933 | { 36934 | const bool synthesis_result = 36935 | synthesize_sf3ext_expression:: 36936 | template compile<vtype, vtype, ctype>(expr_gen, "(t*t)/t", v0, v1, c, result); 36937 | 36938 | exprtk_debug(("v0 / (c / v1) --> (vovoc) (v0 * v1) / c\n")); 36939 | 36940 | return (synthesis_result) ? result : error_node(); 36941 | } 36942 | } 36943 | 36944 | const bool synthesis_result = 36945 | synthesize_sf3ext_expression::template compile<vtype, ctype, vtype> 36946 | (expr_gen, id(expr_gen, o0, o1), v0, c, v1, result); 36947 | 36948 | if (synthesis_result) 36949 | return result; 36950 | 36951 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 36952 | binary_functor_t f1 = reinterpret_cast<binary_functor_t>(0); 36953 | 36954 | if (!expr_gen.valid_operator(o0,f0)) 36955 | return error_node(); 36956 | else if (!expr_gen.valid_operator(o1,f1)) 36957 | return error_node(); 36958 | else 36959 | return node_type::allocate(*(expr_gen.node_allocator_), v0, c, v1, f0, f1); 36960 | } 36961 | 36962 | static inline std::string id(expression_generator<Type>& expr_gen, 36963 | const details::operator_type o0, 36964 | const details::operator_type o1) 36965 | { 36966 | return details::build_string() 36967 | << "t" << expr_gen.to_str(o0) 36968 | << "(t" << expr_gen.to_str(o1) 36969 | << "t)" 36970 | } 36971 | }; 36972 | 36973 | struct synthesize_covov_expression0 36974 | { 36975 | typedef typename covov_t::type0 node_type; 36976 | typedef typename covov_t::sf3_type sf3_type; 36977 | 36978 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 36979 | const details::operator_type& operation, 36980 | expression_node_ptr (&branch)[2]) 36981 | { 36982 | // (c o0 v0) o1 (v1) 36983 | const details::cov_base_node<Type>* cov = static_cast<details::cov_base_node<Type>*>(branch[0]); 36984 | const Type c = cov->c(); 36985 | const Type& v0 = cov->v(); 36986 | const Type& v1 = static_cast<details::variable_node<Type>*>(branch[1])->ref(); 36987 | const details::operator_type o0 = cov->operation(); 36988 | const details::operator_type o1 = operation; 36989 | 36990 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 36991 | 36992 | expression_node_ptr result = error_node(); 36993 | 36994 | if (expr_gen.parser_->settings_.strength_reduction_enabled()) 36995 | { 36996 | // (c / v0) / v1 --> (covov) c / (v0 * v1) 36997 | if ((details::e_div == o0) && (details::e_div == o1)) 36998 | { 36999 | const bool synthesis_result = 37000 | synthesize_sf3ext_expression:: 37001 | template compile<ctype, vtype, vtype>(expr_gen, "t/(t*t)", c, v0, v1, result); 37002 | 37003 | exprtk_debug(("(c / v0) / v1 --> (covov) c / (v0 * v1)\n")); 37004 | 37005 | return (synthesis_result) ? result : error_node(); 37006 | } 37007 | } 37008 | 37009 | const bool synthesis_result = 37010 | synthesize_sf3ext_expression::template compile<ctype, vtype, vtype> 37011 | (expr_gen, id(expr_gen, o0, o1), c, v0, v1, result); 37012 | 37013 | if (synthesis_result) 37014 | return result; 37015 | 37016 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 37017 | binary_functor_t f1 = reinterpret_cast<binary_functor_t>(0); 37018 | 37019 | if (!expr_gen.valid_operator(o0,f0)) 37020 | return error_node(); 37021 | else if (!expr_gen.valid_operator(o1,f1)) 37022 | return error_node(); 37023 | else 37024 | return node_type::allocate(*(expr_gen.node_allocator_), c, v0, v1, f0, f1); 37025 | } 37026 | 37027 | static inline std::string id(expression_generator<Type>& expr_gen, 37028 | const details::operator_type o0, 37029 | const details::operator_type o1) 37030 | { 37031 | return details::build_string() 37032 | << "(t" << expr_gen.to_str(o0) 37033 | << "t)" << expr_gen.to_str(o1) 37034 | << "t" 37035 | } 37036 | }; 37037 | 37038 | struct synthesize_covov_expression1 37039 | { 37040 | typedef typename covov_t::type1 node_type; 37041 | typedef typename covov_t::sf3_type sf3_type; 37042 | 37043 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 37044 | const details::operator_type& operation, 37045 | expression_node_ptr (&branch)[2]) 37046 | { 37047 | // (c) o0 (v0 o1 v1) 37048 | const details::vov_base_node<Type>* vov = static_cast<details::vov_base_node<Type>*>(branch[1]); 37049 | const Type c = static_cast<details::literal_node<Type>*>(branch[0])->value(); 37050 | const Type& v0 = vov->v0(); 37051 | const Type& v1 = vov->v1(); 37052 | const details::operator_type o0 = operation; 37053 | const details::operator_type o1 = vov->operation(); 37054 | 37055 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 37056 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 37057 | 37058 | expression_node_ptr result = error_node(); 37059 | 37060 | if (expr_gen.parser_->settings_.strength_reduction_enabled()) 37061 | { 37062 | // c / (v0 / v1) --> (covov) (c * v1) / v0 37063 | if ((details::e_div == o0) && (details::e_div == o1)) 37064 | { 37065 | const bool synthesis_result = 37066 | synthesize_sf3ext_expression:: 37067 | template compile<ctype, vtype, vtype>(expr_gen, "(t*t)/t", c, v1, v0, result); 37068 | 37069 | exprtk_debug(("c / (v0 / v1) --> (covov) (c * v1) / v0\n")); 37070 | 37071 | return (synthesis_result) ? result : error_node(); 37072 | } 37073 | } 37074 | 37075 | const bool synthesis_result = 37076 | synthesize_sf3ext_expression::template compile<ctype, vtype, vtype> 37077 | (expr_gen, id(expr_gen, o0, o1), c, v0, v1, result); 37078 | 37079 | if (synthesis_result) 37080 | return result; 37081 | 37082 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 37083 | binary_functor_t f1 = reinterpret_cast<binary_functor_t>(0); 37084 | 37085 | if (!expr_gen.valid_operator(o0,f0)) 37086 | return error_node(); 37087 | else if (!expr_gen.valid_operator(o1,f1)) 37088 | return error_node(); 37089 | else 37090 | return node_type::allocate(*(expr_gen.node_allocator_), c, v0, v1, f0, f1); 37091 | } 37092 | 37093 | static inline std::string id(expression_generator<Type>& expr_gen, 37094 | const details::operator_type o0, 37095 | const details::operator_type o1) 37096 | { 37097 | return details::build_string() 37098 | << "t" << expr_gen.to_str(o0) 37099 | << "(t" << expr_gen.to_str(o1) 37100 | << "t)" 37101 | } 37102 | }; 37103 | 37104 | struct synthesize_covoc_expression0 37105 | { 37106 | typedef typename covoc_t::type0 node_type; 37107 | typedef typename covoc_t::sf3_type sf3_type; 37108 | 37109 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 37110 | const details::operator_type& operation, 37111 | expression_node_ptr (&branch)[2]) 37112 | { 37113 | // (c0 o0 v) o1 (c1) 37114 | const details::cov_base_node<Type>* cov = static_cast<details::cov_base_node<Type>*>(branch[0]); 37115 | const Type c0 = cov->c(); 37116 | const Type& v = cov->v(); 37117 | const Type c1 = static_cast<details::literal_node<Type>*>(branch[1])->value(); 37118 | const details::operator_type o0 = cov->operation(); 37119 | const details::operator_type o1 = operation; 37120 | 37121 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 37122 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 37123 | 37124 | expression_node_ptr result = error_node(); 37125 | 37126 | if (expr_gen.parser_->settings_.strength_reduction_enabled()) 37127 | { 37128 | // (c0 + v) + c1 --> (cov) (c0 + c1) + v 37129 | if ((details::e_add == o0) && (details::e_add == o1)) 37130 | { 37131 | exprtk_debug(("(c0 + v) + c1 --> (cov) (c0 + c1) + v\n")); 37132 | 37133 | return expr_gen.node_allocator_-> 37134 | template allocate_cr<typename details::cov_node<Type,details::add_op<Type> > >(c0 + c1, v); 37135 | } 37136 | // (c0 + v) - c1 --> (cov) (c0 - c1) + v 37137 | else if ((details::e_add == o0) && (details::e_sub == o1)) 37138 | { 37139 | exprtk_debug(("(c0 + v) - c1 --> (cov) (c0 - c1) + v\n")); 37140 | 37141 | return expr_gen.node_allocator_-> 37142 | template allocate_cr<typename details::cov_node<Type,details::add_op<Type> > >(c0 - c1, v); 37143 | } 37144 | // (c0 - v) + c1 --> (cov) (c0 + c1) - v 37145 | else if ((details::e_sub == o0) && (details::e_add == o1)) 37146 | { 37147 | exprtk_debug(("(c0 - v) + c1 --> (cov) (c0 + c1) - v\n")); 37148 | 37149 | return expr_gen.node_allocator_-> 37150 | template allocate_cr<typename details::cov_node<Type,details::sub_op<Type> > >(c0 + c1, v); 37151 | } 37152 | // (c0 - v) - c1 --> (cov) (c0 - c1) - v 37153 | else if ((details::e_sub == o0) && (details::e_sub == o1)) 37154 | { 37155 | exprtk_debug(("(c0 - v) - c1 --> (cov) (c0 - c1) - v\n")); 37156 | 37157 | return expr_gen.node_allocator_-> 37158 | template allocate_cr<typename details::cov_node<Type,details::sub_op<Type> > >(c0 - c1, v); 37159 | } 37160 | // (c0 * v) * c1 --> (cov) (c0 * c1) * v 37161 | else if ((details::e_mul == o0) && (details::e_mul == o1)) 37162 | { 37163 | exprtk_debug(("(c0 * v) * c1 --> (cov) (c0 * c1) * v\n")); 37164 | 37165 | return expr_gen.node_allocator_-> 37166 | template allocate_cr<typename details::cov_node<Type,details::mul_op<Type> > >(c0 * c1, v); 37167 | } 37168 | // (c0 * v) / c1 --> (cov) (c0 / c1) * v 37169 | else if ((details::e_mul == o0) && (details::e_div == o1)) 37170 | { 37171 | exprtk_debug(("(c0 * v) / c1 --> (cov) (c0 / c1) * v\n")); 37172 | 37173 | return expr_gen.node_allocator_-> 37174 | template allocate_cr<typename details::cov_node<Type,details::mul_op<Type> > >(c0 / c1, v); 37175 | } 37176 | // (c0 / v) * c1 --> (cov) (c0 * c1) / v 37177 | else if ((details::e_div == o0) && (details::e_mul == o1)) 37178 | { 37179 | exprtk_debug(("(c0 / v) * c1 --> (cov) (c0 * c1) / v\n")); 37180 | 37181 | return expr_gen.node_allocator_-> 37182 | template allocate_cr<typename details::cov_node<Type,details::div_op<Type> > >(c0 * c1, v); 37183 | } 37184 | // (c0 / v) / c1 --> (cov) (c0 / c1) / v 37185 | else if ((details::e_div == o0) && (details::e_div == o1)) 37186 | { 37187 | exprtk_debug(("(c0 / v) / c1 --> (cov) (c0 / c1) / v\n")); 37188 | 37189 | return expr_gen.node_allocator_-> 37190 | template allocate_cr<typename details::cov_node<Type,details::div_op<Type> > >(c0 / c1, v); 37191 | } 37192 | } 37193 | 37194 | const bool synthesis_result = 37195 | synthesize_sf3ext_expression::template compile<ctype, vtype, ctype> 37196 | (expr_gen, id(expr_gen, o0, o1), c0, v, c1, result); 37197 | 37198 | if (synthesis_result) 37199 | return result; 37200 | 37201 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 37202 | binary_functor_t f1 = reinterpret_cast<binary_functor_t>(0); 37203 | 37204 | if (!expr_gen.valid_operator(o0,f0)) 37205 | return error_node(); 37206 | else if (!expr_gen.valid_operator(o1,f1)) 37207 | return error_node(); 37208 | else 37209 | return node_type::allocate(*(expr_gen.node_allocator_), c0, v, c1, f0, f1); 37210 | } 37211 | 37212 | static inline std::string id(expression_generator<Type>& expr_gen, 37213 | const details::operator_type o0, 37214 | const details::operator_type o1) 37215 | { 37216 | return details::build_string() 37217 | << "(t" << expr_gen.to_str(o0) 37218 | << "t)" << expr_gen.to_str(o1) 37219 | << "t" 37220 | } 37221 | }; 37222 | 37223 | struct synthesize_covoc_expression1 37224 | { 37225 | typedef typename covoc_t::type1 node_type; 37226 | typedef typename covoc_t::sf3_type sf3_type; 37227 | 37228 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 37229 | const details::operator_type& operation, 37230 | expression_node_ptr (&branch)[2]) 37231 | { 37232 | // (c0) o0 (v o1 c1) 37233 | const details::voc_base_node<Type>* voc = static_cast<details::voc_base_node<Type>*>(branch[1]); 37234 | const Type c0 = static_cast<details::literal_node<Type>*>(branch[0])->value(); 37235 | const Type& v = voc->v(); 37236 | const Type c1 = voc->c(); 37237 | const details::operator_type o0 = operation; 37238 | const details::operator_type o1 = voc->operation(); 37239 | 37240 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 37241 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 37242 | 37243 | expression_node_ptr result = error_node(); 37244 | 37245 | if (expr_gen.parser_->settings_.strength_reduction_enabled()) 37246 | { 37247 | // (c0) + (v + c1) --> (cov) (c0 + c1) + v 37248 | if ((details::e_add == o0) && (details::e_add == o1)) 37249 | { 37250 | exprtk_debug(("(c0) + (v + c1) --> (cov) (c0 + c1) + v\n")); 37251 | 37252 | return expr_gen.node_allocator_-> 37253 | template allocate_cr<typename details::cov_node<Type,details::add_op<Type> > >(c0 + c1, v); 37254 | } 37255 | // (c0) + (v - c1) --> (cov) (c0 - c1) + v 37256 | else if ((details::e_add == o0) && (details::e_sub == o1)) 37257 | { 37258 | exprtk_debug(("(c0) + (v - c1) --> (cov) (c0 - c1) + v\n")); 37259 | 37260 | return expr_gen.node_allocator_-> 37261 | template allocate_cr<typename details::cov_node<Type,details::add_op<Type> > >(c0 - c1, v); 37262 | } 37263 | // (c0) - (v + c1) --> (cov) (c0 - c1) - v 37264 | else if ((details::e_sub == o0) && (details::e_add == o1)) 37265 | { 37266 | exprtk_debug(("(c0) - (v + c1) --> (cov) (c0 - c1) - v\n")); 37267 | 37268 | return expr_gen.node_allocator_-> 37269 | template allocate_cr<typename details::cov_node<Type,details::sub_op<Type> > >(c0 - c1, v); 37270 | } 37271 | // (c0) - (v - c1) --> (cov) (c0 + c1) - v 37272 | else if ((details::e_sub == o0) && (details::e_sub == o1)) 37273 | { 37274 | exprtk_debug(("(c0) - (v - c1) --> (cov) (c0 + c1) - v\n")); 37275 | 37276 | return expr_gen.node_allocator_-> 37277 | template allocate_cr<typename details::cov_node<Type,details::sub_op<Type> > >(c0 + c1, v); 37278 | } 37279 | // (c0) * (v * c1) --> (voc) v * (c0 * c1) 37280 | else if ((details::e_mul == o0) && (details::e_mul == o1)) 37281 | { 37282 | exprtk_debug(("(c0) * (v * c1) --> (voc) v * (c0 * c1)\n")); 37283 | 37284 | return expr_gen.node_allocator_-> 37285 | template allocate_cr<typename details::cov_node<Type,details::mul_op<Type> > >(c0 * c1, v); 37286 | } 37287 | // (c0) * (v / c1) --> (cov) (c0 / c1) * v 37288 | else if ((details::e_mul == o0) && (details::e_div == o1)) 37289 | { 37290 | exprtk_debug(("(c0) * (v / c1) --> (cov) (c0 / c1) * v\n")); 37291 | 37292 | return expr_gen.node_allocator_-> 37293 | template allocate_cr<typename details::cov_node<Type,details::mul_op<Type> > >(c0 / c1, v); 37294 | } 37295 | // (c0) / (v * c1) --> (cov) (c0 / c1) / v 37296 | else if ((details::e_div == o0) && (details::e_mul == o1)) 37297 | { 37298 | exprtk_debug(("(c0) / (v * c1) --> (cov) (c0 / c1) / v\n")); 37299 | 37300 | return expr_gen.node_allocator_-> 37301 | template allocate_cr<typename details::cov_node<Type,details::div_op<Type> > >(c0 / c1, v); 37302 | } 37303 | // (c0) / (v / c1) --> (cov) (c0 * c1) / v 37304 | else if ((details::e_div == o0) && (details::e_div == o1)) 37305 | { 37306 | exprtk_debug(("(c0) / (v / c1) --> (cov) (c0 * c1) / v\n")); 37307 | 37308 | return expr_gen.node_allocator_-> 37309 | template allocate_cr<typename details::cov_node<Type,details::div_op<Type> > >(c0 * c1, v); 37310 | } 37311 | } 37312 | 37313 | const bool synthesis_result = 37314 | synthesize_sf3ext_expression::template compile<ctype, vtype, ctype> 37315 | (expr_gen, id(expr_gen, o0, o1), c0, v, c1, result); 37316 | 37317 | if (synthesis_result) 37318 | return result; 37319 | 37320 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 37321 | binary_functor_t f1 = reinterpret_cast<binary_functor_t>(0); 37322 | 37323 | if (!expr_gen.valid_operator(o0,f0)) 37324 | return error_node(); 37325 | else if (!expr_gen.valid_operator(o1,f1)) 37326 | return error_node(); 37327 | else 37328 | return node_type::allocate(*(expr_gen.node_allocator_), c0, v, c1, f0, f1); 37329 | } 37330 | 37331 | static inline std::string id(expression_generator<Type>& expr_gen, 37332 | const details::operator_type o0, 37333 | const details::operator_type o1) 37334 | { 37335 | return details::build_string() 37336 | << "t" << expr_gen.to_str(o0) 37337 | << "(t" << expr_gen.to_str(o1) 37338 | << "t)" 37339 | } 37340 | }; 37341 | 37342 | struct synthesize_cocov_expression0 37343 | { 37344 | typedef typename cocov_t::type0 node_type; 37345 | static inline expression_node_ptr process(expression_generator<Type>&, 37346 | const details::operator_type&, 37347 | expression_node_ptr (&)[2]) 37348 | { 37349 | // (c0 o0 c1) o1 (v) - Not possible. 37350 | return error_node(); 37351 | } 37352 | }; 37353 | 37354 | struct synthesize_cocov_expression1 37355 | { 37356 | typedef typename cocov_t::type1 node_type; 37357 | typedef typename cocov_t::sf3_type sf3_type; 37358 | 37359 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 37360 | const details::operator_type& operation, 37361 | expression_node_ptr (&branch)[2]) 37362 | { 37363 | // (c0) o0 (c1 o1 v) 37364 | const details::cov_base_node<Type>* cov = static_cast<details::cov_base_node<Type>*>(branch[1]); 37365 | const Type c0 = static_cast<details::literal_node<Type>*>(branch[0])->value(); 37366 | const Type c1 = cov->c(); 37367 | const Type& v = cov->v(); 37368 | const details::operator_type o0 = operation; 37369 | const details::operator_type o1 = cov->operation(); 37370 | 37371 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 37372 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 37373 | 37374 | expression_node_ptr result = error_node(); 37375 | 37376 | if (expr_gen.parser_->settings_.strength_reduction_enabled()) 37377 | { 37378 | // (c0) + (c1 + v) --> (cov) (c0 + c1) + v 37379 | if ((details::e_add == o0) && (details::e_add == o1)) 37380 | { 37381 | exprtk_debug(("(c0) + (c1 + v) --> (cov) (c0 + c1) + v\n")); 37382 | 37383 | return expr_gen.node_allocator_-> 37384 | template allocate_cr<typename details::cov_node<Type,details::add_op<Type> > >(c0 + c1, v); 37385 | } 37386 | // (c0) + (c1 - v) --> (cov) (c0 + c1) - v 37387 | else if ((details::e_add == o0) && (details::e_sub == o1)) 37388 | { 37389 | exprtk_debug(("(c0) + (c1 - v) --> (cov) (c0 + c1) - v\n")); 37390 | 37391 | return expr_gen.node_allocator_-> 37392 | template allocate_cr<typename details::cov_node<Type,details::sub_op<Type> > >(c0 + c1, v); 37393 | } 37394 | // (c0) - (c1 + v) --> (cov) (c0 - c1) - v 37395 | else if ((details::e_sub == o0) && (details::e_add == o1)) 37396 | { 37397 | exprtk_debug(("(c0) - (c1 + v) --> (cov) (c0 - c1) - v\n")); 37398 | 37399 | return expr_gen.node_allocator_-> 37400 | template allocate_cr<typename details::cov_node<Type,details::sub_op<Type> > >(c0 - c1, v); 37401 | } 37402 | // (c0) - (c1 - v) --> (cov) (c0 - c1) + v 37403 | else if ((details::e_sub == o0) && (details::e_sub == o1)) 37404 | { 37405 | exprtk_debug(("(c0) - (c1 - v) --> (cov) (c0 - c1) + v\n")); 37406 | 37407 | return expr_gen.node_allocator_-> 37408 | template allocate_cr<typename details::cov_node<Type,details::add_op<Type> > >(c0 - c1, v); 37409 | } 37410 | // (c0) * (c1 * v) --> (cov) (c0 * c1) * v 37411 | else if ((details::e_mul == o0) && (details::e_mul == o1)) 37412 | { 37413 | exprtk_debug(("(c0) * (c1 * v) --> (cov) (c0 * c1) * v\n")); 37414 | 37415 | return expr_gen.node_allocator_-> 37416 | template allocate_cr<typename details::cov_node<Type,details::mul_op<Type> > >(c0 * c1, v); 37417 | } 37418 | // (c0) * (c1 / v) --> (cov) (c0 * c1) / v 37419 | else if ((details::e_mul == o0) && (details::e_div == o1)) 37420 | { 37421 | exprtk_debug(("(c0) * (c1 / v) --> (cov) (c0 * c1) / v\n")); 37422 | 37423 | return expr_gen.node_allocator_-> 37424 | template allocate_cr<typename details::cov_node<Type,details::div_op<Type> > >(c0 * c1, v); 37425 | } 37426 | // (c0) / (c1 * v) --> (cov) (c0 / c1) / v 37427 | else if ((details::e_div == o0) && (details::e_mul == o1)) 37428 | { 37429 | exprtk_debug(("(c0) / (c1 * v) --> (cov) (c0 / c1) / v\n")); 37430 | 37431 | return expr_gen.node_allocator_-> 37432 | template allocate_cr<typename details::cov_node<Type,details::div_op<Type> > >(c0 / c1, v); 37433 | } 37434 | // (c0) / (c1 / v) --> (cov) (c0 / c1) * v 37435 | else if ((details::e_div == o0) && (details::e_div == o1)) 37436 | { 37437 | exprtk_debug(("(c0) / (c1 / v) --> (cov) (c0 / c1) * v\n")); 37438 | 37439 | return expr_gen.node_allocator_-> 37440 | template allocate_cr<typename details::cov_node<Type,details::mul_op<Type> > >(c0 / c1, v); 37441 | } 37442 | } 37443 | 37444 | const bool synthesis_result = 37445 | synthesize_sf3ext_expression::template compile<ctype, ctype, vtype> 37446 | (expr_gen, id(expr_gen, o0, o1), c0, c1, v, result); 37447 | 37448 | if (synthesis_result) 37449 | return result; 37450 | 37451 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 37452 | binary_functor_t f1 = reinterpret_cast<binary_functor_t>(0); 37453 | 37454 | if (!expr_gen.valid_operator(o0,f0)) 37455 | return error_node(); 37456 | else if (!expr_gen.valid_operator(o1,f1)) 37457 | return error_node(); 37458 | else 37459 | return node_type::allocate(*(expr_gen.node_allocator_), c0, c1, v, f0, f1); 37460 | } 37461 | 37462 | static inline std::string id(expression_generator<Type>& expr_gen, 37463 | const details::operator_type o0, 37464 | const details::operator_type o1) 37465 | { 37466 | return details::build_string() 37467 | << "t" << expr_gen.to_str(o0) 37468 | << "(t" << expr_gen.to_str(o1) 37469 | << "t)" 37470 | } 37471 | }; 37472 | 37473 | struct synthesize_vococ_expression0 37474 | { 37475 | typedef typename vococ_t::type0 node_type; 37476 | typedef typename vococ_t::sf3_type sf3_type; 37477 | 37478 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 37479 | const details::operator_type& operation, 37480 | expression_node_ptr (&branch)[2]) 37481 | { 37482 | // (v o0 c0) o1 (c1) 37483 | const details::voc_base_node<Type>* voc = static_cast<details::voc_base_node<Type>*>(branch[0]); 37484 | const Type& v = voc->v(); 37485 | const Type& c0 = voc->c(); 37486 | const Type& c1 = static_cast<details::literal_node<Type>*>(branch[1])->value(); 37487 | const details::operator_type o0 = voc->operation(); 37488 | const details::operator_type o1 = operation; 37489 | 37490 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 37491 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 37492 | 37493 | expression_node_ptr result = error_node(); 37494 | 37495 | if (expr_gen.parser_->settings_.strength_reduction_enabled()) 37496 | { 37497 | // (v + c0) + c1 --> (voc) v + (c0 + c1) 37498 | if ((details::e_add == o0) && (details::e_add == o1)) 37499 | { 37500 | exprtk_debug(("(v + c0) + c1 --> (voc) v + (c0 + c1)\n")); 37501 | 37502 | return expr_gen.node_allocator_-> 37503 | template allocate_rc<typename details::voc_node<Type,details::add_op<Type> > >(v, c0 + c1); 37504 | } 37505 | // (v + c0) - c1 --> (voc) v + (c0 - c1) 37506 | else if ((details::e_add == o0) && (details::e_sub == o1)) 37507 | { 37508 | exprtk_debug(("(v + c0) - c1 --> (voc) v + (c0 - c1)\n")); 37509 | 37510 | return expr_gen.node_allocator_-> 37511 | template allocate_rc<typename details::voc_node<Type,details::add_op<Type> > >(v, c0 - c1); 37512 | } 37513 | // (v - c0) + c1 --> (voc) v - (c0 + c1) 37514 | else if ((details::e_sub == o0) && (details::e_add == o1)) 37515 | { 37516 | exprtk_debug(("(v - c0) + c1 --> (voc) v - (c0 + c1)\n")); 37517 | 37518 | return expr_gen.node_allocator_-> 37519 | template allocate_rc<typename details::voc_node<Type,details::add_op<Type> > >(v, c1 - c0); 37520 | } 37521 | // (v - c0) - c1 --> (voc) v - (c0 + c1) 37522 | else if ((details::e_sub == o0) && (details::e_sub == o1)) 37523 | { 37524 | exprtk_debug(("(v - c0) - c1 --> (voc) v - (c0 + c1)\n")); 37525 | 37526 | return expr_gen.node_allocator_-> 37527 | template allocate_rc<typename details::voc_node<Type,details::sub_op<Type> > >(v, c0 + c1); 37528 | } 37529 | // (v * c0) * c1 --> (voc) v * (c0 * c1) 37530 | else if ((details::e_mul == o0) && (details::e_mul == o1)) 37531 | { 37532 | exprtk_debug(("(v * c0) * c1 --> (voc) v * (c0 * c1)\n")); 37533 | 37534 | return expr_gen.node_allocator_-> 37535 | template allocate_rc<typename details::voc_node<Type,details::mul_op<Type> > >(v, c0 * c1); 37536 | } 37537 | // (v * c0) / c1 --> (voc) v * (c0 / c1) 37538 | else if ((details::e_mul == o0) && (details::e_div == o1)) 37539 | { 37540 | exprtk_debug(("(v * c0) / c1 --> (voc) v * (c0 / c1)\n")); 37541 | 37542 | return expr_gen.node_allocator_-> 37543 | template allocate_rc<typename details::voc_node<Type,details::mul_op<Type> > >(v, c0 / c1); 37544 | } 37545 | // (v / c0) * c1 --> (voc) v * (c1 / c0) 37546 | else if ((details::e_div == o0) && (details::e_mul == o1)) 37547 | { 37548 | exprtk_debug(("(v / c0) * c1 --> (voc) v * (c1 / c0)\n")); 37549 | 37550 | return expr_gen.node_allocator_-> 37551 | template allocate_rc<typename details::voc_node<Type,details::mul_op<Type> > >(v, c1 / c0); 37552 | } 37553 | // (v / c0) / c1 --> (voc) v / (c0 * c1) 37554 | else if ((details::e_div == o0) && (details::e_div == o1)) 37555 | { 37556 | exprtk_debug(("(v / c0) / c1 --> (voc) v / (c0 * c1)\n")); 37557 | 37558 | return expr_gen.node_allocator_-> 37559 | template allocate_rc<typename details::voc_node<Type,details::div_op<Type> > >(v, c0 * c1); 37560 | } 37561 | // (v ^ c0) ^ c1 --> (voc) v ^ (c0 * c1) 37562 | else if ((details::e_pow == o0) && (details::e_pow == o1)) 37563 | { 37564 | exprtk_debug(("(v ^ c0) ^ c1 --> (voc) v ^ (c0 * c1)\n")); 37565 | 37566 | return expr_gen.node_allocator_-> 37567 | template allocate_rc<typename details::voc_node<Type,details::pow_op<Type> > >(v, c0 * c1); 37568 | } 37569 | } 37570 | 37571 | const bool synthesis_result = 37572 | synthesize_sf3ext_expression::template compile<vtype, ctype, ctype> 37573 | (expr_gen, id(expr_gen, o0, o1), v, c0, c1, result); 37574 | 37575 | if (synthesis_result) 37576 | return result; 37577 | 37578 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 37579 | binary_functor_t f1 = reinterpret_cast<binary_functor_t>(0); 37580 | 37581 | if (!expr_gen.valid_operator(o0,f0)) 37582 | return error_node(); 37583 | else if (!expr_gen.valid_operator(o1,f1)) 37584 | return error_node(); 37585 | else 37586 | return node_type::allocate(*(expr_gen.node_allocator_), v, c0, c1, f0, f1); 37587 | } 37588 | 37589 | static inline std::string id(expression_generator<Type>& expr_gen, 37590 | const details::operator_type o0, 37591 | const details::operator_type o1) 37592 | { 37593 | return details::build_string() 37594 | << "(t" << expr_gen.to_str(o0) 37595 | << "t)" << expr_gen.to_str(o1) 37596 | << "t" 37597 | } 37598 | }; 37599 | 37600 | struct synthesize_vococ_expression1 37601 | { 37602 | typedef typename vococ_t::type0 node_type; 37603 | 37604 | static inline expression_node_ptr process(expression_generator<Type>&, 37605 | const details::operator_type&, 37606 | expression_node_ptr (&)[2]) 37607 | { 37608 | // (v) o0 (c0 o1 c1) - Not possible. 37609 | exprtk_debug(("(v) o0 (c0 o1 c1) - Not possible.\n")); 37610 | return error_node(); 37611 | } 37612 | }; 37613 | 37614 | struct synthesize_vovovov_expression0 37615 | { 37616 | typedef typename vovovov_t::type0 node_type; 37617 | typedef typename vovovov_t::sf4_type sf4_type; 37618 | typedef typename node_type::T0 T0; 37619 | typedef typename node_type::T1 T1; 37620 | typedef typename node_type::T2 T2; 37621 | typedef typename node_type::T3 T3; 37622 | 37623 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 37624 | const details::operator_type& operation, 37625 | expression_node_ptr (&branch)[2]) 37626 | { 37627 | // (v0 o0 v1) o1 (v2 o2 v3) 37628 | const details::vov_base_node<Type>* vov0 = static_cast<details::vov_base_node<Type>*>(branch[0]); 37629 | const details::vov_base_node<Type>* vov1 = static_cast<details::vov_base_node<Type>*>(branch[1]); 37630 | const Type& v0 = vov0->v0(); 37631 | const Type& v1 = vov0->v1(); 37632 | const Type& v2 = vov1->v0(); 37633 | const Type& v3 = vov1->v1(); 37634 | const details::operator_type o0 = vov0->operation(); 37635 | const details::operator_type o1 = operation; 37636 | const details::operator_type o2 = vov1->operation(); 37637 | 37638 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 37639 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 37640 | 37641 | expression_node_ptr result = error_node(); 37642 | 37643 | if (expr_gen.parser_->settings_.strength_reduction_enabled()) 37644 | { 37645 | // (v0 / v1) * (v2 / v3) --> (vovovov) (v0 * v2) / (v1 * v3) 37646 | if ((details::e_div == o0) && (details::e_mul == o1) && (details::e_div == o2)) 37647 | { 37648 | const bool synthesis_result = 37649 | synthesize_sf4ext_expression:: 37650 | template compile<vtype, vtype, vtype, vtype>(expr_gen, "(t*t)/(t*t)", v0, v2, v1, v3, result); 37651 | 37652 | exprtk_debug(("(v0 / v1) * (v2 / v3) --> (vovovov) (v0 * v2) / (v1 * v3)\n")); 37653 | 37654 | return (synthesis_result) ? result : error_node(); 37655 | } 37656 | // (v0 / v1) / (v2 / v3) --> (vovovov) (v0 * v3) / (v1 * v2) 37657 | else if ((details::e_div == o0) && (details::e_div == o1) && (details::e_div == o2)) 37658 | { 37659 | const bool synthesis_result = 37660 | synthesize_sf4ext_expression:: 37661 | template compile<vtype, vtype, vtype, vtype>(expr_gen, "(t*t)/(t*t)", v0, v3, v1, v2, result); 37662 | 37663 | exprtk_debug(("(v0 / v1) / (v2 / v3) --> (vovovov) (v0 * v3) / (v1 * v2)\n")); 37664 | 37665 | return (synthesis_result) ? result : error_node(); 37666 | } 37667 | // (v0 + v1) / (v2 / v3) --> (vovovov) (v0 + v1) * (v3 / v2) 37668 | else if ((details::e_add == o0) && (details::e_div == o1) && (details::e_div == o2)) 37669 | { 37670 | const bool synthesis_result = 37671 | synthesize_sf4ext_expression:: 37672 | template compile<vtype, vtype, vtype, vtype>(expr_gen, "(t+t)*(t/t)", v0, v1, v3, v2, result); 37673 | 37674 | exprtk_debug(("(v0 + v1) / (v2 / v3) --> (vovovov) (v0 + v1) * (v3 / v2)\n")); 37675 | 37676 | return (synthesis_result) ? result : error_node(); 37677 | } 37678 | // (v0 - v1) / (v2 / v3) --> (vovovov) (v0 + v1) * (v3 / v2) 37679 | else if ((details::e_sub == o0) && (details::e_div == o1) && (details::e_div == o2)) 37680 | { 37681 | const bool synthesis_result = 37682 | synthesize_sf4ext_expression:: 37683 | template compile<vtype, vtype, vtype, vtype>(expr_gen, "(t-t)*(t/t)", v0, v1, v3, v2, result); 37684 | 37685 | exprtk_debug(("(v0 - v1) / (v2 / v3) --> (vovovov) (v0 - v1) * (v3 / v2)\n")); 37686 | 37687 | return (synthesis_result) ? result : error_node(); 37688 | } 37689 | // (v0 * v1) / (v2 / v3) --> (vovovov) ((v0 * v1) * v3) / v2 37690 | else if ((details::e_mul == o0) && (details::e_div == o1) && (details::e_div == o2)) 37691 | { 37692 | const bool synthesis_result = 37693 | synthesize_sf4ext_expression:: 37694 | template compile<vtype, vtype, vtype, vtype>(expr_gen, "((t*t)*t)/t", v0, v1, v3, v2, result); 37695 | 37696 | exprtk_debug(("(v0 * v1) / (v2 / v3) --> (vovovov) ((v0 * v1) * v3) / v2\n")); 37697 | 37698 | return (synthesis_result) ? result : error_node(); 37699 | } 37700 | } 37701 | 37702 | const bool synthesis_result = 37703 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 37704 | (expr_gen, id(expr_gen, o0, o1, o2), v0, v1, v2, v3, result); 37705 | 37706 | if (synthesis_result) 37707 | return result; 37708 | 37709 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 37710 | binary_functor_t f1 = reinterpret_cast<binary_functor_t>(0); 37711 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 37712 | 37713 | if (!expr_gen.valid_operator(o0,f0)) 37714 | return error_node(); 37715 | else if (!expr_gen.valid_operator(o1,f1)) 37716 | return error_node(); 37717 | else if (!expr_gen.valid_operator(o2,f2)) 37718 | return error_node(); 37719 | else 37720 | return node_type::allocate(*(expr_gen.node_allocator_), v0, v1, v2, v3, f0, f1, f2); 37721 | } 37722 | 37723 | static inline std::string id(expression_generator<Type>& expr_gen, 37724 | const details::operator_type o0, 37725 | const details::operator_type o1, 37726 | const details::operator_type o2) 37727 | { 37728 | return details::build_string() 37729 | << "(t" << expr_gen.to_str(o0) 37730 | << "t)" << expr_gen.to_str(o1) 37731 | << "(t" << expr_gen.to_str(o2) 37732 | << "t)" 37733 | } 37734 | }; 37735 | 37736 | struct synthesize_vovovoc_expression0 37737 | { 37738 | typedef typename vovovoc_t::type0 node_type; 37739 | typedef typename vovovoc_t::sf4_type sf4_type; 37740 | typedef typename node_type::T0 T0; 37741 | typedef typename node_type::T1 T1; 37742 | typedef typename node_type::T2 T2; 37743 | typedef typename node_type::T3 T3; 37744 | 37745 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 37746 | const details::operator_type& operation, 37747 | expression_node_ptr (&branch)[2]) 37748 | { 37749 | // (v0 o0 v1) o1 (v2 o2 c) 37750 | const details::vov_base_node<Type>* vov = static_cast<details::vov_base_node<Type>*>(branch[0]); 37751 | const details::voc_base_node<Type>* voc = static_cast<details::voc_base_node<Type>*>(branch[1]); 37752 | const Type& v0 = vov->v0(); 37753 | const Type& v1 = vov->v1(); 37754 | const Type& v2 = voc->v (); 37755 | const Type c = voc->c (); 37756 | const details::operator_type o0 = vov->operation(); 37757 | const details::operator_type o1 = operation; 37758 | const details::operator_type o2 = voc->operation(); 37759 | 37760 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 37761 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 37762 | 37763 | expression_node_ptr result = error_node(); 37764 | 37765 | if (expr_gen.parser_->settings_.strength_reduction_enabled()) 37766 | { 37767 | // (v0 / v1) * (v2 / c) --> (vovovoc) (v0 * v2) / (v1 * c) 37768 | if ((details::e_div == o0) && (details::e_mul == o1) && (details::e_div == o2)) 37769 | { 37770 | const bool synthesis_result = 37771 | synthesize_sf4ext_expression:: 37772 | template compile<vtype, vtype, vtype, ctype>(expr_gen, "(t*t)/(t*t)", v0, v2, v1, c, result); 37773 | 37774 | exprtk_debug(("(v0 / v1) * (v2 / c) --> (vovovoc) (v0 * v2) / (v1 * c)\n")); 37775 | 37776 | return (synthesis_result) ? result : error_node(); 37777 | } 37778 | // (v0 / v1) / (v2 / c) --> (vocovov) (v0 * c) / (v1 * v2) 37779 | if ((details::e_div == o0) && (details::e_div == o1) && (details::e_div == o2)) 37780 | { 37781 | const bool synthesis_result = 37782 | synthesize_sf4ext_expression:: 37783 | template compile<vtype, ctype, vtype, vtype>(expr_gen, "(t*t)/(t*t)", v0, c, v1, v2, result); 37784 | 37785 | exprtk_debug(("(v0 / v1) / (v2 / c) --> (vocovov) (v0 * c) / (v1 * v2)\n")); 37786 | 37787 | return (synthesis_result) ? result : error_node(); 37788 | } 37789 | } 37790 | 37791 | const bool synthesis_result = 37792 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 37793 | (expr_gen, id(expr_gen, o0, o1, o2), v0, v1, v2, c, result); 37794 | 37795 | if (synthesis_result) 37796 | return result; 37797 | 37798 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 37799 | binary_functor_t f1 = reinterpret_cast<binary_functor_t>(0); 37800 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 37801 | 37802 | if (!expr_gen.valid_operator(o0,f0)) 37803 | return error_node(); 37804 | else if (!expr_gen.valid_operator(o1,f1)) 37805 | return error_node(); 37806 | else if (!expr_gen.valid_operator(o2,f2)) 37807 | return error_node(); 37808 | else 37809 | return node_type::allocate(*(expr_gen.node_allocator_), v0, v1, v2, c, f0, f1, f2); 37810 | } 37811 | 37812 | static inline std::string id(expression_generator<Type>& expr_gen, 37813 | const details::operator_type o0, 37814 | const details::operator_type o1, 37815 | const details::operator_type o2) 37816 | { 37817 | return details::build_string() 37818 | << "(t" << expr_gen.to_str(o0) 37819 | << "t)" << expr_gen.to_str(o1) 37820 | << "(t" << expr_gen.to_str(o2) 37821 | << "t)" 37822 | } 37823 | }; 37824 | 37825 | struct synthesize_vovocov_expression0 37826 | { 37827 | typedef typename vovocov_t::type0 node_type; 37828 | typedef typename vovocov_t::sf4_type sf4_type; 37829 | typedef typename node_type::T0 T0; 37830 | typedef typename node_type::T1 T1; 37831 | typedef typename node_type::T2 T2; 37832 | typedef typename node_type::T3 T3; 37833 | 37834 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 37835 | const details::operator_type& operation, 37836 | expression_node_ptr (&branch)[2]) 37837 | { 37838 | // (v0 o0 v1) o1 (c o2 v2) 37839 | const details::vov_base_node<Type>* vov = static_cast<details::vov_base_node<Type>*>(branch[0]); 37840 | const details::cov_base_node<Type>* cov = static_cast<details::cov_base_node<Type>*>(branch[1]); 37841 | const Type& v0 = vov->v0(); 37842 | const Type& v1 = vov->v1(); 37843 | const Type& v2 = cov->v (); 37844 | const Type c = cov->c (); 37845 | const details::operator_type o0 = vov->operation(); 37846 | const details::operator_type o1 = operation; 37847 | const details::operator_type o2 = cov->operation(); 37848 | 37849 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 37850 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 37851 | 37852 | expression_node_ptr result = error_node(); 37853 | 37854 | if (expr_gen.parser_->settings_.strength_reduction_enabled()) 37855 | { 37856 | // (v0 / v1) * (c / v2) --> (vocovov) (v0 * c) / (v1 * v2) 37857 | if ((details::e_div == o0) && (details::e_mul == o1) && (details::e_div == o2)) 37858 | { 37859 | const bool synthesis_result = 37860 | synthesize_sf4ext_expression:: 37861 | template compile<vtype, ctype, vtype, vtype>(expr_gen, "(t*t)/(t*t)", v0, c, v1, v2, result); 37862 | 37863 | exprtk_debug(("(v0 / v1) * (c / v2) --> (vocovov) (v0 * c) / (v1 * v2)\n")); 37864 | 37865 | return (synthesis_result) ? result : error_node(); 37866 | } 37867 | // (v0 / v1) / (c / v2) --> (vovovoc) (v0 * v2) / (v1 * c) 37868 | if ((details::e_div == o0) && (details::e_div == o1) && (details::e_div == o2)) 37869 | { 37870 | const bool synthesis_result = 37871 | synthesize_sf4ext_expression:: 37872 | template compile<vtype, vtype, vtype, ctype>(expr_gen, "(t*t)/(t*t)", v0, v2, v1, c, result); 37873 | 37874 | exprtk_debug(("(v0 / v1) / (c / v2) --> (vovovoc) (v0 * v2) / (v1 * c)\n")); 37875 | 37876 | return (synthesis_result) ? result : error_node(); 37877 | } 37878 | } 37879 | 37880 | const bool synthesis_result = 37881 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 37882 | (expr_gen, id(expr_gen, o0, o1, o2), v0, v1, c, v2, result); 37883 | 37884 | if (synthesis_result) 37885 | return result; 37886 | 37887 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 37888 | binary_functor_t f1 = reinterpret_cast<binary_functor_t>(0); 37889 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 37890 | 37891 | if (!expr_gen.valid_operator(o0,f0)) 37892 | return error_node(); 37893 | else if (!expr_gen.valid_operator(o1,f1)) 37894 | return error_node(); 37895 | else if (!expr_gen.valid_operator(o2,f2)) 37896 | return error_node(); 37897 | else 37898 | return node_type::allocate(*(expr_gen.node_allocator_), v0, v1, c, v2, f0, f1, f2); 37899 | } 37900 | 37901 | static inline std::string id(expression_generator<Type>& expr_gen, 37902 | const details::operator_type o0, 37903 | const details::operator_type o1, 37904 | const details::operator_type o2) 37905 | { 37906 | return details::build_string() 37907 | << "(t" << expr_gen.to_str(o0) 37908 | << "t)" << expr_gen.to_str(o1) 37909 | << "(t" << expr_gen.to_str(o2) 37910 | << "t)" 37911 | } 37912 | }; 37913 | 37914 | struct synthesize_vocovov_expression0 37915 | { 37916 | typedef typename vocovov_t::type0 node_type; 37917 | typedef typename vocovov_t::sf4_type sf4_type; 37918 | typedef typename node_type::T0 T0; 37919 | typedef typename node_type::T1 T1; 37920 | typedef typename node_type::T2 T2; 37921 | typedef typename node_type::T3 T3; 37922 | 37923 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 37924 | const details::operator_type& operation, 37925 | expression_node_ptr (&branch)[2]) 37926 | { 37927 | // (v0 o0 c) o1 (v1 o2 v2) 37928 | const details::voc_base_node<Type>* voc = static_cast<details::voc_base_node<Type>*>(branch[0]); 37929 | const details::vov_base_node<Type>* vov = static_cast<details::vov_base_node<Type>*>(branch[1]); 37930 | const Type c = voc->c (); 37931 | const Type& v0 = voc->v (); 37932 | const Type& v1 = vov->v0(); 37933 | const Type& v2 = vov->v1(); 37934 | const details::operator_type o0 = voc->operation(); 37935 | const details::operator_type o1 = operation; 37936 | const details::operator_type o2 = vov->operation(); 37937 | 37938 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 37939 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 37940 | 37941 | expression_node_ptr result = error_node(); 37942 | 37943 | if (expr_gen.parser_->settings_.strength_reduction_enabled()) 37944 | { 37945 | // (v0 / c) * (v1 / v2) --> (vovocov) (v0 * v1) / (c * v2) 37946 | if ((details::e_div == o0) && (details::e_mul == o1) && (details::e_div == o2)) 37947 | { 37948 | const bool synthesis_result = 37949 | synthesize_sf4ext_expression:: 37950 | template compile<vtype, vtype, ctype, vtype>(expr_gen, "(t*t)/(t*t)", v0, v1, c, v2, result); 37951 | 37952 | exprtk_debug(("(v0 / c) * (v1 / v2) --> (vovocov) (v0 * v1) / (c * v2)\n")); 37953 | 37954 | return (synthesis_result) ? result : error_node(); 37955 | } 37956 | // (v0 / c) / (v1 / v2) --> (vovocov) (v0 * v2) / (c * v1) 37957 | if ((details::e_div == o0) && (details::e_div == o1) && (details::e_div == o2)) 37958 | { 37959 | const bool synthesis_result = 37960 | synthesize_sf4ext_expression:: 37961 | template compile<vtype, vtype, ctype, vtype>(expr_gen, "(t*t)/(t*t)", v0, v2, c, v1, result); 37962 | 37963 | exprtk_debug(("(v0 / c) / (v1 / v2) --> (vovocov) (v0 * v2) / (c * v1)\n")); 37964 | 37965 | return (synthesis_result) ? result : error_node(); 37966 | } 37967 | } 37968 | 37969 | const bool synthesis_result = 37970 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 37971 | (expr_gen, id(expr_gen, o0, o1, o2), v0, c, v1, v2, result); 37972 | 37973 | if (synthesis_result) 37974 | return result; 37975 | 37976 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 37977 | binary_functor_t f1 = reinterpret_cast<binary_functor_t>(0); 37978 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 37979 | 37980 | if (!expr_gen.valid_operator(o0,f0)) 37981 | return error_node(); 37982 | else if (!expr_gen.valid_operator(o1,f1)) 37983 | return error_node(); 37984 | else if (!expr_gen.valid_operator(o2,f2)) 37985 | return error_node(); 37986 | else 37987 | return node_type::allocate(*(expr_gen.node_allocator_), v0, c, v1, v2, f0, f1, f2); 37988 | } 37989 | 37990 | static inline std::string id(expression_generator<Type>& expr_gen, 37991 | const details::operator_type o0, 37992 | const details::operator_type o1, 37993 | const details::operator_type o2) 37994 | { 37995 | return details::build_string() 37996 | << "(t" << expr_gen.to_str(o0) 37997 | << "t)" << expr_gen.to_str(o1) 37998 | << "(t" << expr_gen.to_str(o2) 37999 | << "t)" 38000 | } 38001 | }; 38002 | 38003 | struct synthesize_covovov_expression0 38004 | { 38005 | typedef typename covovov_t::type0 node_type; 38006 | typedef typename covovov_t::sf4_type sf4_type; 38007 | typedef typename node_type::T0 T0; 38008 | typedef typename node_type::T1 T1; 38009 | typedef typename node_type::T2 T2; 38010 | typedef typename node_type::T3 T3; 38011 | 38012 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 38013 | const details::operator_type& operation, 38014 | expression_node_ptr (&branch)[2]) 38015 | { 38016 | // (c o0 v0) o1 (v1 o2 v2) 38017 | const details::cov_base_node<Type>* cov = static_cast<details::cov_base_node<Type>*>(branch[0]); 38018 | const details::vov_base_node<Type>* vov = static_cast<details::vov_base_node<Type>*>(branch[1]); 38019 | const Type c = cov->c (); 38020 | const Type& v0 = cov->v (); 38021 | const Type& v1 = vov->v0(); 38022 | const Type& v2 = vov->v1(); 38023 | const details::operator_type o0 = cov->operation(); 38024 | const details::operator_type o1 = operation; 38025 | const details::operator_type o2 = vov->operation(); 38026 | 38027 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 38028 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 38029 | 38030 | expression_node_ptr result = error_node(); 38031 | 38032 | if (expr_gen.parser_->settings_.strength_reduction_enabled()) 38033 | { 38034 | // (c / v0) * (v1 / v2) --> (covovov) (c * v1) / (v0 * v2) 38035 | if ((details::e_div == o0) && (details::e_mul == o1) && (details::e_div == o2)) 38036 | { 38037 | const bool synthesis_result = 38038 | synthesize_sf4ext_expression:: 38039 | template compile<ctype, vtype, vtype, vtype>(expr_gen, "(t*t)/(t*t)", c, v1, v0, v2, result); 38040 | 38041 | exprtk_debug(("(c / v0) * (v1 / v2) --> (covovov) (c * v1) / (v0 * v2)\n")); 38042 | 38043 | return (synthesis_result) ? result : error_node(); 38044 | } 38045 | // (c / v0) / (v1 / v2) --> (covovov) (c * v2) / (v0 * v1) 38046 | if ((details::e_div == o0) && (details::e_div == o1) && (details::e_div == o2)) 38047 | { 38048 | const bool synthesis_result = 38049 | synthesize_sf4ext_expression:: 38050 | template compile<ctype, vtype, vtype, vtype>(expr_gen, "(t*t)/(t*t)", c, v2, v0, v1, result); 38051 | 38052 | exprtk_debug(("(c / v0) / (v1 / v2) --> (covovov) (c * v2) / (v0 * v1)\n")); 38053 | 38054 | return (synthesis_result) ? result : error_node(); 38055 | } 38056 | } 38057 | 38058 | const bool synthesis_result = 38059 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 38060 | (expr_gen, id(expr_gen, o0, o1, o2), c, v0, v1, v2, result); 38061 | 38062 | if (synthesis_result) 38063 | return result; 38064 | 38065 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 38066 | binary_functor_t f1 = reinterpret_cast<binary_functor_t>(0); 38067 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 38068 | 38069 | if (!expr_gen.valid_operator(o0,f0)) 38070 | return error_node(); 38071 | else if (!expr_gen.valid_operator(o1,f1)) 38072 | return error_node(); 38073 | else if (!expr_gen.valid_operator(o2,f2)) 38074 | return error_node(); 38075 | else 38076 | return node_type::allocate(*(expr_gen.node_allocator_), c, v0, v1, v2, f0, f1, f2); 38077 | } 38078 | 38079 | static inline std::string id(expression_generator<Type>& expr_gen, 38080 | const details::operator_type o0, 38081 | const details::operator_type o1, 38082 | const details::operator_type o2) 38083 | { 38084 | return details::build_string() 38085 | << "(t" << expr_gen.to_str(o0) 38086 | << "t)" << expr_gen.to_str(o1) 38087 | << "(t" << expr_gen.to_str(o2) 38088 | << "t)" 38089 | } 38090 | }; 38091 | 38092 | struct synthesize_covocov_expression0 38093 | { 38094 | typedef typename covocov_t::type0 node_type; 38095 | typedef typename covocov_t::sf4_type sf4_type; 38096 | typedef typename node_type::T0 T0; 38097 | typedef typename node_type::T1 T1; 38098 | typedef typename node_type::T2 T2; 38099 | typedef typename node_type::T3 T3; 38100 | 38101 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 38102 | const details::operator_type& operation, 38103 | expression_node_ptr (&branch)[2]) 38104 | { 38105 | // (c0 o0 v0) o1 (c1 o2 v1) 38106 | const details::cov_base_node<Type>* cov0 = static_cast<details::cov_base_node<Type>*>(branch[0]); 38107 | const details::cov_base_node<Type>* cov1 = static_cast<details::cov_base_node<Type>*>(branch[1]); 38108 | const Type c0 = cov0->c(); 38109 | const Type& v0 = cov0->v(); 38110 | const Type c1 = cov1->c(); 38111 | const Type& v1 = cov1->v(); 38112 | const details::operator_type o0 = cov0->operation(); 38113 | const details::operator_type o1 = operation; 38114 | const details::operator_type o2 = cov1->operation(); 38115 | 38116 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 38117 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 38118 | 38119 | expression_node_ptr result = error_node(); 38120 | 38121 | if (expr_gen.parser_->settings_.strength_reduction_enabled()) 38122 | { 38123 | // (c0 + v0) + (c1 + v1) --> (covov) (c0 + c1) + v0 + v1 38124 | if ((details::e_add == o0) && (details::e_add == o1) && (details::e_add == o2)) 38125 | { 38126 | const bool synthesis_result = 38127 | synthesize_sf3ext_expression:: 38128 | template compile<ctype, vtype, vtype>(expr_gen, "(t+t)+t", (c0 + c1), v0, v1, result); 38129 | 38130 | exprtk_debug(("(c0 + v0) + (c1 + v1) --> (covov) (c0 + c1) + v0 + v1\n")); 38131 | 38132 | return (synthesis_result) ? result : error_node(); 38133 | } 38134 | // (c0 + v0) - (c1 + v1) --> (covov) (c0 - c1) + v0 - v1 38135 | else if ((details::e_add == o0) && (details::e_sub == o1) && (details::e_add == o2)) 38136 | { 38137 | const bool synthesis_result = 38138 | synthesize_sf3ext_expression:: 38139 | template compile<ctype, vtype, vtype>(expr_gen, "(t+t)-t", (c0 - c1), v0, v1, result); 38140 | 38141 | exprtk_debug(("(c0 + v0) - (c1 + v1) --> (covov) (c0 - c1) + v0 - v1\n")); 38142 | 38143 | return (synthesis_result) ? result : error_node(); 38144 | } 38145 | // (c0 - v0) - (c1 - v1) --> (covov) (c0 - c1) - v0 + v1 38146 | else if ((details::e_sub == o0) && (details::e_sub == o1) && (details::e_sub == o2)) 38147 | { 38148 | const bool synthesis_result = 38149 | synthesize_sf3ext_expression:: 38150 | template compile<ctype, vtype, vtype>(expr_gen, "(t-t)+t", (c0 - c1), v0, v1, result); 38151 | 38152 | exprtk_debug(("(c0 - v0) - (c1 - v1) --> (covov) (c0 - c1) - v0 + v1\n")); 38153 | 38154 | return (synthesis_result) ? result : error_node(); 38155 | } 38156 | // (c0 * v0) * (c1 * v1) --> (covov) (c0 * c1) * v0 * v1 38157 | else if ((details::e_mul == o0) && (details::e_mul == o1) && (details::e_mul == o2)) 38158 | { 38159 | const bool synthesis_result = 38160 | synthesize_sf3ext_expression:: 38161 | template compile<ctype, vtype, vtype>(expr_gen, "(t*t)*t", (c0 * c1), v0, v1, result); 38162 | 38163 | exprtk_debug(("(c0 * v0) * (c1 * v1) --> (covov) (c0 * c1) * v0 * v1\n")); 38164 | 38165 | return (synthesis_result) ? result : error_node(); 38166 | } 38167 | // (c0 * v0) / (c1 * v1) --> (covov) (c0 / c1) * (v0 / v1) 38168 | else if ((details::e_mul == o0) && (details::e_div == o1) && (details::e_mul == o2)) 38169 | { 38170 | const bool synthesis_result = 38171 | synthesize_sf3ext_expression:: 38172 | template compile<ctype, vtype, vtype>(expr_gen, "(t*t)/t", (c0 / c1), v0, v1, result); 38173 | 38174 | exprtk_debug(("(c0 * v0) / (c1 * v1) --> (covov) (c0 / c1) * (v0 / v1)\n")); 38175 | 38176 | return (synthesis_result) ? result : error_node(); 38177 | } 38178 | // (c0 / v0) * (c1 / v1) --> (covov) (c0 * c1) / (v0 * v1) 38179 | else if ((details::e_div == o0) && (details::e_mul == o1) && (details::e_div == o2)) 38180 | { 38181 | const bool synthesis_result = 38182 | synthesize_sf3ext_expression:: 38183 | template compile<ctype, vtype, vtype>(expr_gen, "t/(t*t)", (c0 * c1), v0, v1, result); 38184 | 38185 | exprtk_debug(("(c0 / v0) * (c1 / v1) --> (covov) (c0 * c1) / (v0 * v1)\n")); 38186 | 38187 | return (synthesis_result) ? result : error_node(); 38188 | } 38189 | // (c0 / v0) / (c1 / v1) --> (covov) ((c0 / c1) * v1) / v0 38190 | else if ((details::e_div == o0) && (details::e_div == o1) && (details::e_div == o2)) 38191 | { 38192 | const bool synthesis_result = 38193 | synthesize_sf3ext_expression:: 38194 | template compile<ctype, vtype, vtype>(expr_gen, "(t*t)/t", (c0 / c1), v1, v0, result); 38195 | 38196 | exprtk_debug(("(c0 / v0) / (c1 / v1) --> (covov) ((c0 / c1) * v1) / v0\n")); 38197 | 38198 | return (synthesis_result) ? result : error_node(); 38199 | } 38200 | // (c0 * v0) / (c1 / v1) --> (covov) (c0 / c1) * (v0 * v1) 38201 | else if ((details::e_mul == o0) && (details::e_div == o1) && (details::e_div == o2)) 38202 | { 38203 | const bool synthesis_result = 38204 | synthesize_sf3ext_expression:: 38205 | template compile<ctype, vtype, vtype>(expr_gen, "t*(t*t)", (c0 / c1), v0, v1, result); 38206 | 38207 | exprtk_debug(("(c0 * v0) / (c1 / v1) --> (covov) (c0 / c1) * (v0 * v1)\n")); 38208 | 38209 | return (synthesis_result) ? result : error_node(); 38210 | } 38211 | // (c0 / v0) / (c1 * v1) --> (covov) (c0 / c1) / (v0 * v1) 38212 | else if ((details::e_div == o0) && (details::e_div == o1) && (details::e_mul == o2)) 38213 | { 38214 | const bool synthesis_result = 38215 | synthesize_sf3ext_expression:: 38216 | template compile<ctype, vtype, vtype>(expr_gen, "t/(t*t)", (c0 / c1), v0, v1, result); 38217 | 38218 | exprtk_debug(("(c0 / v0) / (c1 * v1) --> (covov) (c0 / c1) / (v0 * v1)\n")); 38219 | 38220 | return (synthesis_result) ? result : error_node(); 38221 | } 38222 | // (c * v0) +/- (c * v1) --> (covov) c * (v0 +/- v1) 38223 | else if ( 38224 | (std::equal_to<T>()(c0,c1)) && 38225 | (details::e_mul == o0) && 38226 | (details::e_mul == o2) && 38227 | ( 38228 | (details::e_add == o1) || 38229 | (details::e_sub == o1) 38230 | ) 38231 | ) 38232 | { 38233 | std::string specfunc; 38234 | 38235 | switch (o1) 38236 | { 38237 | case details::e_add : specfunc = "t*(t+t)" break; 38238 | case details::e_sub : specfunc = "t*(t-t)" break; 38239 | default : return error_node(); 38240 | } 38241 | 38242 | const bool synthesis_result = 38243 | synthesize_sf3ext_expression:: 38244 | template compile<ctype, vtype, vtype>(expr_gen, specfunc, c0, v0, v1, result); 38245 | 38246 | exprtk_debug(("(c * v0) +/- (c * v1) --> (covov) c * (v0 +/- v1)\n")); 38247 | 38248 | return (synthesis_result) ? result : error_node(); 38249 | } 38250 | } 38251 | 38252 | const bool synthesis_result = 38253 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 38254 | (expr_gen, id(expr_gen, o0, o1, o2), c0, v0, c1, v1, result); 38255 | 38256 | if (synthesis_result) 38257 | return result; 38258 | 38259 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 38260 | binary_functor_t f1 = reinterpret_cast<binary_functor_t>(0); 38261 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 38262 | 38263 | if (!expr_gen.valid_operator(o0,f0)) 38264 | return error_node(); 38265 | else if (!expr_gen.valid_operator(o1,f1)) 38266 | return error_node(); 38267 | else if (!expr_gen.valid_operator(o2,f2)) 38268 | return error_node(); 38269 | else 38270 | return node_type::allocate(*(expr_gen.node_allocator_), c0, v0, c1, v1, f0, f1, f2); 38271 | } 38272 | 38273 | static inline std::string id(expression_generator<Type>& expr_gen, 38274 | const details::operator_type o0, 38275 | const details::operator_type o1, 38276 | const details::operator_type o2) 38277 | { 38278 | return details::build_string() 38279 | << "(t" << expr_gen.to_str(o0) 38280 | << "t)" << expr_gen.to_str(o1) 38281 | << "(t" << expr_gen.to_str(o2) 38282 | << "t)" 38283 | } 38284 | }; 38285 | 38286 | struct synthesize_vocovoc_expression0 38287 | { 38288 | typedef typename vocovoc_t::type0 node_type; 38289 | typedef typename vocovoc_t::sf4_type sf4_type; 38290 | typedef typename node_type::T0 T0; 38291 | typedef typename node_type::T1 T1; 38292 | typedef typename node_type::T2 T2; 38293 | typedef typename node_type::T3 T3; 38294 | 38295 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 38296 | const details::operator_type& operation, 38297 | expression_node_ptr (&branch)[2]) 38298 | { 38299 | // (v0 o0 c0) o1 (v1 o2 c1) 38300 | const details::voc_base_node<Type>* voc0 = static_cast<details::voc_base_node<Type>*>(branch[0]); 38301 | const details::voc_base_node<Type>* voc1 = static_cast<details::voc_base_node<Type>*>(branch[1]); 38302 | const Type c0 = voc0->c(); 38303 | const Type& v0 = voc0->v(); 38304 | const Type c1 = voc1->c(); 38305 | const Type& v1 = voc1->v(); 38306 | const details::operator_type o0 = voc0->operation(); 38307 | const details::operator_type o1 = operation; 38308 | const details::operator_type o2 = voc1->operation(); 38309 | 38310 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 38311 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 38312 | 38313 | expression_node_ptr result = error_node(); 38314 | 38315 | if (expr_gen.parser_->settings_.strength_reduction_enabled()) 38316 | { 38317 | // (v0 + c0) + (v1 + c1) --> (covov) (c0 + c1) + v0 + v1 38318 | if ((details::e_add == o0) && (details::e_add == o1) && (details::e_add == o2)) 38319 | { 38320 | const bool synthesis_result = 38321 | synthesize_sf3ext_expression:: 38322 | template compile<ctype, vtype, vtype>(expr_gen, "(t+t)+t", (c0 + c1), v0, v1, result); 38323 | 38324 | exprtk_debug(("(v0 + c0) + (v1 + c1) --> (covov) (c0 + c1) + v0 + v1\n")); 38325 | 38326 | return (synthesis_result) ? result : error_node(); 38327 | } 38328 | // (v0 + c0) - (v1 + c1) --> (covov) (c0 - c1) + v0 - v1 38329 | else if ((details::e_add == o0) && (details::e_sub == o1) && (details::e_add == o2)) 38330 | { 38331 | const bool synthesis_result = 38332 | synthesize_sf3ext_expression:: 38333 | template compile<ctype, vtype, vtype>(expr_gen, "(t+t)-t", (c0 - c1), v0, v1, result); 38334 | 38335 | exprtk_debug(("(v0 + c0) - (v1 + c1) --> (covov) (c0 - c1) + v0 - v1\n")); 38336 | 38337 | return (synthesis_result) ? result : error_node(); 38338 | } 38339 | // (v0 - c0) - (v1 - c1) --> (covov) (c1 - c0) + v0 - v1 38340 | else if ((details::e_sub == o0) && (details::e_sub == o1) && (details::e_sub == o2)) 38341 | { 38342 | const bool synthesis_result = 38343 | synthesize_sf3ext_expression:: 38344 | template compile<ctype, vtype, vtype>(expr_gen, "(t+t)-t", (c1 - c0), v0, v1, result); 38345 | 38346 | exprtk_debug(("(v0 - c0) - (v1 - c1) --> (covov) (c1 - c0) + v0 - v1\n")); 38347 | 38348 | return (synthesis_result) ? result : error_node(); 38349 | } 38350 | // (v0 * c0) * (v1 * c1) --> (covov) (c0 * c1) * v0 * v1 38351 | else if ((details::e_mul == o0) && (details::e_mul == o1) && (details::e_mul == o2)) 38352 | { 38353 | const bool synthesis_result = 38354 | synthesize_sf3ext_expression:: 38355 | template compile<ctype, vtype, vtype>(expr_gen, "(t*t)*t", (c0 * c1), v0, v1, result); 38356 | 38357 | exprtk_debug(("(v0 * c0) * (v1 * c1) --> (covov) (c0 * c1) * v0 * v1\n")); 38358 | 38359 | return (synthesis_result) ? result : error_node(); 38360 | } 38361 | // (v0 * c0) / (v1 * c1) --> (covov) (c0 / c1) * (v0 / v1) 38362 | else if ((details::e_mul == o0) && (details::e_div == o1) && (details::e_mul == o2)) 38363 | { 38364 | const bool synthesis_result = 38365 | synthesize_sf3ext_expression:: 38366 | template compile<ctype, vtype, vtype>(expr_gen, "(t*t)/t", (c0 / c1), v0, v1, result); 38367 | 38368 | exprtk_debug(("(v0 * c0) / (v1 * c1) --> (covov) (c0 / c1) * (v0 / v1)\n")); 38369 | 38370 | return (synthesis_result) ? result : error_node(); 38371 | } 38372 | // (v0 / c0) * (v1 / c1) --> (covov) (1 / (c0 * c1)) * v0 * v1 38373 | else if ((details::e_div == o0) && (details::e_mul == o1) && (details::e_div == o2)) 38374 | { 38375 | const bool synthesis_result = 38376 | synthesize_sf3ext_expression:: 38377 | template compile<ctype, vtype, vtype>(expr_gen, "(t*t)*t", Type(1) / (c0 * c1), v0, v1, result); 38378 | 38379 | exprtk_debug(("(v0 / c0) * (v1 / c1) --> (covov) (1 / (c0 * c1)) * v0 * v1\n")); 38380 | 38381 | return (synthesis_result) ? result : error_node(); 38382 | } 38383 | // (v0 / c0) / (v1 / c1) --> (covov) ((c1 / c0) * v0) / v1 38384 | else if ((details::e_div == o0) && (details::e_div == o1) && (details::e_div == o2)) 38385 | { 38386 | const bool synthesis_result = 38387 | synthesize_sf3ext_expression:: 38388 | template compile<ctype, vtype, vtype>(expr_gen, "(t*t)/t", (c1 / c0), v0, v1, result); 38389 | 38390 | exprtk_debug(("(v0 / c0) / (v1 / c1) --> (covov) ((c1 / c0) * v0) / v1\n")); 38391 | 38392 | return (synthesis_result) ? result : error_node(); 38393 | } 38394 | // (v0 * c0) / (v1 / c1) --> (covov) (c0 * c1) * (v0 / v1) 38395 | else if ((details::e_mul == o0) && (details::e_div == o1) && (details::e_div == o2)) 38396 | { 38397 | const bool synthesis_result = 38398 | synthesize_sf3ext_expression:: 38399 | template compile<ctype, vtype, vtype>(expr_gen, "t*(t/t)", (c0 * c1), v0, v1, result); 38400 | 38401 | exprtk_debug(("(v0 * c0) / (v1 / c1) --> (covov) (c0 * c1) * (v0 / v1)\n")); 38402 | 38403 | return (synthesis_result) ? result : error_node(); 38404 | } 38405 | // (v0 / c0) / (v1 * c1) --> (covov) (1 / (c0 * c1)) * v0 / v1 38406 | else if ((details::e_div == o0) && (details::e_div == o1) && (details::e_mul == o2)) 38407 | { 38408 | const bool synthesis_result = 38409 | synthesize_sf3ext_expression:: 38410 | template compile<ctype, vtype, vtype>(expr_gen, "t*(t/t)", Type(1) / (c0 * c1), v0, v1, result); 38411 | 38412 | exprtk_debug(("(v0 / c0) / (v1 * c1) --> (covov) (1 / (c0 * c1)) * v0 / v1\n")); 38413 | 38414 | return (synthesis_result) ? result : error_node(); 38415 | } 38416 | // (v0 / c0) * (v1 + c1) --> (vocovoc) (v0 * (1 / c0)) * (v1 + c1) 38417 | else if ((details::e_div == o0) && (details::e_mul == o1) && (details::e_add == o2)) 38418 | { 38419 | const bool synthesis_result = 38420 | synthesize_sf4ext_expression:: 38421 | template compile<vtype, ctype, vtype, ctype>(expr_gen, "(t*t)*(t+t)", v0, T(1) / c0, v1, c1, result); 38422 | 38423 | exprtk_debug(("(v0 / c0) * (v1 + c1) --> (vocovoc) (v0 * (1 / c0)) * (v1 + c1)\n")); 38424 | 38425 | return (synthesis_result) ? result : error_node(); 38426 | } 38427 | // (v0 / c0) * (v1 - c1) --> (vocovoc) (v0 * (1 / c0)) * (v1 - c1) 38428 | else if ((details::e_div == o0) && (details::e_mul == o1) && (details::e_sub == o2)) 38429 | { 38430 | const bool synthesis_result = 38431 | synthesize_sf4ext_expression:: 38432 | template compile<vtype, ctype, vtype, ctype>(expr_gen, "(t*t)*(t-t)", v0, T(1) / c0, v1, c1, result); 38433 | 38434 | exprtk_debug(("(v0 / c0) * (v1 - c1) --> (vocovoc) (v0 * (1 / c0)) * (v1 - c1)\n")); 38435 | 38436 | return (synthesis_result) ? result : error_node(); 38437 | } 38438 | // (v0 * c) +/- (v1 * c) --> (covov) c * (v0 +/- v1) 38439 | else if ( 38440 | (std::equal_to<T>()(c0,c1)) && 38441 | (details::e_mul == o0) && 38442 | (details::e_mul == o2) && 38443 | ( 38444 | (details::e_add == o1) || 38445 | (details::e_sub == o1) 38446 | ) 38447 | ) 38448 | { 38449 | std::string specfunc; 38450 | 38451 | switch (o1) 38452 | { 38453 | case details::e_add : specfunc = "t*(t+t)" break; 38454 | case details::e_sub : specfunc = "t*(t-t)" break; 38455 | default : return error_node(); 38456 | } 38457 | 38458 | const bool synthesis_result = 38459 | synthesize_sf3ext_expression:: 38460 | template compile<ctype, vtype, vtype>(expr_gen, specfunc, c0, v0, v1, result); 38461 | 38462 | exprtk_debug(("(v0 * c) +/- (v1 * c) --> (covov) c * (v0 +/- v1)\n")); 38463 | 38464 | return (synthesis_result) ? result : error_node(); 38465 | } 38466 | // (v0 / c) +/- (v1 / c) --> (vovoc) (v0 +/- v1) / c 38467 | else if ( 38468 | (std::equal_to<T>()(c0,c1)) && 38469 | (details::e_div == o0) && 38470 | (details::e_div == o2) && 38471 | ( 38472 | (details::e_add == o1) || 38473 | (details::e_sub == o1) 38474 | ) 38475 | ) 38476 | { 38477 | std::string specfunc; 38478 | 38479 | switch (o1) 38480 | { 38481 | case details::e_add : specfunc = "(t+t)/t" break; 38482 | case details::e_sub : specfunc = "(t-t)/t" break; 38483 | default : return error_node(); 38484 | } 38485 | 38486 | const bool synthesis_result = 38487 | synthesize_sf3ext_expression:: 38488 | template compile<vtype, vtype, ctype>(expr_gen, specfunc, v0, v1, c0, result); 38489 | 38490 | exprtk_debug(("(v0 / c) +/- (v1 / c) --> (vovoc) (v0 +/- v1) / c\n")); 38491 | 38492 | return (synthesis_result) ? result : error_node(); 38493 | } 38494 | } 38495 | 38496 | const bool synthesis_result = 38497 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 38498 | (expr_gen, id(expr_gen, o0, o1, o2), v0, c0, v1, c1, result); 38499 | 38500 | if (synthesis_result) 38501 | return result; 38502 | 38503 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 38504 | binary_functor_t f1 = reinterpret_cast<binary_functor_t>(0); 38505 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 38506 | 38507 | if (!expr_gen.valid_operator(o0,f0)) 38508 | return error_node(); 38509 | else if (!expr_gen.valid_operator(o1,f1)) 38510 | return error_node(); 38511 | else if (!expr_gen.valid_operator(o2,f2)) 38512 | return error_node(); 38513 | else 38514 | return node_type::allocate(*(expr_gen.node_allocator_), v0, c0, v1, c1, f0, f1, f2); 38515 | } 38516 | 38517 | static inline std::string id(expression_generator<Type>& expr_gen, 38518 | const details::operator_type o0, 38519 | const details::operator_type o1, 38520 | const details::operator_type o2) 38521 | { 38522 | return details::build_string() 38523 | << "(t" << expr_gen.to_str(o0) 38524 | << "t)" << expr_gen.to_str(o1) 38525 | << "(t" << expr_gen.to_str(o2) 38526 | << "t)" 38527 | } 38528 | }; 38529 | 38530 | struct synthesize_covovoc_expression0 38531 | { 38532 | typedef typename covovoc_t::type0 node_type; 38533 | typedef typename covovoc_t::sf4_type sf4_type; 38534 | typedef typename node_type::T0 T0; 38535 | typedef typename node_type::T1 T1; 38536 | typedef typename node_type::T2 T2; 38537 | typedef typename node_type::T3 T3; 38538 | 38539 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 38540 | const details::operator_type& operation, 38541 | expression_node_ptr (&branch)[2]) 38542 | { 38543 | // (c0 o0 v0) o1 (v1 o2 c1) 38544 | const details::cov_base_node<Type>* cov = static_cast<details::cov_base_node<Type>*>(branch[0]); 38545 | const details::voc_base_node<Type>* voc = static_cast<details::voc_base_node<Type>*>(branch[1]); 38546 | const Type c0 = cov->c(); 38547 | const Type& v0 = cov->v(); 38548 | const Type c1 = voc->c(); 38549 | const Type& v1 = voc->v(); 38550 | const details::operator_type o0 = cov->operation(); 38551 | const details::operator_type o1 = operation; 38552 | const details::operator_type o2 = voc->operation(); 38553 | 38554 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 38555 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 38556 | 38557 | expression_node_ptr result = error_node(); 38558 | 38559 | if (expr_gen.parser_->settings_.strength_reduction_enabled()) 38560 | { 38561 | // (c0 + v0) + (v1 + c1) --> (covov) (c0 + c1) + v0 + v1 38562 | if ((details::e_add == o0) && (details::e_add == o1) && (details::e_add == o2)) 38563 | { 38564 | const bool synthesis_result = 38565 | synthesize_sf3ext_expression:: 38566 | template compile<ctype, vtype, vtype>(expr_gen, "(t+t)+t", (c0 + c1), v0, v1, result); 38567 | 38568 | exprtk_debug(("(c0 + v0) + (v1 + c1) --> (covov) (c0 + c1) + v0 + v1\n")); 38569 | 38570 | return (synthesis_result) ? result : error_node(); 38571 | } 38572 | // (c0 + v0) - (v1 + c1) --> (covov) (c0 - c1) + v0 - v1 38573 | else if ((details::e_add == o0) && (details::e_sub == o1) && (details::e_add == o2)) 38574 | { 38575 | const bool synthesis_result = 38576 | synthesize_sf3ext_expression:: 38577 | template compile<ctype, vtype, vtype>(expr_gen, "(t+t)-t", (c0 - c1), v0, v1, result); 38578 | 38579 | exprtk_debug(("(c0 + v0) - (v1 + c1) --> (covov) (c0 - c1) + v0 - v1\n")); 38580 | 38581 | return (synthesis_result) ? result : error_node(); 38582 | } 38583 | // (c0 - v0) - (v1 - c1) --> (covov) (c0 + c1) - v0 - v1 38584 | else if ((details::e_sub == o0) && (details::e_sub == o1) && (details::e_sub == o2)) 38585 | { 38586 | const bool synthesis_result = 38587 | synthesize_sf3ext_expression:: 38588 | template compile<ctype, vtype, vtype>(expr_gen, "t-(t+t)", (c0 + c1), v0, v1, result); 38589 | 38590 | exprtk_debug(("(c0 - v0) - (v1 - c1) --> (covov) (c0 + c1) - v0 - v1\n")); 38591 | 38592 | return (synthesis_result) ? result : error_node(); 38593 | } 38594 | // (c0 * v0) * (v1 * c1) --> (covov) (c0 * c1) * v0 * v1 38595 | else if ((details::e_mul == o0) && (details::e_mul == o1) && (details::e_mul == o2)) 38596 | { 38597 | const bool synthesis_result = 38598 | synthesize_sf3ext_expression:: 38599 | template compile<ctype, vtype, vtype>(expr_gen, "(t*t)*t", (c0 * c1), v0, v1, result); 38600 | 38601 | exprtk_debug(("(c0 * v0) * (v1 * c1) --> (covov) (c0 * c1) * v0 * v1\n")); 38602 | 38603 | return (synthesis_result) ? result : error_node(); 38604 | } 38605 | // (c0 * v0) / (v1 * c1) --> (covov) (c0 / c1) * (v0 / v1) 38606 | else if ((details::e_mul == o0) && (details::e_div == o1) && (details::e_mul == o2)) 38607 | { 38608 | const bool synthesis_result = 38609 | synthesize_sf3ext_expression:: 38610 | template compile<ctype, vtype, vtype>(expr_gen, "(t*t)/t", (c0 / c1), v0, v1, result); 38611 | 38612 | exprtk_debug(("(c0 * v0) / (v1 * c1) --> (covov) (c0 / c1) * (v0 / v1)\n")); 38613 | 38614 | return (synthesis_result) ? result : error_node(); 38615 | } 38616 | // (c0 / v0) * (v1 / c1) --> (covov) (c0 / c1) * (v1 / v0) 38617 | else if ((details::e_div == o0) && (details::e_mul == o1) && (details::e_div == o2)) 38618 | { 38619 | const bool synthesis_result = 38620 | synthesize_sf3ext_expression:: 38621 | template compile<ctype, vtype, vtype>(expr_gen, "t*(t/t)", (c0 / c1), v1, v0, result); 38622 | 38623 | exprtk_debug(("(c0 / v0) * (v1 / c1) --> (covov) (c0 / c1) * (v1 / v0)\n")); 38624 | 38625 | return (synthesis_result) ? result : error_node(); 38626 | } 38627 | // (c0 / v0) / (v1 / c1) --> (covov) (c0 * c1) / (v0 * v1) 38628 | else if ((details::e_div == o0) && (details::e_div == o1) && (details::e_div == o2)) 38629 | { 38630 | const bool synthesis_result = 38631 | synthesize_sf3ext_expression:: 38632 | template compile<ctype, vtype, vtype>(expr_gen, "t/(t*t)", (c0 * c1), v0, v1, result); 38633 | 38634 | exprtk_debug(("(c0 / v0) / (v1 / c1) --> (covov) (c0 * c1) / (v0 * v1)\n")); 38635 | 38636 | return (synthesis_result) ? result : error_node(); 38637 | } 38638 | // (c0 * v0) / (v1 / c1) --> (covov) (c0 * c1) * (v0 / v1) 38639 | else if ((details::e_mul == o0) && (details::e_div == o1) && (details::e_div == o2)) 38640 | { 38641 | const bool synthesis_result = 38642 | synthesize_sf3ext_expression:: 38643 | template compile<ctype, vtype, vtype>(expr_gen, "(t*t)/t", (c0 * c1), v0, v1, result); 38644 | 38645 | exprtk_debug(("(c0 * v0) / (v1 / c1) --> (covov) (c0 * c1) * (v0 / v1)\n")); 38646 | 38647 | return (synthesis_result) ? result : error_node(); 38648 | } 38649 | // (c0 / v0) / (v1 * c1) --> (covov) (c0 / c1) / (v0 * v1) 38650 | else if ((details::e_div == o0) && (details::e_div == o1) && (details::e_mul == o2)) 38651 | { 38652 | const bool synthesis_result = 38653 | synthesize_sf3ext_expression:: 38654 | template compile<ctype, vtype, vtype>(expr_gen, "t/(t*t)", (c0 / c1), v0, v1, result); 38655 | 38656 | exprtk_debug(("(c0 / v0) / (v1 * c1) --> (covov) (c0 / c1) / (v0 * v1)\n")); 38657 | 38658 | return (synthesis_result) ? result : error_node(); 38659 | } 38660 | // (c * v0) +/- (v1 * c) --> (covov) c * (v0 +/- v1) 38661 | else if ( 38662 | (std::equal_to<T>()(c0,c1)) && 38663 | (details::e_mul == o0) && 38664 | (details::e_mul == o2) && 38665 | ( 38666 | (details::e_add == o1) || 38667 | (details::e_sub == o1) 38668 | ) 38669 | ) 38670 | { 38671 | std::string specfunc; 38672 | 38673 | switch (o1) 38674 | { 38675 | case details::e_add : specfunc = "t*(t+t)" break; 38676 | case details::e_sub : specfunc = "t*(t-t)" break; 38677 | default : return error_node(); 38678 | } 38679 | 38680 | const bool synthesis_result = 38681 | synthesize_sf3ext_expression:: 38682 | template compile<ctype, vtype, vtype>(expr_gen, specfunc, c0, v0, v1, result); 38683 | 38684 | exprtk_debug(("(c * v0) +/- (v1 * c) --> (covov) c * (v0 +/- v1)\n")); 38685 | 38686 | return (synthesis_result) ? result : error_node(); 38687 | } 38688 | } 38689 | 38690 | const bool synthesis_result = 38691 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 38692 | (expr_gen, id(expr_gen, o0, o1, o2), c0, v0, v1, c1, result); 38693 | 38694 | if (synthesis_result) 38695 | return result; 38696 | 38697 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 38698 | binary_functor_t f1 = reinterpret_cast<binary_functor_t>(0); 38699 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 38700 | 38701 | if (!expr_gen.valid_operator(o0,f0)) 38702 | return error_node(); 38703 | else if (!expr_gen.valid_operator(o1,f1)) 38704 | return error_node(); 38705 | else if (!expr_gen.valid_operator(o2,f2)) 38706 | return error_node(); 38707 | else 38708 | return node_type::allocate(*(expr_gen.node_allocator_), c0, v0, v1, c1, f0, f1, f2); 38709 | } 38710 | 38711 | static inline std::string id(expression_generator<Type>& expr_gen, 38712 | const details::operator_type o0, 38713 | const details::operator_type o1, 38714 | const details::operator_type o2) 38715 | { 38716 | return details::build_string() 38717 | << "(t" << expr_gen.to_str(o0) 38718 | << "t)" << expr_gen.to_str(o1) 38719 | << "(t" << expr_gen.to_str(o2) 38720 | << "t)" 38721 | } 38722 | }; 38723 | 38724 | struct synthesize_vococov_expression0 38725 | { 38726 | typedef typename vococov_t::type0 node_type; 38727 | typedef typename vococov_t::sf4_type sf4_type; 38728 | typedef typename node_type::T0 T0; 38729 | typedef typename node_type::T1 T1; 38730 | typedef typename node_type::T2 T2; 38731 | typedef typename node_type::T3 T3; 38732 | 38733 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 38734 | const details::operator_type& operation, 38735 | expression_node_ptr (&branch)[2]) 38736 | { 38737 | // (v0 o0 c0) o1 (c1 o2 v1) 38738 | const details::voc_base_node<Type>* voc = static_cast<details::voc_base_node<Type>*>(branch[0]); 38739 | const details::cov_base_node<Type>* cov = static_cast<details::cov_base_node<Type>*>(branch[1]); 38740 | const Type c0 = voc->c(); 38741 | const Type& v0 = voc->v(); 38742 | const Type c1 = cov->c(); 38743 | const Type& v1 = cov->v(); 38744 | const details::operator_type o0 = voc->operation(); 38745 | const details::operator_type o1 = operation; 38746 | const details::operator_type o2 = cov->operation(); 38747 | 38748 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 38749 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 38750 | 38751 | expression_node_ptr result = error_node(); 38752 | 38753 | if (expr_gen.parser_->settings_.strength_reduction_enabled()) 38754 | { 38755 | // (v0 + c0) + (c1 + v1) --> (covov) (c0 + c1) + v0 + v1 38756 | if ((details::e_add == o0) && (details::e_add == o1) && (details::e_add == o2)) 38757 | { 38758 | const bool synthesis_result = 38759 | synthesize_sf3ext_expression:: 38760 | template compile<ctype, vtype, vtype>(expr_gen, "(t+t)+t", (c0 + c1), v0, v1, result); 38761 | 38762 | exprtk_debug(("(v0 + c0) + (c1 + v1) --> (covov) (c0 + c1) + v0 + v1\n")); 38763 | 38764 | return (synthesis_result) ? result : error_node(); 38765 | } 38766 | // (v0 + c0) - (c1 + v1) --> (covov) (c0 - c1) + v0 - v1 38767 | else if ((details::e_add == o0) && (details::e_sub == o1) && (details::e_add == o2)) 38768 | { 38769 | const bool synthesis_result = 38770 | synthesize_sf3ext_expression:: 38771 | template compile<ctype, vtype, vtype>(expr_gen, "(t+t)-t", (c0 - c1), v0, v1, result); 38772 | 38773 | exprtk_debug(("(v0 + c0) - (c1 + v1) --> (covov) (c0 - c1) + v0 - v1\n")); 38774 | 38775 | return (synthesis_result) ? result : error_node(); 38776 | } 38777 | // (v0 - c0) - (c1 - v1) --> (vovoc) v0 + v1 - (c1 + c0) 38778 | else if ((details::e_sub == o0) && (details::e_sub == o1) && (details::e_sub == o2)) 38779 | { 38780 | const bool synthesis_result = 38781 | synthesize_sf3ext_expression:: 38782 | template compile<vtype, vtype, ctype>(expr_gen, "(t+t)-t", v0, v1, (c1 + c0), result); 38783 | 38784 | exprtk_debug(("(v0 - c0) - (c1 - v1) --> (vovoc) v0 + v1 - (c1 + c0)\n")); 38785 | 38786 | return (synthesis_result) ? result : error_node(); 38787 | } 38788 | // (v0 * c0) * (c1 * v1) --> (covov) (c0 * c1) * v0 * v1 38789 | else if ((details::e_mul == o0) && (details::e_mul == o1) && (details::e_mul == o2)) 38790 | { 38791 | const bool synthesis_result = 38792 | synthesize_sf3ext_expression:: 38793 | template compile<ctype, vtype, vtype>(expr_gen, "(t*t)*t", (c0 * c1), v0, v1, result); 38794 | 38795 | exprtk_debug(("(v0 * c0) * (c1 * v1) --> (covov) (c0 * c1) * v0 * v1\n")); 38796 | 38797 | return (synthesis_result) ? result : error_node(); 38798 | } 38799 | // (v0 * c0) / (c1 * v1) --> (covov) (c0 / c1) * (v0 * v1) 38800 | else if ((details::e_mul == o0) && (details::e_div == o1) && (details::e_mul == o2)) 38801 | { 38802 | const bool synthesis_result = 38803 | synthesize_sf3ext_expression:: 38804 | template compile<ctype, vtype, vtype>(expr_gen, "(t*t)/t", (c0 / c1), v0, v1, result); 38805 | 38806 | exprtk_debug(("(v0 * c0) / (c1 * v1) --> (covov) (c0 / c1) * (v0 * v1)\n")); 38807 | 38808 | return (synthesis_result) ? result : error_node(); 38809 | } 38810 | // (v0 / c0) * (c1 / v1) --> (covov) (c1 / c0) * (v0 / v1) 38811 | else if ((details::e_div == o0) && (details::e_mul == o1) && (details::e_div == o2)) 38812 | { 38813 | const bool synthesis_result = 38814 | synthesize_sf3ext_expression:: 38815 | template compile<ctype, vtype, vtype>(expr_gen, "(t*t)/t", (c1 / c0), v0, v1, result); 38816 | 38817 | exprtk_debug(("(v0 / c0) * (c1 / v1) --> (covov) (c1 / c0) * (v0 / v1)\n")); 38818 | 38819 | return (synthesis_result) ? result : error_node(); 38820 | } 38821 | // (v0 * c0) / (c1 / v1) --> (covov) (c0 / c1) * (v0 * v1) 38822 | else if ((details::e_mul == o0) && (details::e_div == o1) && (details::e_div == o2)) 38823 | { 38824 | const bool synthesis_result = 38825 | synthesize_sf3ext_expression:: 38826 | template compile<ctype, vtype, vtype>(expr_gen, "(t*t)*t", (c0 / c1), v0, v1, result); 38827 | 38828 | exprtk_debug(("(v0 * c0) / (c1 / v1) --> (covov) (c0 / c1) * (v0 * v1)\n")); 38829 | 38830 | return (synthesis_result) ? result : error_node(); 38831 | } 38832 | // (v0 / c0) / (c1 * v1) --> (covov) (1 / (c0 * c1)) * (v0 / v1) 38833 | else if ((details::e_div == o0) && (details::e_div == o1) && (details::e_mul == o2)) 38834 | { 38835 | const bool synthesis_result = 38836 | synthesize_sf3ext_expression:: 38837 | template compile<ctype, vtype, vtype>(expr_gen, "(t*t)/t", Type(1) / (c0 * c1), v0, v1, result); 38838 | 38839 | exprtk_debug(("(v0 / c0) / (c1 * v1) --> (covov) (1 / (c0 * c1)) * (v0 / v1)\n")); 38840 | 38841 | return (synthesis_result) ? result : error_node(); 38842 | } 38843 | // (v0 / c0) / (c1 / v1) --> (vovoc) (v0 * v1) * (1 / (c0 * c1)) 38844 | else if ((details::e_div == o0) && (details::e_div == o1) && (details::e_div == o2)) 38845 | { 38846 | const bool synthesis_result = 38847 | synthesize_sf3ext_expression:: 38848 | template compile<vtype, vtype, ctype>(expr_gen, "(t*t)*t", v0, v1, Type(1) / (c0 * c1), result); 38849 | 38850 | exprtk_debug(("(v0 / c0) / (c1 / v1) --> (vovoc) (v0 * v1) * (1 / (c0 * c1))\n")); 38851 | 38852 | return (synthesis_result) ? result : error_node(); 38853 | } 38854 | // (v0 * c) +/- (c * v1) --> (covov) c * (v0 +/- v1) 38855 | else if ( 38856 | (std::equal_to<T>()(c0,c1)) && 38857 | (details::e_mul == o0) && 38858 | (details::e_mul == o2) && 38859 | ( 38860 | (details::e_add == o1) || (details::e_sub == o1) 38861 | ) 38862 | ) 38863 | { 38864 | std::string specfunc; 38865 | 38866 | switch (o1) 38867 | { 38868 | case details::e_add : specfunc = "t*(t+t)" break; 38869 | case details::e_sub : specfunc = "t*(t-t)" break; 38870 | default : return error_node(); 38871 | } 38872 | 38873 | const bool synthesis_result = 38874 | synthesize_sf3ext_expression:: 38875 | template compile<ctype, vtype, vtype>(expr_gen, specfunc, c0, v0, v1, result); 38876 | 38877 | exprtk_debug(("(v0 * c) +/- (c * v1) --> (covov) c * (v0 +/- v1)\n")); 38878 | 38879 | return (synthesis_result) ? result : error_node(); 38880 | } 38881 | } 38882 | 38883 | const bool synthesis_result = 38884 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 38885 | (expr_gen, id(expr_gen, o0, o1, o2), v0, c0, c1, v1, result); 38886 | 38887 | if (synthesis_result) 38888 | return result; 38889 | 38890 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 38891 | binary_functor_t f1 = reinterpret_cast<binary_functor_t>(0); 38892 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 38893 | 38894 | if (!expr_gen.valid_operator(o0,f0)) 38895 | return error_node(); 38896 | else if (!expr_gen.valid_operator(o1,f1)) 38897 | return error_node(); 38898 | else if (!expr_gen.valid_operator(o2,f2)) 38899 | return error_node(); 38900 | else 38901 | return node_type::allocate(*(expr_gen.node_allocator_), v0, c0, c1, v1, f0, f1, f2); 38902 | } 38903 | 38904 | static inline std::string id(expression_generator<Type>& expr_gen, 38905 | const details::operator_type o0, 38906 | const details::operator_type o1, 38907 | const details::operator_type o2) 38908 | { 38909 | return details::build_string() 38910 | << "(t" << expr_gen.to_str(o0) 38911 | << "t)" << expr_gen.to_str(o1) 38912 | << "(t" << expr_gen.to_str(o2) 38913 | << "t)" 38914 | } 38915 | }; 38916 | 38917 | struct synthesize_vovovov_expression1 38918 | { 38919 | typedef typename vovovov_t::type1 node_type; 38920 | typedef typename vovovov_t::sf4_type sf4_type; 38921 | typedef typename node_type::T0 T0; 38922 | typedef typename node_type::T1 T1; 38923 | typedef typename node_type::T2 T2; 38924 | typedef typename node_type::T3 T3; 38925 | 38926 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 38927 | const details::operator_type& operation, 38928 | expression_node_ptr (&branch)[2]) 38929 | { 38930 | // v0 o0 (v1 o1 (v2 o2 v3)) 38931 | typedef typename synthesize_vovov_expression1::node_type lcl_vovov_t; 38932 | 38933 | const lcl_vovov_t* vovov = static_cast<const lcl_vovov_t*>(branch[1]); 38934 | const Type& v0 = static_cast<details::variable_node<Type>*>(branch[0])->ref(); 38935 | const Type& v1 = vovov->t0(); 38936 | const Type& v2 = vovov->t1(); 38937 | const Type& v3 = vovov->t2(); 38938 | const details::operator_type o0 = operation; 38939 | const details::operator_type o1 = expr_gen.get_operator(vovov->f0()); 38940 | const details::operator_type o2 = expr_gen.get_operator(vovov->f1()); 38941 | 38942 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 38943 | binary_functor_t f1 = vovov->f0(); 38944 | binary_functor_t f2 = vovov->f1(); 38945 | 38946 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 38947 | 38948 | expression_node_ptr result = error_node(); 38949 | 38950 | const bool synthesis_result = 38951 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 38952 | (expr_gen,id(expr_gen, o0, o1, o2), v0, v1, v2, v3, result); 38953 | 38954 | if (synthesis_result) 38955 | return result; 38956 | else if (!expr_gen.valid_operator(o0,f0)) 38957 | return error_node(); 38958 | 38959 | exprtk_debug(("v0 o0 (v1 o1 (v2 o2 v3))\n")); 38960 | 38961 | return node_type::allocate(*(expr_gen.node_allocator_), v0, v1, v2, v3, f0, f1, f2); 38962 | } 38963 | 38964 | static inline std::string id(expression_generator<Type>& expr_gen, 38965 | const details::operator_type o0, 38966 | const details::operator_type o1, 38967 | const details::operator_type o2) 38968 | { 38969 | return details::build_string() 38970 | << "t" << expr_gen.to_str(o0) 38971 | << "(t" << expr_gen.to_str(o1) 38972 | << "(t" << expr_gen.to_str(o2) 38973 | << "t))" 38974 | } 38975 | }; 38976 | 38977 | struct synthesize_vovovoc_expression1 38978 | { 38979 | typedef typename vovovoc_t::type1 node_type; 38980 | typedef typename vovovoc_t::sf4_type sf4_type; 38981 | typedef typename node_type::T0 T0; 38982 | typedef typename node_type::T1 T1; 38983 | typedef typename node_type::T2 T2; 38984 | typedef typename node_type::T3 T3; 38985 | 38986 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 38987 | const details::operator_type& operation, 38988 | expression_node_ptr (&branch)[2]) 38989 | { 38990 | // v0 o0 (v1 o1 (v2 o2 c)) 38991 | typedef typename synthesize_vovoc_expression1::node_type lcl_vovoc_t; 38992 | 38993 | const lcl_vovoc_t* vovoc = static_cast<const lcl_vovoc_t*>(branch[1]); 38994 | const Type& v0 = static_cast<details::variable_node<Type>*>(branch[0])->ref(); 38995 | const Type& v1 = vovoc->t0(); 38996 | const Type& v2 = vovoc->t1(); 38997 | const Type c = vovoc->t2(); 38998 | const details::operator_type o0 = operation; 38999 | const details::operator_type o1 = expr_gen.get_operator(vovoc->f0()); 39000 | const details::operator_type o2 = expr_gen.get_operator(vovoc->f1()); 39001 | 39002 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 39003 | binary_functor_t f1 = vovoc->f0(); 39004 | binary_functor_t f2 = vovoc->f1(); 39005 | 39006 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 39007 | 39008 | expression_node_ptr result = error_node(); 39009 | 39010 | const bool synthesis_result = 39011 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 39012 | (expr_gen, id(expr_gen, o0, o1, o2), v0, v1, v2, c, result); 39013 | 39014 | if (synthesis_result) 39015 | return result; 39016 | else if (!expr_gen.valid_operator(o0,f0)) 39017 | return error_node(); 39018 | 39019 | exprtk_debug(("v0 o0 (v1 o1 (v2 o2 c))\n")); 39020 | 39021 | return node_type::allocate(*(expr_gen.node_allocator_), v0, v1, v2, c, f0, f1, f2); 39022 | } 39023 | 39024 | static inline std::string id(expression_generator<Type>& expr_gen, 39025 | const details::operator_type o0, 39026 | const details::operator_type o1, 39027 | const details::operator_type o2) 39028 | { 39029 | return details::build_string() 39030 | << "t" << expr_gen.to_str(o0) 39031 | << "(t" << expr_gen.to_str(o1) 39032 | << "(t" << expr_gen.to_str(o2) 39033 | << "t))" 39034 | } 39035 | }; 39036 | 39037 | struct synthesize_vovocov_expression1 39038 | { 39039 | typedef typename vovocov_t::type1 node_type; 39040 | typedef typename vovocov_t::sf4_type sf4_type; 39041 | typedef typename node_type::T0 T0; 39042 | typedef typename node_type::T1 T1; 39043 | typedef typename node_type::T2 T2; 39044 | typedef typename node_type::T3 T3; 39045 | 39046 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 39047 | const details::operator_type& operation, 39048 | expression_node_ptr (&branch)[2]) 39049 | { 39050 | // v0 o0 (v1 o1 (c o2 v2)) 39051 | typedef typename synthesize_vocov_expression1::node_type lcl_vocov_t; 39052 | 39053 | const lcl_vocov_t* vocov = static_cast<const lcl_vocov_t*>(branch[1]); 39054 | const Type& v0 = static_cast<details::variable_node<Type>*>(branch[0])->ref(); 39055 | const Type& v1 = vocov->t0(); 39056 | const Type c = vocov->t1(); 39057 | const Type& v2 = vocov->t2(); 39058 | const details::operator_type o0 = operation; 39059 | const details::operator_type o1 = expr_gen.get_operator(vocov->f0()); 39060 | const details::operator_type o2 = expr_gen.get_operator(vocov->f1()); 39061 | 39062 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 39063 | binary_functor_t f1 = vocov->f0(); 39064 | binary_functor_t f2 = vocov->f1(); 39065 | 39066 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 39067 | 39068 | expression_node_ptr result = error_node(); 39069 | 39070 | const bool synthesis_result = 39071 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 39072 | (expr_gen, id(expr_gen, o0, o1, o2), v0, v1, c, v2, result); 39073 | 39074 | if (synthesis_result) 39075 | return result; 39076 | if (!expr_gen.valid_operator(o0,f0)) 39077 | return error_node(); 39078 | 39079 | exprtk_debug(("v0 o0 (v1 o1 (c o2 v2))\n")); 39080 | 39081 | return node_type::allocate(*(expr_gen.node_allocator_), v0, v1, c, v2, f0, f1, f2); 39082 | } 39083 | 39084 | static inline std::string id(expression_generator<Type>& expr_gen, 39085 | const details::operator_type o0, 39086 | const details::operator_type o1, 39087 | const details::operator_type o2) 39088 | { 39089 | return details::build_string() 39090 | << "t" << expr_gen.to_str(o0) 39091 | << "(t" << expr_gen.to_str(o1) 39092 | << "(t" << expr_gen.to_str(o2) 39093 | << "t))" 39094 | } 39095 | }; 39096 | 39097 | struct synthesize_vocovov_expression1 39098 | { 39099 | typedef typename vocovov_t::type1 node_type; 39100 | typedef typename vocovov_t::sf4_type sf4_type; 39101 | typedef typename node_type::T0 T0; 39102 | typedef typename node_type::T1 T1; 39103 | typedef typename node_type::T2 T2; 39104 | typedef typename node_type::T3 T3; 39105 | 39106 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 39107 | const details::operator_type& operation, 39108 | expression_node_ptr (&branch)[2]) 39109 | { 39110 | // v0 o0 (c o1 (v1 o2 v2)) 39111 | typedef typename synthesize_covov_expression1::node_type lcl_covov_t; 39112 | 39113 | const lcl_covov_t* covov = static_cast<const lcl_covov_t*>(branch[1]); 39114 | const Type& v0 = static_cast<details::variable_node<Type>*>(branch[0])->ref(); 39115 | const Type c = covov->t0(); 39116 | const Type& v1 = covov->t1(); 39117 | const Type& v2 = covov->t2(); 39118 | const details::operator_type o0 = operation; 39119 | const details::operator_type o1 = expr_gen.get_operator(covov->f0()); 39120 | const details::operator_type o2 = expr_gen.get_operator(covov->f1()); 39121 | 39122 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 39123 | binary_functor_t f1 = covov->f0(); 39124 | binary_functor_t f2 = covov->f1(); 39125 | 39126 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 39127 | 39128 | expression_node_ptr result = error_node(); 39129 | 39130 | const bool synthesis_result = 39131 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 39132 | (expr_gen, id(expr_gen, o0, o1, o2), v0, c, v1, v2, result); 39133 | 39134 | if (synthesis_result) 39135 | return result; 39136 | else if (!expr_gen.valid_operator(o0,f0)) 39137 | return error_node(); 39138 | 39139 | exprtk_debug(("v0 o0 (c o1 (v1 o2 v2))\n")); 39140 | 39141 | return node_type::allocate(*(expr_gen.node_allocator_), v0, c, v1, v2, f0, f1, f2); 39142 | } 39143 | 39144 | static inline std::string id(expression_generator<Type>& expr_gen, 39145 | const details::operator_type o0, 39146 | const details::operator_type o1, 39147 | const details::operator_type o2) 39148 | { 39149 | return details::build_string() 39150 | << "t" << expr_gen.to_str(o0) 39151 | << "(t" << expr_gen.to_str(o1) 39152 | << "(t" << expr_gen.to_str(o2) 39153 | << "t))" 39154 | } 39155 | }; 39156 | 39157 | struct synthesize_covovov_expression1 39158 | { 39159 | typedef typename covovov_t::type1 node_type; 39160 | typedef typename covovov_t::sf4_type sf4_type; 39161 | typedef typename node_type::T0 T0; 39162 | typedef typename node_type::T1 T1; 39163 | typedef typename node_type::T2 T2; 39164 | typedef typename node_type::T3 T3; 39165 | 39166 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 39167 | const details::operator_type& operation, 39168 | expression_node_ptr (&branch)[2]) 39169 | { 39170 | // c o0 (v0 o1 (v1 o2 v2)) 39171 | typedef typename synthesize_vovov_expression1::node_type lcl_vovov_t; 39172 | 39173 | const lcl_vovov_t* vovov = static_cast<const lcl_vovov_t*>(branch[1]); 39174 | const Type c = static_cast<details::literal_node<Type>*>(branch[0])->value(); 39175 | const Type& v0 = vovov->t0(); 39176 | const Type& v1 = vovov->t1(); 39177 | const Type& v2 = vovov->t2(); 39178 | const details::operator_type o0 = operation; 39179 | const details::operator_type o1 = expr_gen.get_operator(vovov->f0()); 39180 | const details::operator_type o2 = expr_gen.get_operator(vovov->f1()); 39181 | 39182 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 39183 | binary_functor_t f1 = vovov->f0(); 39184 | binary_functor_t f2 = vovov->f1(); 39185 | 39186 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 39187 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 39188 | 39189 | expression_node_ptr result = error_node(); 39190 | 39191 | const bool synthesis_result = 39192 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 39193 | (expr_gen, id(expr_gen, o0, o1, o2), c, v0, v1, v2, result); 39194 | 39195 | if (synthesis_result) 39196 | return result; 39197 | if (!expr_gen.valid_operator(o0,f0)) 39198 | return error_node(); 39199 | 39200 | exprtk_debug(("c o0 (v0 o1 (v1 o2 v2))\n")); 39201 | 39202 | return node_type::allocate(*(expr_gen.node_allocator_), c, v0, v1, v2, f0, f1, f2); 39203 | } 39204 | 39205 | static inline std::string id(expression_generator<Type>& expr_gen, 39206 | const details::operator_type o0, 39207 | const details::operator_type o1, 39208 | const details::operator_type o2) 39209 | { 39210 | return details::build_string() 39211 | << "t" << expr_gen.to_str(o0) 39212 | << "(t" << expr_gen.to_str(o1) 39213 | << "(t" << expr_gen.to_str(o2) 39214 | << "t))" 39215 | } 39216 | }; 39217 | 39218 | struct synthesize_covocov_expression1 39219 | { 39220 | typedef typename covocov_t::type1 node_type; 39221 | typedef typename covocov_t::sf4_type sf4_type; 39222 | typedef typename node_type::T0 T0; 39223 | typedef typename node_type::T1 T1; 39224 | typedef typename node_type::T2 T2; 39225 | typedef typename node_type::T3 T3; 39226 | 39227 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 39228 | const details::operator_type& operation, 39229 | expression_node_ptr (&branch)[2]) 39230 | { 39231 | // c0 o0 (v0 o1 (c1 o2 v1)) 39232 | typedef typename synthesize_vocov_expression1::node_type lcl_vocov_t; 39233 | 39234 | const lcl_vocov_t* vocov = static_cast<const lcl_vocov_t*>(branch[1]); 39235 | const Type c0 = static_cast<details::literal_node<Type>*>(branch[0])->value(); 39236 | const Type& v0 = vocov->t0(); 39237 | const Type c1 = vocov->t1(); 39238 | const Type& v1 = vocov->t2(); 39239 | const details::operator_type o0 = operation; 39240 | const details::operator_type o1 = expr_gen.get_operator(vocov->f0()); 39241 | const details::operator_type o2 = expr_gen.get_operator(vocov->f1()); 39242 | 39243 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 39244 | binary_functor_t f1 = vocov->f0(); 39245 | binary_functor_t f2 = vocov->f1(); 39246 | 39247 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 39248 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 39249 | 39250 | expression_node_ptr result = error_node(); 39251 | 39252 | const bool synthesis_result = 39253 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 39254 | (expr_gen, id(expr_gen, o0, o1, o2), c0, v0, c1, v1, result); 39255 | 39256 | if (synthesis_result) 39257 | return result; 39258 | else if (!expr_gen.valid_operator(o0,f0)) 39259 | return error_node(); 39260 | 39261 | exprtk_debug(("c0 o0 (v0 o1 (c1 o2 v1))\n")); 39262 | 39263 | return node_type::allocate(*(expr_gen.node_allocator_), c0, v0, c1, v1, f0, f1, f2); 39264 | } 39265 | 39266 | static inline std::string id(expression_generator<Type>& expr_gen, 39267 | const details::operator_type o0, 39268 | const details::operator_type o1, 39269 | const details::operator_type o2) 39270 | { 39271 | return details::build_string() 39272 | << "t" << expr_gen.to_str(o0) 39273 | << "(t" << expr_gen.to_str(o1) 39274 | << "(t" << expr_gen.to_str(o2) 39275 | << "t))" 39276 | } 39277 | }; 39278 | 39279 | struct synthesize_vocovoc_expression1 39280 | { 39281 | typedef typename vocovoc_t::type1 node_type; 39282 | typedef typename vocovoc_t::sf4_type sf4_type; 39283 | typedef typename node_type::T0 T0; 39284 | typedef typename node_type::T1 T1; 39285 | typedef typename node_type::T2 T2; 39286 | typedef typename node_type::T3 T3; 39287 | 39288 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 39289 | const details::operator_type& operation, 39290 | expression_node_ptr (&branch)[2]) 39291 | { 39292 | // v0 o0 (c0 o1 (v1 o2 c2)) 39293 | typedef typename synthesize_covoc_expression1::node_type lcl_covoc_t; 39294 | 39295 | const lcl_covoc_t* covoc = static_cast<const lcl_covoc_t*>(branch[1]); 39296 | const Type& v0 = static_cast<details::variable_node<Type>*>(branch[0])->ref(); 39297 | const Type c0 = covoc->t0(); 39298 | const Type& v1 = covoc->t1(); 39299 | const Type c1 = covoc->t2(); 39300 | const details::operator_type o0 = operation; 39301 | const details::operator_type o1 = expr_gen.get_operator(covoc->f0()); 39302 | const details::operator_type o2 = expr_gen.get_operator(covoc->f1()); 39303 | 39304 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 39305 | binary_functor_t f1 = covoc->f0(); 39306 | binary_functor_t f2 = covoc->f1(); 39307 | 39308 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 39309 | 39310 | expression_node_ptr result = error_node(); 39311 | 39312 | const bool synthesis_result = 39313 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 39314 | (expr_gen, id(expr_gen, o0, o1, o2), v0, c0, v1, c1, result); 39315 | 39316 | if (synthesis_result) 39317 | return result; 39318 | else if (!expr_gen.valid_operator(o0,f0)) 39319 | return error_node(); 39320 | 39321 | exprtk_debug(("v0 o0 (c0 o1 (v1 o2 c2))\n")); 39322 | 39323 | return node_type::allocate(*(expr_gen.node_allocator_), v0, c0, v1, c1, f0, f1, f2); 39324 | } 39325 | 39326 | static inline std::string id(expression_generator<Type>& expr_gen, 39327 | const details::operator_type o0, 39328 | const details::operator_type o1, 39329 | const details::operator_type o2) 39330 | { 39331 | return details::build_string() 39332 | << "t" << expr_gen.to_str(o0) 39333 | << "(t" << expr_gen.to_str(o1) 39334 | << "(t" << expr_gen.to_str(o2) 39335 | << "t))" 39336 | } 39337 | }; 39338 | 39339 | struct synthesize_covovoc_expression1 39340 | { 39341 | typedef typename covovoc_t::type1 node_type; 39342 | typedef typename covovoc_t::sf4_type sf4_type; 39343 | typedef typename node_type::T0 T0; 39344 | typedef typename node_type::T1 T1; 39345 | typedef typename node_type::T2 T2; 39346 | typedef typename node_type::T3 T3; 39347 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 39348 | const details::operator_type& operation, 39349 | expression_node_ptr (&branch)[2]) 39350 | { 39351 | // c0 o0 (v0 o1 (v1 o2 c1)) 39352 | typedef typename synthesize_vovoc_expression1::node_type lcl_vovoc_t; 39353 | 39354 | const lcl_vovoc_t* vovoc = static_cast<const lcl_vovoc_t*>(branch[1]); 39355 | const Type c0 = static_cast<details::literal_node<Type>*>(branch[0])->value(); 39356 | const Type& v0 = vovoc->t0(); 39357 | const Type& v1 = vovoc->t1(); 39358 | const Type c1 = vovoc->t2(); 39359 | const details::operator_type o0 = operation; 39360 | const details::operator_type o1 = expr_gen.get_operator(vovoc->f0()); 39361 | const details::operator_type o2 = expr_gen.get_operator(vovoc->f1()); 39362 | 39363 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 39364 | binary_functor_t f1 = vovoc->f0(); 39365 | binary_functor_t f2 = vovoc->f1(); 39366 | 39367 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 39368 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 39369 | 39370 | expression_node_ptr result = error_node(); 39371 | 39372 | const bool synthesis_result = 39373 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 39374 | (expr_gen, id(expr_gen, o0, o1, o2), c0, v0, v1, c1, result); 39375 | 39376 | if (synthesis_result) 39377 | return result; 39378 | else if (!expr_gen.valid_operator(o0,f0)) 39379 | return error_node(); 39380 | 39381 | exprtk_debug(("c0 o0 (v0 o1 (v1 o2 c1))\n")); 39382 | 39383 | return node_type::allocate(*(expr_gen.node_allocator_), c0, v0, v1, c1, f0, f1, f2); 39384 | } 39385 | 39386 | static inline std::string id(expression_generator<Type>& expr_gen, 39387 | const details::operator_type o0, 39388 | const details::operator_type o1, 39389 | const details::operator_type o2) 39390 | { 39391 | return details::build_string() 39392 | << "t" << expr_gen.to_str(o0) 39393 | << "(t" << expr_gen.to_str(o1) 39394 | << "(t" << expr_gen.to_str(o2) 39395 | << "t))" 39396 | } 39397 | }; 39398 | 39399 | struct synthesize_vococov_expression1 39400 | { 39401 | typedef typename vococov_t::type1 node_type; 39402 | typedef typename vococov_t::sf4_type sf4_type; 39403 | typedef typename node_type::T0 T0; 39404 | typedef typename node_type::T1 T1; 39405 | typedef typename node_type::T2 T2; 39406 | typedef typename node_type::T3 T3; 39407 | 39408 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 39409 | const details::operator_type& operation, 39410 | expression_node_ptr (&branch)[2]) 39411 | { 39412 | // v0 o0 (c0 o1 (c1 o2 v1)) 39413 | typedef typename synthesize_cocov_expression1::node_type lcl_cocov_t; 39414 | 39415 | const lcl_cocov_t* cocov = static_cast<const lcl_cocov_t*>(branch[1]); 39416 | const Type& v0 = static_cast<details::variable_node<Type>*>(branch[0])->ref(); 39417 | const Type c0 = cocov->t0(); 39418 | const Type c1 = cocov->t1(); 39419 | const Type& v1 = cocov->t2(); 39420 | const details::operator_type o0 = operation; 39421 | const details::operator_type o1 = expr_gen.get_operator(cocov->f0()); 39422 | const details::operator_type o2 = expr_gen.get_operator(cocov->f1()); 39423 | 39424 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 39425 | binary_functor_t f1 = cocov->f0(); 39426 | binary_functor_t f2 = cocov->f1(); 39427 | 39428 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 39429 | 39430 | expression_node_ptr result = error_node(); 39431 | 39432 | const bool synthesis_result = 39433 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 39434 | (expr_gen, id(expr_gen, o0, o1, o2), v0, c0, c1, v1, result); 39435 | 39436 | if (synthesis_result) 39437 | return result; 39438 | else if (!expr_gen.valid_operator(o0,f0)) 39439 | return error_node(); 39440 | 39441 | exprtk_debug(("v0 o0 (c0 o1 (c1 o2 v1))\n")); 39442 | 39443 | return node_type::allocate(*(expr_gen.node_allocator_), v0, c0, c1, v1, f0, f1, f2); 39444 | } 39445 | 39446 | static inline std::string id(expression_generator<Type>& expr_gen, 39447 | const details::operator_type o0, 39448 | const details::operator_type o1, 39449 | const details::operator_type o2) 39450 | { 39451 | return details::build_string() 39452 | << "t" << expr_gen.to_str(o0) 39453 | << "(t" << expr_gen.to_str(o1) 39454 | << "(t" << expr_gen.to_str(o2) 39455 | << "t))" 39456 | } 39457 | }; 39458 | 39459 | struct synthesize_vovovov_expression2 39460 | { 39461 | typedef typename vovovov_t::type2 node_type; 39462 | typedef typename vovovov_t::sf4_type sf4_type; 39463 | typedef typename node_type::T0 T0; 39464 | typedef typename node_type::T1 T1; 39465 | typedef typename node_type::T2 T2; 39466 | typedef typename node_type::T3 T3; 39467 | 39468 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 39469 | const details::operator_type& operation, 39470 | expression_node_ptr (&branch)[2]) 39471 | { 39472 | // v0 o0 ((v1 o1 v2) o2 v3) 39473 | typedef typename synthesize_vovov_expression0::node_type lcl_vovov_t; 39474 | 39475 | const lcl_vovov_t* vovov = static_cast<const lcl_vovov_t*>(branch[1]); 39476 | const Type& v0 = static_cast<details::variable_node<Type>*>(branch[0])->ref(); 39477 | const Type& v1 = vovov->t0(); 39478 | const Type& v2 = vovov->t1(); 39479 | const Type& v3 = vovov->t2(); 39480 | const details::operator_type o0 = operation; 39481 | const details::operator_type o1 = expr_gen.get_operator(vovov->f0()); 39482 | const details::operator_type o2 = expr_gen.get_operator(vovov->f1()); 39483 | 39484 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 39485 | binary_functor_t f1 = vovov->f0(); 39486 | binary_functor_t f2 = vovov->f1(); 39487 | 39488 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 39489 | 39490 | expression_node_ptr result = error_node(); 39491 | 39492 | const bool synthesis_result = 39493 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 39494 | (expr_gen, id(expr_gen, o0, o1, o2), v0, v1, v2, v3, result); 39495 | 39496 | if (synthesis_result) 39497 | return result; 39498 | else if (!expr_gen.valid_operator(o0,f0)) 39499 | return error_node(); 39500 | 39501 | exprtk_debug(("v0 o0 ((v1 o1 v2) o2 v3)\n")); 39502 | 39503 | return node_type::allocate(*(expr_gen.node_allocator_), v0, v1, v2, v3, f0, f1, f2); 39504 | } 39505 | 39506 | static inline std::string id(expression_generator<Type>& expr_gen, 39507 | const details::operator_type o0, 39508 | const details::operator_type o1, 39509 | const details::operator_type o2) 39510 | { 39511 | return details::build_string() 39512 | << "t" << expr_gen.to_str(o0) 39513 | << "((t" << expr_gen.to_str(o1) 39514 | << "t)" << expr_gen.to_str(o2) 39515 | << "t)" 39516 | } 39517 | }; 39518 | 39519 | struct synthesize_vovovoc_expression2 39520 | { 39521 | typedef typename vovovoc_t::type2 node_type; 39522 | typedef typename vovovoc_t::sf4_type sf4_type; 39523 | typedef typename node_type::T0 T0; 39524 | typedef typename node_type::T1 T1; 39525 | typedef typename node_type::T2 T2; 39526 | typedef typename node_type::T3 T3; 39527 | 39528 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 39529 | const details::operator_type& operation, 39530 | expression_node_ptr (&branch)[2]) 39531 | { 39532 | // v0 o0 ((v1 o1 v2) o2 c) 39533 | typedef typename synthesize_vovoc_expression0::node_type lcl_vovoc_t; 39534 | 39535 | const lcl_vovoc_t* vovoc = static_cast<const lcl_vovoc_t*>(branch[1]); 39536 | const Type& v0 = static_cast<details::variable_node<Type>*>(branch[0])->ref(); 39537 | const Type& v1 = vovoc->t0(); 39538 | const Type& v2 = vovoc->t1(); 39539 | const Type c = vovoc->t2(); 39540 | const details::operator_type o0 = operation; 39541 | const details::operator_type o1 = expr_gen.get_operator(vovoc->f0()); 39542 | const details::operator_type o2 = expr_gen.get_operator(vovoc->f1()); 39543 | 39544 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 39545 | binary_functor_t f1 = vovoc->f0(); 39546 | binary_functor_t f2 = vovoc->f1(); 39547 | 39548 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 39549 | 39550 | expression_node_ptr result = error_node(); 39551 | 39552 | const bool synthesis_result = 39553 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 39554 | (expr_gen, id(expr_gen, o0, o1, o2), v0, v1, v2, c, result); 39555 | 39556 | if (synthesis_result) 39557 | return result; 39558 | else if (!expr_gen.valid_operator(o0,f0)) 39559 | return error_node(); 39560 | 39561 | exprtk_debug(("v0 o0 ((v1 o1 v2) o2 c)\n")); 39562 | 39563 | return node_type::allocate(*(expr_gen.node_allocator_), v0, v1, v2, c, f0, f1, f2); 39564 | } 39565 | 39566 | static inline std::string id(expression_generator<Type>& expr_gen, 39567 | const details::operator_type o0, 39568 | const details::operator_type o1, 39569 | const details::operator_type o2) 39570 | { 39571 | return details::build_string() 39572 | << "t" << expr_gen.to_str(o0) 39573 | << "((t" << expr_gen.to_str(o1) 39574 | << "t)" << expr_gen.to_str(o2) 39575 | << "t)" 39576 | } 39577 | }; 39578 | 39579 | struct synthesize_vovocov_expression2 39580 | { 39581 | typedef typename vovocov_t::type2 node_type; 39582 | typedef typename vovocov_t::sf4_type sf4_type; 39583 | typedef typename node_type::T0 T0; 39584 | typedef typename node_type::T1 T1; 39585 | typedef typename node_type::T2 T2; 39586 | typedef typename node_type::T3 T3; 39587 | 39588 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 39589 | const details::operator_type& operation, 39590 | expression_node_ptr (&branch)[2]) 39591 | { 39592 | // v0 o0 ((v1 o1 c) o2 v2) 39593 | typedef typename synthesize_vocov_expression0::node_type lcl_vocov_t; 39594 | 39595 | const lcl_vocov_t* vocov = static_cast<const lcl_vocov_t*>(branch[1]); 39596 | const Type& v0 = static_cast<details::variable_node<Type>*>(branch[0])->ref(); 39597 | const Type& v1 = vocov->t0(); 39598 | const Type c = vocov->t1(); 39599 | const Type& v2 = vocov->t2(); 39600 | const details::operator_type o0 = operation; 39601 | const details::operator_type o1 = expr_gen.get_operator(vocov->f0()); 39602 | const details::operator_type o2 = expr_gen.get_operator(vocov->f1()); 39603 | 39604 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 39605 | binary_functor_t f1 = vocov->f0(); 39606 | binary_functor_t f2 = vocov->f1(); 39607 | 39608 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 39609 | 39610 | expression_node_ptr result = error_node(); 39611 | 39612 | const bool synthesis_result = 39613 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 39614 | (expr_gen, id(expr_gen, o0, o1, o2), v0, v1, c, v2, result); 39615 | 39616 | if (synthesis_result) 39617 | return result; 39618 | else if (!expr_gen.valid_operator(o0,f0)) 39619 | return error_node(); 39620 | 39621 | exprtk_debug(("v0 o0 ((v1 o1 c) o2 v2)\n")); 39622 | 39623 | return node_type::allocate(*(expr_gen.node_allocator_), v0, v1, c, v2, f0, f1, f2); 39624 | } 39625 | 39626 | static inline std::string id(expression_generator<Type>& expr_gen, 39627 | const details::operator_type o0, 39628 | const details::operator_type o1, 39629 | const details::operator_type o2) 39630 | { 39631 | return details::build_string() 39632 | << "t" << expr_gen.to_str(o0) 39633 | << "((t" << expr_gen.to_str(o1) 39634 | << "t)" << expr_gen.to_str(o2) 39635 | << "t)" 39636 | } 39637 | }; 39638 | 39639 | struct synthesize_vocovov_expression2 39640 | { 39641 | typedef typename vocovov_t::type2 node_type; 39642 | typedef typename vocovov_t::sf4_type sf4_type; 39643 | typedef typename node_type::T0 T0; 39644 | typedef typename node_type::T1 T1; 39645 | typedef typename node_type::T2 T2; 39646 | typedef typename node_type::T3 T3; 39647 | 39648 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 39649 | const details::operator_type& operation, 39650 | expression_node_ptr (&branch)[2]) 39651 | { 39652 | // v0 o0 ((c o1 v1) o2 v2) 39653 | typedef typename synthesize_covov_expression0::node_type lcl_covov_t; 39654 | 39655 | const lcl_covov_t* covov = static_cast<const lcl_covov_t*>(branch[1]); 39656 | const Type& v0 = static_cast<details::variable_node<Type>*>(branch[0])->ref(); 39657 | const Type c = covov->t0(); 39658 | const Type& v1 = covov->t1(); 39659 | const Type& v2 = covov->t2(); 39660 | const details::operator_type o0 = operation; 39661 | const details::operator_type o1 = expr_gen.get_operator(covov->f0()); 39662 | const details::operator_type o2 = expr_gen.get_operator(covov->f1()); 39663 | 39664 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 39665 | binary_functor_t f1 = covov->f0(); 39666 | binary_functor_t f2 = covov->f1(); 39667 | 39668 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 39669 | 39670 | expression_node_ptr result = error_node(); 39671 | 39672 | const bool synthesis_result = 39673 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 39674 | (expr_gen, id(expr_gen, o0, o1, o2), v0, c, v1, v2, result); 39675 | 39676 | if (synthesis_result) 39677 | return result; 39678 | else if (!expr_gen.valid_operator(o0,f0)) 39679 | return error_node(); 39680 | 39681 | exprtk_debug(("v0 o0 ((c o1 v1) o2 v2)\n")); 39682 | 39683 | return node_type::allocate(*(expr_gen.node_allocator_), v0, c, v1, v2, f0, f1, f2); 39684 | } 39685 | 39686 | static inline std::string id(expression_generator<Type>& expr_gen, 39687 | const details::operator_type o0, 39688 | const details::operator_type o1, 39689 | const details::operator_type o2) 39690 | { 39691 | return details::build_string() 39692 | << "t" << expr_gen.to_str(o0) 39693 | << "((t" << expr_gen.to_str(o1) 39694 | << "t)" << expr_gen.to_str(o2) 39695 | << "t)" 39696 | } 39697 | }; 39698 | 39699 | struct synthesize_covovov_expression2 39700 | { 39701 | typedef typename covovov_t::type2 node_type; 39702 | typedef typename covovov_t::sf4_type sf4_type; 39703 | typedef typename node_type::T0 T0; 39704 | typedef typename node_type::T1 T1; 39705 | typedef typename node_type::T2 T2; 39706 | typedef typename node_type::T3 T3; 39707 | 39708 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 39709 | const details::operator_type& operation, 39710 | expression_node_ptr (&branch)[2]) 39711 | { 39712 | // c o0 ((v1 o1 v2) o2 v3) 39713 | typedef typename synthesize_vovov_expression0::node_type lcl_vovov_t; 39714 | 39715 | const lcl_vovov_t* vovov = static_cast<const lcl_vovov_t*>(branch[1]); 39716 | const Type c = static_cast<details::literal_node<Type>*>(branch[0])->value(); 39717 | const Type& v0 = vovov->t0(); 39718 | const Type& v1 = vovov->t1(); 39719 | const Type& v2 = vovov->t2(); 39720 | const details::operator_type o0 = operation; 39721 | const details::operator_type o1 = expr_gen.get_operator(vovov->f0()); 39722 | const details::operator_type o2 = expr_gen.get_operator(vovov->f1()); 39723 | 39724 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 39725 | binary_functor_t f1 = vovov->f0(); 39726 | binary_functor_t f2 = vovov->f1(); 39727 | 39728 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 39729 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 39730 | 39731 | expression_node_ptr result = error_node(); 39732 | 39733 | const bool synthesis_result = 39734 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 39735 | (expr_gen, id(expr_gen, o0, o1, o2), c, v0, v1, v2, result); 39736 | 39737 | if (synthesis_result) 39738 | return result; 39739 | else if (!expr_gen.valid_operator(o0,f0)) 39740 | return error_node(); 39741 | 39742 | exprtk_debug(("c o0 ((v1 o1 v2) o2 v3)\n")); 39743 | 39744 | return node_type::allocate(*(expr_gen.node_allocator_), c, v0, v1, v2, f0, f1, f2); 39745 | } 39746 | 39747 | static inline std::string id(expression_generator<Type>& expr_gen, 39748 | const details::operator_type o0, 39749 | const details::operator_type o1, 39750 | const details::operator_type o2) 39751 | { 39752 | return details::build_string() 39753 | << "t" << expr_gen.to_str(o0) 39754 | << "((t" << expr_gen.to_str(o1) 39755 | << "t)" << expr_gen.to_str(o2) 39756 | << "t)" 39757 | } 39758 | }; 39759 | 39760 | struct synthesize_covocov_expression2 39761 | { 39762 | typedef typename covocov_t::type2 node_type; 39763 | typedef typename covocov_t::sf4_type sf4_type; 39764 | typedef typename node_type::T0 T0; 39765 | typedef typename node_type::T1 T1; 39766 | typedef typename node_type::T2 T2; 39767 | typedef typename node_type::T3 T3; 39768 | 39769 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 39770 | const details::operator_type& operation, 39771 | expression_node_ptr (&branch)[2]) 39772 | { 39773 | // c0 o0 ((v0 o1 c1) o2 v1) 39774 | typedef typename synthesize_vocov_expression0::node_type lcl_vocov_t; 39775 | 39776 | const lcl_vocov_t* vocov = static_cast<const lcl_vocov_t*>(branch[1]); 39777 | const Type c0 = static_cast<details::literal_node<Type>*>(branch[0])->value(); 39778 | const Type& v0 = vocov->t0(); 39779 | const Type c1 = vocov->t1(); 39780 | const Type& v1 = vocov->t2(); 39781 | const details::operator_type o0 = operation; 39782 | const details::operator_type o1 = expr_gen.get_operator(vocov->f0()); 39783 | const details::operator_type o2 = expr_gen.get_operator(vocov->f1()); 39784 | 39785 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 39786 | binary_functor_t f1 = vocov->f0(); 39787 | binary_functor_t f2 = vocov->f1(); 39788 | 39789 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 39790 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 39791 | 39792 | expression_node_ptr result = error_node(); 39793 | 39794 | const bool synthesis_result = 39795 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 39796 | (expr_gen, id(expr_gen, o0, o1, o2), c0, v0, c1, v1, result); 39797 | 39798 | if (synthesis_result) 39799 | return result; 39800 | else if (!expr_gen.valid_operator(o0,f0)) 39801 | return error_node(); 39802 | 39803 | exprtk_debug(("c0 o0 ((v0 o1 c1) o2 v1)\n")); 39804 | 39805 | return node_type::allocate(*(expr_gen.node_allocator_), c0, v0, c1, v1, f0, f1, f2); 39806 | } 39807 | 39808 | static inline std::string id(expression_generator<Type>& expr_gen, 39809 | const details::operator_type o0, 39810 | const details::operator_type o1, 39811 | const details::operator_type o2) 39812 | { 39813 | return details::build_string() 39814 | << "t" << expr_gen.to_str(o0) 39815 | << "((t" << expr_gen.to_str(o1) 39816 | << "t)" << expr_gen.to_str(o2) 39817 | << "t)" 39818 | } 39819 | }; 39820 | 39821 | struct synthesize_vocovoc_expression2 39822 | { 39823 | typedef typename vocovoc_t::type2 node_type; 39824 | typedef typename vocovoc_t::sf4_type sf4_type; 39825 | typedef typename node_type::T0 T0; 39826 | typedef typename node_type::T1 T1; 39827 | typedef typename node_type::T2 T2; 39828 | typedef typename node_type::T3 T3; 39829 | 39830 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 39831 | const details::operator_type& operation, 39832 | expression_node_ptr (&branch)[2]) 39833 | { 39834 | // v0 o0 ((c0 o1 v1) o2 c1) 39835 | typedef typename synthesize_covoc_expression0::node_type lcl_covoc_t; 39836 | 39837 | const lcl_covoc_t* covoc = static_cast<const lcl_covoc_t*>(branch[1]); 39838 | const Type& v0 = static_cast<details::variable_node<Type>*>(branch[0])->ref(); 39839 | const Type c0 = covoc->t0(); 39840 | const Type& v1 = covoc->t1(); 39841 | const Type c1 = covoc->t2(); 39842 | const details::operator_type o0 = operation; 39843 | const details::operator_type o1 = expr_gen.get_operator(covoc->f0()); 39844 | const details::operator_type o2 = expr_gen.get_operator(covoc->f1()); 39845 | 39846 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 39847 | binary_functor_t f1 = covoc->f0(); 39848 | binary_functor_t f2 = covoc->f1(); 39849 | 39850 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 39851 | 39852 | expression_node_ptr result = error_node(); 39853 | 39854 | const bool synthesis_result = 39855 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 39856 | (expr_gen, id(expr_gen, o0, o1, o2), v0, c0, v1, c1, result); 39857 | 39858 | if (synthesis_result) 39859 | return result; 39860 | else if (!expr_gen.valid_operator(o0,f0)) 39861 | return error_node(); 39862 | 39863 | exprtk_debug(("v0 o0 ((c0 o1 v1) o2 c1)\n")); 39864 | 39865 | return node_type::allocate(*(expr_gen.node_allocator_), v0, c0, v1, c1, f0, f1, f2); 39866 | } 39867 | 39868 | static inline std::string id(expression_generator<Type>& expr_gen, 39869 | const details::operator_type o0, 39870 | const details::operator_type o1, 39871 | const details::operator_type o2) 39872 | { 39873 | return details::build_string() 39874 | << "t" << expr_gen.to_str(o0) 39875 | << "((t" << expr_gen.to_str(o1) 39876 | << "t)" << expr_gen.to_str(o2) 39877 | << "t)" 39878 | } 39879 | }; 39880 | 39881 | struct synthesize_covovoc_expression2 39882 | { 39883 | typedef typename covovoc_t::type2 node_type; 39884 | typedef typename covovoc_t::sf4_type sf4_type; 39885 | typedef typename node_type::T0 T0; 39886 | typedef typename node_type::T1 T1; 39887 | typedef typename node_type::T2 T2; 39888 | typedef typename node_type::T3 T3; 39889 | 39890 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 39891 | const details::operator_type& operation, 39892 | expression_node_ptr (&branch)[2]) 39893 | { 39894 | // c0 o0 ((v0 o1 v1) o2 c1) 39895 | typedef typename synthesize_vovoc_expression0::node_type lcl_vovoc_t; 39896 | 39897 | const lcl_vovoc_t* vovoc = static_cast<const lcl_vovoc_t*>(branch[1]); 39898 | const Type c0 = static_cast<details::literal_node<Type>*>(branch[0])->value(); 39899 | const Type& v0 = vovoc->t0(); 39900 | const Type& v1 = vovoc->t1(); 39901 | const Type c1 = vovoc->t2(); 39902 | const details::operator_type o0 = operation; 39903 | const details::operator_type o1 = expr_gen.get_operator(vovoc->f0()); 39904 | const details::operator_type o2 = expr_gen.get_operator(vovoc->f1()); 39905 | 39906 | binary_functor_t f0 = reinterpret_cast<binary_functor_t>(0); 39907 | binary_functor_t f1 = vovoc->f0(); 39908 | binary_functor_t f2 = vovoc->f1(); 39909 | 39910 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 39911 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 39912 | 39913 | expression_node_ptr result = error_node(); 39914 | 39915 | const bool synthesis_result = 39916 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 39917 | (expr_gen, id(expr_gen, o0, o1, o2), c0, v0, v1, c1, result); 39918 | 39919 | if (synthesis_result) 39920 | return result; 39921 | else if (!expr_gen.valid_operator(o0,f0)) 39922 | return error_node(); 39923 | 39924 | exprtk_debug(("c0 o0 ((v0 o1 v1) o2 c1)\n")); 39925 | 39926 | return node_type::allocate(*(expr_gen.node_allocator_), c0, v0, v1, c1, f0, f1, f2); 39927 | } 39928 | 39929 | static inline std::string id(expression_generator<Type>& expr_gen, 39930 | const details::operator_type o0, 39931 | const details::operator_type o1, 39932 | const details::operator_type o2) 39933 | { 39934 | return details::build_string() 39935 | << "t" << expr_gen.to_str(o0) 39936 | << "((t" << expr_gen.to_str(o1) 39937 | << "t)" << expr_gen.to_str(o2) 39938 | << "t)" 39939 | } 39940 | }; 39941 | 39942 | struct synthesize_vococov_expression2 39943 | { 39944 | typedef typename vococov_t::type2 node_type; 39945 | static inline expression_node_ptr process(expression_generator<Type>&, 39946 | const details::operator_type&, 39947 | expression_node_ptr (&)[2]) 39948 | { 39949 | // v0 o0 ((c0 o1 c1) o2 v1) - Not possible 39950 | exprtk_debug(("v0 o0 ((c0 o1 c1) o2 v1) - Not possible\n")); 39951 | return error_node(); 39952 | } 39953 | 39954 | static inline std::string id(expression_generator<Type>&, 39955 | const details::operator_type, 39956 | const details::operator_type, 39957 | const details::operator_type) 39958 | { 39959 | return "INVALID" 39960 | } 39961 | }; 39962 | 39963 | struct synthesize_vovovov_expression3 39964 | { 39965 | typedef typename vovovov_t::type3 node_type; 39966 | typedef typename vovovov_t::sf4_type sf4_type; 39967 | typedef typename node_type::T0 T0; 39968 | typedef typename node_type::T1 T1; 39969 | typedef typename node_type::T2 T2; 39970 | typedef typename node_type::T3 T3; 39971 | 39972 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 39973 | const details::operator_type& operation, 39974 | expression_node_ptr (&branch)[2]) 39975 | { 39976 | // ((v0 o0 v1) o1 v2) o2 v3 39977 | typedef typename synthesize_vovov_expression0::node_type lcl_vovov_t; 39978 | 39979 | const lcl_vovov_t* vovov = static_cast<const lcl_vovov_t*>(branch[0]); 39980 | const Type& v0 = vovov->t0(); 39981 | const Type& v1 = vovov->t1(); 39982 | const Type& v2 = vovov->t2(); 39983 | const Type& v3 = static_cast<details::variable_node<Type>*>(branch[1])->ref(); 39984 | const details::operator_type o0 = expr_gen.get_operator(vovov->f0()); 39985 | const details::operator_type o1 = expr_gen.get_operator(vovov->f1()); 39986 | const details::operator_type o2 = operation; 39987 | 39988 | binary_functor_t f0 = vovov->f0(); 39989 | binary_functor_t f1 = vovov->f1(); 39990 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 39991 | 39992 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 39993 | 39994 | expression_node_ptr result = error_node(); 39995 | 39996 | const bool synthesis_result = 39997 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 39998 | (expr_gen, id(expr_gen, o0, o1, o2), v0, v1, v2, v3, result); 39999 | 40000 | if (synthesis_result) 40001 | return result; 40002 | else if (!expr_gen.valid_operator(o2,f2)) 40003 | return error_node(); 40004 | 40005 | exprtk_debug(("((v0 o0 v1) o1 v2) o2 v3\n")); 40006 | 40007 | return node_type::allocate(*(expr_gen.node_allocator_), v0, v1, v2, v3, f0, f1, f2); 40008 | } 40009 | 40010 | static inline std::string id(expression_generator<Type>& expr_gen, 40011 | const details::operator_type o0, 40012 | const details::operator_type o1, 40013 | const details::operator_type o2) 40014 | { 40015 | return details::build_string() 40016 | << "((t" << expr_gen.to_str(o0) 40017 | << "t)" << expr_gen.to_str(o1) 40018 | << "t)" << expr_gen.to_str(o2) 40019 | << "t" 40020 | } 40021 | }; 40022 | 40023 | struct synthesize_vovovoc_expression3 40024 | { 40025 | typedef typename vovovoc_t::type3 node_type; 40026 | typedef typename vovovoc_t::sf4_type sf4_type; 40027 | typedef typename node_type::T0 T0; 40028 | typedef typename node_type::T1 T1; 40029 | typedef typename node_type::T2 T2; 40030 | typedef typename node_type::T3 T3; 40031 | 40032 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 40033 | const details::operator_type& operation, 40034 | expression_node_ptr (&branch)[2]) 40035 | { 40036 | // ((v0 o0 v1) o1 v2) o2 c 40037 | typedef typename synthesize_vovov_expression0::node_type lcl_vovov_t; 40038 | 40039 | const lcl_vovov_t* vovov = static_cast<const lcl_vovov_t*>(branch[0]); 40040 | const Type& v0 = vovov->t0(); 40041 | const Type& v1 = vovov->t1(); 40042 | const Type& v2 = vovov->t2(); 40043 | const Type c = static_cast<details::literal_node<Type>*>(branch[1])->value(); 40044 | const details::operator_type o0 = expr_gen.get_operator(vovov->f0()); 40045 | const details::operator_type o1 = expr_gen.get_operator(vovov->f1()); 40046 | const details::operator_type o2 = operation; 40047 | 40048 | binary_functor_t f0 = vovov->f0(); 40049 | binary_functor_t f1 = vovov->f1(); 40050 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 40051 | 40052 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 40053 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 40054 | 40055 | expression_node_ptr result = error_node(); 40056 | 40057 | const bool synthesis_result = 40058 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 40059 | (expr_gen, id(expr_gen, o0, o1, o2), v0, v1, v2, c, result); 40060 | 40061 | if (synthesis_result) 40062 | return result; 40063 | else if (!expr_gen.valid_operator(o2,f2)) 40064 | return error_node(); 40065 | 40066 | exprtk_debug(("((v0 o0 v1) o1 v2) o2 c\n")); 40067 | 40068 | return node_type::allocate(*(expr_gen.node_allocator_), v0, v1, v2, c, f0, f1, f2); 40069 | } 40070 | 40071 | static inline std::string id(expression_generator<Type>& expr_gen, 40072 | const details::operator_type o0, 40073 | const details::operator_type o1, 40074 | const details::operator_type o2) 40075 | { 40076 | return details::build_string() 40077 | << "((t" << expr_gen.to_str(o0) 40078 | << "t)" << expr_gen.to_str(o1) 40079 | << "t)" << expr_gen.to_str(o2) 40080 | << "t" 40081 | } 40082 | }; 40083 | 40084 | struct synthesize_vovocov_expression3 40085 | { 40086 | typedef typename vovocov_t::type3 node_type; 40087 | typedef typename vovocov_t::sf4_type sf4_type; 40088 | typedef typename node_type::T0 T0; 40089 | typedef typename node_type::T1 T1; 40090 | typedef typename node_type::T2 T2; 40091 | typedef typename node_type::T3 T3; 40092 | 40093 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 40094 | const details::operator_type& operation, 40095 | expression_node_ptr (&branch)[2]) 40096 | { 40097 | // ((v0 o0 v1) o1 c) o2 v2 40098 | typedef typename synthesize_vovoc_expression0::node_type lcl_vovoc_t; 40099 | 40100 | const lcl_vovoc_t* vovoc = static_cast<const lcl_vovoc_t*>(branch[0]); 40101 | const Type& v0 = vovoc->t0(); 40102 | const Type& v1 = vovoc->t1(); 40103 | const Type c = vovoc->t2(); 40104 | const Type& v2 = static_cast<details::variable_node<Type>*>(branch[1])->ref(); 40105 | const details::operator_type o0 = expr_gen.get_operator(vovoc->f0()); 40106 | const details::operator_type o1 = expr_gen.get_operator(vovoc->f1()); 40107 | const details::operator_type o2 = operation; 40108 | 40109 | binary_functor_t f0 = vovoc->f0(); 40110 | binary_functor_t f1 = vovoc->f1(); 40111 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 40112 | 40113 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 40114 | 40115 | expression_node_ptr result = error_node(); 40116 | 40117 | const bool synthesis_result = 40118 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 40119 | (expr_gen, id(expr_gen, o0, o1, o2), v0, v1, c, v2, result); 40120 | 40121 | if (synthesis_result) 40122 | return result; 40123 | else if (!expr_gen.valid_operator(o2,f2)) 40124 | return error_node(); 40125 | 40126 | exprtk_debug(("((v0 o0 v1) o1 c) o2 v2\n")); 40127 | 40128 | return node_type::allocate(*(expr_gen.node_allocator_), v0, v1, c, v2, f0, f1, f2); 40129 | } 40130 | 40131 | static inline std::string id(expression_generator<Type>& expr_gen, 40132 | const details::operator_type o0, 40133 | const details::operator_type o1, 40134 | const details::operator_type o2) 40135 | { 40136 | return details::build_string() 40137 | << "((t" << expr_gen.to_str(o0) 40138 | << "t)" << expr_gen.to_str(o1) 40139 | << "t)" << expr_gen.to_str(o2) 40140 | << "t" 40141 | } 40142 | }; 40143 | 40144 | struct synthesize_vocovov_expression3 40145 | { 40146 | typedef typename vocovov_t::type3 node_type; 40147 | typedef typename vocovov_t::sf4_type sf4_type; 40148 | typedef typename node_type::T0 T0; 40149 | typedef typename node_type::T1 T1; 40150 | typedef typename node_type::T2 T2; 40151 | typedef typename node_type::T3 T3; 40152 | 40153 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 40154 | const details::operator_type& operation, 40155 | expression_node_ptr (&branch)[2]) 40156 | { 40157 | // ((v0 o0 c) o1 v1) o2 v2 40158 | typedef typename synthesize_vocov_expression0::node_type lcl_vocov_t; 40159 | 40160 | const lcl_vocov_t* vocov = static_cast<const lcl_vocov_t*>(branch[0]); 40161 | const Type& v0 = vocov->t0(); 40162 | const Type c = vocov->t1(); 40163 | const Type& v1 = vocov->t2(); 40164 | const Type& v2 = static_cast<details::variable_node<Type>*>(branch[1])->ref(); 40165 | const details::operator_type o0 = expr_gen.get_operator(vocov->f0()); 40166 | const details::operator_type o1 = expr_gen.get_operator(vocov->f1()); 40167 | const details::operator_type o2 = operation; 40168 | 40169 | binary_functor_t f0 = vocov->f0(); 40170 | binary_functor_t f1 = vocov->f1(); 40171 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 40172 | 40173 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 40174 | 40175 | expression_node_ptr result = error_node(); 40176 | 40177 | const bool synthesis_result = 40178 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 40179 | (expr_gen, id(expr_gen, o0, o1, o2), v0, c, v1, v2, result); 40180 | 40181 | if (synthesis_result) 40182 | return result; 40183 | else if (!expr_gen.valid_operator(o2,f2)) 40184 | return error_node(); 40185 | 40186 | exprtk_debug(("((v0 o0 c) o1 v1) o2 v2\n")); 40187 | 40188 | return node_type::allocate(*(expr_gen.node_allocator_), v0, c, v1, v2, f0, f1, f2); 40189 | } 40190 | 40191 | static inline std::string id(expression_generator<Type>& expr_gen, 40192 | const details::operator_type o0, 40193 | const details::operator_type o1, 40194 | const details::operator_type o2) 40195 | { 40196 | return details::build_string() 40197 | << "((t" << expr_gen.to_str(o0) 40198 | << "t)" << expr_gen.to_str(o1) 40199 | << "t)" << expr_gen.to_str(o2) 40200 | << "t" 40201 | } 40202 | }; 40203 | 40204 | struct synthesize_covovov_expression3 40205 | { 40206 | typedef typename covovov_t::type3 node_type; 40207 | typedef typename covovov_t::sf4_type sf4_type; 40208 | typedef typename node_type::T0 T0; 40209 | typedef typename node_type::T1 T1; 40210 | typedef typename node_type::T2 T2; 40211 | typedef typename node_type::T3 T3; 40212 | 40213 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 40214 | const details::operator_type& operation, 40215 | expression_node_ptr (&branch)[2]) 40216 | { 40217 | // ((c o0 v0) o1 v1) o2 v2 40218 | typedef typename synthesize_covov_expression0::node_type lcl_covov_t; 40219 | 40220 | const lcl_covov_t* covov = static_cast<const lcl_covov_t*>(branch[0]); 40221 | const Type c = covov->t0(); 40222 | const Type& v0 = covov->t1(); 40223 | const Type& v1 = covov->t2(); 40224 | const Type& v2 = static_cast<details::variable_node<Type>*>(branch[1])->ref(); 40225 | const details::operator_type o0 = expr_gen.get_operator(covov->f0()); 40226 | const details::operator_type o1 = expr_gen.get_operator(covov->f1()); 40227 | const details::operator_type o2 = operation; 40228 | 40229 | binary_functor_t f0 = covov->f0(); 40230 | binary_functor_t f1 = covov->f1(); 40231 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 40232 | 40233 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 40234 | 40235 | expression_node_ptr result = error_node(); 40236 | 40237 | const bool synthesis_result = 40238 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 40239 | (expr_gen, id(expr_gen, o0, o1, o2), c, v0, v1, v2, result); 40240 | 40241 | if (synthesis_result) 40242 | return result; 40243 | else if (!expr_gen.valid_operator(o2,f2)) 40244 | return error_node(); 40245 | 40246 | exprtk_debug(("((c o0 v0) o1 v1) o2 v2\n")); 40247 | 40248 | return node_type::allocate(*(expr_gen.node_allocator_), c, v0, v1, v2, f0, f1, f2); 40249 | } 40250 | 40251 | static inline std::string id(expression_generator<Type>& expr_gen, 40252 | const details::operator_type o0, 40253 | const details::operator_type o1, 40254 | const details::operator_type o2) 40255 | { 40256 | return details::build_string() 40257 | << "((t" << expr_gen.to_str(o0) 40258 | << "t)" << expr_gen.to_str(o1) 40259 | << "t)" << expr_gen.to_str(o2) 40260 | << "t" 40261 | } 40262 | }; 40263 | 40264 | struct synthesize_covocov_expression3 40265 | { 40266 | typedef typename covocov_t::type3 node_type; 40267 | typedef typename covocov_t::sf4_type sf4_type; 40268 | typedef typename node_type::T0 T0; 40269 | typedef typename node_type::T1 T1; 40270 | typedef typename node_type::T2 T2; 40271 | typedef typename node_type::T3 T3; 40272 | 40273 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 40274 | const details::operator_type& operation, 40275 | expression_node_ptr (&branch)[2]) 40276 | { 40277 | // ((c0 o0 v0) o1 c1) o2 v1 40278 | typedef typename synthesize_covoc_expression0::node_type lcl_covoc_t; 40279 | 40280 | const lcl_covoc_t* covoc = static_cast<const lcl_covoc_t*>(branch[0]); 40281 | const Type c0 = covoc->t0(); 40282 | const Type& v0 = covoc->t1(); 40283 | const Type c1 = covoc->t2(); 40284 | const Type& v1 = static_cast<details::variable_node<Type>*>(branch[1])->ref(); 40285 | const details::operator_type o0 = expr_gen.get_operator(covoc->f0()); 40286 | const details::operator_type o1 = expr_gen.get_operator(covoc->f1()); 40287 | const details::operator_type o2 = operation; 40288 | 40289 | binary_functor_t f0 = covoc->f0(); 40290 | binary_functor_t f1 = covoc->f1(); 40291 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 40292 | 40293 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 40294 | 40295 | expression_node_ptr result = error_node(); 40296 | 40297 | const bool synthesis_result = 40298 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 40299 | (expr_gen, id(expr_gen, o0, o1, o2), c0, v0, c1, v1, result); 40300 | 40301 | if (synthesis_result) 40302 | return result; 40303 | else if (!expr_gen.valid_operator(o2,f2)) 40304 | return error_node(); 40305 | 40306 | exprtk_debug(("((c0 o0 v0) o1 c1) o2 v1\n")); 40307 | 40308 | return node_type::allocate(*(expr_gen.node_allocator_), c0, v0, c1, v1, f0, f1, f2); 40309 | } 40310 | 40311 | static inline std::string id(expression_generator<Type>& expr_gen, 40312 | const details::operator_type o0, 40313 | const details::operator_type o1, 40314 | const details::operator_type o2) 40315 | { 40316 | return details::build_string() 40317 | << "((t" << expr_gen.to_str(o0) 40318 | << "t)" << expr_gen.to_str(o1) 40319 | << "t)" << expr_gen.to_str(o2) 40320 | << "t" 40321 | } 40322 | }; 40323 | 40324 | struct synthesize_vocovoc_expression3 40325 | { 40326 | typedef typename vocovoc_t::type3 node_type; 40327 | typedef typename vocovoc_t::sf4_type sf4_type; 40328 | typedef typename node_type::T0 T0; 40329 | typedef typename node_type::T1 T1; 40330 | typedef typename node_type::T2 T2; 40331 | typedef typename node_type::T3 T3; 40332 | 40333 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 40334 | const details::operator_type& operation, 40335 | expression_node_ptr (&branch)[2]) 40336 | { 40337 | // ((v0 o0 c0) o1 v1) o2 c1 40338 | typedef typename synthesize_vocov_expression0::node_type lcl_vocov_t; 40339 | 40340 | const lcl_vocov_t* vocov = static_cast<const lcl_vocov_t*>(branch[0]); 40341 | const Type& v0 = vocov->t0(); 40342 | const Type c0 = vocov->t1(); 40343 | const Type& v1 = vocov->t2(); 40344 | const Type c1 = static_cast<details::literal_node<Type>*>(branch[1])->value(); 40345 | const details::operator_type o0 = expr_gen.get_operator(vocov->f0()); 40346 | const details::operator_type o1 = expr_gen.get_operator(vocov->f1()); 40347 | const details::operator_type o2 = operation; 40348 | 40349 | binary_functor_t f0 = vocov->f0(); 40350 | binary_functor_t f1 = vocov->f1(); 40351 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 40352 | 40353 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 40354 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 40355 | 40356 | expression_node_ptr result = error_node(); 40357 | 40358 | const bool synthesis_result = 40359 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 40360 | (expr_gen, id(expr_gen, o0, o1, o2), v0, c0, v1, c1, result); 40361 | 40362 | if (synthesis_result) 40363 | return result; 40364 | else if (!expr_gen.valid_operator(o2,f2)) 40365 | return error_node(); 40366 | 40367 | exprtk_debug(("((v0 o0 c0) o1 v1) o2 c1\n")); 40368 | 40369 | return node_type::allocate(*(expr_gen.node_allocator_), v0, c0, v1, c1, f0, f1, f2); 40370 | } 40371 | 40372 | static inline std::string id(expression_generator<Type>& expr_gen, 40373 | const details::operator_type o0, 40374 | const details::operator_type o1, 40375 | const details::operator_type o2) 40376 | { 40377 | return details::build_string() 40378 | << "((t" << expr_gen.to_str(o0) 40379 | << "t)" << expr_gen.to_str(o1) 40380 | << "t)" << expr_gen.to_str(o2) 40381 | << "t" 40382 | } 40383 | }; 40384 | 40385 | struct synthesize_covovoc_expression3 40386 | { 40387 | typedef typename covovoc_t::type3 node_type; 40388 | typedef typename covovoc_t::sf4_type sf4_type; 40389 | typedef typename node_type::T0 T0; 40390 | typedef typename node_type::T1 T1; 40391 | typedef typename node_type::T2 T2; 40392 | typedef typename node_type::T3 T3; 40393 | 40394 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 40395 | const details::operator_type& operation, 40396 | expression_node_ptr (&branch)[2]) 40397 | { 40398 | // ((c0 o0 v0) o1 v1) o2 c1 40399 | typedef typename synthesize_covov_expression0::node_type lcl_covov_t; 40400 | 40401 | const lcl_covov_t* covov = static_cast<const lcl_covov_t*>(branch[0]); 40402 | const Type c0 = covov->t0(); 40403 | const Type& v0 = covov->t1(); 40404 | const Type& v1 = covov->t2(); 40405 | const Type c1 = static_cast<details::literal_node<Type>*>(branch[1])->value(); 40406 | const details::operator_type o0 = expr_gen.get_operator(covov->f0()); 40407 | const details::operator_type o1 = expr_gen.get_operator(covov->f1()); 40408 | const details::operator_type o2 = operation; 40409 | 40410 | binary_functor_t f0 = covov->f0(); 40411 | binary_functor_t f1 = covov->f1(); 40412 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 40413 | 40414 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 40415 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 40416 | 40417 | expression_node_ptr result = error_node(); 40418 | 40419 | const bool synthesis_result = 40420 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 40421 | (expr_gen, id(expr_gen, o0, o1, o2), c0, v0, v1, c1, result); 40422 | 40423 | if (synthesis_result) 40424 | return result; 40425 | else if (!expr_gen.valid_operator(o2,f2)) 40426 | return error_node(); 40427 | 40428 | exprtk_debug(("((c0 o0 v0) o1 v1) o2 c1\n")); 40429 | 40430 | return node_type::allocate(*(expr_gen.node_allocator_), c0, v0, v1, c1, f0, f1, f2); 40431 | } 40432 | 40433 | static inline std::string id(expression_generator<Type>& expr_gen, 40434 | const details::operator_type o0, 40435 | const details::operator_type o1, 40436 | const details::operator_type o2) 40437 | { 40438 | return details::build_string() 40439 | << "((t" << expr_gen.to_str(o0) 40440 | << "t)" << expr_gen.to_str(o1) 40441 | << "t)" << expr_gen.to_str(o2) 40442 | << "t" 40443 | } 40444 | }; 40445 | 40446 | struct synthesize_vococov_expression3 40447 | { 40448 | typedef typename vococov_t::type3 node_type; 40449 | typedef typename vococov_t::sf4_type sf4_type; 40450 | typedef typename node_type::T0 T0; 40451 | typedef typename node_type::T1 T1; 40452 | typedef typename node_type::T2 T2; 40453 | typedef typename node_type::T3 T3; 40454 | 40455 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 40456 | const details::operator_type& operation, 40457 | expression_node_ptr (&branch)[2]) 40458 | { 40459 | // ((v0 o0 c0) o1 c1) o2 v1 40460 | typedef typename synthesize_vococ_expression0::node_type lcl_vococ_t; 40461 | 40462 | const lcl_vococ_t* vococ = static_cast<const lcl_vococ_t*>(branch[0]); 40463 | const Type& v0 = vococ->t0(); 40464 | const Type c0 = vococ->t1(); 40465 | const Type c1 = vococ->t2(); 40466 | const Type& v1 = static_cast<details::variable_node<Type>*>(branch[1])->ref(); 40467 | const details::operator_type o0 = expr_gen.get_operator(vococ->f0()); 40468 | const details::operator_type o1 = expr_gen.get_operator(vococ->f1()); 40469 | const details::operator_type o2 = operation; 40470 | 40471 | binary_functor_t f0 = vococ->f0(); 40472 | binary_functor_t f1 = vococ->f1(); 40473 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 40474 | 40475 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 40476 | 40477 | expression_node_ptr result = error_node(); 40478 | 40479 | const bool synthesis_result = 40480 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 40481 | (expr_gen, id(expr_gen, o0, o1, o2), v0, c0, c1, v1, result); 40482 | 40483 | if (synthesis_result) 40484 | return result; 40485 | else if (!expr_gen.valid_operator(o2,f2)) 40486 | return error_node(); 40487 | 40488 | exprtk_debug(("((v0 o0 c0) o1 c1) o2 v1\n")); 40489 | 40490 | return node_type::allocate(*(expr_gen.node_allocator_), v0, c0, c1, v1, f0, f1, f2); 40491 | } 40492 | 40493 | static inline std::string id(expression_generator<Type>& expr_gen, 40494 | const details::operator_type o0, 40495 | const details::operator_type o1, 40496 | const details::operator_type o2) 40497 | { 40498 | return details::build_string() 40499 | << "((t" << expr_gen.to_str(o0) 40500 | << "t)" << expr_gen.to_str(o1) 40501 | << "t)" << expr_gen.to_str(o2) 40502 | << "t" 40503 | } 40504 | }; 40505 | 40506 | struct synthesize_vovovov_expression4 40507 | { 40508 | typedef typename vovovov_t::type4 node_type; 40509 | typedef typename vovovov_t::sf4_type sf4_type; 40510 | typedef typename node_type::T0 T0; 40511 | typedef typename node_type::T1 T1; 40512 | typedef typename node_type::T2 T2; 40513 | typedef typename node_type::T3 T3; 40514 | 40515 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 40516 | const details::operator_type& operation, 40517 | expression_node_ptr (&branch)[2]) 40518 | { 40519 | // (v0 o0 (v1 o1 v2)) o2 v3 40520 | typedef typename synthesize_vovov_expression1::node_type lcl_vovov_t; 40521 | 40522 | const lcl_vovov_t* vovov = static_cast<const lcl_vovov_t*>(branch[0]); 40523 | const Type& v0 = vovov->t0(); 40524 | const Type& v1 = vovov->t1(); 40525 | const Type& v2 = vovov->t2(); 40526 | const Type& v3 = static_cast<details::variable_node<Type>*>(branch[1])->ref(); 40527 | const details::operator_type o0 = expr_gen.get_operator(vovov->f0()); 40528 | const details::operator_type o1 = expr_gen.get_operator(vovov->f1()); 40529 | const details::operator_type o2 = operation; 40530 | 40531 | binary_functor_t f0 = vovov->f0(); 40532 | binary_functor_t f1 = vovov->f1(); 40533 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 40534 | 40535 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 40536 | 40537 | expression_node_ptr result = error_node(); 40538 | 40539 | const bool synthesis_result = 40540 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 40541 | (expr_gen, id(expr_gen, o0, o1, o2), v0, v1, v2, v3, result); 40542 | 40543 | if (synthesis_result) 40544 | return result; 40545 | else if (!expr_gen.valid_operator(o2,f2)) 40546 | return error_node(); 40547 | 40548 | exprtk_debug(("(v0 o0 (v1 o1 v2)) o2 v3\n")); 40549 | 40550 | return node_type::allocate(*(expr_gen.node_allocator_), v0, v1, v2, v3, f0, f1, f2); 40551 | } 40552 | 40553 | static inline std::string id(expression_generator<Type>& expr_gen, 40554 | const details::operator_type o0, 40555 | const details::operator_type o1, 40556 | const details::operator_type o2) 40557 | { 40558 | return details::build_string() 40559 | << "(t" << expr_gen.to_str(o0) 40560 | << "(t" << expr_gen.to_str(o1) 40561 | << "t)" << expr_gen.to_str(o2) 40562 | << "t" 40563 | } 40564 | }; 40565 | 40566 | struct synthesize_vovovoc_expression4 40567 | { 40568 | typedef typename vovovoc_t::type4 node_type; 40569 | typedef typename vovovoc_t::sf4_type sf4_type; 40570 | typedef typename node_type::T0 T0; 40571 | typedef typename node_type::T1 T1; 40572 | typedef typename node_type::T2 T2; 40573 | typedef typename node_type::T3 T3; 40574 | 40575 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 40576 | const details::operator_type& operation, 40577 | expression_node_ptr (&branch)[2]) 40578 | { 40579 | // ((v0 o0 (v1 o1 v2)) o2 c) 40580 | typedef typename synthesize_vovov_expression1::node_type lcl_vovov_t; 40581 | 40582 | const lcl_vovov_t* vovov = static_cast<const lcl_vovov_t*>(branch[0]); 40583 | const Type& v0 = vovov->t0(); 40584 | const Type& v1 = vovov->t1(); 40585 | const Type& v2 = vovov->t2(); 40586 | const Type c = static_cast<details::literal_node<Type>*>(branch[1])->value(); 40587 | const details::operator_type o0 = expr_gen.get_operator(vovov->f0()); 40588 | const details::operator_type o1 = expr_gen.get_operator(vovov->f1()); 40589 | const details::operator_type o2 = operation; 40590 | 40591 | binary_functor_t f0 = vovov->f0(); 40592 | binary_functor_t f1 = vovov->f1(); 40593 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 40594 | 40595 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 40596 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 40597 | 40598 | expression_node_ptr result = error_node(); 40599 | 40600 | const bool synthesis_result = 40601 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 40602 | (expr_gen, id(expr_gen, o0, o1, o2), v0, v1, v2, c, result); 40603 | 40604 | if (synthesis_result) 40605 | return result; 40606 | else if (!expr_gen.valid_operator(o2,f2)) 40607 | return error_node(); 40608 | 40609 | exprtk_debug(("((v0 o0 (v1 o1 v2)) o2 c)\n")); 40610 | 40611 | return node_type::allocate(*(expr_gen.node_allocator_), v0, v1, v2, c, f0, f1, f2); 40612 | } 40613 | 40614 | static inline std::string id(expression_generator<Type>& expr_gen, 40615 | const details::operator_type o0, 40616 | const details::operator_type o1, 40617 | const details::operator_type o2) 40618 | { 40619 | return details::build_string() 40620 | << "(t" << expr_gen.to_str(o0) 40621 | << "(t" << expr_gen.to_str(o1) 40622 | << "t)" << expr_gen.to_str(o2) 40623 | << "t" 40624 | } 40625 | }; 40626 | 40627 | struct synthesize_vovocov_expression4 40628 | { 40629 | typedef typename vovocov_t::type4 node_type; 40630 | typedef typename vovocov_t::sf4_type sf4_type; 40631 | typedef typename node_type::T0 T0; 40632 | typedef typename node_type::T1 T1; 40633 | typedef typename node_type::T2 T2; 40634 | typedef typename node_type::T3 T3; 40635 | 40636 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 40637 | const details::operator_type& operation, 40638 | expression_node_ptr (&branch)[2]) 40639 | { 40640 | // ((v0 o0 (v1 o1 c)) o2 v1) 40641 | typedef typename synthesize_vovoc_expression1::node_type lcl_vovoc_t; 40642 | 40643 | const lcl_vovoc_t* vovoc = static_cast<const lcl_vovoc_t*>(branch[0]); 40644 | const Type& v0 = vovoc->t0(); 40645 | const Type& v1 = vovoc->t1(); 40646 | const Type c = vovoc->t2(); 40647 | const Type& v2 = static_cast<details::variable_node<Type>*>(branch[1])->ref(); 40648 | const details::operator_type o0 = expr_gen.get_operator(vovoc->f0()); 40649 | const details::operator_type o1 = expr_gen.get_operator(vovoc->f1()); 40650 | const details::operator_type o2 = operation; 40651 | 40652 | binary_functor_t f0 = vovoc->f0(); 40653 | binary_functor_t f1 = vovoc->f1(); 40654 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 40655 | 40656 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 40657 | 40658 | expression_node_ptr result = error_node(); 40659 | 40660 | const bool synthesis_result = 40661 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 40662 | (expr_gen, id(expr_gen, o0, o1, o2), v0, v1, c, v2, result); 40663 | 40664 | if (synthesis_result) 40665 | return result; 40666 | else if (!expr_gen.valid_operator(o2,f2)) 40667 | return error_node(); 40668 | 40669 | exprtk_debug(("((v0 o0 (v1 o1 c)) o2 v1)\n")); 40670 | 40671 | return node_type::allocate(*(expr_gen.node_allocator_), v0, v1, c, v2, f0, f1, f2); 40672 | } 40673 | 40674 | static inline std::string id(expression_generator<Type>& expr_gen, 40675 | const details::operator_type o0, 40676 | const details::operator_type o1, 40677 | const details::operator_type o2) 40678 | { 40679 | return details::build_string() 40680 | << "(t" << expr_gen.to_str(o0) 40681 | << "(t" << expr_gen.to_str(o1) 40682 | << "t)" << expr_gen.to_str(o2) 40683 | << "t" 40684 | } 40685 | }; 40686 | 40687 | struct synthesize_vocovov_expression4 40688 | { 40689 | typedef typename vocovov_t::type4 node_type; 40690 | typedef typename vocovov_t::sf4_type sf4_type; 40691 | typedef typename node_type::T0 T0; 40692 | typedef typename node_type::T1 T1; 40693 | typedef typename node_type::T2 T2; 40694 | typedef typename node_type::T3 T3; 40695 | 40696 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 40697 | const details::operator_type& operation, 40698 | expression_node_ptr (&branch)[2]) 40699 | { 40700 | // ((v0 o0 (c o1 v1)) o2 v2) 40701 | typedef typename synthesize_vocov_expression1::node_type lcl_vocov_t; 40702 | 40703 | const lcl_vocov_t* vocov = static_cast<const lcl_vocov_t*>(branch[0]); 40704 | const Type& v0 = vocov->t0(); 40705 | const Type c = vocov->t1(); 40706 | const Type& v1 = vocov->t2(); 40707 | const Type& v2 = static_cast<details::variable_node<Type>*>(branch[1])->ref(); 40708 | const details::operator_type o0 = expr_gen.get_operator(vocov->f0()); 40709 | const details::operator_type o1 = expr_gen.get_operator(vocov->f1()); 40710 | const details::operator_type o2 = operation; 40711 | 40712 | binary_functor_t f0 = vocov->f0(); 40713 | binary_functor_t f1 = vocov->f1(); 40714 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 40715 | 40716 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 40717 | expression_node_ptr result = error_node(); 40718 | 40719 | const bool synthesis_result = 40720 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 40721 | (expr_gen, id(expr_gen, o0, o1, o2), v0, c, v1, v2, result); 40722 | 40723 | if (synthesis_result) 40724 | return result; 40725 | else if (!expr_gen.valid_operator(o2,f2)) 40726 | return error_node(); 40727 | 40728 | exprtk_debug(("((v0 o0 (c o1 v1)) o2 v2)\n")); 40729 | 40730 | return node_type::allocate(*(expr_gen.node_allocator_), v0, c, v1, v2, f0, f1, f2); 40731 | } 40732 | 40733 | static inline std::string id(expression_generator<Type>& expr_gen, 40734 | const details::operator_type o0, 40735 | const details::operator_type o1, 40736 | const details::operator_type o2) 40737 | { 40738 | return details::build_string() 40739 | << "(t" << expr_gen.to_str(o0) 40740 | << "(t" << expr_gen.to_str(o1) 40741 | << "t)" << expr_gen.to_str(o2) 40742 | << "t" 40743 | } 40744 | }; 40745 | 40746 | struct synthesize_covovov_expression4 40747 | { 40748 | typedef typename covovov_t::type4 node_type; 40749 | typedef typename covovov_t::sf4_type sf4_type; 40750 | typedef typename node_type::T0 T0; 40751 | typedef typename node_type::T1 T1; 40752 | typedef typename node_type::T2 T2; 40753 | typedef typename node_type::T3 T3; 40754 | 40755 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 40756 | const details::operator_type& operation, 40757 | expression_node_ptr (&branch)[2]) 40758 | { 40759 | // ((c o0 (v0 o1 v1)) o2 v2) 40760 | typedef typename synthesize_covov_expression1::node_type lcl_covov_t; 40761 | 40762 | const lcl_covov_t* covov = static_cast<const lcl_covov_t*>(branch[0]); 40763 | const Type c = covov->t0(); 40764 | const Type& v0 = covov->t1(); 40765 | const Type& v1 = covov->t2(); 40766 | const Type& v2 = static_cast<details::variable_node<Type>*>(branch[1])->ref(); 40767 | const details::operator_type o0 = expr_gen.get_operator(covov->f0()); 40768 | const details::operator_type o1 = expr_gen.get_operator(covov->f1()); 40769 | const details::operator_type o2 = operation; 40770 | 40771 | binary_functor_t f0 = covov->f0(); 40772 | binary_functor_t f1 = covov->f1(); 40773 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 40774 | 40775 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 40776 | 40777 | expression_node_ptr result = error_node(); 40778 | 40779 | const bool synthesis_result = 40780 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 40781 | (expr_gen, id(expr_gen, o0, o1, o2), c, v0, v1, v2, result); 40782 | 40783 | if (synthesis_result) 40784 | return result; 40785 | else if (!expr_gen.valid_operator(o2,f2)) 40786 | return error_node(); 40787 | 40788 | exprtk_debug(("((c o0 (v0 o1 v1)) o2 v2)\n")); 40789 | 40790 | return node_type::allocate(*(expr_gen.node_allocator_), c, v0, v1, v2, f0, f1, f2); 40791 | } 40792 | 40793 | static inline std::string id(expression_generator<Type>& expr_gen, 40794 | const details::operator_type o0, 40795 | const details::operator_type o1, 40796 | const details::operator_type o2) 40797 | { 40798 | return details::build_string() 40799 | << "(t" << expr_gen.to_str(o0) 40800 | << "(t" << expr_gen.to_str(o1) 40801 | << "t)" << expr_gen.to_str(o2) 40802 | << "t" 40803 | } 40804 | }; 40805 | 40806 | struct synthesize_covocov_expression4 40807 | { 40808 | typedef typename covocov_t::type4 node_type; 40809 | typedef typename covocov_t::sf4_type sf4_type; 40810 | typedef typename node_type::T0 T0; 40811 | typedef typename node_type::T1 T1; 40812 | typedef typename node_type::T2 T2; 40813 | typedef typename node_type::T3 T3; 40814 | 40815 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 40816 | const details::operator_type& operation, 40817 | expression_node_ptr (&branch)[2]) 40818 | { 40819 | // ((c0 o0 (v0 o1 c1)) o2 v1) 40820 | typedef typename synthesize_covoc_expression1::node_type lcl_covoc_t; 40821 | 40822 | const lcl_covoc_t* covoc = static_cast<const lcl_covoc_t*>(branch[0]); 40823 | const Type c0 = covoc->t0(); 40824 | const Type& v0 = covoc->t1(); 40825 | const Type c1 = covoc->t2(); 40826 | const Type& v1 = static_cast<details::variable_node<Type>*>(branch[1])->ref(); 40827 | const details::operator_type o0 = expr_gen.get_operator(covoc->f0()); 40828 | const details::operator_type o1 = expr_gen.get_operator(covoc->f1()); 40829 | const details::operator_type o2 = operation; 40830 | 40831 | binary_functor_t f0 = covoc->f0(); 40832 | binary_functor_t f1 = covoc->f1(); 40833 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 40834 | 40835 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 40836 | 40837 | expression_node_ptr result = error_node(); 40838 | 40839 | const bool synthesis_result = 40840 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 40841 | (expr_gen, id(expr_gen, o0, o1, o2), c0, v0, c1, v1, result); 40842 | 40843 | if (synthesis_result) 40844 | return result; 40845 | else if (!expr_gen.valid_operator(o2,f2)) 40846 | return error_node(); 40847 | 40848 | exprtk_debug(("((c0 o0 (v0 o1 c1)) o2 v1)\n")); 40849 | 40850 | return node_type::allocate(*(expr_gen.node_allocator_), c0, v0, c1, v1, f0, f1, f2); 40851 | } 40852 | 40853 | static inline std::string id(expression_generator<Type>& expr_gen, 40854 | const details::operator_type o0, 40855 | const details::operator_type o1, 40856 | const details::operator_type o2) 40857 | { 40858 | return details::build_string() 40859 | << "(t" << expr_gen.to_str(o0) 40860 | << "(t" << expr_gen.to_str(o1) 40861 | << "t)" << expr_gen.to_str(o2) 40862 | << "t" 40863 | } 40864 | }; 40865 | 40866 | struct synthesize_vocovoc_expression4 40867 | { 40868 | typedef typename vocovoc_t::type4 node_type; 40869 | typedef typename vocovoc_t::sf4_type sf4_type; 40870 | typedef typename node_type::T0 T0; 40871 | typedef typename node_type::T1 T1; 40872 | typedef typename node_type::T2 T2; 40873 | typedef typename node_type::T3 T3; 40874 | 40875 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 40876 | const details::operator_type& operation, 40877 | expression_node_ptr (&branch)[2]) 40878 | { 40879 | // ((v0 o0 (c0 o1 v1)) o2 c1) 40880 | typedef typename synthesize_vocov_expression1::node_type lcl_vocov_t; 40881 | 40882 | const lcl_vocov_t* vocov = static_cast<const lcl_vocov_t*>(branch[0]); 40883 | const Type& v0 = vocov->t0(); 40884 | const Type c0 = vocov->t1(); 40885 | const Type& v1 = vocov->t2(); 40886 | const Type c1 = static_cast<details::literal_node<Type>*>(branch[1])->value(); 40887 | const details::operator_type o0 = expr_gen.get_operator(vocov->f0()); 40888 | const details::operator_type o1 = expr_gen.get_operator(vocov->f1()); 40889 | const details::operator_type o2 = operation; 40890 | 40891 | binary_functor_t f0 = vocov->f0(); 40892 | binary_functor_t f1 = vocov->f1(); 40893 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 40894 | 40895 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 40896 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 40897 | 40898 | expression_node_ptr result = error_node(); 40899 | 40900 | const bool synthesis_result = 40901 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 40902 | (expr_gen, id(expr_gen, o0, o1, o2), v0, c0, v1, c1, result); 40903 | 40904 | if (synthesis_result) 40905 | return result; 40906 | else if (!expr_gen.valid_operator(o2,f2)) 40907 | return error_node(); 40908 | 40909 | exprtk_debug(("((v0 o0 (c0 o1 v1)) o2 c1)\n")); 40910 | 40911 | return node_type::allocate(*(expr_gen.node_allocator_), v0, c0, v1, c1, f0, f1, f2); 40912 | } 40913 | 40914 | static inline std::string id(expression_generator<Type>& expr_gen, 40915 | const details::operator_type o0, 40916 | const details::operator_type o1, 40917 | const details::operator_type o2) 40918 | { 40919 | return details::build_string() 40920 | << "(t" << expr_gen.to_str(o0) 40921 | << "(t" << expr_gen.to_str(o1) 40922 | << "t)" << expr_gen.to_str(o2) 40923 | << "t" 40924 | } 40925 | }; 40926 | 40927 | struct synthesize_covovoc_expression4 40928 | { 40929 | typedef typename covovoc_t::type4 node_type; 40930 | typedef typename covovoc_t::sf4_type sf4_type; 40931 | typedef typename node_type::T0 T0; 40932 | typedef typename node_type::T1 T1; 40933 | typedef typename node_type::T2 T2; 40934 | typedef typename node_type::T3 T3; 40935 | 40936 | static inline expression_node_ptr process(expression_generator<Type>& expr_gen, 40937 | const details::operator_type& operation, 40938 | expression_node_ptr (&branch)[2]) 40939 | { 40940 | // ((c0 o0 (v0 o1 v1)) o2 c1) 40941 | typedef typename synthesize_covov_expression1::node_type lcl_covov_t; 40942 | 40943 | const lcl_covov_t* covov = static_cast<const lcl_covov_t*>(branch[0]); 40944 | const Type c0 = covov->t0(); 40945 | const Type& v0 = covov->t1(); 40946 | const Type& v1 = covov->t2(); 40947 | const Type c1 = static_cast<details::literal_node<Type>*>(branch[1])->value(); 40948 | const details::operator_type o0 = expr_gen.get_operator(covov->f0()); 40949 | const details::operator_type o1 = expr_gen.get_operator(covov->f1()); 40950 | const details::operator_type o2 = operation; 40951 | 40952 | binary_functor_t f0 = covov->f0(); 40953 | binary_functor_t f1 = covov->f1(); 40954 | binary_functor_t f2 = reinterpret_cast<binary_functor_t>(0); 40955 | 40956 | details::free_node(*(expr_gen.node_allocator_),branch[0]); 40957 | details::free_node(*(expr_gen.node_allocator_),branch[1]); 40958 | 40959 | expression_node_ptr result = error_node(); 40960 | 40961 | const bool synthesis_result = 40962 | synthesize_sf4ext_expression::template compile<T0, T1, T2, T3> 40963 | (expr_gen, id(expr_gen, o0, o1, o2), c0, v0, v1, c1, result); 40964 | 40965 | if (synthesis_result) 40966 | return result; 40967 | else if (!expr_gen.valid_operator(o2,f2)) 40968 | return error_node(); 40969 | 40970 | exprtk_debug(("((c0 o0 (v0 o1 v1)) o2 c1)\n")); 40971 | 40972 | return node_type::allocate(*(expr_gen.node_allocator_), c0, v0, v1, c1, f0, f1, f2); 40973 | } 40974 | 40975 | static inline std::string id(expression_generator<Type>& expr_gen, 40976 | const details::operator_type o0, 40977 | const details::operator_type o1, 40978 | const details::operator_type o2) 40979 | { 40980 | return details::build_string() 40981 | << "(t" << expr_gen.to_str(o0) 40982 | << "(t" << expr_gen.to_str(o1) 40983 | << "t)" << expr_gen.to_str(o2) 40984 | << "t" 40985 | } 40986 | }; 40987 | 40988 | struct synthesize_vococov_expression4 40989 | { 40990 | typedef typename vococov_t::type4 node_type; 40991 | static inline expression_node_ptr process(expression_generator<Type>&, 40992 | const details::operator_type&, 40993 | expression_node_ptr (&)[2]) 40994 | { 40995 | // ((v0 o0 (c0 o1 c1)) o2 v1) - Not possible 40996 | exprtk_debug(("((v0 o0 (c0 o1 c1)) o2 v1) - Not possible\n")); 40997 | return error_node(); 40998 | } 40999 | 41000 | static inline std::string id(expression_generator<Type>&, 41001 | const details::operator_type, 41002 | const details::operator_type, 41003 | const details::operator_type) 41004 | { 41005 | return "INVALID" 41006 | } 41007 | }; 41008 | #endif 41009 | 41010 | inline expression_node_ptr synthesize_uvouv_expression(const details::operator_type& operation, expression_node_ptr (&branch)[2]) 41011 | { 41012 | // Definition: uv o uv 41013 | details::operator_type o0 = static_cast<details::uv_base_node<Type>*>(branch[0])->operation(); 41014 | details::operator_type o1 = static_cast<details::uv_base_node<Type>*>(branch[1])->operation(); 41015 | const Type& v0 = static_cast<details::uv_base_node<Type>*>(branch[0])->v(); 41016 | const Type& v1 = static_cast<details::uv_base_node<Type>*>(branch[1])->v(); 41017 | unary_functor_t u0 = reinterpret_cast<unary_functor_t> (0); 41018 | unary_functor_t u1 = reinterpret_cast<unary_functor_t> (0); 41019 | binary_functor_t f = reinterpret_cast<binary_functor_t>(0); 41020 | 41021 | if (!valid_operator(o0,u0)) 41022 | return error_node(); 41023 | else if (!valid_operator(o1,u1)) 41024 | return error_node(); 41025 | else if (!valid_operator(operation,f)) 41026 | return error_node(); 41027 | 41028 | expression_node_ptr result = error_node(); 41029 | 41030 | if ( 41031 | (details::e_neg == o0) && 41032 | (details::e_neg == o1) 41033 | ) 41034 | { 41035 | switch (operation) 41036 | { 41037 | // (-v0 + -v1) --> -(v0 + v1) 41038 | case details::e_add : result = (*this)(details::e_neg, 41039 | node_allocator_-> 41040 | allocate_rr<typename details:: 41041 | vov_node<Type,details::add_op<Type> > >(v0, v1)); 41042 | exprtk_debug(("(-v0 + -v1) --> -(v0 + v1)\n")); 41043 | break; 41044 | 41045 | // (-v0 - -v1) --> (v1 - v0) 41046 | case details::e_sub : result = node_allocator_-> 41047 | allocate_rr<typename details:: 41048 | vov_node<Type,details::sub_op<Type> > >(v1, v0); 41049 | exprtk_debug(("(-v0 - -v1) --> (v1 - v0)\n")); 41050 | break; 41051 | 41052 | // (-v0 * -v1) --> (v0 * v1) 41053 | case details::e_mul : result = node_allocator_-> 41054 | allocate_rr<typename details:: 41055 | vov_node<Type,details::mul_op<Type> > >(v0, v1); 41056 | exprtk_debug(("(-v0 * -v1) --> (v0 * v1)\n")); 41057 | break; 41058 | 41059 | // (-v0 / -v1) --> (v0 / v1) 41060 | case details::e_div : result = node_allocator_-> 41061 | allocate_rr<typename details:: 41062 | vov_node<Type,details::div_op<Type> > >(v0, v1); 41063 | exprtk_debug(("(-v0 / -v1) --> (v0 / v1)\n")); 41064 | break; 41065 | 41066 | default : break; 41067 | } 41068 | } 41069 | 41070 | if (0 == result) 41071 | { 41072 | result = node_allocator_-> 41073 | allocate_rrrrr<typename details::uvouv_node<Type> >(v0, v1, u0, u1, f); 41074 | } 41075 | 41076 | details::free_all_nodes(*node_allocator_,branch); 41077 | return result; 41078 | } 41079 | 41080 | #undef basic_opr_switch_statements 41081 | #undef extended_opr_switch_statements 41082 | #undef unary_opr_switch_statements 41083 | 41084 | #ifndef exprtk_disable_string_capabilities 41085 | 41086 | #define string_opr_switch_statements \ 41087 | case_stmt(details::e_lt , details::lt_op ) \ 41088 | case_stmt(details::e_lte , details::lte_op ) \ 41089 | case_stmt(details::e_gt , details::gt_op ) \ 41090 | case_stmt(details::e_gte , details::gte_op ) \ 41091 | case_stmt(details::e_eq , details::eq_op ) \ 41092 | case_stmt(details::e_ne , details::ne_op ) \ 41093 | case_stmt(details::e_in , details::in_op ) \ 41094 | case_stmt(details::e_like , details::like_op ) \ 41095 | case_stmt(details::e_ilike , details::ilike_op) \ 41096 | 41097 | template <typename T0, typename T1> 41098 | inline expression_node_ptr synthesize_str_xrox_expression_impl(const details::operator_type& opr, 41099 | T0 s0, T1 s1, 41100 | range_t rp0) 41101 | { 41102 | switch (opr) 41103 | { 41104 | #define case_stmt(op0, op1) \ 41105 | case op0 : return node_allocator_-> \ 41106 | allocate_ttt<typename details::str_xrox_node<Type,T0,T1,range_t,op1<Type> >,T0,T1> \ 41107 | (s0, s1, rp0); \ 41108 | 41109 | string_opr_switch_statements 41110 | #undef case_stmt 41111 | default : return error_node(); 41112 | } 41113 | } 41114 | 41115 | template <typename T0, typename T1> 41116 | inline expression_node_ptr synthesize_str_xoxr_expression_impl(const details::operator_type& opr, 41117 | T0 s0, T1 s1, 41118 | range_t rp1) 41119 | { 41120 | switch (opr) 41121 | { 41122 | #define case_stmt(op0, op1) \ 41123 | case op0 : return node_allocator_-> \ 41124 | allocate_ttt<typename details::str_xoxr_node<Type,T0,T1,range_t,op1<Type> >,T0,T1> \ 41125 | (s0, s1, rp1); \ 41126 | 41127 | string_opr_switch_statements 41128 | #undef case_stmt 41129 | default : return error_node(); 41130 | } 41131 | } 41132 | 41133 | template <typename T0, typename T1> 41134 | inline expression_node_ptr synthesize_str_xroxr_expression_impl(const details::operator_type& opr, 41135 | T0 s0, T1 s1, 41136 | range_t rp0, range_t rp1) 41137 | { 41138 | switch (opr) 41139 | { 41140 | #define case_stmt(op0, op1) \ 41141 | case op0 : return node_allocator_-> \ 41142 | allocate_tttt<typename details::str_xroxr_node<Type,T0,T1,range_t,op1<Type> >,T0,T1> \ 41143 | (s0, s1, rp0, rp1); \ 41144 | 41145 | string_opr_switch_statements 41146 | #undef case_stmt 41147 | default : return error_node(); 41148 | } 41149 | } 41150 | 41151 | template <typename T0, typename T1> 41152 | inline expression_node_ptr synthesize_sos_expression_impl(const details::operator_type& opr, T0 s0, T1 s1) 41153 | { 41154 | switch (opr) 41155 | { 41156 | #define case_stmt(op0, op1) \ 41157 | case op0 : return node_allocator_-> \ 41158 | allocate_tt<typename details::sos_node<Type,T0,T1,op1<Type> >,T0,T1>(s0, s1); \ 41159 | 41160 | string_opr_switch_statements 41161 | #undef case_stmt 41162 | default : return error_node(); 41163 | } 41164 | } 41165 | 41166 | inline expression_node_ptr synthesize_sos_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) 41167 | { 41168 | std::string& s0 = static_cast<details::stringvar_node<Type>*>(branch[0])->ref(); 41169 | std::string& s1 = static_cast<details::stringvar_node<Type>*>(branch[1])->ref(); 41170 | 41171 | return synthesize_sos_expression_impl<std::string&,std::string&>(opr, s0, s1); 41172 | } 41173 | 41174 | inline expression_node_ptr synthesize_sros_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) 41175 | { 41176 | std::string& s0 = static_cast<details::string_range_node<Type>*>(branch[0])->ref (); 41177 | std::string& s1 = static_cast<details::stringvar_node<Type>*> (branch[1])->ref (); 41178 | range_t rp0 = static_cast<details::string_range_node<Type>*>(branch[0])->range(); 41179 | 41180 | static_cast<details::string_range_node<Type>*>(branch[0])->range_ref().clear(); 41181 | 41182 | details::free_node(*node_allocator_,branch[0]); 41183 | 41184 | return synthesize_str_xrox_expression_impl<std::string&,std::string&>(opr, s0, s1, rp0); 41185 | } 41186 | 41187 | inline expression_node_ptr synthesize_sosr_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) 41188 | { 41189 | std::string& s0 = static_cast<details::stringvar_node<Type>*> (branch[0])->ref (); 41190 | std::string& s1 = static_cast<details::string_range_node<Type>*>(branch[1])->ref (); 41191 | range_t rp1 = static_cast<details::string_range_node<Type>*>(branch[1])->range(); 41192 | 41193 | static_cast<details::string_range_node<Type>*>(branch[1])->range_ref().clear(); 41194 | 41195 | details::free_node(*node_allocator_,branch[1]); 41196 | 41197 | return synthesize_str_xoxr_expression_impl<std::string&,std::string&>(opr, s0, s1, rp1); 41198 | } 41199 | 41200 | inline expression_node_ptr synthesize_socsr_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) 41201 | { 41202 | std::string& s0 = static_cast<details::stringvar_node<Type>*> (branch[0])->ref (); 41203 | std::string s1 = static_cast<details::const_string_range_node<Type>*>(branch[1])->str (); 41204 | range_t rp1 = static_cast<details::const_string_range_node<Type>*>(branch[1])->range(); 41205 | 41206 | static_cast<details::const_string_range_node<Type>*>(branch[1])->range_ref().clear(); 41207 | 41208 | details::free_node(*node_allocator_,branch[1]); 41209 | 41210 | return synthesize_str_xoxr_expression_impl<std::string&, const std::string>(opr, s0, s1, rp1); 41211 | } 41212 | 41213 | inline expression_node_ptr synthesize_srosr_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) 41214 | { 41215 | std::string& s0 = static_cast<details::string_range_node<Type>*>(branch[0])->ref (); 41216 | std::string& s1 = static_cast<details::string_range_node<Type>*>(branch[1])->ref (); 41217 | range_t rp0 = static_cast<details::string_range_node<Type>*>(branch[0])->range(); 41218 | range_t rp1 = static_cast<details::string_range_node<Type>*>(branch[1])->range(); 41219 | 41220 | static_cast<details::string_range_node<Type>*>(branch[0])->range_ref().clear(); 41221 | static_cast<details::string_range_node<Type>*>(branch[1])->range_ref().clear(); 41222 | 41223 | details::free_node(*node_allocator_,branch[0]); 41224 | details::free_node(*node_allocator_,branch[1]); 41225 | 41226 | return synthesize_str_xroxr_expression_impl<std::string&,std::string&>(opr, s0, s1, rp0, rp1); 41227 | } 41228 | 41229 | inline expression_node_ptr synthesize_socs_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) 41230 | { 41231 | std::string& s0 = static_cast< details::stringvar_node<Type>*>(branch[0])->ref(); 41232 | std::string s1 = static_cast<details::string_literal_node<Type>*>(branch[1])->str(); 41233 | 41234 | details::free_node(*node_allocator_,branch[1]); 41235 | 41236 | return synthesize_sos_expression_impl<std::string&, const std::string>(opr, s0, s1); 41237 | } 41238 | 41239 | inline expression_node_ptr synthesize_csos_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) 41240 | { 41241 | std::string s0 = static_cast<details::string_literal_node<Type>*>(branch[0])->str(); 41242 | std::string& s1 = static_cast<details::stringvar_node<Type>* >(branch[1])->ref(); 41243 | 41244 | details::free_node(*node_allocator_,branch[0]); 41245 | 41246 | return synthesize_sos_expression_impl<const std::string,std::string&>(opr, s0, s1); 41247 | } 41248 | 41249 | inline expression_node_ptr synthesize_csosr_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) 41250 | { 41251 | std::string s0 = static_cast<details::string_literal_node<Type>*>(branch[0])->str (); 41252 | std::string& s1 = static_cast<details::string_range_node<Type>* >(branch[1])->ref (); 41253 | range_t rp1 = static_cast<details::string_range_node<Type>* >(branch[1])->range(); 41254 | 41255 | static_cast<details::string_range_node<Type>*>(branch[1])->range_ref().clear(); 41256 | 41257 | details::free_node(*node_allocator_,branch[0]); 41258 | details::free_node(*node_allocator_,branch[1]); 41259 | 41260 | return synthesize_str_xoxr_expression_impl<const std::string,std::string&>(opr, s0, s1, rp1); 41261 | } 41262 | 41263 | inline expression_node_ptr synthesize_srocs_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) 41264 | { 41265 | std::string& s0 = static_cast<details::string_range_node<Type>* >(branch[0])->ref (); 41266 | std::string s1 = static_cast<details::string_literal_node<Type>*>(branch[1])->str (); 41267 | range_t rp0 = static_cast<details::string_range_node<Type>* >(branch[0])->range(); 41268 | 41269 | static_cast<details::string_range_node<Type>*>(branch[0])->range_ref().clear(); 41270 | 41271 | details::free_node(*node_allocator_,branch[0]); 41272 | details::free_node(*node_allocator_,branch[1]); 41273 | 41274 | return synthesize_str_xrox_expression_impl<std::string&, const std::string>(opr, s0, s1, rp0); 41275 | } 41276 | 41277 | inline expression_node_ptr synthesize_srocsr_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) 41278 | { 41279 | std::string& s0 = static_cast<details::string_range_node<Type>* >(branch[0])->ref (); 41280 | std::string s1 = static_cast<details::const_string_range_node<Type>*>(branch[1])->str (); 41281 | range_t rp0 = static_cast<details::string_range_node<Type>* >(branch[0])->range(); 41282 | range_t rp1 = static_cast<details::const_string_range_node<Type>*>(branch[1])->range(); 41283 | 41284 | static_cast<details::string_range_node<Type>*> (branch[0])->range_ref().clear(); 41285 | static_cast<details::const_string_range_node<Type>*>(branch[1])->range_ref().clear(); 41286 | 41287 | details::free_node(*node_allocator_,branch[0]); 41288 | details::free_node(*node_allocator_,branch[1]); 41289 | 41290 | return synthesize_str_xroxr_expression_impl<std::string&, const std::string>(opr, s0, s1, rp0, rp1); 41291 | } 41292 | 41293 | inline expression_node_ptr synthesize_csocs_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) 41294 | { 41295 | const std::string s0 = static_cast<details::string_literal_node<Type>*>(branch[0])->str(); 41296 | const std::string s1 = static_cast<details::string_literal_node<Type>*>(branch[1])->str(); 41297 | 41298 | expression_node_ptr result = error_node(); 41299 | 41300 | if (details::e_add == opr) 41301 | result = node_allocator_->allocate_c<details::string_literal_node<Type> >(s0 + s1); 41302 | else if (details::e_in == opr) 41303 | result = node_allocator_->allocate_c<details::literal_node<Type> >(details::in_op <Type>::process(s0,s1)); 41304 | else if (details::e_like == opr) 41305 | result = node_allocator_->allocate_c<details::literal_node<Type> >(details::like_op <Type>::process(s0,s1)); 41306 | else if (details::e_ilike == opr) 41307 | result = node_allocator_->allocate_c<details::literal_node<Type> >(details::ilike_op<Type>::process(s0,s1)); 41308 | else 41309 | { 41310 | expression_node_ptr temp = synthesize_sos_expression_impl<const std::string, const std::string>(opr, s0, s1); 41311 | 41312 | const Type v = temp->value(); 41313 | 41314 | details::free_node(*node_allocator_,temp); 41315 | 41316 | result = node_allocator_->allocate<literal_node_t>(v); 41317 | } 41318 | 41319 | details::free_all_nodes(*node_allocator_,branch); 41320 | 41321 | return result; 41322 | } 41323 | 41324 | inline expression_node_ptr synthesize_csocsr_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) 41325 | { 41326 | const std::string s0 = static_cast<details::string_literal_node<Type>* >(branch[0])->str (); 41327 | std::string s1 = static_cast<details::const_string_range_node<Type>*>(branch[1])->str (); 41328 | range_t rp1 = static_cast<details::const_string_range_node<Type>*>(branch[1])->range(); 41329 | 41330 | static_cast<details::const_string_range_node<Type>*>(branch[1])->range_ref().clear(); 41331 | 41332 | details::free_node(*node_allocator_,branch[0]); 41333 | details::free_node(*node_allocator_,branch[1]); 41334 | 41335 | return synthesize_str_xoxr_expression_impl<const std::string, const std::string>(opr, s0, s1, rp1); 41336 | } 41337 | 41338 | inline expression_node_ptr synthesize_csros_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) 41339 | { 41340 | std::string s0 = static_cast<details::const_string_range_node<Type>*>(branch[0])->str (); 41341 | std::string& s1 = static_cast<details::stringvar_node<Type>* >(branch[1])->ref (); 41342 | range_t rp0 = static_cast<details::const_string_range_node<Type>*>(branch[0])->range(); 41343 | 41344 | static_cast<details::const_string_range_node<Type>*>(branch[0])->range_ref().clear(); 41345 | 41346 | details::free_node(*node_allocator_,branch[0]); 41347 | 41348 | return synthesize_str_xrox_expression_impl<const std::string,std::string&>(opr, s0, s1, rp0); 41349 | } 41350 | 41351 | inline expression_node_ptr synthesize_csrosr_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) 41352 | { 41353 | const std::string s0 = static_cast<details::const_string_range_node<Type>*>(branch[0])->str (); 41354 | std::string& s1 = static_cast<details::string_range_node<Type>* >(branch[1])->ref (); 41355 | const range_t rp0 = static_cast<details::const_string_range_node<Type>*>(branch[0])->range(); 41356 | const range_t rp1 = static_cast<details::string_range_node<Type>* >(branch[1])->range(); 41357 | 41358 | static_cast<details::const_string_range_node<Type>*>(branch[0])->range_ref().clear(); 41359 | static_cast<details::string_range_node<Type>*> (branch[1])->range_ref().clear(); 41360 | 41361 | details::free_node(*node_allocator_,branch[0]); 41362 | details::free_node(*node_allocator_,branch[1]); 41363 | 41364 | return synthesize_str_xroxr_expression_impl<const std::string,std::string&>(opr, s0, s1, rp0, rp1); 41365 | } 41366 | 41367 | inline expression_node_ptr synthesize_csrocs_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) 41368 | { 41369 | const std::string s0 = static_cast<details::const_string_range_node<Type>*>(branch[0])->str (); 41370 | const std::string s1 = static_cast<details::string_literal_node<Type>* >(branch[1])->str (); 41371 | const range_t rp0 = static_cast<details::const_string_range_node<Type>*>(branch[0])->range(); 41372 | 41373 | static_cast<details::const_string_range_node<Type>*>(branch[0])->range_ref().clear(); 41374 | 41375 | details::free_all_nodes(*node_allocator_,branch); 41376 | 41377 | return synthesize_str_xrox_expression_impl<const std::string,std::string>(opr, s0, s1, rp0); 41378 | } 41379 | 41380 | inline expression_node_ptr synthesize_csrocsr_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) 41381 | { 41382 | const std::string s0 = static_cast<details::const_string_range_node<Type>*>(branch[0])->str (); 41383 | const std::string s1 = static_cast<details::const_string_range_node<Type>*>(branch[1])->str (); 41384 | const range_t rp0 = static_cast<details::const_string_range_node<Type>*>(branch[0])->range(); 41385 | const range_t rp1 = static_cast<details::const_string_range_node<Type>*>(branch[1])->range(); 41386 | 41387 | static_cast<details::const_string_range_node<Type>*>(branch[0])->range_ref().clear(); 41388 | static_cast<details::const_string_range_node<Type>*>(branch[1])->range_ref().clear(); 41389 | 41390 | details::free_all_nodes(*node_allocator_,branch); 41391 | 41392 | return synthesize_str_xroxr_expression_impl<const std::string, const std::string>(opr, s0, s1, rp0, rp1); 41393 | } 41394 | 41395 | inline expression_node_ptr synthesize_strogen_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) 41396 | { 41397 | switch (opr) 41398 | { 41399 | #define case_stmt(op0, op1) \ 41400 | case op0 : return node_allocator_-> \ 41401 | allocate_ttt<typename details::str_sogens_node<Type,op1<Type> > > \ 41402 | (opr, branch[0], branch[1]); \ 41403 | 41404 | string_opr_switch_statements 41405 | #undef case_stmt 41406 | default : return error_node(); 41407 | } 41408 | } 41409 | 41410 | #undef string_opr_switch_statements 41411 | #endif 41412 | 41413 | #ifndef exprtk_disable_string_capabilities 41414 | inline expression_node_ptr synthesize_string_expression(const details::operator_type& opr, expression_node_ptr (&branch)[2]) 41415 | { 41416 | if ((0 == branch[0]) || (0 == branch[1])) 41417 | { 41418 | details::free_all_nodes(*node_allocator_,branch); 41419 | 41420 | return error_node(); 41421 | } 41422 | 41423 | const bool b0_is_s = details::is_string_node (branch[0]); 41424 | const bool b0_is_cs = details::is_const_string_node (branch[0]); 41425 | const bool b0_is_sr = details::is_string_range_node (branch[0]); 41426 | const bool b0_is_csr = details::is_const_string_range_node(branch[0]); 41427 | 41428 | const bool b1_is_s = details::is_string_node (branch[1]); 41429 | const bool b1_is_cs = details::is_const_string_node (branch[1]); 41430 | const bool b1_is_sr = details::is_string_range_node (branch[1]); 41431 | const bool b1_is_csr = details::is_const_string_range_node(branch[1]); 41432 | 41433 | const bool b0_is_gen = details::is_string_assignment_node (branch[0]) || 41434 | details::is_genricstring_range_node(branch[0]) || 41435 | details::is_string_concat_node (branch[0]) || 41436 | details::is_string_function_node (branch[0]) || 41437 | details::is_string_condition_node (branch[0]) || 41438 | details::is_string_ccondition_node (branch[0]) || 41439 | details::is_string_vararg_node (branch[0]) ; 41440 | 41441 | const bool b1_is_gen = details::is_string_assignment_node (branch[1]) || 41442 | details::is_genricstring_range_node(branch[1]) || 41443 | details::is_string_concat_node (branch[1]) || 41444 | details::is_string_function_node (branch[1]) || 41445 | details::is_string_condition_node (branch[1]) || 41446 | details::is_string_ccondition_node (branch[1]) || 41447 | details::is_string_vararg_node (branch[1]) ; 41448 | 41449 | if (details::e_add == opr) 41450 | { 41451 | if (!b0_is_cs || !b1_is_cs) 41452 | { 41453 | return synthesize_expression<string_concat_node_t,2>(opr,branch); 41454 | } 41455 | } 41456 | 41457 | if (b0_is_gen || b1_is_gen) 41458 | { 41459 | return synthesize_strogen_expression(opr,branch); 41460 | } 41461 | else if (b0_is_s) 41462 | { 41463 | if (b1_is_s ) return synthesize_sos_expression (opr,branch); 41464 | else if (b1_is_cs ) return synthesize_socs_expression (opr,branch); 41465 | else if (b1_is_sr ) return synthesize_sosr_expression (opr,branch); 41466 | else if (b1_is_csr) return synthesize_socsr_expression (opr,branch); 41467 | } 41468 | else if (b0_is_cs) 41469 | { 41470 | if (b1_is_s ) return synthesize_csos_expression (opr,branch); 41471 | else if (b1_is_cs ) return synthesize_csocs_expression (opr,branch); 41472 | else if (b1_is_sr ) return synthesize_csosr_expression (opr,branch); 41473 | else if (b1_is_csr) return synthesize_csocsr_expression(opr,branch); 41474 | } 41475 | else if (b0_is_sr) 41476 | { 41477 | if (b1_is_s ) return synthesize_sros_expression (opr,branch); 41478 | else if (b1_is_sr ) return synthesize_srosr_expression (opr,branch); 41479 | else if (b1_is_cs ) return synthesize_srocs_expression (opr,branch); 41480 | else if (b1_is_csr) return synthesize_srocsr_expression(opr,branch); 41481 | } 41482 | else if (b0_is_csr) 41483 | { 41484 | if (b1_is_s ) return synthesize_csros_expression (opr,branch); 41485 | else if (b1_is_sr ) return synthesize_csrosr_expression (opr,branch); 41486 | else if (b1_is_cs ) return synthesize_csrocs_expression (opr,branch); 41487 | else if (b1_is_csr) return synthesize_csrocsr_expression(opr,branch); 41488 | } 41489 | 41490 | return error_node(); 41491 | } 41492 | #else 41493 | inline expression_node_ptr synthesize_string_expression(const details::operator_type&, expression_node_ptr (&branch)[2]) 41494 | { 41495 | details::free_all_nodes(*node_allocator_,branch); 41496 | return error_node(); 41497 | } 41498 | #endif 41499 | 41500 | #ifndef exprtk_disable_string_capabilities 41501 | inline expression_node_ptr synthesize_string_expression(const details::operator_type& opr, expression_node_ptr (&branch)[3]) 41502 | { 41503 | if (details::e_inrange != opr) 41504 | return error_node(); 41505 | else if ((0 == branch[0]) || (0 == branch[1]) || (0 == branch[2])) 41506 | { 41507 | details::free_all_nodes(*node_allocator_,branch); 41508 | 41509 | return error_node(); 41510 | } 41511 | else if ( 41512 | details::is_const_string_node(branch[0]) && 41513 | details::is_const_string_node(branch[1]) && 41514 | details::is_const_string_node(branch[2]) 41515 | ) 41516 | { 41517 | const std::string s0 = static_cast<details::string_literal_node<Type>*>(branch[0])->str(); 41518 | const std::string s1 = static_cast<details::string_literal_node<Type>*>(branch[1])->str(); 41519 | const std::string s2 = static_cast<details::string_literal_node<Type>*>(branch[2])->str(); 41520 | 41521 | const Type v = (((s0 <= s1) && (s1 <= s2)) ? Type(1) : Type(0)); 41522 | 41523 | details::free_all_nodes(*node_allocator_,branch); 41524 | 41525 | return node_allocator_->allocate_c<details::literal_node<Type> >(v); 41526 | } 41527 | else if ( 41528 | details::is_string_node(branch[0]) && 41529 | details::is_string_node(branch[1]) && 41530 | details::is_string_node(branch[2]) 41531 | ) 41532 | { 41533 | std::string& s0 = static_cast<details::stringvar_node<Type>*>(branch[0])->ref(); 41534 | std::string& s1 = static_cast<details::stringvar_node<Type>*>(branch[1])->ref(); 41535 | std::string& s2 = static_cast<details::stringvar_node<Type>*>(branch[2])->ref(); 41536 | 41537 | typedef typename details::sosos_node<Type, std::string&, std::string&, std::string&, details::inrange_op<Type> > inrange_t; 41538 | 41539 | return node_allocator_->allocate_type<inrange_t, std::string&, std::string&, std::string&>(s0, s1, s2); 41540 | } 41541 | else if ( 41542 | details::is_const_string_node(branch[0]) && 41543 | details::is_string_node(branch[1]) && 41544 | details::is_const_string_node(branch[2]) 41545 | ) 41546 | { 41547 | std::string s0 = static_cast<details::string_literal_node<Type>*>(branch[0])->str(); 41548 | std::string& s1 = static_cast<details::stringvar_node<Type>* >(branch[1])->ref(); 41549 | std::string s2 = static_cast<details::string_literal_node<Type>*>(branch[2])->str(); 41550 | 41551 | typedef typename details::sosos_node<Type, std::string, std::string&, std::string, details::inrange_op<Type> > inrange_t; 41552 | 41553 | details::free_node(*node_allocator_,branch[0]); 41554 | details::free_node(*node_allocator_,branch[2]); 41555 | 41556 | return node_allocator_->allocate_type<inrange_t, std::string, std::string&, std::string>(s0, s1, s2); 41557 | } 41558 | else if ( 41559 | details::is_string_node(branch[0]) && 41560 | details::is_const_string_node(branch[1]) && 41561 | details::is_string_node(branch[2]) 41562 | ) 41563 | { 41564 | std::string& s0 = static_cast<details::stringvar_node<Type>* >(branch[0])->ref(); 41565 | std::string s1 = static_cast<details::string_literal_node<Type>*>(branch[1])->str(); 41566 | std::string& s2 = static_cast<details::stringvar_node<Type>* >(branch[2])->ref(); 41567 | 41568 | typedef typename details::sosos_node<Type, std::string&, std::string, std::string&, details::inrange_op<Type> > inrange_t; 41569 | 41570 | details::free_node(*node_allocator_,branch[1]); 41571 | 41572 | return node_allocator_->allocate_type<inrange_t, std::string&, std::string, std::string&>(s0, s1, s2); 41573 | } 41574 | else if ( 41575 | details::is_string_node(branch[0]) && 41576 | details::is_string_node(branch[1]) && 41577 | details::is_const_string_node(branch[2]) 41578 | ) 41579 | { 41580 | std::string& s0 = static_cast<details::stringvar_node<Type>* >(branch[0])->ref(); 41581 | std::string& s1 = static_cast<details::stringvar_node<Type>* >(branch[1])->ref(); 41582 | std::string s2 = static_cast<details::string_literal_node<Type>*>(branch[2])->str(); 41583 | 41584 | typedef typename details::sosos_node<Type, std::string&, std::string&, std::string, details::inrange_op<Type> > inrange_t; 41585 | 41586 | details::free_node(*node_allocator_,branch[2]); 41587 | 41588 | return node_allocator_->allocate_type<inrange_t, std::string&, std::string&, std::string>(s0, s1, s2); 41589 | } 41590 | else if ( 41591 | details::is_const_string_node(branch[0]) && 41592 | details:: is_string_node(branch[1]) && 41593 | details:: is_string_node(branch[2]) 41594 | ) 41595 | { 41596 | std::string s0 = static_cast<details::string_literal_node<Type>*>(branch[0])->str(); 41597 | std::string& s1 = static_cast<details::stringvar_node<Type>* >(branch[1])->ref(); 41598 | std::string& s2 = static_cast<details::stringvar_node<Type>* >(branch[2])->ref(); 41599 | 41600 | typedef typename details::sosos_node<Type, std::string, std::string&, std::string&, details::inrange_op<Type> > inrange_t; 41601 | 41602 | details::free_node(*node_allocator_,branch[0]); 41603 | 41604 | return node_allocator_->allocate_type<inrange_t, std::string, std::string&, std::string&>(s0, s1, s2); 41605 | } 41606 | else 41607 | return error_node(); 41608 | } 41609 | #else 41610 | inline expression_node_ptr synthesize_string_expression(const details::operator_type&, expression_node_ptr (&branch)[3]) 41611 | { 41612 | details::free_all_nodes(*node_allocator_,branch); 41613 | return error_node(); 41614 | } 41615 | #endif 41616 | 41617 | inline expression_node_ptr synthesize_null_expression(const details::operator_type& operation, expression_node_ptr (&branch)[2]) 41618 | { 41619 | /* 41620 | Note: The following are the type promotion rules 41621 | that relate to operations that include 'null': 41622 | 0. null ==/!= null --> true false 41623 | 1. null operation null --> null 41624 | 2. x ==/!= null --> true/false 41625 | 3. null ==/!= x --> true/false 41626 | 4. x operation null --> x 41627 | 5. null operation x --> x 41628 | */ 41629 | 41630 | typedef typename details::null_eq_node<T> nulleq_node_t; 41631 | 41632 | const bool b0_null = details::is_null_node(branch[0]); 41633 | const bool b1_null = details::is_null_node(branch[1]); 41634 | 41635 | if (b0_null && b1_null) 41636 | { 41637 | expression_node_ptr result = error_node(); 41638 | 41639 | if (details::e_eq == operation) 41640 | result = node_allocator_->allocate_c<literal_node_t>(T(1)); 41641 | else if (details::e_ne == operation) 41642 | result = node_allocator_->allocate_c<literal_node_t>(T(0)); 41643 | 41644 | if (result) 41645 | { 41646 | details::free_node(*node_allocator_,branch[0]); 41647 | details::free_node(*node_allocator_,branch[1]); 41648 | 41649 | return result; 41650 | } 41651 | 41652 | details::free_node(*node_allocator_,branch[1]); 41653 | 41654 | return branch[0]; 41655 | } 41656 | else if (details::e_eq == operation) 41657 | { 41658 | expression_node_ptr result = node_allocator_-> 41659 | allocate_rc<nulleq_node_t>(branch[b0_null ? 0 : 1],true); 41660 | 41661 | details::free_node(*node_allocator_,branch[b0_null ? 1 : 0]); 41662 | 41663 | return result; 41664 | } 41665 | else if (details::e_ne == operation) 41666 | { 41667 | expression_node_ptr result = node_allocator_-> 41668 | allocate_rc<nulleq_node_t>(branch[b0_null ? 0 : 1],false); 41669 | 41670 | details::free_node(*node_allocator_,branch[b0_null ? 1 : 0]); 41671 | 41672 | return result; 41673 | } 41674 | else if (b0_null) 41675 | { 41676 | details::free_node(*node_allocator_,branch[0]); 41677 | branch[0] = branch[1]; 41678 | branch[1] = error_node(); 41679 | } 41680 | else if (b1_null) 41681 | { 41682 | details::free_node(*node_allocator_,branch[1]); 41683 | branch[1] = error_node(); 41684 | } 41685 | 41686 | if ( 41687 | (details::e_add == operation) || (details::e_sub == operation) || 41688 | (details::e_mul == operation) || (details::e_div == operation) || 41689 | (details::e_mod == operation) || (details::e_pow == operation) 41690 | ) 41691 | { 41692 | return branch[0]; 41693 | } 41694 | 41695 | details::free_node(*node_allocator_, branch[0]); 41696 | 41697 | if ( 41698 | (details::e_lt == operation) || (details::e_lte == operation) || 41699 | (details::e_gt == operation) || (details::e_gte == operation) || 41700 | (details::e_and == operation) || (details::e_nand == operation) || 41701 | (details::e_or == operation) || (details::e_nor == operation) || 41702 | (details::e_xor == operation) || (details::e_xnor == operation) || 41703 | (details::e_in == operation) || (details::e_like == operation) || 41704 | (details::e_ilike == operation) 41705 | ) 41706 | { 41707 | return node_allocator_->allocate_c<literal_node_t>(T(0)); 41708 | } 41709 | 41710 | return node_allocator_->allocate<details::null_node<Type> >(); 41711 | } 41712 | 41713 | template <typename NodeType, std::size_t N> 41714 | inline expression_node_ptr synthesize_expression(const details::operator_type& operation, expression_node_ptr (&branch)[N]) 41715 | { 41716 | if ( 41717 | (details::e_in == operation) || 41718 | (details::e_like == operation) || 41719 | (details::e_ilike == operation) 41720 | ) 41721 | { 41722 | free_all_nodes(*node_allocator_,branch); 41723 | 41724 | return error_node(); 41725 | } 41726 | else if (!details::all_nodes_valid<N>(branch)) 41727 | { 41728 | free_all_nodes(*node_allocator_,branch); 41729 | 41730 | return error_node(); 41731 | } 41732 | else if ((details::e_default != operation)) 41733 | { 41734 | // Attempt simple constant folding optimisation. 41735 | expression_node_ptr expression_point = node_allocator_->allocate<NodeType>(operation,branch); 41736 | 41737 | if (is_constant_foldable<N>(branch)) 41738 | { 41739 | const Type v = expression_point->value(); 41740 | details::free_node(*node_allocator_,expression_point); 41741 | 41742 | return node_allocator_->allocate<literal_node_t>(v); 41743 | } 41744 | 41745 | if (expression_point && expression_point->valid()) 41746 | { 41747 | return expression_point; 41748 | } 41749 | 41750 | parser_->set_error(parser_error::make_error( 41751 | parser_error::e_parser, 41752 | token_t(), 41753 | "ERR281 - Failed to synthesize node: NodeType", 41754 | exprtk_error_location)); 41755 | 41756 | details::free_node(*node_allocator_, expression_point); 41757 | } 41758 | 41759 | return error_node(); 41760 | } 41761 | 41762 | template <typename NodeType, std::size_t N> 41763 | inline expression_node_ptr synthesize_expression(F* f, expression_node_ptr (&branch)[N]) 41764 | { 41765 | if (!details::all_nodes_valid<N>(branch)) 41766 | { 41767 | free_all_nodes(*node_allocator_,branch); 41768 | 41769 | return error_node(); 41770 | } 41771 | 41772 | typedef typename details::function_N_node<T,ifunction_t,N> function_N_node_t; 41773 | 41774 | // Attempt simple constant folding optimisation. 41775 | 41776 | expression_node_ptr expression_point = node_allocator_->allocate<NodeType>(f); 41777 | function_N_node_t* func_node_ptr = dynamic_cast<function_N_node_t*>(expression_point); 41778 | 41779 | if (0 == func_node_ptr) 41780 | { 41781 | free_all_nodes(*node_allocator_,branch); 41782 | 41783 | return error_node(); 41784 | } 41785 | else 41786 | func_node_ptr->init_branches(branch); 41787 | 41788 | if (is_constant_foldable<N>(branch) && !f->has_side_effects()) 41789 | { 41790 | Type v = expression_point->value(); 41791 | details::free_node(*node_allocator_,expression_point); 41792 | 41793 | return node_allocator_->allocate<literal_node_t>(v); 41794 | } 41795 | 41796 | parser_->state_.activate_side_effect("synthesize_expression(function<NT,N>)"); 41797 | 41798 | return expression_point; 41799 | } 41800 | 41801 | bool strength_reduction_enabled_; 41802 | details::node_allocator* node_allocator_; 41803 | synthesize_map_t synthesize_map_; 41804 | unary_op_map_t* unary_op_map_; 41805 | binary_op_map_t* binary_op_map_; 41806 | inv_binary_op_map_t* inv_binary_op_map_; 41807 | sf3_map_t* sf3_map_; 41808 | sf4_map_t* sf4_map_; 41809 | parser_t* parser_; 41810 | }; // class expression_generator 41811 | 41812 | inline void set_error(const parser_error::type& error_type) 41813 | { 41814 | error_list_.push_back(error_type); 41815 | } 41816 | 41817 | inline void remove_last_error() 41818 | { 41819 | if (!error_list_.empty()) 41820 | { 41821 | error_list_.pop_back(); 41822 | } 41823 | } 41824 | 41825 | inline void set_synthesis_error(const std::string& synthesis_error_message) 41826 | { 41827 | if (synthesis_error_.empty()) 41828 | { 41829 | synthesis_error_ = synthesis_error_message; 41830 | } 41831 | } 41832 | 41833 | inline void register_local_vars(expression<T>& e) 41834 | { 41835 | for (std::size_t i = 0; i < sem_.size(); ++i) 41836 | { 41837 | scope_element& se = sem_.get_element(i); 41838 | 41839 | exprtk_debug(("register_local_vars() - se[%s]\n", se.name.c_str())); 41840 | 41841 | if ( 41842 | (scope_element::e_variable == se.type) || 41843 | (scope_element::e_literal == se.type) || 41844 | (scope_element::e_vecelem == se.type) 41845 | ) 41846 | { 41847 | if (se.var_node) 41848 | { 41849 | e.register_local_var(se.var_node); 41850 | } 41851 | 41852 | if (se.data) 41853 | { 41854 | e.register_local_data(se.data, 1, 0); 41855 | } 41856 | } 41857 | else if (scope_element::e_vector == se.type) 41858 | { 41859 | if (se.vec_node) 41860 | { 41861 | e.register_local_var(se.vec_node); 41862 | } 41863 | 41864 | if (se.data) 41865 | { 41866 | e.register_local_data(se.data, se.size, 1); 41867 | } 41868 | } 41869 | #ifndef exprtk_disable_string_capabilities 41870 | else if (scope_element::e_string == se.type) 41871 | { 41872 | if (se.str_node) 41873 | { 41874 | e.register_local_var(se.str_node); 41875 | } 41876 | 41877 | if (se.data) 41878 | { 41879 | e.register_local_data(se.data, se.size, 2); 41880 | } 41881 | } 41882 | #endif 41883 | 41884 | se.var_node = 0; 41885 | se.vec_node = 0; 41886 | #ifndef exprtk_disable_string_capabilities 41887 | se.str_node = 0; 41888 | #endif 41889 | se.data = 0; 41890 | se.ref_count = 0; 41891 | se.active = false; 41892 | } 41893 | } 41894 | 41895 | inline void register_return_results(expression<T>& e) 41896 | { 41897 | e.register_return_results(results_context_); 41898 | results_context_ = 0; 41899 | } 41900 | 41901 | inline void load_unary_operations_map(unary_op_map_t& m) 41902 | { 41903 | #define register_unary_op(Op, UnaryFunctor) \ 41904 | m.insert(std::make_pair(Op,UnaryFunctor<T>::process)); \ 41905 | 41906 | register_unary_op(details::e_abs , details::abs_op ) 41907 | register_unary_op(details::e_acos , details::acos_op ) 41908 | register_unary_op(details::e_acosh , details::acosh_op) 41909 | register_unary_op(details::e_asin , details::asin_op ) 41910 | register_unary_op(details::e_asinh , details::asinh_op) 41911 | register_unary_op(details::e_atanh , details::atanh_op) 41912 | register_unary_op(details::e_ceil , details::ceil_op ) 41913 | register_unary_op(details::e_cos , details::cos_op ) 41914 | register_unary_op(details::e_cosh , details::cosh_op ) 41915 | register_unary_op(details::e_exp , details::exp_op ) 41916 | register_unary_op(details::e_expm1 , details::expm1_op) 41917 | register_unary_op(details::e_floor , details::floor_op) 41918 | register_unary_op(details::e_log , details::log_op ) 41919 | register_unary_op(details::e_log10 , details::log10_op) 41920 | register_unary_op(details::e_log2 , details::log2_op ) 41921 | register_unary_op(details::e_log1p , details::log1p_op) 41922 | register_unary_op(details::e_neg , details::neg_op ) 41923 | register_unary_op(details::e_pos , details::pos_op ) 41924 | register_unary_op(details::e_round , details::round_op) 41925 | register_unary_op(details::e_sin , details::sin_op ) 41926 | register_unary_op(details::e_sinc , details::sinc_op ) 41927 | register_unary_op(details::e_sinh , details::sinh_op ) 41928 | register_unary_op(details::e_sqrt , details::sqrt_op ) 41929 | register_unary_op(details::e_tan , details::tan_op ) 41930 | register_unary_op(details::e_tanh , details::tanh_op ) 41931 | register_unary_op(details::e_cot , details::cot_op ) 41932 | register_unary_op(details::e_sec , details::sec_op ) 41933 | register_unary_op(details::e_csc , details::csc_op ) 41934 | register_unary_op(details::e_r2d , details::r2d_op ) 41935 | register_unary_op(details::e_d2r , details::d2r_op ) 41936 | register_unary_op(details::e_d2g , details::d2g_op ) 41937 | register_unary_op(details::e_g2d , details::g2d_op ) 41938 | register_unary_op(details::e_notl , details::notl_op ) 41939 | register_unary_op(details::e_sgn , details::sgn_op ) 41940 | register_unary_op(details::e_erf , details::erf_op ) 41941 | register_unary_op(details::e_erfc , details::erfc_op ) 41942 | register_unary_op(details::e_ncdf , details::ncdf_op ) 41943 | register_unary_op(details::e_frac , details::frac_op ) 41944 | register_unary_op(details::e_trunc , details::trunc_op) 41945 | #undef register_unary_op 41946 | } 41947 | 41948 | inline void load_binary_operations_map(binary_op_map_t& m) 41949 | { 41950 | typedef typename binary_op_map_t::value_type value_type; 41951 | 41952 | #define register_binary_op(Op, BinaryFunctor) \ 41953 | m.insert(value_type(Op,BinaryFunctor<T>::process)); \ 41954 | 41955 | register_binary_op(details::e_add , details::add_op ) 41956 | register_binary_op(details::e_sub , details::sub_op ) 41957 | register_binary_op(details::e_mul , details::mul_op ) 41958 | register_binary_op(details::e_div , details::div_op ) 41959 | register_binary_op(details::e_mod , details::mod_op ) 41960 | register_binary_op(details::e_pow , details::pow_op ) 41961 | register_binary_op(details::e_lt , details::lt_op ) 41962 | register_binary_op(details::e_lte , details::lte_op ) 41963 | register_binary_op(details::e_gt , details::gt_op ) 41964 | register_binary_op(details::e_gte , details::gte_op ) 41965 | register_binary_op(details::e_eq , details::eq_op ) 41966 | register_binary_op(details::e_ne , details::ne_op ) 41967 | register_binary_op(details::e_and , details::and_op ) 41968 | register_binary_op(details::e_nand , details::nand_op) 41969 | register_binary_op(details::e_or , details::or_op ) 41970 | register_binary_op(details::e_nor , details::nor_op ) 41971 | register_binary_op(details::e_xor , details::xor_op ) 41972 | register_binary_op(details::e_xnor , details::xnor_op) 41973 | #undef register_binary_op 41974 | } 41975 | 41976 | inline void load_inv_binary_operations_map(inv_binary_op_map_t& m) 41977 | { 41978 | typedef typename inv_binary_op_map_t::value_type value_type; 41979 | 41980 | #define register_binary_op(Op, BinaryFunctor) \ 41981 | m.insert(value_type(BinaryFunctor<T>::process,Op)); \ 41982 | 41983 | register_binary_op(details::e_add , details::add_op ) 41984 | register_binary_op(details::e_sub , details::sub_op ) 41985 | register_binary_op(details::e_mul , details::mul_op ) 41986 | register_binary_op(details::e_div , details::div_op ) 41987 | register_binary_op(details::e_mod , details::mod_op ) 41988 | register_binary_op(details::e_pow , details::pow_op ) 41989 | register_binary_op(details::e_lt , details::lt_op ) 41990 | register_binary_op(details::e_lte , details::lte_op ) 41991 | register_binary_op(details::e_gt , details::gt_op ) 41992 | register_binary_op(details::e_gte , details::gte_op ) 41993 | register_binary_op(details::e_eq , details::eq_op ) 41994 | register_binary_op(details::e_ne , details::ne_op ) 41995 | register_binary_op(details::e_and , details::and_op ) 41996 | register_binary_op(details::e_nand , details::nand_op) 41997 | register_binary_op(details::e_or , details::or_op ) 41998 | register_binary_op(details::e_nor , details::nor_op ) 41999 | register_binary_op(details::e_xor , details::xor_op ) 42000 | register_binary_op(details::e_xnor , details::xnor_op) 42001 | #undef register_binary_op 42002 | } 42003 | 42004 | inline void load_sf3_map(sf3_map_t& sf3_map) 42005 | { 42006 | typedef std::pair<trinary_functor_t,details::operator_type> pair_t; 42007 | 42008 | #define register_sf3(Op) \ 42009 | sf3_map[details::sf##Op##_op<T>::id()] = pair_t(details::sf##Op##_op<T>::process,details::e_sf##Op); \ 42010 | 42011 | register_sf3(00) register_sf3(01) register_sf3(02) register_sf3(03) 42012 | register_sf3(04) register_sf3(05) register_sf3(06) register_sf3(07) 42013 | register_sf3(08) register_sf3(09) register_sf3(10) register_sf3(11) 42014 | register_sf3(12) register_sf3(13) register_sf3(14) register_sf3(15) 42015 | register_sf3(16) register_sf3(17) register_sf3(18) register_sf3(19) 42016 | register_sf3(20) register_sf3(21) register_sf3(22) register_sf3(23) 42017 | register_sf3(24) register_sf3(25) register_sf3(26) register_sf3(27) 42018 | register_sf3(28) register_sf3(29) register_sf3(30) 42019 | #undef register_sf3 42020 | 42021 | #define register_sf3_extid(Id, Op) \ 42022 | sf3_map[Id] = pair_t(details::sf##Op##_op<T>::process,details::e_sf##Op); \ 42023 | 42024 | register_sf3_extid("(t-t)-t",23) // (t-t)-t --> t-(t+t) 42025 | #undef register_sf3_extid 42026 | } 42027 | 42028 | inline void load_sf4_map(sf4_map_t& sf4_map) 42029 | { 42030 | typedef std::pair<quaternary_functor_t,details::operator_type> pair_t; 42031 | 42032 | #define register_sf4(Op) \ 42033 | sf4_map[details::sf##Op##_op<T>::id()] = pair_t(details::sf##Op##_op<T>::process,details::e_sf##Op); \ 42034 | 42035 | register_sf4(48) register_sf4(49) register_sf4(50) register_sf4(51) 42036 | register_sf4(52) register_sf4(53) register_sf4(54) register_sf4(55) 42037 | register_sf4(56) register_sf4(57) register_sf4(58) register_sf4(59) 42038 | register_sf4(60) register_sf4(61) register_sf4(62) register_sf4(63) 42039 | register_sf4(64) register_sf4(65) register_sf4(66) register_sf4(67) 42040 | register_sf4(68) register_sf4(69) register_sf4(70) register_sf4(71) 42041 | register_sf4(72) register_sf4(73) register_sf4(74) register_sf4(75) 42042 | register_sf4(76) register_sf4(77) register_sf4(78) register_sf4(79) 42043 | register_sf4(80) register_sf4(81) register_sf4(82) register_sf4(83) 42044 | #undef register_sf4 42045 | 42046 | #define register_sf4ext(Op) \ 42047 | sf4_map[details::sfext##Op##_op<T>::id()] = pair_t(details::sfext##Op##_op<T>::process,details::e_sf4ext##Op); \ 42048 | 42049 | register_sf4ext(00) register_sf4ext(01) register_sf4ext(02) register_sf4ext(03) 42050 | register_sf4ext(04) register_sf4ext(05) register_sf4ext(06) register_sf4ext(07) 42051 | register_sf4ext(08) register_sf4ext(09) register_sf4ext(10) register_sf4ext(11) 42052 | register_sf4ext(12) register_sf4ext(13) register_sf4ext(14) register_sf4ext(15) 42053 | register_sf4ext(16) register_sf4ext(17) register_sf4ext(18) register_sf4ext(19) 42054 | register_sf4ext(20) register_sf4ext(21) register_sf4ext(22) register_sf4ext(23) 42055 | register_sf4ext(24) register_sf4ext(25) register_sf4ext(26) register_sf4ext(27) 42056 | register_sf4ext(28) register_sf4ext(29) register_sf4ext(30) register_sf4ext(31) 42057 | register_sf4ext(32) register_sf4ext(33) register_sf4ext(34) register_sf4ext(35) 42058 | register_sf4ext(36) register_sf4ext(36) register_sf4ext(38) register_sf4ext(39) 42059 | register_sf4ext(40) register_sf4ext(41) register_sf4ext(42) register_sf4ext(43) 42060 | register_sf4ext(44) register_sf4ext(45) register_sf4ext(46) register_sf4ext(47) 42061 | register_sf4ext(48) register_sf4ext(49) register_sf4ext(50) register_sf4ext(51) 42062 | register_sf4ext(52) register_sf4ext(53) register_sf4ext(54) register_sf4ext(55) 42063 | register_sf4ext(56) register_sf4ext(57) register_sf4ext(58) register_sf4ext(59) 42064 | register_sf4ext(60) register_sf4ext(61) 42065 | #undef register_sf4ext 42066 | } 42067 | 42068 | inline results_context_t& results_ctx() 42069 | { 42070 | if (0 == results_context_) 42071 | { 42072 | results_context_ = new results_context_t(); 42073 | } 42074 | 42075 | return (*results_context_); 42076 | } 42077 | 42078 | inline void return_cleanup() 42079 | { 42080 | #ifndef exprtk_disable_return_statement 42081 | if (results_context_) 42082 | { 42083 | delete results_context_; 42084 | results_context_ = 0; 42085 | } 42086 | 42087 | state_.return_stmt_present = false; 42088 | #endif 42089 | } 42090 | 42091 | inline bool valid_settings() 42092 | { 42093 | const std::size_t max_local_vector_size_bytes = sizeof(T) * settings_.max_local_vector_size(); 42094 | 42095 | if (max_local_vector_size_bytes > settings_.max_total_local_symbol_size_bytes()) 42096 | { 42097 | set_error(make_error( 42098 | parser_error::e_parser, 42099 | "ERR282 - Max local vector size of " + details::to_str(max_local_vector_size_bytes) + " bytes " 42100 | "is larger than max total local symbol size of " + details::to_str(settings_.max_total_local_symbol_size_bytes()) + " bytes", 42101 | exprtk_error_location)); 42102 | 42103 | return false; 42104 | } 42105 | 42106 | return true; 42107 | } 42108 | 42109 | private: 42110 | 42111 | parser(const parser<T>&) exprtk_delete; 42112 | parser<T>& operator=(const parser<T>&) exprtk_delete; 42113 | 42114 | settings_store settings_; 42115 | expression_generator<T> expression_generator_; 42116 | details::node_allocator node_allocator_; 42117 | symtab_store symtab_store_; 42118 | dependent_entity_collector dec_; 42119 | std::deque<parser_error::type> error_list_; 42120 | std::deque<bool> brkcnt_list_; 42121 | parser_state state_; 42122 | bool resolve_unknown_symbol_; 42123 | results_context_t* results_context_; 42124 | unknown_symbol_resolver* unknown_symbol_resolver_; 42125 | unknown_symbol_resolver default_usr_; 42126 | base_ops_map_t base_ops_map_; 42127 | unary_op_map_t unary_op_map_; 42128 | binary_op_map_t binary_op_map_; 42129 | inv_binary_op_map_t inv_binary_op_map_; 42130 | sf3_map_t sf3_map_; 42131 | sf4_map_t sf4_map_; 42132 | std::string synthesis_error_; 42133 | scope_element_manager sem_; 42134 | std::vector<state_t> current_state_stack_; 42135 | 42136 | immutable_memory_map_t immutable_memory_map_; 42137 | immutable_symtok_map_t immutable_symtok_map_; 42138 | 42139 | lexer::helper::helper_assembly helper_assembly_; 42140 | 42141 | lexer::helper::commutative_inserter commutative_inserter_; 42142 | lexer::helper::operator_joiner operator_joiner_2_; 42143 | lexer::helper::operator_joiner operator_joiner_3_; 42144 | lexer::helper::symbol_replacer symbol_replacer_; 42145 | lexer::helper::bracket_checker bracket_checker_; 42146 | lexer::helper::numeric_checker<T> numeric_checker_; 42147 | lexer::helper::sequence_validator sequence_validator_; 42148 | lexer::helper::sequence_validator_3tokens sequence_validator_3tkns_; 42149 | 42150 | loop_runtime_check_ptr loop_runtime_check_; 42151 | vector_access_runtime_check_ptr vector_access_runtime_check_; 42152 | compilation_check_ptr compilation_check_ptr_; 42153 | assert_check_ptr assert_check_; 42154 | std::set<std::string> assert_ids_; 42155 | 42156 | template <typename ParserType> 42157 | friend void details::disable_type_checking(ParserType& p); 42158 | }; // class parser 42159 | 42160 | namespace details 42161 | { 42162 | template <typename T> 42163 | struct collector_helper 42164 | { 42165 | typedef exprtk::symbol_table<T> symbol_table_t; 42166 | typedef exprtk::expression<T> expression_t; 42167 | typedef exprtk::parser<T> parser_t; 42168 | typedef typename parser_t::dependent_entity_collector::symbol_t symbol_t; 42169 | typedef typename parser_t::unknown_symbol_resolver usr_t; 42170 | 42171 | struct resolve_as_vector : public usr_t 42172 | { 42173 | typedef exprtk::parser<T> parser_t; 42174 | 42175 | using usr_t::process; 42176 | 42177 | resolve_as_vector() 42178 | : usr_t(usr_t::e_usrmode_extended) 42179 | {} 42180 | 42181 | virtual bool process(const std::string& unknown_symbol, 42182 | symbol_table_t& symbol_table, 42183 | std::string&) exprtk_override 42184 | { 42185 | static T v[1]; 42186 | symbol_table.add_vector(unknown_symbol,v); 42187 | return true; 42188 | } 42189 | }; 42190 | 42191 | static inline bool collection_pass(const std::string& expression_string, 42192 | std::set<std::string>& symbol_set, 42193 | const bool collect_variables, 42194 | const bool collect_functions, 42195 | const bool vector_pass, 42196 | symbol_table_t& ext_symbol_table) 42197 | { 42198 | symbol_table_t symbol_table; 42199 | expression_t expression; 42200 | parser_t parser; 42201 | 42202 | resolve_as_vector vect_resolver; 42203 | 42204 | expression.register_symbol_table(symbol_table ); 42205 | expression.register_symbol_table(ext_symbol_table); 42206 | 42207 | if (vector_pass) 42208 | parser.enable_unknown_symbol_resolver(&vect_resolver); 42209 | else 42210 | parser.enable_unknown_symbol_resolver(); 42211 | 42212 | if (collect_variables) 42213 | parser.dec().collect_variables() = true; 42214 | 42215 | if (collect_functions) 42216 | parser.dec().collect_functions() = true; 42217 | 42218 | bool pass_result = false; 42219 | 42220 | details::disable_type_checking(parser); 42221 | 42222 | if (parser.compile(expression_string, expression)) 42223 | { 42224 | pass_result = true; 42225 | 42226 | std::deque<symbol_t> symb_list; 42227 | parser.dec().symbols(symb_list); 42228 | 42229 | for (std::size_t i = 0; i < symb_list.size(); ++i) 42230 | { 42231 | symbol_set.insert(symb_list[i].first); 42232 | } 42233 | } 42234 | 42235 | return pass_result; 42236 | } 42237 | }; 42238 | } 42239 | 42240 | template <typename Allocator, 42241 | template <typename, typename> class Sequence> 42242 | inline bool collect_variables(const std::string& expression, 42243 | Sequence<std::string, Allocator>& symbol_list) 42244 | { 42245 | typedef double T; 42246 | typedef details::collector_helper<T> collect_t; 42247 | 42248 | collect_t::symbol_table_t null_symbol_table; 42249 | 42250 | std::set<std::string> symbol_set; 42251 | 42252 | const bool variable_pass = collect_t::collection_pass 42253 | (expression, symbol_set, true, false, false, null_symbol_table); 42254 | const bool vector_pass = collect_t::collection_pass 42255 | (expression, symbol_set, true, false, true, null_symbol_table); 42256 | 42257 | if (!variable_pass && !vector_pass) 42258 | return false; 42259 | 42260 | std::set<std::string>::iterator itr = symbol_set.begin(); 42261 | 42262 | while (symbol_set.end() != itr) 42263 | { 42264 | symbol_list.push_back(*itr); 42265 | ++itr; 42266 | } 42267 | 42268 | return true; 42269 | } 42270 | 42271 | template <typename T, 42272 | typename Allocator, 42273 | template <typename, typename> class Sequence> 42274 | inline bool collect_variables(const std::string& expression, 42275 | exprtk::symbol_table<T>& extrnl_symbol_table, 42276 | Sequence<std::string, Allocator>& symbol_list) 42277 | { 42278 | typedef details::collector_helper<T> collect_t; 42279 | 42280 | std::set<std::string> symbol_set; 42281 | 42282 | const bool variable_pass = collect_t::collection_pass 42283 | (expression, symbol_set, true, false, false, extrnl_symbol_table); 42284 | const bool vector_pass = collect_t::collection_pass 42285 | (expression, symbol_set, true, false, true, extrnl_symbol_table); 42286 | 42287 | if (!variable_pass && !vector_pass) 42288 | return false; 42289 | 42290 | std::set<std::string>::iterator itr = symbol_set.begin(); 42291 | 42292 | while (symbol_set.end() != itr) 42293 | { 42294 | symbol_list.push_back(*itr); 42295 | ++itr; 42296 | } 42297 | 42298 | return true; 42299 | } 42300 | 42301 | template <typename Allocator, 42302 | template <typename, typename> class Sequence> 42303 | inline bool collect_functions(const std::string& expression, 42304 | Sequence<std::string, Allocator>& symbol_list) 42305 | { 42306 | typedef double T; 42307 | typedef details::collector_helper<T> collect_t; 42308 | 42309 | collect_t::symbol_table_t null_symbol_table; 42310 | 42311 | std::set<std::string> symbol_set; 42312 | 42313 | const bool variable_pass = collect_t::collection_pass 42314 | (expression, symbol_set, false, true, false, null_symbol_table); 42315 | const bool vector_pass = collect_t::collection_pass 42316 | (expression, symbol_set, false, true, true, null_symbol_table); 42317 | 42318 | if (!variable_pass && !vector_pass) 42319 | return false; 42320 | 42321 | std::set<std::string>::iterator itr = symbol_set.begin(); 42322 | 42323 | while (symbol_set.end() != itr) 42324 | { 42325 | symbol_list.push_back(*itr); 42326 | ++itr; 42327 | } 42328 | 42329 | return true; 42330 | } 42331 | 42332 | template <typename T, 42333 | typename Allocator, 42334 | template <typename, typename> class Sequence> 42335 | inline bool collect_functions(const std::string& expression, 42336 | exprtk::symbol_table<T>& extrnl_symbol_table, 42337 | Sequence<std::string, Allocator>& symbol_list) 42338 | { 42339 | typedef details::collector_helper<T> collect_t; 42340 | 42341 | std::set<std::string> symbol_set; 42342 | 42343 | const bool variable_pass = collect_t::collection_pass 42344 | (expression, symbol_set, false, true, false, extrnl_symbol_table); 42345 | const bool vector_pass = collect_t::collection_pass 42346 | (expression, symbol_set, false, true, true, extrnl_symbol_table); 42347 | 42348 | if (!variable_pass && !vector_pass) 42349 | return false; 42350 | 42351 | std::set<std::string>::iterator itr = symbol_set.begin(); 42352 | 42353 | while (symbol_set.end() != itr) 42354 | { 42355 | symbol_list.push_back(*itr); 42356 | ++itr; 42357 | } 42358 | 42359 | return true; 42360 | } 42361 | 42362 | template <typename T> 42363 | inline T integrate(const expression<T>& e, 42364 | T& x, 42365 | const T& r0, const T& r1, 42366 | const std::size_t number_of_intervals = 1000000) 42367 | { 42368 | if (r0 > r1) 42369 | return T(0); 42370 | 42371 | const T h = (r1 - r0) / (T(2) * number_of_intervals); 42372 | T total_area = T(0); 42373 | 42374 | for (std::size_t i = 0; i < number_of_intervals; ++i) 42375 | { 42376 | x = r0 + T(2) * i * h; 42377 | const T y0 = e.value(); x += h; 42378 | const T y1 = e.value(); x += h; 42379 | const T y2 = e.value(); x += h; 42380 | total_area += h * (y0 + T(4) * y1 + y2) / T(3); 42381 | } 42382 | 42383 | return total_area; 42384 | } 42385 | 42386 | template <typename T> 42387 | inline T integrate(const expression<T>& e, 42388 | const std::string& variable_name, 42389 | const T& r0, const T& r1, 42390 | const std::size_t number_of_intervals = 1000000) 42391 | { 42392 | const symbol_table<T>& sym_table = e.get_symbol_table(); 42393 | 42394 | if (!sym_table.valid()) 42395 | { 42396 | return std::numeric_limits<T>::quiet_NaN(); 42397 | } 42398 | 42399 | details::variable_node<T>* var = sym_table.get_variable(variable_name); 42400 | 42401 | if (var) 42402 | { 42403 | T& x = var->ref(); 42404 | const T x_original = x; 42405 | const T result = integrate(e, x, r0, r1, number_of_intervals); 42406 | x = x_original; 42407 | 42408 | return result; 42409 | } 42410 | 42411 | return std::numeric_limits<T>::quiet_NaN(); 42412 | } 42413 | 42414 | template <typename T> 42415 | inline T derivative(const expression<T>& e, 42416 | T& x, 42417 | const T& h = T(0.00000001)) 42418 | { 42419 | const T x_init = x; 42420 | const T _2h = T(2) * h; 42421 | 42422 | x = x_init + _2h; 42423 | const T y0 = e.value(); 42424 | x = x_init + h; 42425 | const T y1 = e.value(); 42426 | x = x_init - h; 42427 | const T y2 = e.value(); 42428 | x = x_init - _2h; 42429 | const T y3 = e.value(); 42430 | x = x_init; 42431 | 42432 | return (-y0 + T(8) * (y1 - y2) + y3) / (T(12) * h); 42433 | } 42434 | 42435 | template <typename T> 42436 | inline T second_derivative(const expression<T>& e, 42437 | T& x, 42438 | const T& h = T(0.00001)) 42439 | { 42440 | const T x_init = x; 42441 | const T _2h = T(2) * h; 42442 | 42443 | const T y = e.value(); 42444 | x = x_init + _2h; 42445 | const T y0 = e.value(); 42446 | x = x_init + h; 42447 | const T y1 = e.value(); 42448 | x = x_init - h; 42449 | const T y2 = e.value(); 42450 | x = x_init - _2h; 42451 | const T y3 = e.value(); 42452 | x = x_init; 42453 | 42454 | return (-y0 + T(16) * (y1 + y2) - T(30) * y - y3) / (T(12) * h * h); 42455 | } 42456 | 42457 | template <typename T> 42458 | inline T third_derivative(const expression<T>& e, 42459 | T& x, 42460 | const T& h = T(0.0001)) 42461 | { 42462 | const T x_init = x; 42463 | const T _2h = T(2) * h; 42464 | 42465 | x = x_init + _2h; 42466 | const T y0 = e.value(); 42467 | x = x_init + h; 42468 | const T y1 = e.value(); 42469 | x = x_init - h; 42470 | const T y2 = e.value(); 42471 | x = x_init - _2h; 42472 | const T y3 = e.value(); 42473 | x = x_init; 42474 | 42475 | return (y0 + T(2) * (y2 - y1) - y3) / (T(2) * h * h * h); 42476 | } 42477 | 42478 | template <typename T> 42479 | inline T derivative(const expression<T>& e, 42480 | const std::string& variable_name, 42481 | const T& h = T(0.00000001)) 42482 | { 42483 | const symbol_table<T>& sym_table = e.get_symbol_table(); 42484 | 42485 | if (!sym_table.valid()) 42486 | { 42487 | return std::numeric_limits<T>::quiet_NaN(); 42488 | } 42489 | 42490 | details::variable_node<T>* var = sym_table.get_variable(variable_name); 42491 | 42492 | if (var) 42493 | { 42494 | T& x = var->ref(); 42495 | const T x_original = x; 42496 | const T result = derivative(e, x, h); 42497 | x = x_original; 42498 | 42499 | return result; 42500 | } 42501 | 42502 | return std::numeric_limits<T>::quiet_NaN(); 42503 | } 42504 | 42505 | template <typename T> 42506 | inline T second_derivative(const expression<T>& e, 42507 | const std::string& variable_name, 42508 | const T& h = T(0.00001)) 42509 | { 42510 | const symbol_table<T>& sym_table = e.get_symbol_table(); 42511 | 42512 | if (!sym_table.valid()) 42513 | { 42514 | return std::numeric_limits<T>::quiet_NaN(); 42515 | } 42516 | 42517 | details::variable_node<T>* var = sym_table.get_variable(variable_name); 42518 | 42519 | if (var) 42520 | { 42521 | T& x = var->ref(); 42522 | const T x_original = x; 42523 | const T result = second_derivative(e, x, h); 42524 | x = x_original; 42525 | 42526 | return result; 42527 | } 42528 | 42529 | return std::numeric_limits<T>::quiet_NaN(); 42530 | } 42531 | 42532 | template <typename T> 42533 | inline T third_derivative(const expression<T>& e, 42534 | const std::string& variable_name, 42535 | const T& h = T(0.0001)) 42536 | { 42537 | const symbol_table<T>& sym_table = e.get_symbol_table(); 42538 | 42539 | if (!sym_table.valid()) 42540 | { 42541 | return std::numeric_limits<T>::quiet_NaN(); 42542 | } 42543 | 42544 | details::variable_node<T>* var = sym_table.get_variable(variable_name); 42545 | 42546 | if (var) 42547 | { 42548 | T& x = var->ref(); 42549 | const T x_original = x; 42550 | const T result = third_derivative(e, x, h); 42551 | x = x_original; 42552 | 42553 | return result; 42554 | } 42555 | 42556 | return std::numeric_limits<T>::quiet_NaN(); 42557 | } 42558 | 42559 | /* 42560 | Note: The following 'compute' routines are simple helpers, 42561 | for quickly setting up the required pieces of code in order 42562 | to evaluate an expression. By virtue of how they operate 42563 | there will be an overhead with regards to their setup and 42564 | teardown and hence should not be used in time critical 42565 | sections of code. 42566 | Furthermore they only assume a small sub set of variables, 42567 | no string variables or user defined functions. 42568 | */ 42569 | template <typename T> 42570 | inline bool compute(const std::string& expression_string, T& result) 42571 | { 42572 | // No variables 42573 | symbol_table<T> symbol_table; 42574 | symbol_table.add_constants(); 42575 | 42576 | expression<T> expression; 42577 | expression.register_symbol_table(symbol_table); 42578 | 42579 | parser<T> parser; 42580 | 42581 | if (parser.compile(expression_string,expression)) 42582 | { 42583 | result = expression.value(); 42584 | 42585 | return true; 42586 | } 42587 | else 42588 | return false; 42589 | } 42590 | 42591 | template <typename T> 42592 | inline bool compute(const std::string& expression_string, 42593 | const T& x, 42594 | T& result) 42595 | { 42596 | // Only 'x' 42597 | static const std::string x_var("x"); 42598 | 42599 | symbol_table<T> symbol_table; 42600 | symbol_table.add_constants(); 42601 | symbol_table.add_constant(x_var,x); 42602 | 42603 | expression<T> expression; 42604 | expression.register_symbol_table(symbol_table); 42605 | 42606 | parser<T> parser; 42607 | 42608 | if (parser.compile(expression_string,expression)) 42609 | { 42610 | result = expression.value(); 42611 | 42612 | return true; 42613 | } 42614 | else 42615 | return false; 42616 | } 42617 | 42618 | template <typename T> 42619 | inline bool compute(const std::string& expression_string, 42620 | const T&x, const T& y, 42621 | T& result) 42622 | { 42623 | // Only 'x' and 'y' 42624 | static const std::string x_var("x"); 42625 | static const std::string y_var("y"); 42626 | 42627 | symbol_table<T> symbol_table; 42628 | symbol_table.add_constants(); 42629 | symbol_table.add_constant(x_var,x); 42630 | symbol_table.add_constant(y_var,y); 42631 | 42632 | expression<T> expression; 42633 | expression.register_symbol_table(symbol_table); 42634 | 42635 | parser<T> parser; 42636 | 42637 | if (parser.compile(expression_string,expression)) 42638 | { 42639 | result = expression.value(); 42640 | 42641 | return true; 42642 | } 42643 | else 42644 | return false; 42645 | } 42646 | 42647 | template <typename T> 42648 | inline bool compute(const std::string& expression_string, 42649 | const T& x, const T& y, const T& z, 42650 | T& result) 42651 | { 42652 | // Only 'x', 'y' or 'z' 42653 | static const std::string x_var("x"); 42654 | static const std::string y_var("y"); 42655 | static const std::string z_var("z"); 42656 | 42657 | symbol_table<T> symbol_table; 42658 | symbol_table.add_constants(); 42659 | symbol_table.add_constant(x_var,x); 42660 | symbol_table.add_constant(y_var,y); 42661 | symbol_table.add_constant(z_var,z); 42662 | 42663 | expression<T> expression; 42664 | expression.register_symbol_table(symbol_table); 42665 | 42666 | parser<T> parser; 42667 | 42668 | if (parser.compile(expression_string,expression)) 42669 | { 42670 | result = expression.value(); 42671 | 42672 | return true; 42673 | } 42674 | else 42675 | return false; 42676 | } 42677 | 42678 | template <typename T, std::size_t N> 42679 | class polynomial : public ifunction<T> 42680 | { 42681 | private: 42682 | 42683 | template <typename Type, std::size_t NumberOfCoefficients> 42684 | struct poly_impl { }; 42685 | 42686 | template <typename Type> 42687 | struct poly_impl <Type,12> 42688 | { 42689 | static inline T evaluate(const Type x, 42690 | const Type c12, const Type c11, const Type c10, const Type c9, const Type c8, 42691 | const Type c7, const Type c6, const Type c5, const Type c4, const Type c3, 42692 | const Type c2, const Type c1, const Type c0) 42693 | { 42694 | // p(x) = c_12x^12 + c_11x^11 + c_10x^10 + c_9x^9 + c_8x^8 + c_7x^7 + c_6x^6 + c_5x^5 + c_4x^4 + c_3x^3 + c_2x^2 + c_1x^1 + c_0x^0 42695 | return ((((((((((((c12 * x + c11) * x + c10) * x + c9) * x + c8) * x + c7) * x + c6) * x + c5) * x + c4) * x + c3) * x + c2) * x + c1) * x + c0); 42696 | } 42697 | }; 42698 | 42699 | template <typename Type> 42700 | struct poly_impl <Type,11> 42701 | { 42702 | static inline T evaluate(const Type x, 42703 | const Type c11, const Type c10, const Type c9, const Type c8, const Type c7, 42704 | const Type c6, const Type c5, const Type c4, const Type c3, const Type c2, 42705 | const Type c1, const Type c0) 42706 | { 42707 | // p(x) = c_11x^11 + c_10x^10 + c_9x^9 + c_8x^8 + c_7x^7 + c_6x^6 + c_5x^5 + c_4x^4 + c_3x^3 + c_2x^2 + c_1x^1 + c_0x^0 42708 | return (((((((((((c11 * x + c10) * x + c9) * x + c8) * x + c7) * x + c6) * x + c5) * x + c4) * x + c3) * x + c2) * x + c1) * x + c0); 42709 | } 42710 | }; 42711 | 42712 | template <typename Type> 42713 | struct poly_impl <Type,10> 42714 | { 42715 | static inline T evaluate(const Type x, 42716 | const Type c10, const Type c9, const Type c8, const Type c7, const Type c6, 42717 | const Type c5, const Type c4, const Type c3, const Type c2, const Type c1, 42718 | const Type c0) 42719 | { 42720 | // p(x) = c_10x^10 + c_9x^9 + c_8x^8 + c_7x^7 + c_6x^6 + c_5x^5 + c_4x^4 + c_3x^3 + c_2x^2 + c_1x^1 + c_0x^0 42721 | return ((((((((((c10 * x + c9) * x + c8) * x + c7) * x + c6) * x + c5) * x + c4) * x + c3) * x + c2) * x + c1) * x + c0); 42722 | } 42723 | }; 42724 | 42725 | template <typename Type> 42726 | struct poly_impl <Type,9> 42727 | { 42728 | static inline T evaluate(const Type x, 42729 | const Type c9, const Type c8, const Type c7, const Type c6, const Type c5, 42730 | const Type c4, const Type c3, const Type c2, const Type c1, const Type c0) 42731 | { 42732 | // p(x) = c_9x^9 + c_8x^8 + c_7x^7 + c_6x^6 + c_5x^5 + c_4x^4 + c_3x^3 + c_2x^2 + c_1x^1 + c_0x^0 42733 | return (((((((((c9 * x + c8) * x + c7) * x + c6) * x + c5) * x + c4) * x + c3) * x + c2) * x + c1) * x + c0); 42734 | } 42735 | }; 42736 | 42737 | template <typename Type> 42738 | struct poly_impl <Type,8> 42739 | { 42740 | static inline T evaluate(const Type x, 42741 | const Type c8, const Type c7, const Type c6, const Type c5, const Type c4, 42742 | const Type c3, const Type c2, const Type c1, const Type c0) 42743 | { 42744 | // p(x) = c_8x^8 + c_7x^7 + c_6x^6 + c_5x^5 + c_4x^4 + c_3x^3 + c_2x^2 + c_1x^1 + c_0x^0 42745 | return ((((((((c8 * x + c7) * x + c6) * x + c5) * x + c4) * x + c3) * x + c2) * x + c1) * x + c0); 42746 | } 42747 | }; 42748 | 42749 | template <typename Type> 42750 | struct poly_impl <Type,7> 42751 | { 42752 | static inline T evaluate(const Type x, 42753 | const Type c7, const Type c6, const Type c5, const Type c4, const Type c3, 42754 | const Type c2, const Type c1, const Type c0) 42755 | { 42756 | // p(x) = c_7x^7 + c_6x^6 + c_5x^5 + c_4x^4 + c_3x^3 + c_2x^2 + c_1x^1 + c_0x^0 42757 | return (((((((c7 * x + c6) * x + c5) * x + c4) * x + c3) * x + c2) * x + c1) * x + c0); 42758 | } 42759 | }; 42760 | 42761 | template <typename Type> 42762 | struct poly_impl <Type,6> 42763 | { 42764 | static inline T evaluate(const Type x, 42765 | const Type c6, const Type c5, const Type c4, const Type c3, const Type c2, 42766 | const Type c1, const Type c0) 42767 | { 42768 | // p(x) = c_6x^6 + c_5x^5 + c_4x^4 + c_3x^3 + c_2x^2 + c_1x^1 + c_0x^0 42769 | return ((((((c6 * x + c5) * x + c4) * x + c3) * x + c2) * x + c1) * x + c0); 42770 | } 42771 | }; 42772 | 42773 | template <typename Type> 42774 | struct poly_impl <Type,5> 42775 | { 42776 | static inline T evaluate(const Type x, 42777 | const Type c5, const Type c4, const Type c3, const Type c2, 42778 | const Type c1, const Type c0) 42779 | { 42780 | // p(x) = c_5x^5 + c_4x^4 + c_3x^3 + c_2x^2 + c_1x^1 + c_0x^0 42781 | return (((((c5 * x + c4) * x + c3) * x + c2) * x + c1) * x + c0); 42782 | } 42783 | }; 42784 | 42785 | template <typename Type> 42786 | struct poly_impl <Type,4> 42787 | { 42788 | static inline T evaluate(const Type x, const Type c4, const Type c3, const Type c2, const Type c1, const Type c0) 42789 | { 42790 | // p(x) = c_4x^4 + c_3x^3 + c_2x^2 + c_1x^1 + c_0x^0 42791 | return ((((c4 * x + c3) * x + c2) * x + c1) * x + c0); 42792 | } 42793 | }; 42794 | 42795 | template <typename Type> 42796 | struct poly_impl <Type,3> 42797 | { 42798 | static inline T evaluate(const Type x, const Type c3, const Type c2, const Type c1, const Type c0) 42799 | { 42800 | // p(x) = c_3x^3 + c_2x^2 + c_1x^1 + c_0x^0 42801 | return (((c3 * x + c2) * x + c1) * x + c0); 42802 | } 42803 | }; 42804 | 42805 | template <typename Type> 42806 | struct poly_impl <Type,2> 42807 | { 42808 | static inline T evaluate(const Type x, const Type c2, const Type c1, const Type c0) 42809 | { 42810 | // p(x) = c_2x^2 + c_1x^1 + c_0x^0 42811 | return ((c2 * x + c1) * x + c0); 42812 | } 42813 | }; 42814 | 42815 | template <typename Type> 42816 | struct poly_impl <Type,1> 42817 | { 42818 | static inline T evaluate(const Type x, const Type c1, const Type c0) 42819 | { 42820 | // p(x) = c_1x^1 + c_0x^0 42821 | return (c1 * x + c0); 42822 | } 42823 | }; 42824 | 42825 | public: 42826 | 42827 | using ifunction<T>::operator(); 42828 | 42829 | polynomial() 42830 | : ifunction<T>((N+2 <= 20) ? (N + 2) : std::numeric_limits<std::size_t>::max()) 42831 | { 42832 | disable_has_side_effects(*this); 42833 | } 42834 | 42835 | virtual ~polynomial() exprtk_override 42836 | {} 42837 | 42838 | #define poly_rtrn(NN) \ 42839 | return (NN != N) ? std::numeric_limits<T>::quiet_NaN() : 42840 | 42841 | inline virtual T operator() (const T& x, const T& c1, const T& c0) exprtk_override 42842 | { 42843 | poly_rtrn(1) (poly_impl<T,1>::evaluate(x, c1, c0)); 42844 | } 42845 | 42846 | inline virtual T operator() (const T& x, const T& c2, const T& c1, const T& c0) exprtk_override 42847 | { 42848 | poly_rtrn(2) (poly_impl<T,2>::evaluate(x, c2, c1, c0)); 42849 | } 42850 | 42851 | inline virtual T operator() (const T& x, const T& c3, const T& c2, const T& c1, const T& c0) exprtk_override 42852 | { 42853 | poly_rtrn(3) (poly_impl<T,3>::evaluate(x, c3, c2, c1, c0)); 42854 | } 42855 | 42856 | inline virtual T operator() (const T& x, const T& c4, const T& c3, const T& c2, const T& c1, 42857 | const T& c0) exprtk_override 42858 | { 42859 | poly_rtrn(4) (poly_impl<T,4>::evaluate(x, c4, c3, c2, c1, c0)); 42860 | } 42861 | 42862 | inline virtual T operator() (const T& x, const T& c5, const T& c4, const T& c3, const T& c2, 42863 | const T& c1, const T& c0) exprtk_override 42864 | { 42865 | poly_rtrn(5) (poly_impl<T,5>::evaluate(x, c5, c4, c3, c2, c1, c0)); 42866 | } 42867 | 42868 | inline virtual T operator() (const T& x, const T& c6, const T& c5, const T& c4, const T& c3, 42869 | const T& c2, const T& c1, const T& c0) exprtk_override 42870 | { 42871 | poly_rtrn(6) (poly_impl<T,6>::evaluate(x, c6, c5, c4, c3, c2, c1, c0)); 42872 | } 42873 | 42874 | inline virtual T operator() (const T& x, const T& c7, const T& c6, const T& c5, const T& c4, 42875 | const T& c3, const T& c2, const T& c1, const T& c0) exprtk_override 42876 | { 42877 | poly_rtrn(7) (poly_impl<T,7>::evaluate(x, c7, c6, c5, c4, c3, c2, c1, c0)); 42878 | } 42879 | 42880 | inline virtual T operator() (const T& x, const T& c8, const T& c7, const T& c6, const T& c5, 42881 | const T& c4, const T& c3, const T& c2, const T& c1, const T& c0) exprtk_override 42882 | { 42883 | poly_rtrn(8) (poly_impl<T,8>::evaluate(x, c8, c7, c6, c5, c4, c3, c2, c1, c0)); 42884 | } 42885 | 42886 | inline virtual T operator() (const T& x, const T& c9, const T& c8, const T& c7, const T& c6, 42887 | const T& c5, const T& c4, const T& c3, const T& c2, const T& c1, 42888 | const T& c0) exprtk_override 42889 | { 42890 | poly_rtrn(9) (poly_impl<T,9>::evaluate(x, c9, c8, c7, c6, c5, c4, c3, c2, c1, c0)); 42891 | } 42892 | 42893 | inline virtual T operator() (const T& x, const T& c10, const T& c9, const T& c8, const T& c7, 42894 | const T& c6, const T& c5, const T& c4, const T& c3, const T& c2, 42895 | const T& c1, const T& c0) exprtk_override 42896 | { 42897 | poly_rtrn(10) (poly_impl<T,10>::evaluate(x, c10, c9, c8, c7, c6, c5, c4, c3, c2, c1, c0)); 42898 | } 42899 | 42900 | inline virtual T operator() (const T& x, const T& c11, const T& c10, const T& c9, const T& c8, 42901 | const T& c7, const T& c6, const T& c5, const T& c4, const T& c3, 42902 | const T& c2, const T& c1, const T& c0) exprtk_override 42903 | { 42904 | poly_rtrn(11) (poly_impl<T,11>::evaluate(x, c11, c10, c9, c8, c7, c6, c5, c4, c3, c2, c1, c0)); 42905 | } 42906 | 42907 | inline virtual T operator() (const T& x, const T& c12, const T& c11, const T& c10, const T& c9, 42908 | const T& c8, const T& c7, const T& c6, const T& c5, const T& c4, 42909 | const T& c3, const T& c2, const T& c1, const T& c0) exprtk_override 42910 | { 42911 | poly_rtrn(12) (poly_impl<T,12>::evaluate(x, c12, c11, c10, c9, c8, c7, c6, c5, c4, c3, c2, c1, c0)); 42912 | } 42913 | 42914 | #undef poly_rtrn 42915 | 42916 | inline virtual T operator() () exprtk_override 42917 | { 42918 | return std::numeric_limits<T>::quiet_NaN(); 42919 | } 42920 | 42921 | inline virtual T operator() (const T&) exprtk_override 42922 | { 42923 | return std::numeric_limits<T>::quiet_NaN(); 42924 | } 42925 | 42926 | inline virtual T operator() (const T&, const T&) exprtk_override 42927 | { 42928 | return std::numeric_limits<T>::quiet_NaN(); 42929 | } 42930 | }; 42931 | 42932 | template <typename T> 42933 | class function_compositor 42934 | { 42935 | public: 42936 | 42937 | typedef exprtk::expression<T> expression_t; 42938 | typedef exprtk::symbol_table<T> symbol_table_t; 42939 | typedef exprtk::parser<T> parser_t; 42940 | typedef typename parser_t::settings_store settings_t; 42941 | 42942 | struct function 42943 | { 42944 | function() 42945 | {} 42946 | 42947 | explicit function(const std::string& n) 42948 | : name_(n) 42949 | {} 42950 | 42951 | function(const std::string& name, 42952 | const std::string& expression) 42953 | : name_(name) 42954 | , expression_(expression) 42955 | {} 42956 | 42957 | function(const std::string& name, 42958 | const std::string& expression, 42959 | const std::string& v0) 42960 | : name_(name) 42961 | , expression_(expression) 42962 | { 42963 | v_.push_back(v0); 42964 | } 42965 | 42966 | function(const std::string& name, 42967 | const std::string& expression, 42968 | const std::string& v0, const std::string& v1) 42969 | : name_(name) 42970 | , expression_(expression) 42971 | { 42972 | v_.push_back(v0); v_.push_back(v1); 42973 | } 42974 | 42975 | function(const std::string& name, 42976 | const std::string& expression, 42977 | const std::string& v0, const std::string& v1, 42978 | const std::string& v2) 42979 | : name_(name) 42980 | , expression_(expression) 42981 | { 42982 | v_.push_back(v0); v_.push_back(v1); 42983 | v_.push_back(v2); 42984 | } 42985 | 42986 | function(const std::string& name, 42987 | const std::string& expression, 42988 | const std::string& v0, const std::string& v1, 42989 | const std::string& v2, const std::string& v3) 42990 | : name_(name) 42991 | , expression_(expression) 42992 | { 42993 | v_.push_back(v0); v_.push_back(v1); 42994 | v_.push_back(v2); v_.push_back(v3); 42995 | } 42996 | 42997 | function(const std::string& name, 42998 | const std::string& expression, 42999 | const std::string& v0, const std::string& v1, 43000 | const std::string& v2, const std::string& v3, 43001 | const std::string& v4) 43002 | : name_(name) 43003 | , expression_(expression) 43004 | { 43005 | v_.push_back(v0); v_.push_back(v1); 43006 | v_.push_back(v2); v_.push_back(v3); 43007 | v_.push_back(v4); 43008 | } 43009 | 43010 | inline function& name(const std::string& n) 43011 | { 43012 | name_ = n; 43013 | return (*this); 43014 | } 43015 | 43016 | inline function& expression(const std::string& e) 43017 | { 43018 | expression_ = e; 43019 | return (*this); 43020 | } 43021 | 43022 | inline function& var(const std::string& v) 43023 | { 43024 | v_.push_back(v); 43025 | return (*this); 43026 | } 43027 | 43028 | inline function& vars(const std::string& v0, 43029 | const std::string& v1) 43030 | { 43031 | v_.push_back(v0); 43032 | v_.push_back(v1); 43033 | return (*this); 43034 | } 43035 | 43036 | inline function& vars(const std::string& v0, 43037 | const std::string& v1, 43038 | const std::string& v2) 43039 | { 43040 | v_.push_back(v0); 43041 | v_.push_back(v1); 43042 | v_.push_back(v2); 43043 | return (*this); 43044 | } 43045 | 43046 | inline function& vars(const std::string& v0, 43047 | const std::string& v1, 43048 | const std::string& v2, 43049 | const std::string& v3) 43050 | { 43051 | v_.push_back(v0); 43052 | v_.push_back(v1); 43053 | v_.push_back(v2); 43054 | v_.push_back(v3); 43055 | return (*this); 43056 | } 43057 | 43058 | inline function& vars(const std::string& v0, 43059 | const std::string& v1, 43060 | const std::string& v2, 43061 | const std::string& v3, 43062 | const std::string& v4) 43063 | { 43064 | v_.push_back(v0); 43065 | v_.push_back(v1); 43066 | v_.push_back(v2); 43067 | v_.push_back(v3); 43068 | v_.push_back(v4); 43069 | return (*this); 43070 | } 43071 | 43072 | std::string name_; 43073 | std::string expression_; 43074 | std::deque<std::string> v_; 43075 | }; 43076 | 43077 | private: 43078 | 43079 | struct base_func : public exprtk::ifunction<T> 43080 | { 43081 | typedef const T& type; 43082 | typedef exprtk::ifunction<T> function_t; 43083 | typedef std::vector<T*> varref_t; 43084 | typedef std::vector<T> var_t; 43085 | typedef std::vector<std::string> str_t; 43086 | typedef std::pair<T*,std::size_t> lvarref_t; 43087 | typedef std::vector<lvarref_t> lvr_vec_t; 43088 | typedef std::vector<std::string*> lstr_vec_t; 43089 | 43090 | using exprtk::ifunction<T>::operator(); 43091 | 43092 | explicit base_func(const std::size_t& pc = 0) 43093 | : exprtk::ifunction<T>(pc) 43094 | , local_var_stack_size(0) 43095 | , stack_depth(0) 43096 | { 43097 | v.resize(pc); 43098 | } 43099 | 43100 | virtual ~base_func() 43101 | {} 43102 | 43103 | #define exprtk_assign(Index) \ 43104 | (*v[Index]) = v##Index; \ 43105 | 43106 | inline void update(const T& v0) 43107 | { 43108 | exprtk_assign(0) 43109 | } 43110 | 43111 | inline void update(const T& v0, const T& v1) 43112 | { 43113 | exprtk_assign(0) exprtk_assign(1) 43114 | } 43115 | 43116 | inline void update(const T& v0, const T& v1, const T& v2) 43117 | { 43118 | exprtk_assign(0) exprtk_assign(1) 43119 | exprtk_assign(2) 43120 | } 43121 | 43122 | inline void update(const T& v0, const T& v1, const T& v2, const T& v3) 43123 | { 43124 | exprtk_assign(0) exprtk_assign(1) 43125 | exprtk_assign(2) exprtk_assign(3) 43126 | } 43127 | 43128 | inline void update(const T& v0, const T& v1, const T& v2, const T& v3, const T& v4) 43129 | { 43130 | exprtk_assign(0) exprtk_assign(1) 43131 | exprtk_assign(2) exprtk_assign(3) 43132 | exprtk_assign(4) 43133 | } 43134 | 43135 | inline void update(const T& v0, const T& v1, const T& v2, const T& v3, const T& v4, const T& v5) 43136 | { 43137 | exprtk_assign(0) exprtk_assign(1) 43138 | exprtk_assign(2) exprtk_assign(3) 43139 | exprtk_assign(4) exprtk_assign(5) 43140 | } 43141 | 43142 | #ifdef exprtk_assign 43143 | #undef exprtk_assign 43144 | #endif 43145 | 43146 | inline function_t& setup(expression_t& expr) 43147 | { 43148 | expression = expr; 43149 | 43150 | typedef typename expression_t::control_block ctrlblk_t; 43151 | typedef typename ctrlblk_t::local_data_list_t ldl_t; 43152 | typedef typename ctrlblk_t::data_type data_t; 43153 | typedef typename ldl_t::value_type ldl_value_type; 43154 | 43155 | const ldl_t ldl = expr.local_data_list(); 43156 | 43157 | std::vector<std::pair<std::size_t,data_t> > index_list; 43158 | 43159 | for (std::size_t i = 0; i < ldl.size(); ++i) 43160 | { 43161 | exprtk_debug(("base_func::setup() - element[%02d] type: %s size: %d\n", 43162 | static_cast<int>(i), 43163 | expression_t::control_block::to_str(ldl[i].type).c_str(), 43164 | static_cast<int>(ldl[i].size))); 43165 | 43166 | switch (ldl[i].type) 43167 | { 43168 | case ctrlblk_t::e_unknown : continue; 43169 | case ctrlblk_t::e_expr : continue; 43170 | case ctrlblk_t::e_vecholder : continue; 43171 | default : break; 43172 | } 43173 | 43174 | if (ldl[i].size) 43175 | { 43176 | index_list.push_back(std::make_pair(i,ldl[i].type)); 43177 | } 43178 | } 43179 | 43180 | std::size_t input_param_count = 0; 43181 | 43182 | for (std::size_t i = 0; i < index_list.size(); ++i) 43183 | { 43184 | const std::size_t index = index_list[i].first; 43185 | const ldl_value_type& local_var = ldl[index]; 43186 | 43187 | assert(local_var.pointer); 43188 | 43189 | if (i < (index_list.size() - v.size())) 43190 | { 43191 | if (local_var.type == ctrlblk_t::e_string) 43192 | { 43193 | local_str_vars.push_back( 43194 | reinterpret_cast<std::string*>(local_var.pointer)); 43195 | } 43196 | else if ( 43197 | (local_var.type == ctrlblk_t::e_data ) || 43198 | (local_var.type == ctrlblk_t::e_vecdata) 43199 | ) 43200 | { 43201 | local_vars.push_back(std::make_pair( 43202 | reinterpret_cast<T*>(local_var.pointer), 43203 | local_var.size)); 43204 | 43205 | local_var_stack_size += local_var.size; 43206 | } 43207 | } 43208 | else 43209 | { 43210 | v[input_param_count++] = reinterpret_cast<T*>(local_var.pointer); 43211 | } 43212 | } 43213 | 43214 | clear_stack(); 43215 | 43216 | return (*this); 43217 | } 43218 | 43219 | inline void pre() 43220 | { 43221 | if (stack_depth++) 43222 | { 43223 | if (!v.empty()) 43224 | { 43225 | var_t var_stack(v.size(),T(0)); 43226 | copy(v,var_stack); 43227 | input_params_stack.push_back(var_stack); 43228 | } 43229 | 43230 | if (!local_vars.empty()) 43231 | { 43232 | var_t local_vec_frame(local_var_stack_size,T(0)); 43233 | copy(local_vars,local_vec_frame); 43234 | local_var_stack.push_back(local_vec_frame); 43235 | } 43236 | 43237 | if (!local_str_vars.empty()) 43238 | { 43239 | str_t local_str_frame(local_str_vars.size()); 43240 | copy(local_str_vars,local_str_frame); 43241 | local_str_stack.push_back(local_str_frame); 43242 | } 43243 | } 43244 | } 43245 | 43246 | inline void post() 43247 | { 43248 | if (--stack_depth) 43249 | { 43250 | if (!v.empty()) 43251 | { 43252 | copy(input_params_stack.back(), v); 43253 | input_params_stack.pop_back(); 43254 | } 43255 | 43256 | if (!local_vars.empty()) 43257 | { 43258 | copy(local_var_stack.back(), local_vars); 43259 | local_var_stack.pop_back(); 43260 | } 43261 | 43262 | if (!local_str_vars.empty()) 43263 | { 43264 | copy(local_str_stack.back(), local_str_vars); 43265 | local_str_stack.pop_back(); 43266 | } 43267 | } 43268 | } 43269 | 43270 | void copy(const varref_t& src_v, var_t& dest_v) 43271 | { 43272 | for (std::size_t i = 0; i < src_v.size(); ++i) 43273 | { 43274 | dest_v[i] = (*src_v[i]); 43275 | } 43276 | } 43277 | 43278 | void copy(const lstr_vec_t& src_v, str_t& dest_v) 43279 | { 43280 | for (std::size_t i = 0; i < src_v.size(); ++i) 43281 | { 43282 | dest_v[i] = (*src_v[i]); 43283 | } 43284 | } 43285 | 43286 | void copy(const var_t& src_v, varref_t& dest_v) 43287 | { 43288 | for (std::size_t i = 0; i < src_v.size(); ++i) 43289 | { 43290 | (*dest_v[i]) = src_v[i]; 43291 | } 43292 | } 43293 | 43294 | void copy(const lvr_vec_t& src_v, var_t& dest_v) 43295 | { 43296 | typename var_t::iterator itr = dest_v.begin(); 43297 | typedef typename std::iterator_traits<typename var_t::iterator>::difference_type diff_t; 43298 | 43299 | for (std::size_t i = 0; i < src_v.size(); ++i) 43300 | { 43301 | lvarref_t vr = src_v[i]; 43302 | 43303 | if (1 == vr.second) 43304 | *itr++ = (*vr.first); 43305 | else 43306 | { 43307 | std::copy(vr.first, vr.first + vr.second, itr); 43308 | itr += static_cast<diff_t>(vr.second); 43309 | } 43310 | } 43311 | } 43312 | 43313 | void copy(const var_t& src_v, lvr_vec_t& dest_v) 43314 | { 43315 | typename var_t::const_iterator itr = src_v.begin(); 43316 | typedef typename std::iterator_traits<typename var_t::iterator>::difference_type diff_t; 43317 | 43318 | for (std::size_t i = 0; i < dest_v.size(); ++i) 43319 | { 43320 | lvarref_t& vr = dest_v[i]; 43321 | 43322 | assert(vr.first != 0); 43323 | assert(vr.second > 0); 43324 | 43325 | if (1 == vr.second) 43326 | (*vr.first) = *itr++; 43327 | else 43328 | { 43329 | std::copy(itr, itr + static_cast<diff_t>(vr.second), vr.first); 43330 | itr += static_cast<diff_t>(vr.second); 43331 | } 43332 | } 43333 | } 43334 | 43335 | void copy(const str_t& src_str, lstr_vec_t& dest_str) 43336 | { 43337 | assert(src_str.size() == dest_str.size()); 43338 | 43339 | for (std::size_t i = 0; i < dest_str.size(); ++i) 43340 | { 43341 | *dest_str[i] = src_str[i]; 43342 | } 43343 | } 43344 | 43345 | inline void clear_stack() 43346 | { 43347 | for (std::size_t i = 0; i < v.size(); ++i) 43348 | { 43349 | (*v[i]) = 0; 43350 | } 43351 | } 43352 | 43353 | inline virtual T value(expression_t& e) 43354 | { 43355 | return e.value(); 43356 | } 43357 | 43358 | expression_t expression; 43359 | varref_t v; 43360 | lvr_vec_t local_vars; 43361 | lstr_vec_t local_str_vars; 43362 | std::size_t local_var_stack_size; 43363 | std::size_t stack_depth; 43364 | std::deque<var_t> input_params_stack; 43365 | std::deque<var_t> local_var_stack; 43366 | std::deque<str_t> local_str_stack; 43367 | }; 43368 | 43369 | typedef std::map<std::string,base_func*> funcparam_t; 43370 | 43371 | typedef const T& type; 43372 | 43373 | template <typename BaseFuncType> 43374 | struct scoped_bft 43375 | { 43376 | explicit scoped_bft(BaseFuncType& bft) 43377 | : bft_(bft) 43378 | { 43379 | bft_.pre (); 43380 | } 43381 | 43382 | ~scoped_bft() 43383 | { 43384 | bft_.post(); 43385 | } 43386 | 43387 | BaseFuncType& bft_; 43388 | 43389 | private: 43390 | 43391 | scoped_bft(const scoped_bft&) exprtk_delete; 43392 | scoped_bft& operator=(const scoped_bft&) exprtk_delete; 43393 | }; 43394 | 43395 | struct func_0param : public base_func 43396 | { 43397 | using exprtk::ifunction<T>::operator(); 43398 | 43399 | func_0param() : base_func(0) {} 43400 | 43401 | inline T operator() () exprtk_override 43402 | { 43403 | scoped_bft<func_0param> sb(*this); 43404 | return this->value(base_func::expression); 43405 | } 43406 | }; 43407 | 43408 | struct func_1param : public base_func 43409 | { 43410 | using exprtk::ifunction<T>::operator(); 43411 | 43412 | func_1param() : base_func(1) {} 43413 | 43414 | inline T operator() (type v0) exprtk_override 43415 | { 43416 | scoped_bft<func_1param> sb(*this); 43417 | base_func::update(v0); 43418 | return this->value(base_func::expression); 43419 | } 43420 | }; 43421 | 43422 | struct func_2param : public base_func 43423 | { 43424 | using exprtk::ifunction<T>::operator(); 43425 | 43426 | func_2param() : base_func(2) {} 43427 | 43428 | inline T operator() (type v0, type v1) exprtk_override 43429 | { 43430 | scoped_bft<func_2param> sb(*this); 43431 | base_func::update(v0, v1); 43432 | return this->value(base_func::expression); 43433 | } 43434 | }; 43435 | 43436 | struct func_3param : public base_func 43437 | { 43438 | using exprtk::ifunction<T>::operator(); 43439 | 43440 | func_3param() : base_func(3) {} 43441 | 43442 | inline T operator() (type v0, type v1, type v2) exprtk_override 43443 | { 43444 | scoped_bft<func_3param> sb(*this); 43445 | base_func::update(v0, v1, v2); 43446 | return this->value(base_func::expression); 43447 | } 43448 | }; 43449 | 43450 | struct func_4param : public base_func 43451 | { 43452 | using exprtk::ifunction<T>::operator(); 43453 | 43454 | func_4param() : base_func(4) {} 43455 | 43456 | inline T operator() (type v0, type v1, type v2, type v3) exprtk_override 43457 | { 43458 | scoped_bft<func_4param> sb(*this); 43459 | base_func::update(v0, v1, v2, v3); 43460 | return this->value(base_func::expression); 43461 | } 43462 | }; 43463 | 43464 | struct func_5param : public base_func 43465 | { 43466 | using exprtk::ifunction<T>::operator(); 43467 | 43468 | func_5param() : base_func(5) {} 43469 | 43470 | inline T operator() (type v0, type v1, type v2, type v3, type v4) exprtk_override 43471 | { 43472 | scoped_bft<func_5param> sb(*this); 43473 | base_func::update(v0, v1, v2, v3, v4); 43474 | return this->value(base_func::expression); 43475 | } 43476 | }; 43477 | 43478 | struct func_6param : public base_func 43479 | { 43480 | using exprtk::ifunction<T>::operator(); 43481 | 43482 | func_6param() : base_func(6) {} 43483 | 43484 | inline T operator() (type v0, type v1, type v2, type v3, type v4, type v5) exprtk_override 43485 | { 43486 | scoped_bft<func_6param> sb(*this); 43487 | base_func::update(v0, v1, v2, v3, v4, v5); 43488 | return this->value(base_func::expression); 43489 | } 43490 | }; 43491 | 43492 | static T return_value(expression_t& e) 43493 | { 43494 | typedef exprtk::results_context<T> results_context_t; 43495 | typedef typename results_context_t::type_store_t type_t; 43496 | typedef typename type_t::scalar_view scalar_t; 43497 | 43498 | const T result = e.value(); 43499 | 43500 | if (e.return_invoked()) 43501 | { 43502 | // Due to the post compilation checks, it can be safely 43503 | // assumed that there will be at least one parameter 43504 | // and that the first parameter will always be scalar. 43505 | return scalar_t(e.results()[0])(); 43506 | } 43507 | 43508 | return result; 43509 | } 43510 | 43511 | #define def_fp_retval(N) \ 43512 | struct func_##N##param_retval exprtk_final : public func_##N##param \ 43513 | { \ 43514 | inline T value(expression_t& e) exprtk_override \ 43515 | { \ 43516 | return return_value(e); \ 43517 | } \ 43518 | }; \ 43519 | 43520 | def_fp_retval(0) 43521 | def_fp_retval(1) 43522 | def_fp_retval(2) 43523 | def_fp_retval(3) 43524 | def_fp_retval(4) 43525 | def_fp_retval(5) 43526 | def_fp_retval(6) 43527 | 43528 | #undef def_fp_retval 43529 | 43530 | template <typename Allocator, 43531 | template <typename, typename> class Sequence> 43532 | inline bool add(const std::string& name, 43533 | const std::string& expression, 43534 | const Sequence<std::string,Allocator>& var_list, 43535 | const bool override = false) 43536 | { 43537 | const typename std::map<std::string,expression_t>::iterator itr = expr_map_.find(name); 43538 | 43539 | if (expr_map_.end() != itr) 43540 | { 43541 | if (!override) 43542 | { 43543 | exprtk_debug(("Compositor error(add): function '%s' already defined\n", 43544 | name.c_str())); 43545 | 43546 | return false; 43547 | } 43548 | 43549 | remove(name, var_list.size()); 43550 | } 43551 | 43552 | if (compile_expression(name, expression, var_list)) 43553 | { 43554 | const std::size_t n = var_list.size(); 43555 | 43556 | fp_map_[n][name]->setup(expr_map_[name]); 43557 | 43558 | return true; 43559 | } 43560 | else 43561 | { 43562 | exprtk_debug(("Compositor error(add): Failed to compile function '%s'\n", 43563 | name.c_str())); 43564 | 43565 | return false; 43566 | } 43567 | } 43568 | 43569 | public: 43570 | 43571 | function_compositor() 43572 | : parser_(settings_t::default_compile_all_opts + 43573 | settings_t::e_disable_zero_return) 43574 | , fp_map_(7) 43575 | , load_variables_(false) 43576 | , load_vectors_(false) 43577 | {} 43578 | 43579 | explicit function_compositor(const symbol_table_t& st) 43580 | : symbol_table_(st) 43581 | , parser_(settings_t::default_compile_all_opts + 43582 | settings_t::e_disable_zero_return) 43583 | , fp_map_(7) 43584 | , load_variables_(false) 43585 | , load_vectors_(false) 43586 | {} 43587 | 43588 | ~function_compositor() 43589 | { 43590 | clear(); 43591 | } 43592 | 43593 | inline symbol_table_t& symbol_table() 43594 | { 43595 | return symbol_table_; 43596 | } 43597 | 43598 | inline const symbol_table_t& symbol_table() const 43599 | { 43600 | return symbol_table_; 43601 | } 43602 | 43603 | inline void add_auxiliary_symtab(symbol_table_t& symtab) 43604 | { 43605 | auxiliary_symtab_list_.push_back(&symtab); 43606 | } 43607 | 43608 | void load_variables(const bool load = true) 43609 | { 43610 | load_variables_ = load; 43611 | } 43612 | 43613 | void load_vectors(const bool load = true) 43614 | { 43615 | load_vectors_ = load; 43616 | } 43617 | 43618 | inline void register_loop_runtime_check(loop_runtime_check& lrtchk) 43619 | { 43620 | parser_.register_loop_runtime_check(lrtchk); 43621 | } 43622 | 43623 | inline void register_vector_access_runtime_check(vector_access_runtime_check& vartchk) 43624 | { 43625 | parser_.register_vector_access_runtime_check(vartchk); 43626 | } 43627 | 43628 | inline void register_compilation_timeout_check(compilation_check& compchk) 43629 | { 43630 | parser_.register_compilation_timeout_check(compchk); 43631 | } 43632 | 43633 | inline void clear_loop_runtime_check() 43634 | { 43635 | parser_.clear_loop_runtime_check(); 43636 | } 43637 | 43638 | inline void clear_vector_access_runtime_check() 43639 | { 43640 | parser_.clear_vector_access_runtime_check(); 43641 | } 43642 | 43643 | inline void clear_compilation_timeout_check() 43644 | { 43645 | parser_.clear_compilation_timeout_check(); 43646 | } 43647 | 43648 | void clear() 43649 | { 43650 | symbol_table_.clear(); 43651 | expr_map_ .clear(); 43652 | 43653 | for (std::size_t i = 0; i < fp_map_.size(); ++i) 43654 | { 43655 | typename funcparam_t::iterator itr = fp_map_[i].begin(); 43656 | typename funcparam_t::iterator end = fp_map_[i].end (); 43657 | 43658 | while (itr != end) 43659 | { 43660 | delete itr->second; 43661 | ++itr; 43662 | } 43663 | 43664 | fp_map_[i].clear(); 43665 | } 43666 | 43667 | clear_loop_runtime_check (); 43668 | clear_vector_access_runtime_check(); 43669 | clear_compilation_timeout_check (); 43670 | } 43671 | 43672 | inline bool add(const function& f, const bool override = false) 43673 | { 43674 | return add(f.name_, f.expression_, f.v_,override); 43675 | } 43676 | 43677 | inline std::string error() const 43678 | { 43679 | if (!error_list_.empty()) 43680 | { 43681 | return error_list_[0].diagnostic; 43682 | } 43683 | else 43684 | return std::string("No Error"); 43685 | } 43686 | 43687 | inline std::size_t error_count() const 43688 | { 43689 | return error_list_.size(); 43690 | } 43691 | 43692 | inline parser_error::type get_error(const std::size_t& index) const 43693 | { 43694 | if (index < error_list_.size()) 43695 | { 43696 | return error_list_[index]; 43697 | } 43698 | 43699 | throw std::invalid_argument("compositor::get_error() - Invalid error index specified"); 43700 | } 43701 | 43702 | private: 43703 | 43704 | template <typename Allocator, 43705 | template <typename, typename> class Sequence> 43706 | bool compile_expression(const std::string& name, 43707 | const std::string& expression, 43708 | const Sequence<std::string,Allocator>& input_var_list, 43709 | bool return_present = false) 43710 | { 43711 | expression_t compiled_expression; 43712 | symbol_table_t local_symbol_table; 43713 | 43714 | local_symbol_table.load_from(symbol_table_); 43715 | local_symbol_table.add_constants(); 43716 | 43717 | if (load_variables_) 43718 | { 43719 | local_symbol_table.load_variables_from(symbol_table_); 43720 | } 43721 | 43722 | if (load_vectors_) 43723 | { 43724 | local_symbol_table.load_vectors_from(symbol_table_); 43725 | } 43726 | 43727 | error_list_.clear(); 43728 | 43729 | if (!valid(name,input_var_list.size())) 43730 | { 43731 | parser_error::type error = 43732 | parser_error::make_error( 43733 | parser_error::e_parser, 43734 | lexer::token(), 43735 | "ERR283 - Function '" + name + "' is an invalid overload", 43736 | exprtk_error_location); 43737 | 43738 | error_list_.push_back(error); 43739 | return false; 43740 | } 43741 | 43742 | if (!forward(name, 43743 | input_var_list.size(), 43744 | local_symbol_table, 43745 | return_present)) 43746 | return false; 43747 | 43748 | compiled_expression.register_symbol_table(local_symbol_table); 43749 | 43750 | for (std::size_t i = 0; i < auxiliary_symtab_list_.size(); ++i) 43751 | { 43752 | compiled_expression.register_symbol_table((*auxiliary_symtab_list_[i])); 43753 | } 43754 | 43755 | std::string mod_expression; 43756 | 43757 | for (std::size_t i = 0; i < input_var_list.size(); ++i) 43758 | { 43759 | mod_expression += " var " + input_var_list[i] + "{};\n" 43760 | } 43761 | 43762 | if ( 43763 | ('{' == details::front(expression)) && 43764 | ('}' == details::back (expression)) 43765 | ) 43766 | mod_expression += "~" + expression + "" 43767 | else 43768 | mod_expression += "~{" + expression + "};" 43769 | 43770 | if (!parser_.compile(mod_expression,compiled_expression)) 43771 | { 43772 | exprtk_debug(("Compositor Error: %s\n", parser_.error().c_str())); 43773 | exprtk_debug(("Compositor modified expression: \n%s\n", mod_expression.c_str())); 43774 | 43775 | remove(name,input_var_list.size()); 43776 | 43777 | for (std::size_t err_index = 0; err_index < parser_.error_count(); ++err_index) 43778 | { 43779 | error_list_.push_back(parser_.get_error(err_index)); 43780 | } 43781 | 43782 | return false; 43783 | } 43784 | 43785 | if (!return_present && parser_.dec().return_present()) 43786 | { 43787 | remove(name,input_var_list.size()); 43788 | return compile_expression(name, expression, input_var_list, true); 43789 | } 43790 | 43791 | // Make sure every return point has a scalar as its first parameter 43792 | if (parser_.dec().return_present()) 43793 | { 43794 | typedef std::vector<std::string> str_list_t; 43795 | 43796 | str_list_t ret_param_list = parser_.dec().return_param_type_list(); 43797 | 43798 | for (std::size_t i = 0; i < ret_param_list.size(); ++i) 43799 | { 43800 | const std::string& params = ret_param_list[i]; 43801 | 43802 | if (params.empty() || ('T' != params[0])) 43803 | { 43804 | exprtk_debug(("Compositor Error: Return statement in function '%s' is invalid\n", 43805 | name.c_str())); 43806 | 43807 | remove(name,input_var_list.size()); 43808 | 43809 | return false; 43810 | } 43811 | } 43812 | } 43813 | 43814 | expr_map_[name] = compiled_expression; 43815 | 43816 | exprtk::ifunction<T>& ifunc = (*(fp_map_[input_var_list.size()])[name]); 43817 | 43818 | if (symbol_table_.add_function(name,ifunc)) 43819 | return true; 43820 | else 43821 | { 43822 | exprtk_debug(("Compositor Error: Failed to add function '%s' to symbol table\n", 43823 | name.c_str())); 43824 | return false; 43825 | } 43826 | } 43827 | 43828 | inline bool symbol_used(const std::string& symbol) const 43829 | { 43830 | return ( 43831 | symbol_table_.is_variable (symbol) || 43832 | symbol_table_.is_stringvar (symbol) || 43833 | symbol_table_.is_function (symbol) || 43834 | symbol_table_.is_vector (symbol) || 43835 | symbol_table_.is_vararg_function(symbol) 43836 | ); 43837 | } 43838 | 43839 | inline bool valid(const std::string& name, 43840 | const std::size_t& arg_count) const 43841 | { 43842 | if (arg_count > 6) 43843 | return false; 43844 | else if (symbol_used(name)) 43845 | return false; 43846 | else if (fp_map_[arg_count].end() != fp_map_[arg_count].find(name)) 43847 | return false; 43848 | else 43849 | return true; 43850 | } 43851 | 43852 | inline bool forward(const std::string& name, 43853 | const std::size_t& arg_count, 43854 | symbol_table_t& sym_table, 43855 | const bool ret_present = false) 43856 | { 43857 | switch (arg_count) 43858 | { 43859 | #define case_stmt(N) \ 43860 | case N : (fp_map_[arg_count])[name] = \ 43861 | (!ret_present) ? static_cast<base_func*> \ 43862 | (new func_##N##param) : \ 43863 | static_cast<base_func*> \ 43864 | (new func_##N##param_retval) ; \ 43865 | break; \ 43866 | 43867 | case_stmt(0) case_stmt(1) case_stmt(2) 43868 | case_stmt(3) case_stmt(4) case_stmt(5) 43869 | case_stmt(6) 43870 | #undef case_stmt 43871 | } 43872 | 43873 | exprtk::ifunction<T>& ifunc = (*(fp_map_[arg_count])[name]); 43874 | 43875 | return sym_table.add_function(name,ifunc); 43876 | } 43877 | 43878 | inline void remove(const std::string& name, const std::size_t& arg_count) 43879 | { 43880 | if (arg_count > 6) 43881 | return; 43882 | 43883 | const typename std::map<std::string,expression_t>::iterator em_itr = expr_map_.find(name); 43884 | 43885 | if (expr_map_.end() != em_itr) 43886 | { 43887 | expr_map_.erase(em_itr); 43888 | } 43889 | 43890 | const typename funcparam_t::iterator fp_itr = fp_map_[arg_count].find(name); 43891 | 43892 | if (fp_map_[arg_count].end() != fp_itr) 43893 | { 43894 | delete fp_itr->second; 43895 | fp_map_[arg_count].erase(fp_itr); 43896 | } 43897 | 43898 | symbol_table_.remove_function(name); 43899 | } 43900 | 43901 | private: 43902 | 43903 | symbol_table_t symbol_table_; 43904 | parser_t parser_; 43905 | std::map<std::string,expression_t> expr_map_; 43906 | std::vector<funcparam_t> fp_map_; 43907 | std::vector<symbol_table_t*> auxiliary_symtab_list_; 43908 | std::deque<parser_error::type> error_list_; 43909 | bool load_variables_; 43910 | bool load_vectors_; 43911 | }; // class function_compositor 43912 | 43913 | } // namespace exprtk 43914 | 43915 | #if defined(_MSC_VER) || defined(_WIN32) || defined(__WIN32__) || defined(WIN32) 43916 | # ifndef NOMINMAX 43917 | # define NOMINMAX 43918 | # endif 43919 | # ifndef WIN32_LEAN_AND_MEAN 43920 | # define WIN32_LEAN_AND_MEAN 43921 | # endif 43922 | # include 43923 | # include 43924 | #else 43925 | # include 43926 | # include 43927 | # include 43928 | #endif 43929 | 43930 | namespace exprtk 43931 | { 43932 | class timer 43933 | { 43934 | public: 43935 | 43936 | #if defined(_MSC_VER) || defined(_WIN32) || defined(__WIN32__) || defined(WIN32) 43937 | timer() 43938 | : in_use_(false) 43939 | , start_time_{ {0, 0} } 43940 | , stop_time_ { {0, 0} } 43941 | { 43942 | QueryPerformanceFrequency(&clock_frequency_); 43943 | } 43944 | 43945 | inline void start() 43946 | { 43947 | in_use_ = true; 43948 | QueryPerformanceCounter(&start_time_); 43949 | } 43950 | 43951 | inline void stop() 43952 | { 43953 | QueryPerformanceCounter(&stop_time_); 43954 | in_use_ = false; 43955 | } 43956 | 43957 | inline double time() const 43958 | { 43959 | return (1.0 * (stop_time_.QuadPart - start_time_.QuadPart)) / (1.0 * clock_frequency_.QuadPart); 43960 | } 43961 | 43962 | #else 43963 | 43964 | timer() 43965 | : in_use_(false) 43966 | { 43967 | start_time_.tv_sec = 0; 43968 | start_time_.tv_usec = 0; 43969 | 43970 | stop_time_.tv_sec = 0; 43971 | stop_time_.tv_usec = 0; 43972 | } 43973 | 43974 | inline void start() 43975 | { 43976 | in_use_ = true; 43977 | gettimeofday(&start_time_,0); 43978 | } 43979 | 43980 | inline void stop() 43981 | { 43982 | gettimeofday(&stop_time_, 0); 43983 | in_use_ = false; 43984 | } 43985 | 43986 | inline unsigned long long int usec_time() const 43987 | { 43988 | if (!in_use_) 43989 | { 43990 | if (stop_time_.tv_sec >= start_time_.tv_sec) 43991 | { 43992 | return 1000000LLU * static_cast<details::_uint64_t>(stop_time_.tv_sec - start_time_.tv_sec ) + 43993 | static_cast<details::_uint64_t>(stop_time_.tv_usec - start_time_.tv_usec) ; 43994 | } 43995 | else 43996 | return std::numeric_limits<details::_uint64_t>::max(); 43997 | } 43998 | else 43999 | return std::numeric_limits<details::_uint64_t>::max(); 44000 | } 44001 | 44002 | inline double time() const 44003 | { 44004 | return usec_time() * 0.000001; 44005 | } 44006 | 44007 | #endif 44008 | 44009 | inline bool in_use() const 44010 | { 44011 | return in_use_; 44012 | } 44013 | 44014 | private: 44015 | 44016 | bool in_use_; 44017 | 44018 | #if defined(_MSC_VER) || defined(_WIN32) || defined(__WIN32__) || defined(WIN32) 44019 | LARGE_INTEGER start_time_; 44020 | LARGE_INTEGER stop_time_; 44021 | LARGE_INTEGER clock_frequency_; 44022 | #else 44023 | struct timeval start_time_; 44024 | struct timeval stop_time_; 44025 | #endif 44026 | }; 44027 | 44028 | template <typename T> 44029 | struct type_defs 44030 | { 44031 | typedef symbol_table<T> symbol_table_t; 44032 | typedef expression<T> expression_t; 44033 | typedef parser<T> parser_t; 44034 | typedef parser_error::type error_t; 44035 | typedef function_compositor<T> compositor_t; 44036 | typedef typename compositor_t::function function_t; 44037 | }; 44038 | 44039 | } // namespace exprtk 44040 | 44041 | #ifndef exprtk_disable_rtl_io 44042 | namespace exprtk 44043 | { 44044 | namespace rtl { namespace io { namespace details 44045 | { 44046 | template <typename T> 44047 | inline void print_type(const std::string& fmt, 44048 | const T v, 44049 | exprtk::details::numeric::details::real_type_tag) 44050 | { 44051 | #if defined(__clang__) 44052 | #pragma clang diagnostic push 44053 | #pragma clang diagnostic ignored "-Wformat-nonliteral" 44054 | #elif defined(__GNUC__) || defined(__GNUG__) 44055 | #pragma GCC diagnostic push 44056 | #pragma GCC diagnostic ignored "-Wformat-nonliteral" 44057 | #elif defined(_MSC_VER) 44058 | #endif 44059 | 44060 | printf(fmt.c_str(), v); 44061 | 44062 | #if defined(__clang__) 44063 | #pragma clang diagnostic pop 44064 | #elif defined(__GNUC__) || defined(__GNUG__) 44065 | #pragma GCC diagnostic pop 44066 | #elif defined(_MSC_VER) 44067 | #endif 44068 | } 44069 | 44070 | template <typename T> 44071 | struct print_impl 44072 | { 44073 | typedef typename igeneric_function<T>::generic_type generic_type; 44074 | typedef typename igeneric_function<T>::parameter_list_t parameter_list_t; 44075 | typedef typename generic_type::scalar_view scalar_t; 44076 | typedef typename generic_type::vector_view vector_t; 44077 | typedef typename generic_type::string_view string_t; 44078 | typedef typename exprtk::details::numeric::details::number_type<T>::type num_type; 44079 | 44080 | static void process(const std::string& scalar_format, parameter_list_t parameters) 44081 | { 44082 | for (std::size_t i = 0; i < parameters.size(); ++i) 44083 | { 44084 | generic_type& gt = parameters[i]; 44085 | 44086 | switch (gt.type) 44087 | { 44088 | case generic_type::e_scalar : print(scalar_format,scalar_t(gt)); 44089 | break; 44090 | 44091 | case generic_type::e_vector : print(scalar_format,vector_t(gt)); 44092 | break; 44093 | 44094 | case generic_type::e_string : print(string_t(gt)); 44095 | break; 44096 | 44097 | default : continue; 44098 | } 44099 | } 44100 | } 44101 | 44102 | static inline void print(const std::string& scalar_format, const scalar_t& s) 44103 | { 44104 | print_type(scalar_format,s(),num_type()); 44105 | } 44106 | 44107 | static inline void print(const std::string& scalar_format, const vector_t& v) 44108 | { 44109 | for (std::size_t i = 0; i < v.size(); ++i) 44110 | { 44111 | print_type(scalar_format,v[i],num_type()); 44112 | 44113 | if ((i + 1) < v.size()) 44114 | printf(" "); 44115 | } 44116 | } 44117 | 44118 | static inline void print(const string_t& s) 44119 | { 44120 | printf("%s",to_str(s).c_str()); 44121 | } 44122 | }; 44123 | 44124 | } // namespace exprtk::rtl::io::details 44125 | 44126 | template <typename T> 44127 | struct print exprtk_final : public exprtk::igeneric_function<T> 44128 | { 44129 | typedef typename igeneric_function<T>::parameter_list_t parameter_list_t; 44130 | 44131 | using exprtk::igeneric_function<T>::operator(); 44132 | 44133 | explicit print(const std::string& scalar_format = "%10.5f") 44134 | : scalar_format_(scalar_format) 44135 | { 44136 | exprtk::enable_zero_parameters(*this); 44137 | } 44138 | 44139 | inline T operator() (parameter_list_t parameters) exprtk_override 44140 | { 44141 | details::print_impl<T>::process(scalar_format_,parameters); 44142 | return T(0); 44143 | } 44144 | 44145 | std::string scalar_format_; 44146 | }; 44147 | 44148 | template <typename T> 44149 | struct println exprtk_final : public exprtk::igeneric_function<T> 44150 | { 44151 | typedef typename igeneric_function<T>::parameter_list_t parameter_list_t; 44152 | 44153 | using exprtk::igeneric_function<T>::operator(); 44154 | 44155 | explicit println(const std::string& scalar_format = "%10.5f") 44156 | : scalar_format_(scalar_format) 44157 | { 44158 | exprtk::enable_zero_parameters(*this); 44159 | } 44160 | 44161 | inline T operator() (parameter_list_t parameters) exprtk_override 44162 | { 44163 | details::print_impl<T>::process(scalar_format_,parameters); 44164 | printf("\n"); 44165 | return T(0); 44166 | } 44167 | 44168 | std::string scalar_format_; 44169 | }; 44170 | 44171 | template <typename T> 44172 | struct package 44173 | { 44174 | print <T> p; 44175 | println<T> pl; 44176 | 44177 | bool register_package(exprtk::symbol_table<T>& symtab) 44178 | { 44179 | #define exprtk_register_function(FunctionName, FunctionType) \ 44180 | if (!symtab.add_function(FunctionName,FunctionType)) \ 44181 | { \ 44182 | exprtk_debug(( \ 44183 | "exprtk::rtl::io::register_package - Failed to add function: %s\n", \ 44184 | FunctionName)); \ 44185 | return false; \ 44186 | } \ 44187 | 44188 | exprtk_register_function("print" , p ) 44189 | exprtk_register_function("println", pl) 44190 | #undef exprtk_register_function 44191 | 44192 | return true; 44193 | } 44194 | }; 44195 | 44196 | } // namespace exprtk::rtl::io 44197 | } // namespace exprtk::rtl 44198 | } // namespace exprtk 44199 | #endif 44200 | 44201 | #ifndef exprtk_disable_rtl_io_file 44202 | #include 44203 | namespace exprtk 44204 | { 44205 | namespace rtl { namespace io { namespace file { namespace details 44206 | { 44207 | using ::exprtk::details::char_ptr; 44208 | using ::exprtk::details::char_cptr; 44209 | 44210 | enum file_mode 44211 | { 44212 | e_error = 0, 44213 | e_read = 1, 44214 | e_write = 2, 44215 | e_rdwrt = 4 44216 | }; 44217 | 44218 | struct file_descriptor 44219 | { 44220 | file_descriptor(const std::string& fname, const std::string& access) 44221 | : stream_ptr(0) 44222 | , mode(get_file_mode(access)) 44223 | , file_name(fname) 44224 | {} 44225 | 44226 | void* stream_ptr; 44227 | file_mode mode; 44228 | std::string file_name; 44229 | 44230 | bool open() 44231 | { 44232 | if (e_read == mode) 44233 | { 44234 | std::ifstream* stream = new std::ifstream(file_name.c_str(),std::ios::binary); 44235 | 44236 | if (!(*stream)) 44237 | { 44238 | file_name.clear(); 44239 | delete stream; 44240 | 44241 | return false; 44242 | } 44243 | 44244 | stream_ptr = stream; 44245 | 44246 | return true; 44247 | } 44248 | else if (e_write == mode) 44249 | { 44250 | std::ofstream* stream = new std::ofstream(file_name.c_str(),std::ios::binary); 44251 | 44252 | if (!(*stream)) 44253 | { 44254 | file_name.clear(); 44255 | delete stream; 44256 | 44257 | return false; 44258 | } 44259 | 44260 | stream_ptr = stream; 44261 | 44262 | return true; 44263 | } 44264 | else if (e_rdwrt == mode) 44265 | { 44266 | std::fstream* stream = new std::fstream(file_name.c_str(),std::ios::binary); 44267 | 44268 | if (!(*stream)) 44269 | { 44270 | file_name.clear(); 44271 | delete stream; 44272 | 44273 | return false; 44274 | } 44275 | 44276 | stream_ptr = stream; 44277 | 44278 | return true; 44279 | } 44280 | 44281 | return false; 44282 | } 44283 | 44284 | template <typename Stream, typename Ptr> 44285 | void close(Ptr& p) 44286 | { 44287 | Stream* stream = reinterpret_cast<Stream*>(p); 44288 | stream->close(); 44289 | delete stream; 44290 | p = reinterpret_cast<Ptr>(0); 44291 | } 44292 | 44293 | bool close() 44294 | { 44295 | switch (mode) 44296 | { 44297 | case e_read : close<std::ifstream>(stream_ptr); 44298 | break; 44299 | 44300 | case e_write : close<std::ofstream>(stream_ptr); 44301 | break; 44302 | 44303 | case e_rdwrt : close<std::fstream> (stream_ptr); 44304 | break; 44305 | 44306 | default : return false; 44307 | } 44308 | 44309 | return true; 44310 | } 44311 | 44312 | template <typename View> 44313 | bool write(const View& view, const std::size_t amount, const std::size_t offset = 0) 44314 | { 44315 | switch (mode) 44316 | { 44317 | case e_write : reinterpret_cast<std::ofstream*>(stream_ptr)-> 44318 | write(reinterpret_cast<char_cptr>(view.begin() + offset), amount * sizeof(typename View::value_t)); 44319 | break; 44320 | 44321 | case e_rdwrt : reinterpret_cast<std::fstream*>(stream_ptr)-> 44322 | write(reinterpret_cast<char_cptr>(view.begin() + offset) , amount * sizeof(typename View::value_t)); 44323 | break; 44324 | 44325 | default : return false; 44326 | } 44327 | 44328 | return true; 44329 | } 44330 | 44331 | template <typename View> 44332 | bool read(View& view, const std::size_t amount, const std::size_t offset = 0) 44333 | { 44334 | switch (mode) 44335 | { 44336 | case e_read : reinterpret_cast<std::ifstream*>(stream_ptr)-> 44337 | read(reinterpret_cast<char_ptr>(view.begin() + offset), amount * sizeof(typename View::value_t)); 44338 | break; 44339 | 44340 | case e_rdwrt : reinterpret_cast<std::fstream*>(stream_ptr)-> 44341 | read(reinterpret_cast<char_ptr>(view.begin() + offset) , amount * sizeof(typename View::value_t)); 44342 | break; 44343 | 44344 | default : return false; 44345 | } 44346 | 44347 | return true; 44348 | } 44349 | 44350 | bool getline(std::string& s) 44351 | { 44352 | switch (mode) 44353 | { 44354 | case e_read : return (!!std::getline(*reinterpret_cast<std::ifstream*>(stream_ptr),s)); 44355 | case e_rdwrt : return (!!std::getline(*reinterpret_cast<std::fstream* >(stream_ptr),s)); 44356 | default : return false; 44357 | } 44358 | } 44359 | 44360 | bool eof() const 44361 | { 44362 | switch (mode) 44363 | { 44364 | case e_read : return reinterpret_cast<std::ifstream*>(stream_ptr)->eof(); 44365 | case e_write : return reinterpret_cast<std::ofstream*>(stream_ptr)->eof(); 44366 | case e_rdwrt : return reinterpret_cast<std::fstream* >(stream_ptr)->eof(); 44367 | default : return true; 44368 | } 44369 | } 44370 | 44371 | file_mode get_file_mode(const std::string& access) const 44372 | { 44373 | if (access.empty() || access.size() > 2) 44374 | return e_error; 44375 | 44376 | std::size_t w_cnt = 0; 44377 | std::size_t r_cnt = 0; 44378 | 44379 | for (std::size_t i = 0; i < access.size(); ++i) 44380 | { 44381 | switch (std::tolower(access[i])) 44382 | { 44383 | case 'r' : r_cnt++; break; 44384 | case 'w' : w_cnt++; break; 44385 | default : return e_error; 44386 | } 44387 | } 44388 | 44389 | if ((0 == r_cnt) && (0 == w_cnt)) 44390 | return e_error; 44391 | else if ((r_cnt > 1) || (w_cnt > 1)) 44392 | return e_error; 44393 | else if ((1 == r_cnt) && (1 == w_cnt)) 44394 | return e_rdwrt; 44395 | else if (1 == r_cnt) 44396 | return e_read; 44397 | else 44398 | return e_write; 44399 | } 44400 | }; 44401 | 44402 | template <typename T> 44403 | file_descriptor* make_handle(T v) 44404 | { 44405 | const std::size_t fd_size = sizeof(details::file_descriptor*); 44406 | details::file_descriptor* fd = reinterpret_cast<file_descriptor*>(0); 44407 | 44408 | std::memcpy(reinterpret_cast<char_ptr >(&fd), 44409 | reinterpret_cast<char_cptr>(&v ), 44410 | fd_size); 44411 | return fd; 44412 | } 44413 | 44414 | template <typename T> 44415 | void perform_check() 44416 | { 44417 | #ifdef _MSC_VER 44418 | #pragma warning(push) 44419 | #pragma warning(disable: 4127) 44420 | #endif 44421 | if (sizeof(T) < sizeof(void*)) 44422 | { 44423 | throw std::runtime_error("exprtk::rtl::io::file - Error - pointer size larger than holder."); 44424 | } 44425 | #ifdef _MSC_VER 44426 | #pragma warning(pop) 44427 | #endif 44428 | assert(sizeof(T) <= sizeof(void*)); 44429 | } 44430 | 44431 | } // namespace exprtk::rtl::io::file::details 44432 | 44433 | template <typename T> 44434 | class open exprtk_final : public exprtk::igeneric_function<T> 44435 | { 44436 | public: 44437 | 44438 | typedef typename exprtk::igeneric_function<T> igfun_t; 44439 | typedef typename igfun_t::parameter_list_t parameter_list_t; 44440 | typedef typename igfun_t::generic_type generic_type; 44441 | typedef typename generic_type::string_view string_t; 44442 | 44443 | using igfun_t::operator(); 44444 | 44445 | open() 44446 | : exprtk::igeneric_function<T>("S|SS") 44447 | { details::perform_check<T>(); } 44448 | 44449 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 44450 | { 44451 | const std::string file_name = to_str(string_t(parameters[0])); 44452 | 44453 | if (file_name.empty()) 44454 | { 44455 | return T(0); 44456 | } 44457 | 44458 | if ((1 == ps_index) && (0 == string_t(parameters[1]).size())) 44459 | { 44460 | return T(0); 44461 | } 44462 | 44463 | const std::string access = 44464 | (0 == ps_index) ? "r" : to_str(string_t(parameters[1])); 44465 | 44466 | details::file_descriptor* fd = new details::file_descriptor(file_name,access); 44467 | 44468 | if (fd->open()) 44469 | { 44470 | T t = T(0); 44471 | 44472 | const std::size_t fd_size = sizeof(details::file_descriptor*); 44473 | 44474 | std::memcpy(reinterpret_cast<char*>(&t ), 44475 | reinterpret_cast<char*>(&fd), 44476 | fd_size); 44477 | return t; 44478 | } 44479 | else 44480 | { 44481 | delete fd; 44482 | return T(0); 44483 | } 44484 | } 44485 | }; 44486 | 44487 | template <typename T> 44488 | struct close exprtk_final : public exprtk::ifunction<T> 44489 | { 44490 | using exprtk::ifunction<T>::operator(); 44491 | 44492 | close() 44493 | : exprtk::ifunction<T>(1) 44494 | { details::perform_check<T>(); } 44495 | 44496 | inline T operator() (const T& v) exprtk_override 44497 | { 44498 | details::file_descriptor* fd = details::make_handle(v); 44499 | 44500 | if (!fd->close()) 44501 | return T(0); 44502 | 44503 | delete fd; 44504 | 44505 | return T(1); 44506 | } 44507 | }; 44508 | 44509 | template <typename T> 44510 | class write exprtk_final : public exprtk::igeneric_function<T> 44511 | { 44512 | public: 44513 | 44514 | typedef typename exprtk::igeneric_function<T> igfun_t; 44515 | typedef typename igfun_t::parameter_list_t parameter_list_t; 44516 | typedef typename igfun_t::generic_type generic_type; 44517 | typedef typename generic_type::string_view string_t; 44518 | typedef typename generic_type::scalar_view scalar_t; 44519 | typedef typename generic_type::vector_view vector_t; 44520 | 44521 | using igfun_t::operator(); 44522 | 44523 | write() 44524 | : igfun_t("TS|TST|TV|TVT") 44525 | { details::perform_check<T>(); } 44526 | 44527 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 44528 | { 44529 | details::file_descriptor* fd = details::make_handle(scalar_t(parameters[0])()); 44530 | 44531 | switch (ps_index) 44532 | { 44533 | case 0 : { 44534 | const string_t buffer(parameters[1]); 44535 | const std::size_t amount = buffer.size(); 44536 | return T(fd->write(buffer, amount) ? 1 : 0); 44537 | } 44538 | 44539 | case 1 : { 44540 | const string_t buffer(parameters[1]); 44541 | const std::size_t amount = 44542 | std::min(buffer.size(), 44543 | static_cast<std::size_t>(scalar_t(parameters[2])())); 44544 | return T(fd->write(buffer, amount) ? 1 : 0); 44545 | } 44546 | 44547 | case 2 : { 44548 | const vector_t vec(parameters[1]); 44549 | const std::size_t amount = vec.size(); 44550 | return T(fd->write(vec, amount) ? 1 : 0); 44551 | } 44552 | 44553 | case 3 : { 44554 | const vector_t vec(parameters[1]); 44555 | const std::size_t amount = 44556 | std::min(vec.size(), 44557 | static_cast<std::size_t>(scalar_t(parameters[2])())); 44558 | return T(fd->write(vec, amount) ? 1 : 0); 44559 | } 44560 | } 44561 | 44562 | return T(0); 44563 | } 44564 | }; 44565 | 44566 | template <typename T> 44567 | class read exprtk_final : public exprtk::igeneric_function<T> 44568 | { 44569 | public: 44570 | 44571 | typedef typename exprtk::igeneric_function<T> igfun_t; 44572 | typedef typename igfun_t::parameter_list_t parameter_list_t; 44573 | typedef typename igfun_t::generic_type generic_type; 44574 | typedef typename generic_type::string_view string_t; 44575 | typedef typename generic_type::scalar_view scalar_t; 44576 | typedef typename generic_type::vector_view vector_t; 44577 | 44578 | using igfun_t::operator(); 44579 | 44580 | read() 44581 | : igfun_t("TS|TST|TV|TVT") 44582 | { details::perform_check<T>(); } 44583 | 44584 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 44585 | { 44586 | details::file_descriptor* fd = details::make_handle(scalar_t(parameters[0])()); 44587 | 44588 | switch (ps_index) 44589 | { 44590 | case 0 : { 44591 | string_t buffer(parameters[1]); 44592 | const std::size_t amount = buffer.size(); 44593 | return T(fd->read(buffer,amount) ? 1 : 0); 44594 | } 44595 | 44596 | case 1 : { 44597 | string_t buffer(parameters[1]); 44598 | const std::size_t amount = 44599 | std::min(buffer.size(), 44600 | static_cast<std::size_t>(scalar_t(parameters[2])())); 44601 | return T(fd->read(buffer,amount) ? 1 : 0); 44602 | } 44603 | 44604 | case 2 : { 44605 | vector_t vec(parameters[1]); 44606 | const std::size_t amount = vec.size(); 44607 | return T(fd->read(vec,amount) ? 1 : 0); 44608 | } 44609 | 44610 | case 3 : { 44611 | vector_t vec(parameters[1]); 44612 | const std::size_t amount = 44613 | std::min(vec.size(), 44614 | static_cast<std::size_t>(scalar_t(parameters[2])())); 44615 | return T(fd->read(vec,amount) ? 1 : 0); 44616 | } 44617 | } 44618 | 44619 | return T(0); 44620 | } 44621 | }; 44622 | 44623 | template <typename T> 44624 | class getline exprtk_final : public exprtk::igeneric_function<T> 44625 | { 44626 | public: 44627 | 44628 | typedef typename exprtk::igeneric_function<T> igfun_t; 44629 | typedef typename igfun_t::parameter_list_t parameter_list_t; 44630 | typedef typename igfun_t::generic_type generic_type; 44631 | typedef typename generic_type::string_view string_t; 44632 | typedef typename generic_type::scalar_view scalar_t; 44633 | 44634 | using igfun_t::operator(); 44635 | 44636 | getline() 44637 | : igfun_t("T",igfun_t::e_rtrn_string) 44638 | { details::perform_check<T>(); } 44639 | 44640 | inline T operator() (std::string& result, parameter_list_t parameters) exprtk_override 44641 | { 44642 | details::file_descriptor* fd = details::make_handle(scalar_t(parameters[0])()); 44643 | return T(fd->getline(result) ? 1 : 0); 44644 | } 44645 | }; 44646 | 44647 | template <typename T> 44648 | struct eof exprtk_final : public exprtk::ifunction<T> 44649 | { 44650 | using exprtk::ifunction<T>::operator(); 44651 | 44652 | eof() 44653 | : exprtk::ifunction<T>(1) 44654 | { details::perform_check<T>(); } 44655 | 44656 | inline T operator() (const T& v) exprtk_override 44657 | { 44658 | details::file_descriptor* fd = details::make_handle(v); 44659 | return (fd->eof() ? T(1) : T(0)); 44660 | } 44661 | }; 44662 | 44663 | template <typename T> 44664 | struct package 44665 | { 44666 | open <T> o; 44667 | close <T> c; 44668 | write <T> w; 44669 | read <T> r; 44670 | getline<T> g; 44671 | eof <T> e; 44672 | 44673 | bool register_package(exprtk::symbol_table<T>& symtab) 44674 | { 44675 | #define exprtk_register_function(FunctionName, FunctionType) \ 44676 | if (!symtab.add_function(FunctionName,FunctionType)) \ 44677 | { \ 44678 | exprtk_debug(( \ 44679 | "exprtk::rtl::io::file::register_package - Failed to add function: %s\n", \ 44680 | FunctionName)); \ 44681 | return false; \ 44682 | } \ 44683 | 44684 | exprtk_register_function("open" , o) 44685 | exprtk_register_function("close" , c) 44686 | exprtk_register_function("write" , w) 44687 | exprtk_register_function("read" , r) 44688 | exprtk_register_function("getline" , g) 44689 | exprtk_register_function("eof" , e) 44690 | #undef exprtk_register_function 44691 | 44692 | return true; 44693 | } 44694 | }; 44695 | 44696 | } // namespace exprtk::rtl::io::file 44697 | } // namespace exprtk::rtl::io 44698 | } // namespace exprtk::rtl 44699 | } // namespace exprtk 44700 | #endif 44701 | 44702 | #ifndef exprtk_disable_rtl_vecops 44703 | namespace exprtk 44704 | { 44705 | namespace rtl { namespace vecops { 44706 | 44707 | namespace helper 44708 | { 44709 | template <typename Vector> 44710 | inline bool invalid_range(const Vector& v, const std::size_t r0, const std::size_t r1) 44711 | { 44712 | if (r0 > (v.size() - 1)) 44713 | return true; 44714 | else if (r1 > (v.size() - 1)) 44715 | return true; 44716 | else if (r1 < r0) 44717 | return true; 44718 | else 44719 | return false; 44720 | } 44721 | 44722 | template <typename T> 44723 | struct load_vector_range 44724 | { 44725 | typedef typename exprtk::igeneric_function<T> igfun_t; 44726 | typedef typename igfun_t::parameter_list_t parameter_list_t; 44727 | typedef typename igfun_t::generic_type generic_type; 44728 | typedef typename generic_type::scalar_view scalar_t; 44729 | typedef typename generic_type::vector_view vector_t; 44730 | 44731 | static inline bool process(parameter_list_t& parameters, 44732 | std::size_t& r0, std::size_t& r1, 44733 | const std::size_t& r0_prmidx, 44734 | const std::size_t& r1_prmidx, 44735 | const std::size_t vec_idx = 0) 44736 | { 44737 | if (r0_prmidx >= parameters.size()) 44738 | return false; 44739 | 44740 | if (r1_prmidx >= parameters.size()) 44741 | return false; 44742 | 44743 | if (!scalar_t(parameters[r0_prmidx]).to_uint(r0)) 44744 | return false; 44745 | 44746 | if (!scalar_t(parameters[r1_prmidx]).to_uint(r1)) 44747 | return false; 44748 | 44749 | return !invalid_range(vector_t(parameters[vec_idx]), r0, r1); 44750 | } 44751 | }; 44752 | } 44753 | 44754 | namespace details 44755 | { 44756 | template <typename T> 44757 | inline void kahan_sum(T& sum, T& error, const T v) 44758 | { 44759 | const T x = v - error; 44760 | const T y = sum + x; 44761 | error = (y - sum) - x; 44762 | sum = y; 44763 | } 44764 | 44765 | } // namespace exprtk::rtl::details 44766 | 44767 | template <typename T> 44768 | class all_true exprtk_final : public exprtk::igeneric_function<T> 44769 | { 44770 | public: 44771 | 44772 | typedef typename exprtk::igeneric_function<T> igfun_t; 44773 | typedef typename igfun_t::parameter_list_t parameter_list_t; 44774 | typedef typename igfun_t::generic_type generic_type; 44775 | typedef typename generic_type::scalar_view scalar_t; 44776 | typedef typename generic_type::vector_view vector_t; 44777 | 44778 | using igfun_t::operator(); 44779 | 44780 | all_true() 44781 | : exprtk::igeneric_function<T>("V|VTT|T*") 44782 | /* 44783 | Overloads: 44784 | 0. V - vector 44785 | 1. VTT - vector, r0, r1 44786 | 2. T* - T....T 44787 | */ 44788 | {} 44789 | 44790 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 44791 | { 44792 | if (2 == ps_index) 44793 | { 44794 | for (std::size_t i = 0; i < parameters.size(); ++i) 44795 | { 44796 | if (scalar_t(parameters[i])() == T(0)) 44797 | { 44798 | return T(0); 44799 | } 44800 | } 44801 | } 44802 | else 44803 | { 44804 | const vector_t vec(parameters[0]); 44805 | 44806 | std::size_t r0 = 0; 44807 | std::size_t r1 = vec.size() - 1; 44808 | 44809 | if ( 44810 | (1 == ps_index) && 44811 | !helper::load_vector_range<T>::process(parameters, r0, r1, 1, 2, 0) 44812 | ) 44813 | { 44814 | return std::numeric_limits<T>::quiet_NaN(); 44815 | } 44816 | 44817 | for (std::size_t i = r0; i <= r1; ++i) 44818 | { 44819 | if (vec[i] == T(0)) 44820 | { 44821 | return T(0); 44822 | } 44823 | } 44824 | } 44825 | 44826 | return T(1); 44827 | } 44828 | }; 44829 | 44830 | template <typename T> 44831 | class all_false exprtk_final : public exprtk::igeneric_function<T> 44832 | { 44833 | public: 44834 | 44835 | typedef typename exprtk::igeneric_function<T> igfun_t; 44836 | typedef typename igfun_t::parameter_list_t parameter_list_t; 44837 | typedef typename igfun_t::generic_type generic_type; 44838 | typedef typename generic_type::scalar_view scalar_t; 44839 | typedef typename generic_type::vector_view vector_t; 44840 | 44841 | using igfun_t::operator(); 44842 | 44843 | all_false() 44844 | : exprtk::igeneric_function<T>("V|VTT|T*") 44845 | /* 44846 | Overloads: 44847 | 0. V - vector 44848 | 1. VTT - vector, r0, r1 44849 | 2. T* - T....T 44850 | */ 44851 | {} 44852 | 44853 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 44854 | { 44855 | if (2 == ps_index) 44856 | { 44857 | for (std::size_t i = 0; i < parameters.size(); ++i) 44858 | { 44859 | if (scalar_t(parameters[i])() != T(0)) 44860 | { 44861 | return T(0); 44862 | } 44863 | } 44864 | } 44865 | else 44866 | { 44867 | const vector_t vec(parameters[0]); 44868 | 44869 | std::size_t r0 = 0; 44870 | std::size_t r1 = vec.size() - 1; 44871 | 44872 | if ( 44873 | (1 == ps_index) && 44874 | !helper::load_vector_range<T>::process(parameters, r0, r1, 1, 2, 0) 44875 | ) 44876 | { 44877 | return std::numeric_limits<T>::quiet_NaN(); 44878 | } 44879 | 44880 | for (std::size_t i = r0; i <= r1; ++i) 44881 | { 44882 | if (vec[i] != T(0)) 44883 | { 44884 | return T(0); 44885 | } 44886 | } 44887 | } 44888 | 44889 | return T(1); 44890 | } 44891 | }; 44892 | 44893 | template <typename T> 44894 | class any_true exprtk_final : public exprtk::igeneric_function<T> 44895 | { 44896 | public: 44897 | 44898 | typedef typename exprtk::igeneric_function<T> igfun_t; 44899 | typedef typename igfun_t::parameter_list_t parameter_list_t; 44900 | typedef typename igfun_t::generic_type generic_type; 44901 | typedef typename generic_type::scalar_view scalar_t; 44902 | typedef typename generic_type::vector_view vector_t; 44903 | 44904 | using igfun_t::operator(); 44905 | 44906 | any_true() 44907 | : exprtk::igeneric_function<T>("V|VTT|T*") 44908 | /* 44909 | Overloads: 44910 | 0. V - vector 44911 | 1. VTT - vector, r0, r1 44912 | 2. T* - T....T 44913 | */ 44914 | {} 44915 | 44916 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 44917 | { 44918 | if (2 == ps_index) 44919 | { 44920 | for (std::size_t i = 0; i < parameters.size(); ++i) 44921 | { 44922 | if (scalar_t(parameters[i])() != T(0)) 44923 | { 44924 | return T(1); 44925 | } 44926 | } 44927 | } 44928 | else 44929 | { 44930 | const vector_t vec(parameters[0]); 44931 | 44932 | std::size_t r0 = 0; 44933 | std::size_t r1 = vec.size() - 1; 44934 | 44935 | if ( 44936 | (1 == ps_index) && 44937 | !helper::load_vector_range<T>::process(parameters, r0, r1, 1, 2, 0) 44938 | ) 44939 | { 44940 | return std::numeric_limits<T>::quiet_NaN(); 44941 | } 44942 | 44943 | for (std::size_t i = r0; i <= r1; ++i) 44944 | { 44945 | if (vec[i] != T(0)) 44946 | { 44947 | return T(1); 44948 | } 44949 | } 44950 | } 44951 | 44952 | return T(0); 44953 | } 44954 | }; 44955 | 44956 | template <typename T> 44957 | class any_false exprtk_final : public exprtk::igeneric_function<T> 44958 | { 44959 | public: 44960 | 44961 | typedef typename exprtk::igeneric_function<T> igfun_t; 44962 | typedef typename igfun_t::parameter_list_t parameter_list_t; 44963 | typedef typename igfun_t::generic_type generic_type; 44964 | typedef typename generic_type::scalar_view scalar_t; 44965 | typedef typename generic_type::vector_view vector_t; 44966 | 44967 | using igfun_t::operator(); 44968 | 44969 | any_false() 44970 | : exprtk::igeneric_function<T>("V|VTT|T*") 44971 | /* 44972 | Overloads: 44973 | 0. V - vector 44974 | 1. VTT - vector, r0, r1 44975 | 2. T* - T....T 44976 | */ 44977 | {} 44978 | 44979 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 44980 | { 44981 | if (2 == ps_index) 44982 | { 44983 | for (std::size_t i = 0; i < parameters.size(); ++i) 44984 | { 44985 | if (scalar_t(parameters[i])() == T(0)) 44986 | { 44987 | return T(1); 44988 | } 44989 | } 44990 | } 44991 | else 44992 | { 44993 | const vector_t vec(parameters[0]); 44994 | 44995 | std::size_t r0 = 0; 44996 | std::size_t r1 = vec.size() - 1; 44997 | 44998 | if ( 44999 | (1 == ps_index) && 45000 | !helper::load_vector_range<T>::process(parameters, r0, r1, 1, 2, 0) 45001 | ) 45002 | { 45003 | return std::numeric_limits<T>::quiet_NaN(); 45004 | } 45005 | 45006 | for (std::size_t i = r0; i <= r1; ++i) 45007 | { 45008 | if (vec[i] == T(0)) 45009 | { 45010 | return T(1); 45011 | } 45012 | } 45013 | } 45014 | 45015 | return T(0); 45016 | } 45017 | }; 45018 | 45019 | template <typename T> 45020 | class count exprtk_final : public exprtk::igeneric_function<T> 45021 | { 45022 | public: 45023 | 45024 | typedef typename exprtk::igeneric_function<T> igfun_t; 45025 | typedef typename igfun_t::parameter_list_t parameter_list_t; 45026 | typedef typename igfun_t::generic_type generic_type; 45027 | typedef typename generic_type::scalar_view scalar_t; 45028 | typedef typename generic_type::vector_view vector_t; 45029 | 45030 | using igfun_t::operator(); 45031 | 45032 | count() 45033 | : exprtk::igeneric_function<T>("V|VTT|T*") 45034 | /* 45035 | Overloads: 45036 | 0. V - vector 45037 | 1. VTT - vector, r0, r1 45038 | 2. T* - T....T 45039 | */ 45040 | {} 45041 | 45042 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 45043 | { 45044 | std::size_t cnt = 0; 45045 | 45046 | if (2 == ps_index) 45047 | { 45048 | for (std::size_t i = 0; i < parameters.size(); ++i) 45049 | { 45050 | if (scalar_t(parameters[i])() != T(0)) ++cnt; 45051 | } 45052 | } 45053 | else 45054 | { 45055 | const vector_t vec(parameters[0]); 45056 | 45057 | std::size_t r0 = 0; 45058 | std::size_t r1 = vec.size() - 1; 45059 | 45060 | if ( 45061 | (1 == ps_index) && 45062 | !helper::load_vector_range<T>::process(parameters, r0, r1, 1, 2, 0) 45063 | ) 45064 | { 45065 | return std::numeric_limits<T>::quiet_NaN(); 45066 | } 45067 | 45068 | for (std::size_t i = r0; i <= r1; ++i) 45069 | { 45070 | if (vec[i] != T(0)) ++cnt; 45071 | } 45072 | } 45073 | 45074 | return T(cnt); 45075 | } 45076 | }; 45077 | 45078 | template <typename T> 45079 | class copy exprtk_final : public exprtk::igeneric_function<T> 45080 | { 45081 | public: 45082 | 45083 | typedef typename exprtk::igeneric_function<T> igfun_t; 45084 | typedef typename igfun_t::parameter_list_t parameter_list_t; 45085 | typedef typename igfun_t::generic_type generic_type; 45086 | typedef typename generic_type::scalar_view scalar_t; 45087 | typedef typename generic_type::vector_view vector_t; 45088 | 45089 | using igfun_t::operator(); 45090 | 45091 | copy() 45092 | : exprtk::igeneric_function<T>("VV|VTTVTT") 45093 | /* 45094 | Overloads: 45095 | 0. VV - x(vector), y(vector) 45096 | 1. VTTVTT - x(vector), xr0, xr1, y(vector), yr0, yr1, 45097 | */ 45098 | {} 45099 | 45100 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 45101 | { 45102 | const vector_t x(parameters[0]); 45103 | vector_t y(parameters[(0 == ps_index) ? 1 : 3]); 45104 | 45105 | std::size_t xr0 = 0; 45106 | std::size_t xr1 = x.size() - 1; 45107 | 45108 | std::size_t yr0 = 0; 45109 | std::size_t yr1 = y.size() - 1; 45110 | 45111 | if (1 == ps_index) 45112 | { 45113 | if ( 45114 | !helper::load_vector_range<T>::process(parameters, xr0, xr1, 1, 2, 0) || 45115 | !helper::load_vector_range<T>::process(parameters, yr0, yr1, 4, 5, 3) 45116 | ) 45117 | return T(0); 45118 | } 45119 | 45120 | const std::size_t n = std::min(xr1 - xr0 + 1, yr1 - yr0 + 1); 45121 | 45122 | std::copy( 45123 | x.begin() + xr0, 45124 | x.begin() + xr0 + n, 45125 | y.begin() + yr0); 45126 | 45127 | return T(n); 45128 | } 45129 | }; 45130 | 45131 | template <typename T> 45132 | class rol exprtk_final : public exprtk::igeneric_function<T> 45133 | { 45134 | public: 45135 | 45136 | typedef typename exprtk::igeneric_function<T> igfun_t; 45137 | typedef typename igfun_t::parameter_list_t parameter_list_t; 45138 | typedef typename igfun_t::generic_type generic_type; 45139 | typedef typename generic_type::scalar_view scalar_t; 45140 | typedef typename generic_type::vector_view vector_t; 45141 | 45142 | using igfun_t::operator(); 45143 | 45144 | rol() 45145 | : exprtk::igeneric_function<T>("VT|VTTT") 45146 | /* 45147 | Overloads: 45148 | 0. VT - vector, N 45149 | 1. VTTT - vector, N, r0, r1 45150 | */ 45151 | {} 45152 | 45153 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 45154 | { 45155 | vector_t vec(parameters[0]); 45156 | 45157 | std::size_t n = 0; 45158 | std::size_t r0 = 0; 45159 | std::size_t r1 = vec.size() - 1; 45160 | 45161 | if (!scalar_t(parameters[1]).to_uint(n)) 45162 | return T(0); 45163 | 45164 | if ( 45165 | (1 == ps_index) && 45166 | !helper::load_vector_range<T>::process(parameters, r0, r1, 2, 3, 0) 45167 | ) 45168 | return T(0); 45169 | 45170 | const std::size_t dist = r1 - r0 + 1; 45171 | const std::size_t shift = n % dist; 45172 | 45173 | std::rotate( 45174 | vec.begin() + r0, 45175 | vec.begin() + r0 + shift, 45176 | vec.begin() + r1 + 1); 45177 | 45178 | return T(1); 45179 | } 45180 | }; 45181 | 45182 | template <typename T> 45183 | class ror exprtk_final : public exprtk::igeneric_function<T> 45184 | { 45185 | public: 45186 | 45187 | typedef typename exprtk::igeneric_function<T> igfun_t; 45188 | typedef typename igfun_t::parameter_list_t parameter_list_t; 45189 | typedef typename igfun_t::generic_type generic_type; 45190 | typedef typename generic_type::scalar_view scalar_t; 45191 | typedef typename generic_type::vector_view vector_t; 45192 | 45193 | using igfun_t::operator(); 45194 | 45195 | ror() 45196 | : exprtk::igeneric_function<T>("VT|VTTT") 45197 | /* 45198 | Overloads: 45199 | 0. VT - vector, N 45200 | 1. VTTT - vector, N, r0, r1 45201 | */ 45202 | {} 45203 | 45204 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 45205 | { 45206 | vector_t vec(parameters[0]); 45207 | 45208 | std::size_t n = 0; 45209 | std::size_t r0 = 0; 45210 | std::size_t r1 = vec.size() - 1; 45211 | 45212 | if (!scalar_t(parameters[1]).to_uint(n)) 45213 | return T(0); 45214 | 45215 | if ( 45216 | (1 == ps_index) && 45217 | !helper::load_vector_range<T>::process(parameters, r0, r1, 2, 3, 0) 45218 | ) 45219 | return T(0); 45220 | 45221 | const std::size_t dist = r1 - r0 + 1; 45222 | const std::size_t shift = (dist - (n % dist)) % dist; 45223 | 45224 | std::rotate( 45225 | vec.begin() + r0, 45226 | vec.begin() + r0 + shift, 45227 | vec.begin() + r1 + 1); 45228 | 45229 | return T(1); 45230 | } 45231 | }; 45232 | 45233 | template <typename T> 45234 | class reverse exprtk_final : public exprtk::igeneric_function<T> 45235 | { 45236 | public: 45237 | 45238 | typedef typename exprtk::igeneric_function<T> igfun_t; 45239 | typedef typename igfun_t::parameter_list_t parameter_list_t; 45240 | typedef typename igfun_t::generic_type generic_type; 45241 | typedef typename generic_type::scalar_view scalar_t; 45242 | typedef typename generic_type::vector_view vector_t; 45243 | 45244 | using igfun_t::operator(); 45245 | 45246 | reverse() 45247 | : exprtk::igeneric_function<T>("V|VTT") 45248 | /* 45249 | Overloads: 45250 | 0. V - vector 45251 | 1. VTT - vector, r0, r1 45252 | */ 45253 | {} 45254 | 45255 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 45256 | { 45257 | vector_t vec(parameters[0]); 45258 | 45259 | std::size_t r0 = 0; 45260 | std::size_t r1 = vec.size() - 1; 45261 | 45262 | if ( 45263 | (1 == ps_index) && 45264 | !helper::load_vector_range<T>::process(parameters, r0, r1, 1, 2, 0) 45265 | ) 45266 | return T(0); 45267 | 45268 | std::reverse(vec.begin() + r0, vec.begin() + r1 + 1); 45269 | 45270 | return T(1); 45271 | } 45272 | }; 45273 | 45274 | template <typename T> 45275 | class shift_left exprtk_final : public exprtk::igeneric_function<T> 45276 | { 45277 | public: 45278 | 45279 | typedef typename exprtk::igeneric_function<T> igfun_t; 45280 | typedef typename igfun_t::parameter_list_t parameter_list_t; 45281 | typedef typename igfun_t::generic_type generic_type; 45282 | typedef typename generic_type::scalar_view scalar_t; 45283 | typedef typename generic_type::vector_view vector_t; 45284 | 45285 | using igfun_t::operator(); 45286 | 45287 | shift_left() 45288 | : exprtk::igeneric_function<T>("VT|VTTT") 45289 | /* 45290 | Overloads: 45291 | 0. VT - vector, N 45292 | 1. VTTT - vector, N, r0, r1 45293 | */ 45294 | {} 45295 | 45296 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 45297 | { 45298 | vector_t vec(parameters[0]); 45299 | 45300 | std::size_t n = 0; 45301 | std::size_t r0 = 0; 45302 | std::size_t r1 = vec.size() - 1; 45303 | 45304 | if (!scalar_t(parameters[1]).to_uint(n)) 45305 | return T(0); 45306 | 45307 | if ( 45308 | (1 == ps_index) && 45309 | !helper::load_vector_range<T>::process(parameters, r0, r1, 2, 3, 0) 45310 | ) 45311 | return T(0); 45312 | 45313 | const std::size_t dist = r1 - r0 + 1; 45314 | 45315 | if (n > dist) 45316 | return T(0); 45317 | 45318 | std::rotate( 45319 | vec.begin() + r0, 45320 | vec.begin() + r0 + n, 45321 | vec.begin() + r1 + 1); 45322 | 45323 | for (std::size_t i = r1 - n + 1ULL; i <= r1; ++i) 45324 | { 45325 | vec[i] = T(0); 45326 | } 45327 | 45328 | return T(1); 45329 | } 45330 | }; 45331 | 45332 | template <typename T> 45333 | class shift_right exprtk_final : public exprtk::igeneric_function<T> 45334 | { 45335 | public: 45336 | 45337 | typedef typename exprtk::igeneric_function<T> igfun_t; 45338 | typedef typename igfun_t::parameter_list_t parameter_list_t; 45339 | typedef typename igfun_t::generic_type generic_type; 45340 | typedef typename generic_type::scalar_view scalar_t; 45341 | typedef typename generic_type::vector_view vector_t; 45342 | 45343 | using igfun_t::operator(); 45344 | 45345 | shift_right() 45346 | : exprtk::igeneric_function<T>("VT|VTTT") 45347 | /* 45348 | Overloads: 45349 | 0. VT - vector, N 45350 | 1. VTTT - vector, N, r0, r1 45351 | */ 45352 | {} 45353 | 45354 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 45355 | { 45356 | vector_t vec(parameters[0]); 45357 | 45358 | std::size_t n = 0; 45359 | std::size_t r0 = 0; 45360 | std::size_t r1 = vec.size() - 1; 45361 | 45362 | if (!scalar_t(parameters[1]).to_uint(n)) 45363 | return T(0); 45364 | 45365 | if ( 45366 | (1 == ps_index) && 45367 | !helper::load_vector_range<T>::process(parameters, r0, r1, 2, 3, 0) 45368 | ) 45369 | return T(0); 45370 | 45371 | const std::size_t dist = r1 - r0 + 1; 45372 | 45373 | if (n > dist) 45374 | return T(0); 45375 | 45376 | const std::size_t shift = (dist - (n % dist)) % dist; 45377 | 45378 | std::rotate( 45379 | vec.begin() + r0, 45380 | vec.begin() + r0 + shift, 45381 | vec.begin() + r1 + 1); 45382 | 45383 | for (std::size_t i = r0; i < r0 + n; ++i) 45384 | { 45385 | vec[i] = T(0); 45386 | } 45387 | 45388 | return T(1); 45389 | } 45390 | }; 45391 | 45392 | template <typename T> 45393 | class sort exprtk_final : public exprtk::igeneric_function<T> 45394 | { 45395 | public: 45396 | 45397 | typedef typename exprtk::igeneric_function<T> igfun_t; 45398 | typedef typename igfun_t::parameter_list_t parameter_list_t; 45399 | typedef typename igfun_t::generic_type generic_type; 45400 | typedef typename generic_type::string_view string_t; 45401 | typedef typename generic_type::vector_view vector_t; 45402 | 45403 | using igfun_t::operator(); 45404 | 45405 | sort() 45406 | : exprtk::igeneric_function<T>("V|VTT|VS|VSTT") 45407 | /* 45408 | Overloads: 45409 | 0. V - vector 45410 | 1. VTT - vector, r0, r1 45411 | 2. VS - vector, string 45412 | 3. VSTT - vector, string, r0, r1 45413 | */ 45414 | {} 45415 | 45416 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 45417 | { 45418 | vector_t vec(parameters[0]); 45419 | 45420 | std::size_t r0 = 0; 45421 | std::size_t r1 = vec.size() - 1; 45422 | 45423 | if ((1 == ps_index) && !helper::load_vector_range<T>::process(parameters, r0, r1, 1, 2, 0)) 45424 | return T(0); 45425 | if ((3 == ps_index) && !helper::load_vector_range<T>::process(parameters, r0, r1, 2, 3, 0)) 45426 | return T(0); 45427 | 45428 | bool ascending = true; 45429 | 45430 | if ((2 == ps_index) || (3 == ps_index)) 45431 | { 45432 | if (exprtk::details::imatch(to_str(string_t(parameters[1])),"ascending")) 45433 | ascending = true; 45434 | else if (exprtk::details::imatch(to_str(string_t(parameters[1])),"descending")) 45435 | ascending = false; 45436 | else 45437 | return T(0); 45438 | } 45439 | 45440 | if (ascending) 45441 | std::sort( 45442 | vec.begin() + r0, 45443 | vec.begin() + r1 + 1, 45444 | std::less<T>()); 45445 | else 45446 | std::sort( 45447 | vec.begin() + r0, 45448 | vec.begin() + r1 + 1, 45449 | std::greater<T>()); 45450 | 45451 | return T(1); 45452 | } 45453 | }; 45454 | 45455 | template <typename T> 45456 | class nthelement exprtk_final : public exprtk::igeneric_function<T> 45457 | { 45458 | public: 45459 | 45460 | typedef typename exprtk::igeneric_function<T> igfun_t; 45461 | typedef typename igfun_t::parameter_list_t parameter_list_t; 45462 | typedef typename igfun_t::generic_type generic_type; 45463 | typedef typename generic_type::scalar_view scalar_t; 45464 | typedef typename generic_type::vector_view vector_t; 45465 | 45466 | using igfun_t::operator(); 45467 | 45468 | nthelement() 45469 | : exprtk::igeneric_function<T>("VT|VTTT") 45470 | /* 45471 | Overloads: 45472 | 0. VT - vector, nth-element 45473 | 1. VTTT - vector, nth-element, r0, r1 45474 | */ 45475 | {} 45476 | 45477 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 45478 | { 45479 | vector_t vec(parameters[0]); 45480 | 45481 | std::size_t n = 0; 45482 | std::size_t r0 = 0; 45483 | std::size_t r1 = vec.size() - 1; 45484 | 45485 | if (!scalar_t(parameters[1]).to_uint(n)) 45486 | return T(0); 45487 | 45488 | if ((1 == ps_index) && !helper::load_vector_range<T>::process(parameters, r0, r1, 2, 3, 0)) 45489 | { 45490 | return std::numeric_limits<T>::quiet_NaN(); 45491 | } 45492 | 45493 | std::nth_element( 45494 | vec.begin() + r0, 45495 | vec.begin() + r0 + n , 45496 | vec.begin() + r1 + 1); 45497 | 45498 | return T(1); 45499 | } 45500 | }; 45501 | 45502 | template <typename T> 45503 | class assign exprtk_final : public exprtk::igeneric_function<T> 45504 | { 45505 | public: 45506 | 45507 | typedef typename exprtk::igeneric_function<T> igfun_t; 45508 | typedef typename igfun_t::parameter_list_t parameter_list_t; 45509 | typedef typename igfun_t::generic_type generic_type; 45510 | typedef typename generic_type::scalar_view scalar_t; 45511 | typedef typename generic_type::vector_view vector_t; 45512 | 45513 | using igfun_t::operator(); 45514 | 45515 | assign() 45516 | : exprtk::igeneric_function<T>("VT|VTTT|VTTTT") 45517 | /* 45518 | Overloads: 45519 | 0. VT - vector, V 45520 | 1. VTTT - vector, V, r0, r1 45521 | 2. VTTTT - vector, V, r0, r1, SS 45522 | */ 45523 | {} 45524 | 45525 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 45526 | { 45527 | vector_t vec(parameters[0]); 45528 | 45529 | const T assign_value = scalar_t(parameters[1]); 45530 | 45531 | const std::size_t step_size = (2 != ps_index) ? 1 : 45532 | static_cast<std::size_t>(scalar_t(parameters.back())()); 45533 | 45534 | std::size_t r0 = 0; 45535 | std::size_t r1 = vec.size() - 1; 45536 | 45537 | if ( 45538 | ((ps_index == 1) || (ps_index == 2)) && 45539 | !helper::load_vector_range<T>::process(parameters, r0, r1, 2, 3, 0) 45540 | ) 45541 | { 45542 | return T(0); 45543 | } 45544 | 45545 | for (std::size_t i = r0; i <= r1; i += step_size) 45546 | { 45547 | vec[i] = assign_value; 45548 | } 45549 | 45550 | return T(1); 45551 | } 45552 | }; 45553 | 45554 | template <typename T> 45555 | class iota exprtk_final : public exprtk::igeneric_function<T> 45556 | { 45557 | public: 45558 | 45559 | typedef typename exprtk::igeneric_function<T> igfun_t; 45560 | typedef typename igfun_t::parameter_list_t parameter_list_t; 45561 | typedef typename igfun_t::generic_type generic_type; 45562 | typedef typename generic_type::scalar_view scalar_t; 45563 | typedef typename generic_type::vector_view vector_t; 45564 | 45565 | using igfun_t::operator(); 45566 | 45567 | iota() 45568 | : exprtk::igeneric_function<T>("VTT|VT|VTTTT|VTTT") 45569 | /* 45570 | Overloads: 45571 | 0. VTT - vector, SV, SS 45572 | 1. VT - vector, SV, SS (+1) 45573 | 2. VTTT - vector, r0, r1, SV, SS 45574 | 3. VTT - vector, r0, r1, SV, SS (+1) 45575 | 45576 | Where: 45577 | 1. SV - Start value 45578 | 2. SS - Step size 45579 | */ 45580 | {} 45581 | 45582 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 45583 | { 45584 | vector_t vec(parameters[0]); 45585 | 45586 | const T start_value = (ps_index <= 1) ? 45587 | scalar_t(parameters[1]) : 45588 | scalar_t(parameters[3]) ; 45589 | 45590 | const T step_size = ((0 == ps_index) || (2 == ps_index)) ? 45591 | scalar_t(parameters.back())() : 45592 | T(1) ; 45593 | 45594 | std::size_t r0 = 0; 45595 | std::size_t r1 = vec.size() - 1; 45596 | 45597 | if ( 45598 | ((ps_index == 2) || (ps_index == 3)) && 45599 | !helper::load_vector_range<T>::process(parameters, r0, r1, 1, 2, 0) 45600 | ) 45601 | { 45602 | return T(0); 45603 | } 45604 | 45605 | for (std::size_t i = r0; i <= r1; ++i) 45606 | { 45607 | vec[i] = start_value + ((i - r0) * step_size); 45608 | } 45609 | 45610 | return T(1); 45611 | } 45612 | }; 45613 | 45614 | template <typename T> 45615 | class sumk exprtk_final : public exprtk::igeneric_function<T> 45616 | { 45617 | public: 45618 | 45619 | typedef typename exprtk::igeneric_function<T> igfun_t; 45620 | typedef typename igfun_t::parameter_list_t parameter_list_t; 45621 | typedef typename igfun_t::generic_type generic_type; 45622 | typedef typename generic_type::scalar_view scalar_t; 45623 | typedef typename generic_type::vector_view vector_t; 45624 | 45625 | using igfun_t::operator(); 45626 | 45627 | sumk() 45628 | : exprtk::igeneric_function<T>("V|VTT|VTTT") 45629 | /* 45630 | Overloads: 45631 | 0. V - vector 45632 | 1. VTT - vector, r0, r1 45633 | 2. VTTT - vector, r0, r1, stride 45634 | */ 45635 | {} 45636 | 45637 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 45638 | { 45639 | const vector_t vec(parameters[0]); 45640 | 45641 | const std::size_t stride = (2 != ps_index) ? 1 : 45642 | static_cast<std::size_t>(scalar_t(parameters[3])()); 45643 | 45644 | std::size_t r0 = 0; 45645 | std::size_t r1 = vec.size() - 1; 45646 | 45647 | if ( 45648 | ((1 == ps_index) || (2 == ps_index)) && 45649 | !helper::load_vector_range<T>::process(parameters, r0, r1, 1, 2, 0) 45650 | ) 45651 | { 45652 | return std::numeric_limits<T>::quiet_NaN(); 45653 | } 45654 | 45655 | T result = T(0); 45656 | T error = T(0); 45657 | 45658 | for (std::size_t i = r0; i <= r1; i += stride) 45659 | { 45660 | details::kahan_sum(result, error, vec[i]); 45661 | } 45662 | 45663 | return result; 45664 | } 45665 | }; 45666 | 45667 | template <typename T> 45668 | class axpy exprtk_final : public exprtk::igeneric_function<T> 45669 | { 45670 | public: 45671 | 45672 | typedef typename exprtk::igeneric_function<T> igfun_t; 45673 | typedef typename igfun_t::parameter_list_t parameter_list_t; 45674 | typedef typename igfun_t::generic_type generic_type; 45675 | typedef typename generic_type::scalar_view scalar_t; 45676 | typedef typename generic_type::vector_view vector_t; 45677 | 45678 | using igfun_t::operator(); 45679 | 45680 | axpy() 45681 | : exprtk::igeneric_function<T>("TVV|TVVTT") 45682 | /* 45683 | y <- ax + y 45684 | Overloads: 45685 | 0. TVV - a, x(vector), y(vector) 45686 | 1. TVVTT - a, x(vector), y(vector), r0, r1 45687 | */ 45688 | {} 45689 | 45690 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 45691 | { 45692 | const vector_t x(parameters[1]); 45693 | vector_t y(parameters[2]); 45694 | 45695 | std::size_t r0 = 0; 45696 | std::size_t r1 = std::min(x.size(),y.size()) - 1; 45697 | 45698 | if ((1 == ps_index) && !helper::load_vector_range<T>::process(parameters, r0, r1, 3, 4, 1)) 45699 | return std::numeric_limits<T>::quiet_NaN(); 45700 | else if (helper::invalid_range(y, r0, r1)) 45701 | return std::numeric_limits<T>::quiet_NaN(); 45702 | 45703 | const T a = scalar_t(parameters[0])(); 45704 | 45705 | for (std::size_t i = r0; i <= r1; ++i) 45706 | { 45707 | y[i] = (a * x[i]) + y[i]; 45708 | } 45709 | 45710 | return T(1); 45711 | } 45712 | }; 45713 | 45714 | template <typename T> 45715 | class axpby exprtk_final : public exprtk::igeneric_function<T> 45716 | { 45717 | public: 45718 | 45719 | typedef typename exprtk::igeneric_function<T> igfun_t; 45720 | typedef typename igfun_t::parameter_list_t parameter_list_t; 45721 | typedef typename igfun_t::generic_type generic_type; 45722 | typedef typename generic_type::scalar_view scalar_t; 45723 | typedef typename generic_type::vector_view vector_t; 45724 | 45725 | using igfun_t::operator(); 45726 | 45727 | axpby() 45728 | : exprtk::igeneric_function<T>("TVTV|TVTVTT") 45729 | /* 45730 | y <- ax + by 45731 | Overloads: 45732 | 0. TVTV - a, x(vector), b, y(vector) 45733 | 1. TVTVTT - a, x(vector), b, y(vector), r0, r1 45734 | */ 45735 | {} 45736 | 45737 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 45738 | { 45739 | const vector_t x(parameters[1]); 45740 | vector_t y(parameters[3]); 45741 | 45742 | std::size_t r0 = 0; 45743 | std::size_t r1 = std::min(x.size(),y.size()) - 1; 45744 | 45745 | if ((1 == ps_index) && !helper::load_vector_range<T>::process(parameters, r0, r1, 4, 5, 1)) 45746 | return std::numeric_limits<T>::quiet_NaN(); 45747 | else if (helper::invalid_range(y, r0, r1)) 45748 | return std::numeric_limits<T>::quiet_NaN(); 45749 | 45750 | const T a = scalar_t(parameters[0])(); 45751 | const T b = scalar_t(parameters[2])(); 45752 | 45753 | for (std::size_t i = r0; i <= r1; ++i) 45754 | { 45755 | y[i] = (a * x[i]) + (b * y[i]); 45756 | } 45757 | 45758 | return T(1); 45759 | } 45760 | }; 45761 | 45762 | template <typename T> 45763 | class axpyz exprtk_final : public exprtk::igeneric_function<T> 45764 | { 45765 | public: 45766 | 45767 | typedef typename exprtk::igeneric_function<T> igfun_t; 45768 | typedef typename igfun_t::parameter_list_t parameter_list_t; 45769 | typedef typename igfun_t::generic_type generic_type; 45770 | typedef typename generic_type::scalar_view scalar_t; 45771 | typedef typename generic_type::vector_view vector_t; 45772 | 45773 | using igfun_t::operator(); 45774 | 45775 | axpyz() 45776 | : exprtk::igeneric_function<T>("TVVV|TVVVTT") 45777 | /* 45778 | z <- ax + y 45779 | Overloads: 45780 | 0. TVVV - a, x(vector), y(vector), z(vector) 45781 | 1. TVVVTT - a, x(vector), y(vector), z(vector), r0, r1 45782 | */ 45783 | {} 45784 | 45785 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 45786 | { 45787 | const vector_t x(parameters[1]); 45788 | const vector_t y(parameters[2]); 45789 | vector_t z(parameters[3]); 45790 | 45791 | std::size_t r0 = 0; 45792 | std::size_t r1 = std::min(x.size(),y.size()) - 1; 45793 | 45794 | if ((1 == ps_index) && !helper::load_vector_range<T>::process(parameters, r0, r1, 4, 5, 1)) 45795 | return std::numeric_limits<T>::quiet_NaN(); 45796 | else if (helper::invalid_range(y, r0, r1)) 45797 | return std::numeric_limits<T>::quiet_NaN(); 45798 | else if (helper::invalid_range(z, r0, r1)) 45799 | return std::numeric_limits<T>::quiet_NaN(); 45800 | 45801 | const T a = scalar_t(parameters[0])(); 45802 | 45803 | for (std::size_t i = r0; i <= r1; ++i) 45804 | { 45805 | z[i] = (a * x[i]) + y[i]; 45806 | } 45807 | 45808 | return T(1); 45809 | } 45810 | }; 45811 | 45812 | template <typename T> 45813 | class axpbyz exprtk_final : public exprtk::igeneric_function<T> 45814 | { 45815 | public: 45816 | 45817 | typedef typename exprtk::igeneric_function<T> igfun_t; 45818 | typedef typename igfun_t::parameter_list_t parameter_list_t; 45819 | typedef typename igfun_t::generic_type generic_type; 45820 | typedef typename generic_type::scalar_view scalar_t; 45821 | typedef typename generic_type::vector_view vector_t; 45822 | 45823 | using igfun_t::operator(); 45824 | 45825 | axpbyz() 45826 | : exprtk::igeneric_function<T>("TVTVV|TVTVVTT") 45827 | /* 45828 | z <- ax + by 45829 | Overloads: 45830 | 0. TVTVV - a, x(vector), b, y(vector), z(vector) 45831 | 1. TVTVVTT - a, x(vector), b, y(vector), z(vector), r0, r1 45832 | */ 45833 | {} 45834 | 45835 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 45836 | { 45837 | const vector_t x(parameters[1]); 45838 | const vector_t y(parameters[3]); 45839 | vector_t z(parameters[4]); 45840 | 45841 | std::size_t r0 = 0; 45842 | std::size_t r1 = std::min(x.size(),y.size()) - 1; 45843 | 45844 | if ((1 == ps_index) && !helper::load_vector_range<T>::process(parameters, r0, r1, 5, 6, 1)) 45845 | return std::numeric_limits<T>::quiet_NaN(); 45846 | else if (helper::invalid_range(y, r0, r1)) 45847 | return std::numeric_limits<T>::quiet_NaN(); 45848 | else if (helper::invalid_range(z, r0, r1)) 45849 | return std::numeric_limits<T>::quiet_NaN(); 45850 | 45851 | const T a = scalar_t(parameters[0])(); 45852 | const T b = scalar_t(parameters[2])(); 45853 | 45854 | for (std::size_t i = r0; i <= r1; ++i) 45855 | { 45856 | z[i] = (a * x[i]) + (b * y[i]); 45857 | } 45858 | 45859 | return T(1); 45860 | } 45861 | }; 45862 | 45863 | template <typename T> 45864 | class axpbsy exprtk_final : public exprtk::igeneric_function<T> 45865 | { 45866 | public: 45867 | 45868 | typedef typename exprtk::igeneric_function<T> igfun_t; 45869 | typedef typename igfun_t::parameter_list_t parameter_list_t; 45870 | typedef typename igfun_t::generic_type generic_type; 45871 | typedef typename generic_type::scalar_view scalar_t; 45872 | typedef typename generic_type::vector_view vector_t; 45873 | 45874 | using igfun_t::operator(); 45875 | 45876 | axpbsy() 45877 | : exprtk::igeneric_function<T>("TVTTV|TVTTVTT") 45878 | /* 45879 | y <- ax + by 45880 | Overloads: 45881 | 0. TVTVV - a, x(vector), b, shift, y(vector), z(vector) 45882 | 1. TVTVVTT - a, x(vector), b, shift, y(vector), z(vector), r0, r1 45883 | */ 45884 | {} 45885 | 45886 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 45887 | { 45888 | const vector_t x(parameters[1]); 45889 | vector_t y(parameters[4]); 45890 | 45891 | std::size_t r0 = 0; 45892 | std::size_t r1 = std::min(x.size(),y.size()) - 1; 45893 | 45894 | if ((1 == ps_index) && !helper::load_vector_range<T>::process(parameters, r0, r1, 5, 6, 1)) 45895 | return std::numeric_limits<T>::quiet_NaN(); 45896 | else if (helper::invalid_range(y, r0, r1)) 45897 | return std::numeric_limits<T>::quiet_NaN(); 45898 | 45899 | const T a = scalar_t(parameters[0])(); 45900 | const T b = scalar_t(parameters[2])(); 45901 | 45902 | const std::size_t s = static_cast<std::size_t>(scalar_t(parameters[3])()); 45903 | 45904 | for (std::size_t i = r0; i <= r1; ++i) 45905 | { 45906 | y[i] = (a * x[i]) + (b * y[i + s]); 45907 | } 45908 | 45909 | return T(1); 45910 | } 45911 | }; 45912 | 45913 | template <typename T> 45914 | class axpbsyz exprtk_final : public exprtk::igeneric_function<T> 45915 | { 45916 | public: 45917 | 45918 | typedef typename exprtk::igeneric_function<T> igfun_t; 45919 | typedef typename igfun_t::parameter_list_t parameter_list_t; 45920 | typedef typename igfun_t::generic_type generic_type; 45921 | typedef typename generic_type::scalar_view scalar_t; 45922 | typedef typename generic_type::vector_view vector_t; 45923 | 45924 | using igfun_t::operator(); 45925 | 45926 | axpbsyz() 45927 | : exprtk::igeneric_function<T>("TVTTVV|TVTTVVTT") 45928 | /* 45929 | z <- ax + by 45930 | Overloads: 45931 | 0. TVTVV - a, x(vector), b, shift, y(vector), z(vector) 45932 | 1. TVTVVTT - a, x(vector), b, shift, y(vector), z(vector), r0, r1 45933 | */ 45934 | {} 45935 | 45936 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 45937 | { 45938 | const vector_t x(parameters[1]); 45939 | const vector_t y(parameters[4]); 45940 | vector_t z(parameters[5]); 45941 | 45942 | std::size_t r0 = 0; 45943 | std::size_t r1 = std::min(x.size(),y.size()) - 1; 45944 | 45945 | if ((1 == ps_index) && !helper::load_vector_range<T>::process(parameters, r0, r1, 6, 7, 1)) 45946 | return std::numeric_limits<T>::quiet_NaN(); 45947 | else if (helper::invalid_range(y, r0, r1)) 45948 | return std::numeric_limits<T>::quiet_NaN(); 45949 | else if (helper::invalid_range(z, r0, r1)) 45950 | return std::numeric_limits<T>::quiet_NaN(); 45951 | 45952 | const T a = scalar_t(parameters[0])(); 45953 | const T b = scalar_t(parameters[2])(); 45954 | 45955 | const std::size_t s = static_cast<std::size_t>(scalar_t(parameters[3])()); 45956 | 45957 | for (std::size_t i = r0; i <= r1; ++i) 45958 | { 45959 | z[i] = (a * x[i]) + (b * y[i + s]); 45960 | } 45961 | 45962 | return T(1); 45963 | } 45964 | }; 45965 | 45966 | template <typename T> 45967 | class axpbz exprtk_final : public exprtk::igeneric_function<T> 45968 | { 45969 | public: 45970 | 45971 | typedef typename exprtk::igeneric_function<T> igfun_t; 45972 | typedef typename igfun_t::parameter_list_t parameter_list_t; 45973 | typedef typename igfun_t::generic_type generic_type; 45974 | typedef typename generic_type::scalar_view scalar_t; 45975 | typedef typename generic_type::vector_view vector_t; 45976 | 45977 | using igfun_t::operator(); 45978 | 45979 | axpbz() 45980 | : exprtk::igeneric_function<T>("TVTV|TVTVTT") 45981 | /* 45982 | z <- ax + b 45983 | Overloads: 45984 | 0. TVTV - a, x(vector), b, z(vector) 45985 | 1. TVTVTT - a, x(vector), b, z(vector), r0, r1 45986 | */ 45987 | {} 45988 | 45989 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 45990 | { 45991 | const vector_t x(parameters[1]); 45992 | vector_t z(parameters[3]); 45993 | 45994 | std::size_t r0 = 0; 45995 | std::size_t r1 = x.size() - 1; 45996 | 45997 | if ((1 == ps_index) && !helper::load_vector_range<T>::process(parameters, r0, r1, 4, 5, 1)) 45998 | return std::numeric_limits<T>::quiet_NaN(); 45999 | else if (helper::invalid_range(z, r0, r1)) 46000 | return std::numeric_limits<T>::quiet_NaN(); 46001 | 46002 | const T a = scalar_t(parameters[0])(); 46003 | const T b = scalar_t(parameters[2])(); 46004 | 46005 | for (std::size_t i = r0; i <= r1; ++i) 46006 | { 46007 | z[i] = (a * x[i]) + b; 46008 | } 46009 | 46010 | return T(1); 46011 | } 46012 | }; 46013 | 46014 | template <typename T> 46015 | class diff exprtk_final : public exprtk::igeneric_function<T> 46016 | { 46017 | public: 46018 | 46019 | typedef typename exprtk::igeneric_function<T> igfun_t; 46020 | typedef typename igfun_t::parameter_list_t parameter_list_t; 46021 | typedef typename igfun_t::generic_type generic_type; 46022 | typedef typename generic_type::scalar_view scalar_t; 46023 | typedef typename generic_type::vector_view vector_t; 46024 | 46025 | using igfun_t::operator(); 46026 | 46027 | diff() 46028 | : exprtk::igeneric_function<T>("VV|VVT") 46029 | /* 46030 | x_(i - stride) - x_i 46031 | Overloads: 46032 | 0. VV - x(vector), y(vector) 46033 | 1. VVT - x(vector), y(vector), stride 46034 | */ 46035 | {} 46036 | 46037 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 46038 | { 46039 | const vector_t x(parameters[0]); 46040 | vector_t y(parameters[1]); 46041 | 46042 | const std::size_t r0 = 0; 46043 | const std::size_t r1 = std::min(x.size(),y.size()) - 1; 46044 | 46045 | const std::size_t stride = (1 != ps_index) ? 1 : 46046 | std::min(r1,static_cast<std::size_t>(scalar_t(parameters[2])())); 46047 | 46048 | for (std::size_t i = 0; i < stride; ++i) 46049 | { 46050 | y[i] = std::numeric_limits<T>::quiet_NaN(); 46051 | } 46052 | 46053 | for (std::size_t i = (r0 + stride); i <= r1; ++i) 46054 | { 46055 | y[i] = x[i] - x[i - stride]; 46056 | } 46057 | 46058 | return T(1); 46059 | } 46060 | }; 46061 | 46062 | template <typename T> 46063 | class dot exprtk_final : public exprtk::igeneric_function<T> 46064 | { 46065 | public: 46066 | 46067 | typedef typename exprtk::igeneric_function<T> igfun_t; 46068 | typedef typename igfun_t::parameter_list_t parameter_list_t; 46069 | typedef typename igfun_t::generic_type generic_type; 46070 | typedef typename generic_type::scalar_view scalar_t; 46071 | typedef typename generic_type::vector_view vector_t; 46072 | 46073 | using igfun_t::operator(); 46074 | 46075 | dot() 46076 | : exprtk::igeneric_function<T>("VV|VVTT") 46077 | /* 46078 | Overloads: 46079 | 0. VV - x(vector), y(vector) 46080 | 1. VVTT - x(vector), y(vector), r0, r1 46081 | */ 46082 | {} 46083 | 46084 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 46085 | { 46086 | const vector_t x(parameters[0]); 46087 | const vector_t y(parameters[1]); 46088 | 46089 | std::size_t r0 = 0; 46090 | std::size_t r1 = std::min(x.size(),y.size()) - 1; 46091 | 46092 | if ((1 == ps_index) && !helper::load_vector_range<T>::process(parameters, r0, r1, 2, 3, 0)) 46093 | return std::numeric_limits<T>::quiet_NaN(); 46094 | else if (helper::invalid_range(y, r0, r1)) 46095 | return std::numeric_limits<T>::quiet_NaN(); 46096 | 46097 | T result = T(0); 46098 | 46099 | for (std::size_t i = r0; i <= r1; ++i) 46100 | { 46101 | result += (x[i] * y[i]); 46102 | } 46103 | 46104 | return result; 46105 | } 46106 | }; 46107 | 46108 | template <typename T> 46109 | class dotk exprtk_final : public exprtk::igeneric_function<T> 46110 | { 46111 | public: 46112 | 46113 | typedef typename exprtk::igeneric_function<T> igfun_t; 46114 | typedef typename igfun_t::parameter_list_t parameter_list_t; 46115 | typedef typename igfun_t::generic_type generic_type; 46116 | typedef typename generic_type::scalar_view scalar_t; 46117 | typedef typename generic_type::vector_view vector_t; 46118 | 46119 | using igfun_t::operator(); 46120 | 46121 | dotk() 46122 | : exprtk::igeneric_function<T>("VV|VVTT") 46123 | /* 46124 | Overloads: 46125 | 0. VV - x(vector), y(vector) 46126 | 1. VVTT - x(vector), y(vector), r0, r1 46127 | */ 46128 | {} 46129 | 46130 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 46131 | { 46132 | const vector_t x(parameters[0]); 46133 | const vector_t y(parameters[1]); 46134 | 46135 | std::size_t r0 = 0; 46136 | std::size_t r1 = std::min(x.size(),y.size()) - 1; 46137 | 46138 | if ((1 == ps_index) && !helper::load_vector_range<T>::process(parameters, r0, r1, 2, 3, 0)) 46139 | return std::numeric_limits<T>::quiet_NaN(); 46140 | else if (helper::invalid_range(y, r0, r1)) 46141 | return std::numeric_limits<T>::quiet_NaN(); 46142 | 46143 | T result = T(0); 46144 | T error = T(0); 46145 | 46146 | for (std::size_t i = r0; i <= r1; ++i) 46147 | { 46148 | details::kahan_sum(result, error, (x[i] * y[i])); 46149 | } 46150 | 46151 | return result; 46152 | } 46153 | }; 46154 | 46155 | template <typename T> 46156 | class threshold_below exprtk_final : public exprtk::igeneric_function<T> 46157 | { 46158 | public: 46159 | 46160 | typedef typename exprtk::igeneric_function<T> igfun_t; 46161 | typedef typename igfun_t::parameter_list_t parameter_list_t; 46162 | typedef typename igfun_t::generic_type generic_type; 46163 | typedef typename generic_type::scalar_view scalar_t; 46164 | typedef typename generic_type::vector_view vector_t; 46165 | 46166 | using igfun_t::operator(); 46167 | 46168 | threshold_below() 46169 | : exprtk::igeneric_function<T>("VTT|VTTTT") 46170 | /* 46171 | Overloads: 46172 | 0. VTT - vector, TV, SV 46173 | 1. VTTTT - vector, r0, r1, TV, SV 46174 | 46175 | Where: 46176 | TV - Threshold value 46177 | SV - Snap-to value 46178 | */ 46179 | {} 46180 | 46181 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 46182 | { 46183 | vector_t vec(parameters[0]); 46184 | 46185 | const T threshold_value = (0 == ps_index) ? 46186 | scalar_t(parameters[1]) : 46187 | scalar_t(parameters[3]) ; 46188 | 46189 | const T snap_value = scalar_t(parameters.back()); 46190 | 46191 | std::size_t r0 = 0; 46192 | std::size_t r1 = vec.size() - 1; 46193 | 46194 | if ( 46195 | (1 == ps_index) && 46196 | !helper::load_vector_range<T>::process(parameters, r0, r1, 1, 2, 0) 46197 | ) 46198 | { 46199 | return T(0); 46200 | } 46201 | 46202 | for (std::size_t i = r0; i <= r1; ++i) 46203 | { 46204 | if (vec[i] < threshold_value) 46205 | { 46206 | vec[i] = snap_value; 46207 | } 46208 | } 46209 | 46210 | return T(1); 46211 | } 46212 | }; 46213 | 46214 | template <typename T> 46215 | class threshold_above exprtk_final : public exprtk::igeneric_function<T> 46216 | { 46217 | public: 46218 | 46219 | typedef typename exprtk::igeneric_function<T> igfun_t; 46220 | typedef typename igfun_t::parameter_list_t parameter_list_t; 46221 | typedef typename igfun_t::generic_type generic_type; 46222 | typedef typename generic_type::scalar_view scalar_t; 46223 | typedef typename generic_type::vector_view vector_t; 46224 | 46225 | using igfun_t::operator(); 46226 | 46227 | threshold_above() 46228 | : exprtk::igeneric_function<T>("VTT|VTTTT") 46229 | /* 46230 | Overloads: 46231 | 0. VTT - vector, TV, SV 46232 | 1. VTTTT - vector, r0, r1, TV, SV 46233 | 46234 | Where: 46235 | TV - Threshold value 46236 | SV - Snap-to value 46237 | */ 46238 | {} 46239 | 46240 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 46241 | { 46242 | vector_t vec(parameters[0]); 46243 | 46244 | const T threshold_value = (0 == ps_index) ? 46245 | scalar_t(parameters[1]) : 46246 | scalar_t(parameters[3]) ; 46247 | 46248 | const T snap_value = scalar_t(parameters.back()); 46249 | 46250 | std::size_t r0 = 0; 46251 | std::size_t r1 = vec.size() - 1; 46252 | 46253 | if ( 46254 | (1 == ps_index) && 46255 | !helper::load_vector_range<T>::process(parameters, r0, r1, 1, 2, 0) 46256 | ) 46257 | { 46258 | return T(0); 46259 | } 46260 | 46261 | for (std::size_t i = r0; i <= r1; ++i) 46262 | { 46263 | if (vec[i] > threshold_value) 46264 | { 46265 | vec[i] = snap_value; 46266 | } 46267 | } 46268 | 46269 | return T(1); 46270 | } 46271 | }; 46272 | 46273 | template <typename T> 46274 | class min_elemwise exprtk_final : public exprtk::igeneric_function<T> 46275 | { 46276 | public: 46277 | 46278 | typedef typename exprtk::igeneric_function<T> igfun_t; 46279 | typedef typename igfun_t::parameter_list_t parameter_list_t; 46280 | typedef typename igfun_t::generic_type generic_type; 46281 | typedef typename generic_type::scalar_view scalar_t; 46282 | typedef typename generic_type::vector_view vector_t; 46283 | 46284 | using igfun_t::operator(); 46285 | 46286 | min_elemwise() 46287 | : exprtk::igeneric_function<T>("VT|VVT|VTTT|VVTTT") 46288 | /* 46289 | Overloads: 46290 | 0. VT - vector, T 46291 | 0. VVT - vector, vector, T 46292 | 0. VTTT - vector, r0, r1, T 46293 | 0. VVTTT - vector, vector, r0, r1, T 46294 | */ 46295 | {} 46296 | 46297 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 46298 | { 46299 | std::size_t out_vec_index = 0; 46300 | std::size_t in_vec_index = (ps_index & 1) ? 1 : 0; 46301 | std::size_t scalar_index = parameters.size() - 1; 46302 | 46303 | vector_t out_vec(parameters[out_vec_index]); 46304 | vector_t in_vec (parameters[in_vec_index ]); 46305 | 46306 | const T s = scalar_t(parameters[scalar_index ])(); 46307 | 46308 | std::size_t r0 = 0; 46309 | std::size_t r1 = in_vec.size() - 1; 46310 | 46311 | if ((2 == ps_index) || (3 == ps_index)) 46312 | { 46313 | std::size_t rng_idx0 = 0; 46314 | std::size_t rng_idx1 = 0; 46315 | 46316 | switch (ps_index) 46317 | { 46318 | case 2 : { rng_idx0 = 1; rng_idx1 = 2; }; break; 46319 | case 3 : { rng_idx0 = 2; rng_idx1 = 3; }; break; 46320 | } 46321 | 46322 | if (!helper::load_vector_range<T>::process(parameters, r0, r1, rng_idx0, rng_idx1, 0)) 46323 | { 46324 | return T(0); 46325 | } 46326 | } 46327 | 46328 | for (std::size_t i = r0; i <= r1; ++i) 46329 | { 46330 | out_vec[i] = exprtk::details::numeric::min(in_vec[i], s); 46331 | } 46332 | 46333 | return T(1); 46334 | } 46335 | }; 46336 | 46337 | template <typename T> 46338 | class max_elemwise exprtk_final : public exprtk::igeneric_function<T> 46339 | { 46340 | public: 46341 | 46342 | typedef typename exprtk::igeneric_function<T> igfun_t; 46343 | typedef typename igfun_t::parameter_list_t parameter_list_t; 46344 | typedef typename igfun_t::generic_type generic_type; 46345 | typedef typename generic_type::scalar_view scalar_t; 46346 | typedef typename generic_type::vector_view vector_t; 46347 | 46348 | using igfun_t::operator(); 46349 | 46350 | max_elemwise() 46351 | : exprtk::igeneric_function<T>("VT|VVT|VTTT|VVTTT") 46352 | /* 46353 | Overloads: 46354 | 0. VT - vector, T 46355 | 1. VVT - vector, vector, T 46356 | 2. VTTT - vector, r0, r1, T 46357 | 3. VVTTT - vector, vector, r0, r1, T 46358 | */ 46359 | {} 46360 | 46361 | inline T operator() (const std::size_t& ps_index, parameter_list_t parameters) exprtk_override 46362 | { 46363 | std::size_t out_vec_index = 0; 46364 | std::size_t in_vec_index = (ps_index & 1) ? 1 : 0; 46365 | std::size_t scalar_index = parameters.size() - 1; 46366 | 46367 | vector_t out_vec(parameters[out_vec_index]); 46368 | vector_t in_vec (parameters[in_vec_index ]); 46369 | 46370 | const T s = scalar_t(parameters[scalar_index ])(); 46371 | 46372 | std::size_t r0 = 0; 46373 | std::size_t r1 = in_vec.size() - 1; 46374 | 46375 | if ((2 == ps_index) || (3 == ps_index)) 46376 | { 46377 | std::size_t rng_idx0 = 0; 46378 | std::size_t rng_idx1 = 0; 46379 | 46380 | switch (ps_index) 46381 | { 46382 | case 2 : { rng_idx0 = 1; rng_idx1 = 2; }; break; 46383 | case 3 : { rng_idx0 = 2; rng_idx1 = 3; }; break; 46384 | } 46385 | 46386 | if (!helper::load_vector_range<T>::process(parameters, r0, r1, rng_idx0, rng_idx1, 0)) 46387 | { 46388 | return T(0); 46389 | } 46390 | } 46391 | 46392 | for (std::size_t i = r0; i <= r1; ++i) 46393 | { 46394 | out_vec[i] = exprtk::details::numeric::max(in_vec[i], s); 46395 | } 46396 | 46397 | return T(1); 46398 | } 46399 | }; 46400 | 46401 | template <typename T> 46402 | struct package 46403 | { 46404 | all_true <T> at; 46405 | all_false <T> af; 46406 | any_true <T> nt; 46407 | any_false <T> nf; 46408 | count <T> c; 46409 | copy <T> cp; 46410 | rol <T> rl; 46411 | ror <T> rr; 46412 | reverse <T> rev; 46413 | shift_left <T> sl; 46414 | shift_right <T> sr; 46415 | sort <T> st; 46416 | nthelement <T> ne; 46417 | assign <T> an; 46418 | iota <T> ia; 46419 | sumk <T> sk; 46420 | axpy <T> b1_axpy; 46421 | axpby <T> b1_axpby; 46422 | axpyz <T> b1_axpyz; 46423 | axpbyz <T> b1_axpbyz; 46424 | axpbsy <T> b1_axpbsy; 46425 | axpbsyz <T> b1_axpbsyz; 46426 | axpbz <T> b1_axpbz; 46427 | diff <T> df; 46428 | dot <T> dt; 46429 | dotk <T> dtk; 46430 | threshold_above<T> ta; 46431 | threshold_below<T> tb; 46432 | min_elemwise<T> miew; 46433 | max_elemwise<T> maew; 46434 | 46435 | bool register_package(exprtk::symbol_table<T>& symtab) 46436 | { 46437 | #define exprtk_register_function(FunctionName, FunctionType) \ 46438 | if (!symtab.add_function(FunctionName,FunctionType)) \ 46439 | { \ 46440 | exprtk_debug(( \ 46441 | "exprtk::rtl::vecops::register_package - Failed to add function: %s\n", \ 46442 | FunctionName)); \ 46443 | return false; \ 46444 | } \ 46445 | 46446 | exprtk_register_function("all_true" , at ) 46447 | exprtk_register_function("all_false" , af ) 46448 | exprtk_register_function("any_true" , nt ) 46449 | exprtk_register_function("any_false" , nf ) 46450 | exprtk_register_function("count" , c ) 46451 | exprtk_register_function("copy" , cp ) 46452 | exprtk_register_function("rotate_left" , rl ) 46453 | exprtk_register_function("rol" , rl ) 46454 | exprtk_register_function("rotate_right" , rr ) 46455 | exprtk_register_function("ror" , rr ) 46456 | exprtk_register_function("reverse" , rev ) 46457 | exprtk_register_function("shftl" , sl ) 46458 | exprtk_register_function("shftr" , sr ) 46459 | exprtk_register_function("sort" , st ) 46460 | exprtk_register_function("nth_element" , ne ) 46461 | exprtk_register_function("assign" , an ) 46462 | exprtk_register_function("iota" , ia ) 46463 | exprtk_register_function("sumk" , sk ) 46464 | exprtk_register_function("axpy" , b1_axpy ) 46465 | exprtk_register_function("axpby" , b1_axpby ) 46466 | exprtk_register_function("axpyz" , b1_axpyz ) 46467 | exprtk_register_function("axpbyz" , b1_axpbyz ) 46468 | exprtk_register_function("axpbsy" , b1_axpbsy ) 46469 | exprtk_register_function("axpbsyz" , b1_axpbsyz) 46470 | exprtk_register_function("axpbz" , b1_axpbz ) 46471 | exprtk_register_function("diff" , df ) 46472 | exprtk_register_function("dot" , dt ) 46473 | exprtk_register_function("dotk" , dtk ) 46474 | exprtk_register_function("threshold_above" , ta ) 46475 | exprtk_register_function("threshold_below" , tb ) 46476 | exprtk_register_function("min_elemwise" , miew ) 46477 | exprtk_register_function("max_elemwise" , maew ) 46478 | 46479 | #undef exprtk_register_function 46480 | 46481 | return true; 46482 | } 46483 | }; 46484 | 46485 | } // namespace exprtk::rtl::vecops 46486 | } // namespace exprtk::rtl 46487 | } // namespace exprtk 46488 | #endif 46489 | 46490 | namespace exprtk 46491 | { 46492 | namespace information 46493 | { 46494 | using ::exprtk::details::char_cptr; 46495 | 46496 | static char_cptr library = "Mathematical Expression Toolkit" 46497 | static char_cptr version = "2.71828182845904523536028747135266249775724" 46498 | "7093699959574966967627724076630353547594571" 46499 | "3821785251664274274663919320030599218174135" 46500 | "9662904357290033429526059563073813232862794" 46501 | static char_cptr date = "20250101" 46502 | static char_cptr min_cpp = "199711L" 46503 | 46504 | static inline std::string data() 46505 | { 46506 | static const std::string info_str = std::string(library) + 46507 | std::string(" v") + std::string(version) + 46508 | std::string(" (") + date + std::string(")") + 46509 | std::string(" (") + min_cpp + std::string(")"); 46510 | return info_str; 46511 | } 46512 | 46513 | } // namespace information 46514 | 46515 | #ifdef exprtk_debug 46516 | #undef exprtk_debug 46517 | #endif 46518 | 46519 | #ifdef exprtk_error_location 46520 | #undef exprtk_error_location 46521 | #endif 46522 | 46523 | #ifdef exprtk_fallthrough 46524 | #undef exprtk_fallthrough 46525 | #endif 46526 | 46527 | #ifdef exprtk_override 46528 | #undef exprtk_override 46529 | #endif 46530 | 46531 | #ifdef exprtk_final 46532 | #undef exprtk_final 46533 | #endif 46534 | 46535 | #ifdef exprtk_delete 46536 | #undef exprtk_delete 46537 | #endif 46538 | 46539 | } // namespace exprtk 46540 | 46541 | #endif