Module: sip-router Branch: andrei/type_conversion Commit: 04ff69818798e2330587c4109a69d8974908b158 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=04ff6981...
Author: Andrei Pelinescu-Onciul andrei@iptel.org Committer: Andrei Pelinescu-Onciul andrei@iptel.org Date: Tue Apr 28 17:49:54 2009 +0200
core expr eval: minor ==/!= optimization
- replace the generic RVE_EQ_OP/RVE_DIFF_OP with the type specific version (RVE_IEQ_OP/RVE_STREQ_OP...), if the type is known.
---
rvalue.c | 23 +++++++++++++++++++++-- 1 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/rvalue.c b/rvalue.c index 36c6ef4..7e82503 100644 --- a/rvalue.c +++ b/rvalue.c @@ -2341,10 +2341,10 @@ static int rve_op_is_commutative(enum rval_expr_op op, enum rval_type type) case RVE_GTE_OP: case RVE_LT_OP: case RVE_LTE_OP: - case RVE_EQ_OP: + case RVE_CONCAT_OP: return 0; case RVE_DIFF_OP: - case RVE_CONCAT_OP: + case RVE_EQ_OP: #if !defined(UNDEF_EQ_ALWAYS_FALSE) && !defined(UNDEF_EQ_UNDEF_TRUE) return 1; #else @@ -2838,6 +2838,25 @@ static int rve_optimize(struct rval_expr* rve) rve->fpos.e_line, rve->fpos.e_col); } } + /* e1 EQ_OP e2 -> change op if we know e1 basic type + e1 DIFF_OP e2 -> change op if we know e2 basic type */ + if (rve->op==RVE_EQ_OP || rve->op==RVE_DIFF_OP){ + l_type=rve_guess_type(rve->left.rve); + if (l_type==RV_INT){ + rve->op=(rve->op==RVE_EQ_OP)?RVE_IEQ_OP:RVE_IDIFF_OP; + DBG("FIXUP RVE (%d,%d-%d,%d): changed ==/!= into interger" + " ==/!=\n", + rve->fpos.s_line, rve->fpos.s_col, + rve->fpos.e_line, rve->fpos.e_col); + }else if (l_type==RV_STR){ + rve->op=RVE_CONCAT_OP; + rve->op=(rve->op==RVE_EQ_OP)?RVE_STREQ_OP:RVE_STRDIFF_OP; + DBG("FIXUP RVE (%d,%d-%d,%d): changed ==/!= into string" + " ==/!=\n", + rve->fpos.s_line, rve->fpos.s_col, + rve->fpos.e_line, rve->fpos.e_col); + } + } /* $v * 0 => 0; $v * 1 => $v (for *, /, &, |, &&, ||, +, -) */ if (rve_opt_01(rve, type)==1){