expr.y

filter: Statementstmt 85.8% 164 / 191 Branchbran 67.1% 94 / 140 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 77.9% 258 / 331 SCAR 0
CC
0
Cov
0%
CRAP 0
« exprpstr.inc ↑ Summary tags.inc »
1 %pure-parser
2 %lex-param {struct tmplpro_state* state}
3 %lex-param {struct expr_parser* exprobj}
4 %parse-param {struct tmplpro_state* state}
5 %parse-param {struct expr_parser* exprobj}
6 %parse-param {PSTRING* expr_retval_ptr}
7 %{
8 #include <math.h> /* For math functions, cos(), sin(), etc. */
9 #include <stdio.h> /* for printf */
10 #include <stdlib.h> /* for malloc */
11 #include <ctype.h> /* for yylex alnum */
12 #include "calc.h" /* Contains definition of `symrec'. */
13 #include "tmpllog.h"
14 #include "pabstract.h"
15 #include "prostate.h"
16 #include "provalue.h"
17 #include "pparam.h"
18 #include "pmiscdef.h"
19 /* for expr-specific only */
20 #include "exprtool.h"
21 #include "exprpstr.h"
22 #include "parse_expr.h"
23 /* Remember unsigned char assert on win32
24 Debug Assertion Failed! f:\dd\vctools\crt_bld\self_x86\crt\src \isctype.c Expression:(unsigned)(c + 1) <= 256
25 */
26 %}
27 %union {
28 struct exprval numval; /* For returning numbers. */
29 const symrec_const *tptr; /* For returning symbol-table pointers. */
30 struct user_func_call extfunc; /* for user-defined function name */
31 PSTRING uservar;
32 }
33 %{
34 /* the second section is required as we use YYSTYPE here */
35 static void yyerror (struct tmplpro_state* state, struct expr_parser* exprobj, PSTRING* expr_retval_ptr, char const *);
36 static int yylex (YYSTYPE *lvalp, struct tmplpro_state* state, struct expr_parser* exprobj);
37 %}
38 %start line
39 %token <numval> NUM /* poly type. */
40 %token <extfunc> EXTFUNC /* user-defined function */
41 %token <tptr> BUILTIN_VAR /* built-in Variable */
42 %token <tptr> BUILTIN_FNC_DD /* built-in D Function (D). */
43 %token <tptr> BUILTIN_FNC_DDD /* built-in D Function (D,D). */
44 %token <tptr> BUILTIN_FNC_EE /* built-in E Function (E). */
45 %token <uservar> VAR /* user-supplied variable. */
46 %type <numval> numEXP
47 %type <extfunc> arglist
48  
49 /*%right '='*/
50 %left OR
51 %left AND
52 %nonassoc strGT strGE strLT strLE strEQ strNE strCMP
53 %nonassoc numGT numGE numLT numLE numEQ numNE '<' '>'
54 %nonassoc reLIKE reNOTLIKE
55 %left '-' '+'
56 %left '*' '/' '%'
57 %left '!' NOT NEG /* negation--unary minus */
58 %right '^' /* exponentiation */
59 %% /* The grammar follows. */
60  
61 line: numEXP
62 {
63 551 expr_to_str1(state, &$1);
64 551 *expr_retval_ptr=$1.val.strval;
65 }
66 ;
67 /* | error { yyerrok; } */
68  
69 555 numEXP: NUM { $$ = $1; }
70 0 | BUILTIN_VAR { $$.type=EXPR_TYPE_DBL; $$.val.dblval = $1->var; }
71 /*| BUILTIN_VAR '=' numEXP { $$ = $3; $1->value.var = $3; } */
72 | VAR {
73 364 PSTRING varvalue=_get_variable_value(state->param, $1);
74 364 ▶ if (varvalue.begin==NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (varvalue.begin==NULL) { 6 358 364
75 6 int loglevel = state->param->warn_unused ? TMPL_LOG_ERROR : TMPL_LOG_INFO;
76 6 log_expr(exprobj,loglevel, "non-initialized variable %.*s\n",(int)($1.endnext-$1.begin),$1.begin);
77 }
78 364 $$.type=EXPR_TYPE_PSTR;
79 364 $$.val.strval=varvalue;
80 }
81 | arglist ')'
82 {
83 62 $$ = call_expr_userfunc(exprobj, state->param, $1);
84 }
85 | EXTFUNC '(' ')'
86 {
87 8 $1.arglist=state->param->InitExprArglistFuncPtr(state->param->ext_calluserfunc_state);
88 8 $$ = call_expr_userfunc(exprobj, state->param, $1);
89 }
90 | BUILTIN_FNC_EE '(' ')'
91 {
92 13 struct exprval e = NEW_EXPRVAL(EXPR_TYPE_PSTR);
93 13 e.val.strval.begin = NULL;
94 13 e.val.strval.endnext = NULL;
95 13 $$ = (*((func_t_ee)$1->fnctptr))(exprobj, e);
96 }
97 | BUILTIN_FNC_DD '(' numEXP ')'
98 {
99 10 $$.type=EXPR_TYPE_DBL;
100 10 expr_to_dbl1(exprobj, &$3);
101 10 $$.val.dblval = (*((func_t_dd)$1->fnctptr))($3.val.dblval);
102 }
103 | BUILTIN_FNC_DDD '(' numEXP ',' numEXP ')'
104 {
105 0 $$.type=EXPR_TYPE_DBL;
106 0 expr_to_dbl(exprobj, &$3, &$5);
107 0 $$.val.dblval = (*((func_t_ddd)$1->fnctptr))($3.val.dblval,$5.val.dblval);
108 }
109 | BUILTIN_FNC_EE '(' numEXP ')'
110 {
111 42 $$ = (*((func_t_ee)$1->fnctptr))(exprobj,$3);
112 }
113 68 | numEXP '+' numEXP { DO_MATHOP(exprobj, $$,+,$1,$3); }
114 5 | numEXP '-' numEXP { DO_MATHOP(exprobj, $$,-,$1,$3); }
115 12 | numEXP '*' numEXP { DO_MATHOP(exprobj, $$,*,$1,$3); }
116 | numEXP '%' numEXP
117 {
118 8 $$.type=EXPR_TYPE_INT;
119 8 expr_to_int(exprobj, &$1,&$3);
120 8 $$.val.intval = $1.val.intval % $3.val.intval;
121 }
122 /* old division; now always return double (due to compains 1/3==0)
123 | numEXP '/' numEXP
124 {
125 switch ($$.type=expr_to_int_or_dbl(&$1,&$3)) {
126 case EXPR_TYPE_INT:
127 if ($3.val.intval)
128 $$.val.intval = $1.val.intval / $3.val.intval;
129 else
130 {
131 $$.val.intval = 0;
132 log_expr(exprobj, TMPL_LOG_ERROR, "%s\n", "division by zero");
133 }
134 ;break;
135 case EXPR_TYPE_DBL:
136 if ($3.val.dblval)
137 $$.val.dblval = $1.val.dblval / $3.val.dblval;
138 else
139 {
140 $$.val.dblval = 0;
141 log_expr(exprobj, TMPL_LOG_ERROR, "%s\n", "division by zero");
142 }
143 }
144 ;break;
145 }
146 */
147 | numEXP '/' numEXP
148 {
149 4 $$.type=EXPR_TYPE_DBL;
150 4 expr_to_dbl(exprobj, &$1,&$3);
151 4 ▶ if ($3.val.dblval)
Branch: 1 branch
BranchTrueFalseTotal
if ($3.val.dblval) 4 0 4
152 4 $$.val.dblval = $1.val.dblval / $3.val.dblval;
153 else
154 {
155 0 $$.val.dblval = 0;
156 0 log_expr(exprobj, TMPL_LOG_ERROR, "%s\n", "division by zero");
157 }
158 }
159 | '-' numEXP %prec NEG
160 {
161 9 switch ($$.type=$2.type) {
162 5 case EXPR_TYPE_INT:
163 5 $$.val.intval = -$2.val.intval;
164 5 ;break;
165 4 case EXPR_TYPE_DBL:
166 4 $$.val.dblval = -$2.val.dblval;
167 4 ;break;
168 }
169 }
170 | numEXP '^' numEXP
171 {
172 0 $$.type=EXPR_TYPE_DBL;
173 0 expr_to_dbl(exprobj, &$1,&$3);
174 0 $$.val.dblval = pow ($1.val.dblval, $3.val.dblval);
175 }
176 | numEXP OR numEXP
177 {
178 7 ▶ if (exprobj->is_tt_like_logical) {
Branch: 1 branch
BranchTrueFalseTotal
if (exprobj->is_tt_like_logical) { 0 7 7
179 0 $$=$1;
180 0 switch (expr_to_int_or_dbl_logop1(exprobj, &$$)) {
181 0 ▶ case EXPR_TYPE_INT: $$= ($1.val.intval ? $1 : $3); break;
Branch: 1 branch
BranchTrueFalseTotal
case EXPR_TYPE_INT: $$= ($1.val.intval ? $1 : $3); break; 0 0 0
182 0 ▶ case EXPR_TYPE_DBL: $$= ($1.val.dblval ? $1 : $3); break;
Branch: 1 branch
BranchTrueFalseTotal
case EXPR_TYPE_DBL: $$= ($1.val.dblval ? $1 : $3); break; 0 0 0
183 }
184 } else {
185 7 ▶ DO_LOGOP(exprobj, $$,||,$1,$3);
Branch: 4 branches
BranchTrueFalseTotal
DO_LOGOP(exprobj, $$,||,$1,$3); 1 6 7
DO_LOGOP(exprobj, $$,||,$1,$3); 1 0 1
DO_LOGOP(exprobj, $$,||,$1,$3); 0 0 0
DO_LOGOP(exprobj, $$,||,$1,$3); 0 0 0
186 }
187 }
188 | numEXP AND numEXP
189 {
190 21 ▶ if (exprobj->is_tt_like_logical) {
Branch: 1 branch
BranchTrueFalseTotal
if (exprobj->is_tt_like_logical) { 0 21 21
191 0 $$=$1;
192 0 switch (expr_to_int_or_dbl_logop1(exprobj, &$$)) {
193 0 ▶ case EXPR_TYPE_INT: $$= ($1.val.intval ? $3 : $1); break;
Branch: 1 branch
BranchTrueFalseTotal
case EXPR_TYPE_INT: $$= ($1.val.intval ? $3 : $1); break; 0 0 0
194 0 ▶ case EXPR_TYPE_DBL: $$= ($1.val.dblval ? $3 : $1); break;
Branch: 1 branch
BranchTrueFalseTotal
case EXPR_TYPE_DBL: $$= ($1.val.dblval ? $3 : $1); break; 0 0 0
195 }
196 } else {
197 21 ▶ DO_LOGOP(exprobj, $$,&&,$1,$3);
Branch: 4 branches
BranchTrueFalseTotal
DO_LOGOP(exprobj, $$,&&,$1,$3); 16 1 17
DO_LOGOP(exprobj, $$,&&,$1,$3); 16 0 16
DO_LOGOP(exprobj, $$,&&,$1,$3); 4 0 4
DO_LOGOP(exprobj, $$,&&,$1,$3); 4 0 4
198 }
199 }
200 4 | numEXP numGE numEXP { DO_CMPOP(exprobj, $$,>=,$1,$3); }
201 0 | numEXP numLE numEXP { DO_CMPOP(exprobj, $$,<=,$1,$3); }
202 0 | numEXP numNE numEXP { DO_CMPOP(exprobj, $$,!=,$1,$3); }
203 14 | numEXP numEQ numEXP { DO_CMPOP(exprobj, $$,==,$1,$3); }
204 29 | numEXP '>' numEXP %prec numGT { DO_CMPOP(exprobj, $$,>,$1,$3); }
205 3 | numEXP '<' numEXP %prec numLT { DO_CMPOP(exprobj, $$,<,$1,$3); }
206 0 | '!' numEXP %prec NOT { DO_LOGOP1(exprobj, $$,!,$2); }
207 0 | NOT numEXP { DO_LOGOP1(exprobj, $$,!,$2); }
208 49 | '(' numEXP ')' { $$ = $2; }
209 | numEXP strCMP numEXP {
210 8 expr_to_str(state, &$1,&$3);
211 8 $$.type=EXPR_TYPE_INT; $$.val.intval = pstring_ge ($1.val.strval,$3.val.strval)-pstring_le ($1.val.strval,$3.val.strval);
212 }
213 16 | numEXP strGE numEXP { DO_TXTOP($$,pstring_ge,$1,$3,state);}
214 16 | numEXP strLE numEXP { DO_TXTOP($$,pstring_le,$1,$3,state);}
215 20 | numEXP strNE numEXP { DO_TXTOP($$,pstring_ne,$1,$3,state);}
216 68 | numEXP strEQ numEXP { DO_TXTOP($$,pstring_eq,$1,$3,state);}
217 24 | numEXP strGT numEXP { DO_TXTOP($$,pstring_gt,$1,$3,state);}
218 36 | numEXP strLT numEXP { DO_TXTOP($$,pstring_lt,$1,$3,state);}
219 0 | numEXP reLIKE numEXP { DO_TXTOPLOG($$,re_like,$1,$3,exprobj);}
220 0 | numEXP reNOTLIKE numEXP { DO_TXTOPLOG($$,re_notlike,$1,$3,exprobj);}
221 ;
222  
223 arglist: EXTFUNC '(' numEXP {
224 62 $1.arglist=state->param->InitExprArglistFuncPtr(state->param->expr_func_map);
225 62 pusharg_expr_userfunc(exprobj,state->param,$1,$3);
226 62 $$ = $1;
227 }
228 26 | arglist ',' numEXP { pusharg_expr_userfunc(exprobj,state->param,$1,$3); $$ = $1; }
229 ;
230  
231 /* End of grammar. */
232 %%
233  
234 /* Called by yyparse on error. */
235 static void
236 0 yyerror (struct tmplpro_state* state, struct expr_parser* exprobj, PSTRING* expr_retval_ptr, char const *s)
237 {
238 0 log_expr(exprobj, TMPL_LOG_ERROR, "not a valid expression: %s\n", s);
239 0 }
240  
241 #include "calc.inc"
242  
243 static
244 const symrec_const
245 builtin_funcs_symrec[] =
246 {
247 /* built-in funcs */
248 {SYMREC("sin"), BUILTIN_FNC_DD, 0, sin},
249 {SYMREC("cos"), BUILTIN_FNC_DD, 0, cos},
250 {SYMREC("atan"), BUILTIN_FNC_DD, 0, atan},
251 {SYMREC("log"), BUILTIN_FNC_DD, 0, log},
252 {SYMREC("exp"), BUILTIN_FNC_DD, 0, exp},
253 {SYMREC("sqrt"), BUILTIN_FNC_DD, 0, sqrt},
254 {SYMREC("atan2"), BUILTIN_FNC_DDD, 0, atan2},
255 {SYMREC("abs"), BUILTIN_FNC_EE, 0, builtin_abs},
256 {SYMREC("defined"), BUILTIN_FNC_EE, 0, builtin_defined},
257 {SYMREC("int"), BUILTIN_FNC_EE, 0, builtin_int},
258 {SYMREC("hex"), BUILTIN_FNC_EE, 0, builtin_hex},
259 {SYMREC("length"), BUILTIN_FNC_EE, 0, builtin_length},
260 {SYMREC("oct"), BUILTIN_FNC_EE, 0, builtin_oct},
261 {SYMREC("rand"), BUILTIN_FNC_EE, 0, builtin_rand},
262 {SYMREC("srand"), BUILTIN_FNC_EE, 0, builtin_srand},
263 {SYMREC("version"), BUILTIN_FNC_EE, 0, builtin_version},
264 /* end mark */
265 {0, 0, 0}
266 };
267  
268 static
269 const symrec_const
270 builtin_ops_symrec[] =
271 {
272 /* built-in ops */
273 {SYMREC("eq"), strEQ, 0, NULL},
274 {SYMREC("ne"), strNE, 0, NULL},
275 {SYMREC("gt"), strGT, 0, NULL},
276 {SYMREC("ge"), strGE, 0, NULL},
277 {SYMREC("lt"), strLT, 0, NULL},
278 {SYMREC("le"), strLE, 0, NULL},
279 {SYMREC("cmp"), strCMP, 0, NULL},
280 {SYMREC("or"), OR, 0, NULL},
281 {SYMREC("and"),AND, 0, NULL},
282 {SYMREC("not"),NOT, 0, NULL},
283 /* end mark */
284 {0, 0, 0}
285 };
286  
287 TMPLPRO_LOCAL
288 PSTRING
289 551 parse_expr(PSTRING expression, struct tmplpro_state* state)
290 {
291 PSTRING expr_retval;
292 struct expr_parser exprobj;
293 551 expr_retval.begin=expression.begin;
294 551 expr_retval.endnext=expression.begin;
295 551 exprobj.expr_curpos=expression.begin;
296 551 exprobj.exprarea=expression;
297 551 exprobj.state = state;
298 551 exprobj.is_expect_quote_like=1;
299 // TODO!!
300 551 exprobj.is_tt_like_logical=0;
301 551 yyparse (state, &exprobj, &expr_retval);
302 551 ▶ if (NULL!=expr_retval.begin && NULL==expr_retval.endnext) log_expr(&exprobj, TMPL_LOG_ERROR, "parse_expr internal warning: %s\n", "endnext is null pointer");
Branch: 2 branches
BranchTrueFalseTotal
if (NULL!=expr_retval.begin && NULL==expr_retval.endnext) log_expr(&exprobj, TMPL_LOG_ERROR, "parse_expr internal warning: %s\n", "endnext is null pointer"); 551 0 551
if (NULL!=expr_retval.begin && NULL==expr_retval.endnext) log_expr(&exprobj, TMPL_LOG_ERROR, "parse_expr internal warning: %s\n", "endnext is null pointer"); 0 551 551
303 551 return expr_retval;
304 }
305  
306 static
307 void
308 6 log_expr(struct expr_parser* exprobj, int loglevel, const char* fmt, ...)
309 {
310 va_list vl;
311 6 va_start(vl, fmt);
312 6 log_state(exprobj->state, loglevel, "in EXPR:at pos " MOD_TD " [" MOD_TD "]: ",
313 6 TO_PTRDIFF_T((exprobj->expr_curpos)-(exprobj->state->top)),
314 6 TO_PTRDIFF_T((exprobj->expr_curpos)-(exprobj->exprarea).begin));
315 6 tmpl_vlog(loglevel, fmt, vl);
316 6 va_end(vl);
317 6 }
318  
319 static
320 PSTRING
321 697 fill_symbuf (struct expr_parser* exprobj, int is_accepted(unsigned char)) {
322 /* skip first char, already tested */
323 697 PSTRING retval = {exprobj->expr_curpos++};
324 3274 ▶ while (exprobj->expr_curpos < (exprobj->exprarea).endnext && is_accepted(*exprobj->expr_curpos)) exprobj->expr_curpos++;
Branch: 2 branches
BranchTrueFalseTotal
while (exprobj->expr_curpos < (exprobj->exprarea).endnext && is_accepted(*exprobj->expr_curpos)) exprobj->expr_curpos++; 3117 157 3274
while (exprobj->expr_curpos < (exprobj->exprarea).endnext && is_accepted(*exprobj->expr_curpos)) exprobj->expr_curpos++; 2577 540 3117
325 697 retval.endnext= exprobj->expr_curpos;
326 697 return retval;
327 }
328  
329 static
330 int
331 3057 is_alnum_lex (unsigned char c)
332 {
333 3057 ▶ return (c == '_' || isalnum (c));
Branch: 2 branches
BranchTrueFalseTotal
return (c == '_' || isalnum (c)); 2792 265 3057
return (c == '_' || isalnum (c)); 2258 534 2792
334 }
335  
336 static
337 int
338 60 is_not_identifier_ext_end (unsigned char c)
339 {
340 60 return (c != '}');
341 }
342  
343 #define TESTOP(c1,c2,z) if (c1 == c) { char d=*++(exprobj->expr_curpos); if (c2 != d) return c; else (exprobj->expr_curpos)++; return z; }
344 #define TESTOP3(c1,c2,c3,num2,str3) if (c1 == c) { char d=*++(exprobj->expr_curpos); if (c2 == d) {(exprobj->expr_curpos)++; return num2;} else if (c3 == d) {(exprobj->expr_curpos)++; exprobj->is_expect_quote_like=1; return str3;} else return c; }
345  
346 static
347 int
348 2371 yylex (YYSTYPE *lvalp, struct tmplpro_state* state, struct expr_parser* exprobj)
349 {
350 2371 register unsigned char c = 0;
351 int is_identifier_ext;
352 /* TODO: newline? */
353 /* Ignore white space, get first nonwhite character. */
354 2907 ▶ while ((exprobj->expr_curpos)<(exprobj->exprarea).endnext && ((c = *(exprobj->expr_curpos)) == ' ' || c == '\t')) (exprobj->expr_curpos)++;
Branch: 3 branches
BranchTrueFalseTotal
while ((exprobj->expr_curpos)<(exprobj->exprarea).endnext && ((c = *(exprobj->expr_curpos)) == ' ' || c == '\t')) (exprobj->expr_curpos)++; 2356 551 2907
while ((exprobj->expr_curpos)<(exprobj->exprarea).endnext && ((c = *(exprobj->expr_curpos)) == ' ' || c == '\t')) (exprobj->expr_curpos)++; 536 1820 2356
while ((exprobj->expr_curpos)<(exprobj->exprarea).endnext && ((c = *(exprobj->expr_curpos)) == ' ' || c == '\t')) (exprobj->expr_curpos)++; 0 1820 1820
355 2371 ▶ if ((exprobj->expr_curpos)>=(exprobj->exprarea).endnext) return 0;
Branch: 1 branch
BranchTrueFalseTotal
if ((exprobj->expr_curpos)>=(exprobj->exprarea).endnext) return 0; 551 1820 2371
356  
357 /* Char starts a quote => read a string */
358 1820 ▶ if ('\''==c || '"'==c || (exprobj->is_expect_quote_like && '/'==c) ) {
Branch: 4 branches
BranchTrueFalseTotal
if ('\''==c || '"'==c || (exprobj->is_expect_quote_like && '/'==c) ) { 1502 318 1820
if ('\''==c || '"'==c || (exprobj->is_expect_quote_like && '/'==c) ) { 1502 0 1502
if ('\''==c || '"'==c || (exprobj->is_expect_quote_like && '/'==c) ) { 423 1079 1502
if ('\''==c || '"'==c || (exprobj->is_expect_quote_like && '/'==c) ) { 0 423 423
359 PSTRING strvalue;
360 318 unsigned char terminal_quote=c;
361 318 int escape_flag = 0;
362 318 c =* ++(exprobj->expr_curpos);
363 318 strvalue.begin = exprobj->expr_curpos;
364 318 strvalue.endnext = exprobj->expr_curpos;
365  
366 926 ▶ while ((exprobj->expr_curpos)<(exprobj->exprarea).endnext && c != terminal_quote) {
Branch: 2 branches
BranchTrueFalseTotal
while ((exprobj->expr_curpos)<(exprobj->exprarea).endnext && c != terminal_quote) { 926 0 926
while ((exprobj->expr_curpos)<(exprobj->exprarea).endnext && c != terminal_quote) { 608 318 926
367 /* any escaped char with \ , incl. quote */
368 608 ▶ if ('\\' == c) {
Branch: 1 branch
BranchTrueFalseTotal
if ('\\' == c) { 48 560 608
369 48 escape_flag = 1;
370 48 exprobj->expr_curpos+=2;
371 48 c =*(exprobj->expr_curpos);
372 } else {
373 560 c = * ++(exprobj->expr_curpos);
374 }
375 }
376  
377 318 strvalue.endnext = exprobj->expr_curpos;
378 318 ▶ if ((exprobj->expr_curpos)<(exprobj->exprarea).endnext && ((c = *(exprobj->expr_curpos)) == terminal_quote)) (exprobj->expr_curpos)++;
Branch: 2 branches
BranchTrueFalseTotal
if ((exprobj->expr_curpos)<(exprobj->exprarea).endnext && ((c = *(exprobj->expr_curpos)) == terminal_quote)) (exprobj->expr_curpos)++; 318 0 318
if ((exprobj->expr_curpos)<(exprobj->exprarea).endnext && ((c = *(exprobj->expr_curpos)) == terminal_quote)) (exprobj->expr_curpos)++; 318 0 318
379 318 ▶ if (escape_flag) {
Branch: 1 branch
BranchTrueFalseTotal
if (escape_flag) { 40 278 318
380 40 (*lvalp).numval.type=EXPR_TYPE_UPSTR;
381 } else {
382 278 (*lvalp).numval.type=EXPR_TYPE_PSTR;
383 }
384 318 (*lvalp).numval.val.strval=strvalue;
385 318 exprobj->is_expect_quote_like=0;
386 318 return NUM;
387 }
388
389 1502 exprobj->is_expect_quote_like=0;
390 /* Char starts a number => parse the number. */
391 1502 ▶ if (c == '.' || isdigit (c))
Branch: 2 branches
BranchTrueFalseTotal
if (c == '.' || isdigit (c)) 1502 0 1502
if (c == '.' || isdigit (c)) 237 1265 1502
392 {
393 237 (*lvalp).numval=exp_read_number (exprobj, &(exprobj->expr_curpos), (exprobj->exprarea).endnext);
394 237 return NUM;
395 }
396  
397 /*
398 * Emiliano Bruni extension to Expr:
399 * original HTML::Template allows almost arbitrary chars in parameter names,
400 * but original HTML::Template::Expr (as to 0.04) allows only
401 * var to be m![A-Za-z_][A-Za-z0-9_]*!.
402 * with this extension, arbitrary chars can be used
403 * if bracketed in ${}, as, for example, EXPR="${foo.bar} eq 'a'".
404 * first it was bracketing in {}, but it is changed
405 *
406 * COMPATIBILITY WARNING.
407 * Currently, this extension is not present in HTML::Template::Expr (as of 0.04).
408 */
409 /* Let's try to see if this is an identifier between two { } - Emiliano */
410 1265 ▶ is_identifier_ext = (int) (c == '{' || c == '$');
Branch: 2 branches
BranchTrueFalseTotal
is_identifier_ext = (int) (c == '{' || c == '$'); 1265 0 1265
is_identifier_ext = (int) (c == '{' || c == '$'); 6 1259 1265
411  
412 /* Char starts an identifier => read the name. */
413 /* variables with _leading_underscore are allowed too */
414 1265 ▶ if (isalpha (c) || c=='_' || is_identifier_ext) {
Branch: 3 branches
BranchTrueFalseTotal
if (isalpha (c) || c=='_' || is_identifier_ext) { 654 611 1265
if (isalpha (c) || c=='_' || is_identifier_ext) { 574 80 654
if (isalpha (c) || c=='_' || is_identifier_ext) { 6 568 574
415 const symrec_const *s;
416 PSTRING name;
417 697 ▶ if (is_identifier_ext) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_identifier_ext) { 6 691 697
418 6 (exprobj->expr_curpos)++; /* jump over $ or { */
419 6 ▶ if ('$' == c && '{' == *(exprobj->expr_curpos)) {
Branch: 2 branches
BranchTrueFalseTotal
if ('$' == c && '{' == *(exprobj->expr_curpos)) { 6 0 6
if ('$' == c && '{' == *(exprobj->expr_curpos)) { 6 0 6
420 6 (exprobj->expr_curpos)++; /* jump over { */
421 #ifndef ALLOW_OLD_BRACKETING_IN_EXPR
422 } else {
423 0 log_expr(exprobj, TMPL_LOG_ERROR, "{} bracketing is deprecated. Use ${} bracketing.\n");
424 #endif
425 }
426 6 name=fill_symbuf(exprobj, is_not_identifier_ext_end);
427 6 ▶ if ((exprobj->expr_curpos)<(exprobj->exprarea).endnext) (exprobj->expr_curpos)++; /* Jump the last } - Emiliano */
Branch: 1 branch
BranchTrueFalseTotal
if ((exprobj->expr_curpos)<(exprobj->exprarea).endnext) (exprobj->expr_curpos)++; /* Jump the last } - Emiliano */ 6 0 6
428 } else {
429 691 name=fill_symbuf(exprobj, is_alnum_lex);
430 }
431 697 s = getsym (builtin_ops_symrec, name);
432 697 ▶ if (s != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (s != 0) { 198 499 697
433 198 (*lvalp).tptr = s;
434 198 return s->type;
435 }
436  
437 {
438 499 const char* next_char= exprobj->expr_curpos;
439 /* optimization: funcs is always followed by ( */
440 600 ▶ while ((next_char<(exprobj->exprarea).endnext) && isspace(*next_char)) next_char++;
Branch: 2 branches
BranchTrueFalseTotal
while ((next_char<(exprobj->exprarea).endnext) && isspace(*next_char)) next_char++; 439 161 600
while ((next_char<(exprobj->exprarea).endnext) && isspace(*next_char)) next_char++; 101 338 439
441 499 ▶ if ((*next_char)=='(') {
Branch: 1 branch
BranchTrueFalseTotal
if ((*next_char)=='(') { 135 364 499
442 /* user-defined functions have precedence over buit-in */
443 135 ▶ if (((*lvalp).extfunc.func=(state->param->IsExprUserfncFuncPtr)(state->param->expr_func_map, name))) {
Branch: 1 branch
BranchTrueFalseTotal
if (((*lvalp).extfunc.func=(state->param->IsExprUserfncFuncPtr)(state->param->expr_func_map, name))) { 70 65 135
444 70 return EXTFUNC;
445 }
446 65 s = getsym (builtin_funcs_symrec, name);
447 65 ▶ if (s != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (s != 0) { 65 0 65
448 65 (*lvalp).tptr = s;
449 65 return s->type;
450 }
451 }
452 364 (*lvalp).uservar=name;
453 /*log_expr(exprobj,TMPL_LOG_DEBUG2, "yylex: returned variable name %.*s\n",(int)(name.endnext-name.begin),name.begin);*/
454 364 return VAR;
455 }
456 }
457  
458 568 ▶ TESTOP3('=','=','~',numEQ,reLIKE)
Branch: 3 branches
BranchTrueFalseTotal
TESTOP3('=','=','~',numEQ,reLIKE) 14 554 568
TESTOP3('=','=','~',numEQ,reLIKE) 14 0 14
TESTOP3('=','=','~',numEQ,reLIKE) 0 0 0
459 554 ▶ TESTOP3('!','=','~',numNE,reNOTLIKE)
Branch: 3 branches
BranchTrueFalseTotal
TESTOP3('!','=','~',numNE,reNOTLIKE) 0 554 554
TESTOP3('!','=','~',numNE,reNOTLIKE) 0 0 0
TESTOP3('!','=','~',numNE,reNOTLIKE) 0 0 0
460 554 ▶ TESTOP('>','=',numGE)
Branch: 2 branches
BranchTrueFalseTotal
TESTOP('>','=',numGE) 33 521 554
TESTOP('>','=',numGE) 29 4 33
461 521 ▶ TESTOP('<','=',numLE)
Branch: 2 branches
BranchTrueFalseTotal
TESTOP('<','=',numLE) 3 518 521
TESTOP('<','=',numLE) 3 0 3
462 518 ▶ TESTOP('&','&',AND)
Branch: 2 branches
BranchTrueFalseTotal
TESTOP('&','&',AND) 13 505 518
TESTOP('&','&',AND) 0 13 13
463 505 ▶ TESTOP('|','|',OR)
Branch: 2 branches
BranchTrueFalseTotal
TESTOP('|','|',OR) 5 500 505
TESTOP('|','|',OR) 0 5 5
464  
465 /* Any other character is a token by itself. */
466 500 (exprobj->expr_curpos)++;
467 500 return c;
468 }
469  
470 static
471 struct exprval
472 70 call_expr_userfunc(struct expr_parser* exprobj, struct tmplpro_param* param, struct user_func_call USERFUNC) {
473 70 struct exprval emptyval = {EXPR_TYPE_PSTR};
474 70 emptyval.val.strval.begin=NULL;
475 70 emptyval.val.strval.endnext=NULL;
476 70 exprobj->userfunc_call = emptyval;
477 70 param->CallExprUserfncFuncPtr(param->ext_calluserfunc_state, USERFUNC.arglist, USERFUNC.func, &(exprobj->userfunc_call));
478 70 ▶ if (param->debug>6) _tmplpro_expnum_debug (exprobj->userfunc_call, "EXPR: function call: returned ");
Branch: 1 branch
BranchTrueFalseTotal
if (param->debug>6) _tmplpro_expnum_debug (exprobj->userfunc_call, "EXPR: function call: returned "); 0 70 70
479 70 param->FreeExprArglistFuncPtr(USERFUNC.arglist);
480 70 USERFUNC.arglist = NULL;
481 /* never happen; tmplpro_set_expr_as_* never set EXPR_TYPE_NULL *
482 * if (exprobj->userfunc_call.type == EXPR_TYPE_NULL) exprobj->userfunc_call.type = EXPR_TYPE_PSTR; */
483 70 return exprobj->userfunc_call;
484 }
485  
486 static
487 void
488 88 pusharg_expr_userfunc(struct expr_parser* exprobj, struct tmplpro_param* param, struct user_func_call USERFUNC, struct exprval arg) {
489 88 ▶ if (arg.type == EXPR_TYPE_UPSTR) {
Branch: 1 branch
BranchTrueFalseTotal
if (arg.type == EXPR_TYPE_UPSTR) { 20 68 88
490 20 arg.val.strval=expr_unescape_pstring_val(&(exprobj->state->expr_left_pbuffer),arg.val.strval);
491 20 arg.type=EXPR_TYPE_PSTR;
492 }
493 88 exprobj->userfunc_call = arg;
494 88 param->PushExprArglistFuncPtr(USERFUNC.arglist,&(exprobj->userfunc_call));
495 88 ▶ if (param->debug>6) _tmplpro_expnum_debug (arg, "EXPR: arglist: pushed ");
Branch: 1 branch
BranchTrueFalseTotal
if (param->debug>6) _tmplpro_expnum_debug (arg, "EXPR: arglist: pushed "); 0 88 88
496 88 }
497  
498 #include "exprtool.inc"
499 #include "exprpstr.inc"
« exprpstr.inc ↑ Summary tags.inc »