Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Support of shift left and right operation inside VisitorPartialEvaluator #4237

Merged
merged 7 commits into from
Oct 27, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,40 @@ public <T> void visitCtBinaryOperator(CtBinaryOperator<T> operator) {
res.setValue(((Number) leftObject).intValue() ^ ((Number) rightObject).intValue());
}
break;
case SL:
if(isIntegralType(leftObject) && isIntegralType(rightObject)) {
if(leftObject instanceof Byte) {
res.setValue(((Number)leftObject).byteValue() << ((Number)rightObject).longValue());
}
if(leftObject instanceof Short) {
res.setValue(((Number)leftObject).shortValue() << ((Number)rightObject).longValue());
}
if(leftObject instanceof Integer) {
res.setValue(((Number)leftObject).intValue() << ((Number)rightObject).longValue());
}
if(leftObject instanceof Long) {
res.setValue(((Number)leftObject).longValue() << ((Number)rightObject).longValue());
}
break;
}
throw new RuntimeException(operator.getKind() + " is only supported for integral types on both sides");
case SR:
if(isIntegralType(leftObject) && isIntegralType(rightObject)) {
if(leftObject instanceof Byte) {
res.setValue(((Number)leftObject).byteValue() >> ((Number)rightObject).longValue());
}
if(leftObject instanceof Short) {
res.setValue(((Number)leftObject).shortValue() >> ((Number)rightObject).longValue());
}
if(leftObject instanceof Integer) {
res.setValue(((Number)leftObject).intValue() >> ((Number)rightObject).longValue());
}
if(leftObject instanceof Long) {
res.setValue(((Number)leftObject).longValue() >> ((Number)rightObject).longValue());
}
break;
}
throw new RuntimeException(operator.getKind() + " is only supported for integral types on both sides");
default:
throw new RuntimeException("unsupported operator " + operator.getKind());
}
Expand Down Expand Up @@ -449,6 +483,10 @@ public <T> void visitCtInvocation(CtInvocation<T> invocation) {
}
setResult(i);
}

private boolean isIntegralType(Object object) {
return object instanceof Byte || object instanceof Short || object instanceof Integer || object instanceof Long;
}

private boolean isLiteralType(Object object) {
if (object == null) {
Expand Down