Skip to content
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
afd merged 2 commits into
google:masterfrom
AaronGhost:full-binary-operations-typing
Aug 5, 2021
Merged

Update of the typer with shifts and assignments#1154
afd merged 2 commits into
google:masterfrom
AaronGhost:full-binary-operations-typing

Conversation

@AaronGhost

Copy link
Copy Markdown
Contributor

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).

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 afd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread ast/src/main/java/com/graphicsfuzz/common/typing/TyperHelper.java Outdated
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.
@AaronGhost

Copy link
Copy Markdown
Contributor Author

Done!

@afd afd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@afd
afd merged commit 79aa124 into google:master Aug 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants