INRIA / INRIA/spoon

`PartialEvaluator` could add casts to the `CtExpression`s of a `Ct(Unary|Binary)Operator` and remove redundant casts from a `CtExpression`

Open
#5,337 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2k
Forks
392
Avg merge
11h 24m
Merged PRs (30d)
36

Description

Each `CtExpression` has a list of casts that are applied to it. Depending on the type and context of the expression an implicit cast might be performed. This is implemented through the `OperatorHelper.getPromotedType`.

At the moment the code ignores `CtBinaryOperator` where both the left and right are unknown. One could add those casts to the `CtExpression`. For example, the expression `s` in `int a = ...; short s = 1; if (s < a) { ... }` would be promoted to `int`, so the `PartialEvaluator` could add the cast to the list of casts.

Another optimization that came to mind would be to remove unnecessary casts. I have not thought much about when a cast is unnecessary. Only duplicate casts like `(double) (double) value` came to mind. Maybe widening casts like `(int) byte`, but this could conflict with the above that adds casts to expressions.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.