Typer extends ScopeTrackingVisitor { public Type lookupType(Expr expr) { return types.get(expr); } Typer(TranslationUnit tu); @Override void visitParenExpr(ParenExpr parenExpr); @Override void visitFunctionPrototype(FunctionPrototype functionPrototype); @Override void visitFunctionDefinition(FunctionDefinition functionDefinition); @Override void visitFunctionCallExpr(FunctionCallExpr functionCallExpr); boolean prototypeMatches(FunctionPrototype prototype, FunctionCallExpr functionCallExpr); @Override void visitVariableIdentifierExpr(VariableIdentifierExpr variableIdentifierExpr); @Override void visitTypeConstructorExpr(TypeConstructorExpr typeConstructorExpr); @Override void visitUnaryExpr(UnaryExpr unaryExpr); @Override void visitTernaryExpr(TernaryExpr ternaryExpr); @Override void visitBinaryExpr(BinaryExpr binaryExpr); @Override void visitBoolConstantExpr(BoolConstantExpr boolConstantExpr); @Override void visitIntConstantExpr(IntConstantExpr intConstantExpr); @Override void visitUIntConstantExpr(UIntConstantExpr uintConstantExpr); @Override void visitFloatConstantExpr(FloatConstantExpr floatConstantExpr); @Override void visitMemberLookupExpr(MemberLookupExpr memberLookupExpr); @Override void visitArrayConstructorExpr(ArrayConstructorExpr arrayConstructorExpr); Type lookupType(Expr expr); boolean hasType(Expr expr); Set<FunctionPrototype> getPrototypes(String name); @Override void visitStructDefinitionType(StructDefinitionType structDefinitionType); @Override void visitArrayIndexExpr(ArrayIndexExpr arrayIndexExpr); @Override void visitInterfaceBlock(InterfaceBlock interfaceBlock); static Optional<Type> maybeGetTypeOfBuiltinVariable(String name); static ImmutablePair<Type, ArrayInfo> getBaseTypeArrayInfo(Type type); static Type combineBaseTypeAndArrayInfo(Type type, ArrayInfo arrayInfo);  }
@Test public void testOctalIntLiteralTyped() throws Exception { final TranslationUnit tu = ParseHelper.parse("#version 300 es\n" + "void main() {" + " int x = 031;" + "}"); new NullCheckTyper(tu) { @Override public void visitInitializer(Initializer initializer) { super.visitInitializer(initializer); assertSame(lookupType(initializer.getExpr()), BasicType.INT); } }.visit(tu); }
@Test public void testHexIntLiteralTyped() throws Exception { final TranslationUnit tu = ParseHelper.parse("#version 300 es\n" + "void main() {" + " int x = 0xA03B;" + "}"); new NullCheckTyper(tu) { @Override public void visitInitializer(Initializer initializer) { super.visitInitializer(initializer); assertSame(lookupType(initializer.getExpr()), BasicType.INT); } }.visit(tu); }
@Test public void testOctalUnsignedIntLiteralTyped() throws Exception { final TranslationUnit tu = ParseHelper.parse("#version 300 es\n" + "void main() {" + " int x = 031u;" + "}"); new NullCheckTyper(tu) { @Override public void visitInitializer(Initializer initializer) { super.visitInitializer(initializer); assertSame(lookupType(initializer.getExpr()), BasicType.UINT); } }.visit(tu); }
@Test public void testHexUnsignedIntLiteralTyped() throws Exception { final TranslationUnit tu = ParseHelper.parse("#version 300 es\n" + "void main() {" + " int x = 0xA03Bu;" + "}"); new NullCheckTyper(tu) { @Override public void visitInitializer(Initializer initializer) { super.visitInitializer(initializer); assertSame(lookupType(initializer.getExpr()), BasicType.UINT); } }.visit(tu); }