BasicType extends BuiltinType { @Override public Expr getCanonicalConstant(Scope scope) { if (this == FLOAT) { return new FloatConstantExpr("1.0"); } if (this == INT) { return new IntConstantExpr("1"); } if (this == UINT) { return new UIntConstantExpr("1u"); } if (this == BOOL) { return new BoolConstantExpr(true); } return new TypeConstructorExpr(toString(), getElementType().getCanonicalConstant(scope)); } private  BasicType(); @Override String toString(); @Override void accept(IAstVisitor visitor); @Override boolean hasCanonicalConstant(Scope unused); @Override Expr getCanonicalConstant(Scope scope); BasicType getElementType(); int getNumElements(); boolean isBoolean(); static List<BasicType> allScalarTypes(); static List<BasicType> allBasicTypes(); static List<BasicType> allVectorTypes(); static List<BasicType> allMatrixTypes(); static List<BasicType> allSquareMatrixTypes(); static List<BasicType> allNonSquareMatrixTypes(); static List<BasicType> allUnsignedTypes(); static List<BasicType> allGenTypes(); static List<BasicType> allNumericTypes(); static List<BasicType> allIntegerTypes(); static List<BasicType> allNumericTypesExceptNonSquareMatrices(); static List<BasicType> allNonMatrixNumericTypes(); static BasicType makeVectorType(BasicType elementType, int numElements); static BasicType makeMatrixType(int numColumns, int numRows); boolean isScalar(); boolean isVector(); boolean isMatrix(); BasicType transposedMatrixType(); BasicType getColumnType(); int getNumColumns(); int getNumRows(); static final BasicType FLOAT; static final BasicType INT; static final BasicType UINT; static final BasicType BOOL; static final BasicType VEC2; static final BasicType VEC3; static final BasicType VEC4; static final BasicType BVEC2; static final BasicType BVEC3; static final BasicType BVEC4; static final BasicType IVEC2; static final BasicType IVEC3; static final BasicType IVEC4; static final BasicType UVEC2; static final BasicType UVEC3; static final BasicType UVEC4; static final BasicType MAT2X2; static final BasicType MAT2X3; static final BasicType MAT2X4; static final BasicType MAT3X2; static final BasicType MAT3X3; static final BasicType MAT3X4; static final BasicType MAT4X2; static final BasicType MAT4X3; static final BasicType MAT4X4; }
@Test public void testCanonicalConstant() { assertEquals("1", BasicType.INT.getCanonicalConstant(new Scope()).getText()); assertEquals("1u", BasicType.UINT.getCanonicalConstant(new Scope()).getText()); assertEquals("1.0", BasicType.FLOAT.getCanonicalConstant(new Scope()).getText()); assertEquals("true", BasicType.BOOL.getCanonicalConstant(new Scope()).getText()); assertEquals("uvec4(1u)", BasicType.UVEC4.getCanonicalConstant(new Scope()).getText()); assertEquals("mat2(1.0)", BasicType.MAT2X2.getCanonicalConstant(new Scope()).getText()); }