Search in sources :

Example 1 with InternalTypeVarType

use of dyvilx.tools.compiler.ast.type.typevar.InternalTypeVarType in project Dyvil by Dyvil.

the class ClassFormat method readType.

public static IType readType(String desc, int start, int end, boolean nullables) {
    switch(desc.charAt(start)) {
        // primitives
        case 'V':
            return Types.VOID;
        case 'Z':
            return Types.BOOLEAN;
        case 'B':
            return Types.BYTE;
        case 'S':
            return Types.SHORT;
        case 'C':
            return Types.CHAR;
        case 'I':
            return Types.INT;
        case 'J':
            return Types.LONG;
        case 'F':
            return Types.FLOAT;
        case 'D':
            return Types.DOUBLE;
        case // class type
        'L':
            return readReferenceType(desc, start + 1, end, nullables);
        case // reference type
        'R':
            final ReferenceType rt = new ReferenceType();
            readTyped(desc, start + 1, rt::setType, true);
            return rt;
        case // null
        NullType.NULL_DESC:
            return Types.NULL;
        case // none
        NoneType.NONE_DESC:
            return Types.NONE;
        case // any
        AnyType.ANY_DESC:
            return Types.ANY;
        case // type parameter reference
        'T':
            return new InternalTypeVarType(desc.substring(start + 1, end));
        case // array type
        '[':
            final ArrayType arrayType = new ArrayType(readType(desc, start + 1, end, true));
            return nullable(arrayType, nullables);
        case // union
        '|':
            {
                final UnionType union = new UnionType();
                final int end1 = readTyped(desc, start + 1, union::setLeft, nullables);
                readTyped(desc, end1, union::setRight, nullables);
                return union;
            }
        case // intersection
        '&':
            {
                final IntersectionType intersection = new IntersectionType();
                final int end1 = readTyped(desc, start + 1, intersection::setLeft, nullables);
                readTyped(desc, end1, intersection::setRight, nullables);
                return intersection;
            }
        case // option
        '?':
            return new NullableType(readType(desc, start + 1, end, false));
    }
    return null;
}
Also used : InternalTypeVarType(dyvilx.tools.compiler.ast.type.typevar.InternalTypeVarType) ReferenceType(dyvilx.tools.compiler.ast.reference.ReferenceType)

Aggregations

ReferenceType (dyvilx.tools.compiler.ast.reference.ReferenceType)1 InternalTypeVarType (dyvilx.tools.compiler.ast.type.typevar.InternalTypeVarType)1