[SR-Dev] git:andrei/type_conversion: core: new script operators: eq, ne, ieq, ine
Andrei Pelinescu-Onciul
andrei at iptel.org
Tue Apr 28 19:54:15 CEST 2009
Module: sip-router
Branch: andrei/type_conversion
Commit: 298512a2b79ff3bd9405a63c5d05030b5ec21de3
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=298512a2b79ff3bd9405a63c5d05030b5ec21de3
Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date: Tue Apr 28 19:48:11 2009 +0200
core: new script operators: eq, ne, ieq, ine
Added operators for: - string == and string != : eq, ne
- integer == and integer!= : ieq, ine
They are almost equivalent to == or !=, but they force the
conversion of their operands (eq to string and ieq to int),
allowing among other things better type checking on startup
and more optimizations.
Non equiv. examples: 0 == "" (true) is not equivalent to 0 eq ""
(false: it evaluates to "0" eq ""). "a" ieq "b" (true: (int)"a" is
0 and (int)"b" is 0) is not equivalent to "a" == "b" (false).
Note: the names are not final, they are mostly for testing.
Future releases might replace ==/!= with ieq/ine and use eq/ne for
strings.
---
cfg.lex | 8 ++++++++
cfg.y | 8 +++++++-
2 files changed, 15 insertions(+), 1 deletions(-)
diff --git a/cfg.lex b/cfg.lex
index b1f9c55..768f3e9 100644
--- a/cfg.lex
+++ b/cfg.lex
@@ -248,6 +248,10 @@ MINUS "-"
STRLEN "strlen"
STREMPTY "strempty"
DEFINED "defined"
+STREQ eq
+INTEQ ieq
+STRDIFF ne
+INTDIFF ine
/* Attribute specification */
ATTR_MARK "%"
@@ -772,6 +776,10 @@ EAT_ABLE [\ \t\b\r]
<INITIAL>{STRLEN} { count(); return STRLEN; }
<INITIAL>{STREMPTY} { count(); return STREMPTY; }
<INITIAL>{DEFINED} { count(); return DEFINED; }
+<INITIAL>{STREQ} { count(); return STREQ; }
+<INITIAL>{INTEQ} { count(); return INTEQ; }
+<INITIAL>{STRDIFF} { count(); return STRDIFF; }
+<INITIAL>{INTDIFF} { count(); return INTDIFF; }
<INITIAL>{SELECT_MARK} { count(); state = SELECT_S; BEGIN(SELECT); return SELECT_MARK; }
<SELECT>{ID} { count(); addstr(&s_buf, yytext, yyleng);
diff --git a/cfg.y b/cfg.y
index a281052..df3056d 100644
--- a/cfg.y
+++ b/cfg.y
@@ -484,7 +484,7 @@ static int case_check_default(struct case_stms* stms);
%left LOG_AND
%left BIN_OR
%left BIN_AND
-%left EQUAL_T DIFF MATCH
+%left EQUAL_T DIFF MATCH INTEQ INTDIFF STREQ STRDIFF
%left GT LT GTE LTE
%left PLUS MINUS
%left STAR SLASH
@@ -1580,6 +1580,8 @@ exp: rval_expr
equalop:
EQUAL_T {$$=EQUAL_OP; }
| DIFF {$$=DIFF_OP; }
+ | STREQ {$$=EQUAL_OP; } /* for expr. elems equiv. to EQUAL_T*/
+ | STRDIFF {$$=DIFF_OP; } /* for expr. elems. equiv. to DIFF */
;
cmpop:
GT {$$=GT_OP; }
@@ -1597,6 +1599,10 @@ strop:
rve_equalop:
EQUAL_T {$$=RVE_EQ_OP; }
| DIFF {$$=RVE_DIFF_OP; }
+ | INTEQ {$$=RVE_IEQ_OP; }
+ | INTDIFF {$$=RVE_IDIFF_OP; }
+ | STREQ {$$=RVE_STREQ_OP; }
+ | STRDIFF {$$=RVE_STRDIFF_OP; }
;
rve_cmpop:
GT {$$=RVE_GT_OP; }
More information about the sr-dev
mailing list