From 06ebc21dd605058758adef07b57941f3d03b7d83 Mon Sep 17 00:00:00 2001 From: Huamonarch Date: Fri, 15 May 2026 16:23:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20roller2/roller3=20=E4=B8=AD=20init=5Fhol?= =?UTF-8?q?d=5Fexp=5Fstr/exp=5Fmessy=5Fcode=5Fcheck=20=E6=94=B9=E7=94=A8?= =?UTF-8?q?=20ExpressionEngine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eqpalg/algs/roller2.cpp | 26 +++++++------------------- eqpalg/algs/roller3.cpp | 14 ++++++-------- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/eqpalg/algs/roller2.cpp b/eqpalg/algs/roller2.cpp index d9a138e..3a78681 100644 --- a/eqpalg/algs/roller2.cpp +++ b/eqpalg/algs/roller2.cpp @@ -125,27 +125,15 @@ int Roller2::init_X_exp() { rule_json_.at("function").at(exp_stri).at("value").get(); exp_str_ = get_macro_replaced_exp(tmp_exp); var_exp_str_[exp_stri] = exp_str_; - res += init_hold_exp_str(exp_str_); feedback_mode_ = true; - auto messy_code = exp_messy_code_check(exp_str_); - if (messy_code == -1) { - this->error_code_list_.push_back( - {ErrorType::EnCodeError, ErrorLocation::ActExp}); - res += messy_code; - return -1; - } - try { - var_exp_[exp_stri] = - std::make_unique(exp_str_, &mm_vars); - logger_->Debug() << "exp_stri:" << exp_str_ << "=" - << var_exp_[exp_stri]->evaluate() << endl; - } catch (const std::exception& e) { - logger_->Error() << "exp_stri:" << exp_str_ << "计算出错:" << e.what() - << ",location:" << BOOST_CURRENT_LOCATION << endl; + int reg_ret = expr_engine_->registerExpression(exp_stri, exp_str_); + if (reg_ret != 0) { this->error_code_list_.push_back( {ErrorType::CalError, ErrorLocation::FBExp}); return -1; } + logger_->Debug() << "exp_stri:" << exp_str_ << "=" + << expr_engine_->evaluate(exp_stri) << endl; if (rule_json_.at("function").at(exp_stri).at("param").contains("name")) { var_name_[exp_stri] = rule_json_.at("function") .at(exp_stri) @@ -182,11 +170,11 @@ int Roller2::init_X_exp() { void Roller2::refresh_var_result() { try { - for (auto& expi : var_exp_) { + for (auto& expi : var_exp_str_) { if (expi.first == "pre_exp") { - pre_exp_flag_ = expi.second->evaluate(); + pre_exp_flag_ = expr_engine_->evaluateBool(expi.first); } else { - var_Xdouble_[expi.first] = expi.second->evaluate(); + var_Xdouble_[expi.first] = expr_engine_->evaluate(expi.first); } } } catch (const std::exception& e) { diff --git a/eqpalg/algs/roller3.cpp b/eqpalg/algs/roller3.cpp index 50ab459..e7691f5 100644 --- a/eqpalg/algs/roller3.cpp +++ b/eqpalg/algs/roller3.cpp @@ -229,16 +229,14 @@ int Roller3::init_X_exp() { rule_json_.at("function").at("pre_exp").at("value").get(); exp_str_ = get_macro_replaced_exp(tmp_exp); - res += init_hold_exp_str(exp_str_); - - // ExpressionEngine::registerExpression() now handles FunVars processing internally. - feedback_mode_ = false; - auto messy_code = exp_messy_code_check(exp_str_); - if (messy_code == -1) { + int reg_ret = expr_engine_->registerExpression("pre_exp", exp_str_); + if (reg_ret != 0) { this->error_code_list_.push_back( - {ErrorType::EnCodeError, ErrorLocation::ActExp}); - res += messy_code; + {ErrorType::CalError, ErrorLocation::ActExp}); + res += reg_ret; } + + feedback_mode_ = false; } if (rule_json_.at("function").contains("input")) {