This repository was archived by the owner on Dec 8, 2025. It is now read-only.
Update of the typer with shifts and assignments#1154
Merged
Conversation
Updates the Typer class to produce a result in the case of assignments and the TyperHelper class to correctly type shift operations in the case of left and right scalar types (the resulting type is the one from the left operand).
afd
suggested changes
Aug 2, 2021
afd
left a comment
Contributor
There was a problem hiding this comment.
Thanks for spotting this discrepancy!
Please add a test along these lines to TyperTest, right after testLengthTyped:
@Test
public void testLengthTyped() throws Exception {
final TranslationUnit tu = ParseHelper.parse("#version 320 es\n"
+ "void main() {\n"
+ " int a;\n"
+ " uint b;\n"
+ " ivec2 av;\n"
+ " uvec2 bv;\n"
+ "\n"
+ " int x0 = a << a;\n"
+ " int x1 = a << b;\n"
+ " uint x2 = b << a;\n"
+ " uint x3 = b << b;\n"
+ " ivec2 x4 = av << a;\n"
+ " ivec2 x5 = av << b;\n"
+ " ivec2 x6 = av << av;\n"
+ " ivec2 x7 = av << bv;\n"
+ " uvec2 x8 = bv << a;\n"
+ " uvec2 x9 = bv << b;\n"
+ " uvec2 x10 = bv << av;\n"
+ " uvec2 x11 = bv << bv;\n"
+ "}\n");
new NullCheckTyper(tu) {
private int counter = 0;
@Override
public void visitBinaryExpr(BinaryExpr binaryExpr) {
super.visitBinaryExpr(binaryExpr);
if (binaryExpr.getOp() == BinOp.LEFT_SHIFT) {
switch(counter) {
case 0:
case 1:
assertSame(BasicType.INT, lookupType(binaryExpr));
break;
case 2:
case 3:
assertSame(BasicType.UINT, lookupType(binaryExpr));
break;
case 4:
case 5:
case 6:
case 7:
assertSame(BasicType.IVEC2, lookupType(binaryExpr));
break;
case 8:
case 9:
case 10:
case 11:
assertSame(BasicType.UVEC2, lookupType(binaryExpr));
break;
defalt:
fail();
}
counter++;
}
}
}.visit(tu);
}
It's probably syntactically incorrect but hopefully you get the gist and can fix it up (and fix your code to make it pass, if needed).
And can you adapt its name suitably for the << operator, and add an analogous test for the >> operator?
Plus there's one comment in the review about a comment.
Adds a test for the typer with left and right shift operators. Ensures that the typer produce the correct type for shift operations on vectors and rewrite comments accordingly.
Contributor
Author
|
Done! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Updates the Typer class to produce a result in the case of assignments
and the TyperHelper class to correctly type shift operations in the
case of left and right scalar types (the resulting type is the one
from the left operand).