-
Notifications
You must be signed in to change notification settings - Fork 60
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
EssentialType
: Implement correct essential types for bitwise binary operators &
, ^
and |
.
#787
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,8 +192,8 @@ class EssentialEqualityOperationExpr extends EssentialExpr, EqualityOperation { | |
override Type getEssentialType() { result instanceof BoolType } | ||
} | ||
|
||
class EssentialBinaryBitwiseOperationExpr extends EssentialExpr, BinaryBitwiseOperation { | ||
EssentialBinaryBitwiseOperationExpr() { | ||
class EssentialShiftOperationExpr extends EssentialExpr, BinaryBitwiseOperation { | ||
EssentialShiftOperationExpr() { | ||
this instanceof LShiftExpr or | ||
this instanceof RShiftExpr | ||
} | ||
|
@@ -353,6 +353,51 @@ class EssentialBinaryArithmeticExpr extends EssentialExpr, BinaryArithmeticOpera | |
} | ||
} | ||
|
||
class EssentialBinaryBitwiseExpr extends EssentialExpr, BinaryBitwiseOperation { | ||
EssentialBinaryBitwiseExpr() { | ||
not this instanceof LShiftExpr and | ||
not this instanceof RShiftExpr | ||
} | ||
|
||
override Type getEssentialType() { | ||
exists( | ||
Type leftEssentialType, Type rightEssentialType, | ||
EssentialTypeCategory leftEssentialTypeCategory, | ||
EssentialTypeCategory rightEssentialTypeCategory | ||
| | ||
leftEssentialType = getEssentialType(getLeftOperand()) and | ||
rightEssentialType = getEssentialType(getRightOperand()) and | ||
leftEssentialTypeCategory = getEssentialTypeCategory(leftEssentialType) and | ||
rightEssentialTypeCategory = getEssentialTypeCategory(rightEssentialType) | ||
| | ||
if | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this is now the third occurrence of this pattern, may be worth creating some kind of predicate to deduplicate this/reduce the bloat. Perhaps something like |
||
leftEssentialTypeCategory = EssentiallySignedType() and | ||
rightEssentialTypeCategory = EssentiallySignedType() | ||
then | ||
if exists(getValue()) | ||
then result = stlr(this) | ||
else ( | ||
if leftEssentialType.getSize() > rightEssentialType.getSize() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems we should have a predicate |
||
then result = leftEssentialType | ||
else result = rightEssentialType | ||
) | ||
else | ||
if | ||
leftEssentialTypeCategory = EssentiallyUnsignedType() and | ||
rightEssentialTypeCategory = EssentiallyUnsignedType() | ||
then | ||
if exists(getValue()) | ||
then result = utlr(this) | ||
else ( | ||
if leftEssentialType.getSize() > rightEssentialType.getSize() | ||
then result = leftEssentialType | ||
else result = rightEssentialType | ||
) | ||
else result = this.getStandardType() | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* A named Enum type, as per D.5. | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any concern here about future updates to the characteristic predicate of
EssentialShiftOperationExpr
that aren't matched here (and vice versa)? In theory we could not find certain expressions to analyze, or worse, return two results from the overriden member predicates.It may be better to entangle them here, eg,
not this instanceof EssentialBinaryBitwiseOperationExpr