Commit e3299a51 authored by michael's avatar michael

factorize AVEvalExpr alloc and init


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@6809 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent f16a6659
...@@ -283,6 +283,15 @@ static AVEvalExpr * parse_primary(Parser *p) { ...@@ -283,6 +283,15 @@ static AVEvalExpr * parse_primary(Parser *p) {
return d; return d;
} }
static AVEvalExpr * new_eval_expr(int type, int value, AVEvalExpr *p0, AVEvalExpr *p1){
AVEvalExpr * e = av_mallocz(sizeof(AVEvalExpr));
e->type =type ;
e->value =value ;
e->param[0] =p0 ;
e->param[1] =p1 ;
return e;
}
static AVEvalExpr * parse_pow(Parser *p, int *sign){ static AVEvalExpr * parse_pow(Parser *p, int *sign){
*sign= (*p->s == '+') - (*p->s == '-'); *sign= (*p->s == '+') - (*p->s == '-');
p->s += *sign&1; p->s += *sign&1;
...@@ -293,14 +302,10 @@ static AVEvalExpr * parse_factor(Parser *p){ ...@@ -293,14 +302,10 @@ static AVEvalExpr * parse_factor(Parser *p){
int sign, sign2; int sign, sign2;
AVEvalExpr * e = parse_pow(p, &sign); AVEvalExpr * e = parse_pow(p, &sign);
while(p->s[0]=='^'){ while(p->s[0]=='^'){
AVEvalExpr * tmp = av_mallocz(sizeof(AVEvalExpr)); AVEvalExpr * tmp;
p->s++; p->s++;
tmp= new_eval_expr(e_pow, 1, e, parse_pow(p, &sign2));
tmp->type = e_pow;
tmp->value = 1.;
tmp->param[0] = e;
tmp->param[1] = parse_pow(p, &sign2);
if (tmp->param[1]) tmp->param[1]->value *= (sign2|1); if (tmp->param[1]) tmp->param[1]->value *= (sign2|1);
e = tmp; e = tmp;
} }
...@@ -311,13 +316,8 @@ static AVEvalExpr * parse_factor(Parser *p){ ...@@ -311,13 +316,8 @@ static AVEvalExpr * parse_factor(Parser *p){
static AVEvalExpr * parse_term(Parser *p){ static AVEvalExpr * parse_term(Parser *p){
AVEvalExpr * e = parse_factor(p); AVEvalExpr * e = parse_factor(p);
while(p->s[0]=='*' || p->s[0]=='/'){ while(p->s[0]=='*' || p->s[0]=='/'){
AVEvalExpr * tmp = av_mallocz(sizeof(AVEvalExpr)); int c= *p->s++;
if(*p->s++ == '*') tmp->type = e_mul; e= new_eval_expr(c == '*' ? e_mul : e_div, 1, e, parse_factor(p));
else tmp->type = e_div;
tmp->value = 1.;
tmp->param[0] = e;
tmp->param[1] = parse_factor(p);
e = tmp;
} }
return e; return e;
} }
...@@ -332,12 +332,7 @@ static AVEvalExpr * parse_expr(Parser *p) { ...@@ -332,12 +332,7 @@ static AVEvalExpr * parse_expr(Parser *p) {
e = parse_term(p); e = parse_term(p);
while(*p->s == '+' || *p->s == '-') { while(*p->s == '+' || *p->s == '-') {
AVEvalExpr * tmp = av_mallocz(sizeof(AVEvalExpr)); e= new_eval_expr(e_add, 1, e, parse_term(p));
tmp->type = e_add;
tmp->value = 1.;
tmp->param[0] = e;
tmp->param[1] = parse_term(p);
e = tmp;
}; };
p->stack_index++; p->stack_index++;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment