mirror of
https://github.com/zeek/zeek.git
synced 2025-10-04 23:58:20 +00:00
Type coercion fix: transform +=/-= operators with arithmetic targets to explict assignments
This commit is contained in:
parent
e7c6d17156
commit
baf2a91a85
6 changed files with 55 additions and 13 deletions
34
src/parse.y
34
src/parse.y
|
@ -572,7 +572,22 @@ expr:
|
|||
| expr TOK_ADD_TO rhs
|
||||
{
|
||||
set_location(@1, @3);
|
||||
$$ = new AddToExpr({AdoptRef{}, $1}, {AdoptRef{}, $3});
|
||||
|
||||
ExprPtr lhs = {AdoptRef{}, $1};
|
||||
ExprPtr rhs = {AdoptRef{}, $3};
|
||||
auto tag1 = $1->GetType()->Tag();
|
||||
|
||||
if ( IsArithmetic($1->GetType()->Tag()) )
|
||||
{
|
||||
ExprPtr sum = make_intrusive<AddExpr>(lhs, rhs);
|
||||
|
||||
if ( sum->GetType()->Tag() != tag1 )
|
||||
sum = make_intrusive<ArithCoerceExpr>(sum, tag1);
|
||||
|
||||
$$ = new AssignExpr(lhs, sum, false);
|
||||
}
|
||||
else
|
||||
$$ = new AddToExpr(lhs, rhs);
|
||||
}
|
||||
|
||||
| expr '-' expr
|
||||
|
@ -584,7 +599,22 @@ expr:
|
|||
| expr TOK_REMOVE_FROM rhs
|
||||
{
|
||||
set_location(@1, @3);
|
||||
$$ = new RemoveFromExpr({AdoptRef{}, $1}, {AdoptRef{}, $3});
|
||||
|
||||
ExprPtr lhs = {AdoptRef{}, $1};
|
||||
ExprPtr rhs = {AdoptRef{}, $3};
|
||||
auto tag1 = $1->GetType()->Tag();
|
||||
|
||||
if ( IsArithmetic(tag1) )
|
||||
{
|
||||
ExprPtr sum = make_intrusive<SubExpr>(lhs, rhs);
|
||||
|
||||
if ( sum->GetType()->Tag() != tag1 )
|
||||
sum = make_intrusive<ArithCoerceExpr>(sum, tag1);
|
||||
|
||||
$$ = new AssignExpr(lhs, sum, false);
|
||||
}
|
||||
else
|
||||
$$ = new RemoveFromExpr(lhs, rhs);
|
||||
}
|
||||
|
||||
| expr '*' expr
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue