Search in sources :

Example 1 with ReferenceType

use of dyvilx.tools.compiler.ast.reference.ReferenceType in project Dyvil by Dyvil.

the class PostfixType method resolveType.

@Override
public IType resolveType(MarkerList markers, IContext context) {
    final String unqualified = this.name.unqualified;
    final IType argument = this.arguments.get(0);
    if (unqualified.length() == 1) {
        switch(unqualified.charAt(0)) {
            case '?':
                return NullableType.apply(argument).resolveType(markers, context);
            case '!':
                return new ImplicitNullableType(argument).resolveType(markers, context);
            case '*':
                return new ReferenceType(argument).resolveType(markers, context);
            case '^':
                return new ImplicitReferenceType(argument).resolveType(markers, context);
        }
    }
    return super.resolveType(markers, context);
}
Also used : ImplicitNullableType(dyvilx.tools.compiler.ast.type.compound.ImplicitNullableType) ImplicitReferenceType(dyvilx.tools.compiler.ast.reference.ImplicitReferenceType) ImplicitReferenceType(dyvilx.tools.compiler.ast.reference.ImplicitReferenceType) ReferenceType(dyvilx.tools.compiler.ast.reference.ReferenceType) IType(dyvilx.tools.compiler.ast.type.IType)

Example 2 with ReferenceType

use of dyvilx.tools.compiler.ast.reference.ReferenceType 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)

Example 3 with ReferenceType

use of dyvilx.tools.compiler.ast.reference.ReferenceType in project Dyvil by Dyvil.

the class IType method readType.

static IType readType(DataInput dis) throws IOException {
    int tag = dis.readUnsignedByte();
    IType type;
    switch(tag) {
        case UNKNOWN:
            return Types.UNKNOWN;
        case NULL:
            return Types.NULL;
        case NONE:
            return Types.NONE;
        case ANY:
            return Types.ANY;
        case PRIMITIVE:
            return PrimitiveType.fromTypecode(dis.readByte());
        case CLASS:
            type = new ClassType();
            break;
        case PACKAGE:
            type = new PackageType();
            break;
        case GENERIC:
            type = new ClassGenericType();
            break;
        case TUPLE:
            type = new TupleType();
            break;
        case LAMBDA:
            type = new LambdaType();
            break;
        case ARRAY:
            type = new ArrayType();
            break;
        case MAP:
            type = new MapType();
            break;
        case OPTIONAL:
            type = new NullableType();
            break;
        case IMPLICIT_OPTIONAL:
            type = new ImplicitNullableType();
            break;
        case REFERENCE:
            type = new ReferenceType();
            break;
        case ANNOTATED:
            type = new AnnotatedType();
            break;
        case TYPE_VAR:
            type = new NamedType();
            break;
        case WILDCARD_TYPE:
            type = new WildcardType();
            break;
        case MISSING_TAG:
            return null;
        default:
            throw new Error("Cannot decode TypeTag " + tag);
    }
    type.read(dis);
    return type;
}
Also used : NamedType(dyvilx.tools.compiler.ast.type.raw.NamedType) ClassType(dyvilx.tools.compiler.ast.type.raw.ClassType) ReferenceType(dyvilx.tools.compiler.ast.reference.ReferenceType) PackageType(dyvilx.tools.compiler.ast.type.raw.PackageType) ClassGenericType(dyvilx.tools.compiler.ast.type.generic.ClassGenericType)

Example 4 with ReferenceType

use of dyvilx.tools.compiler.ast.reference.ReferenceType in project Dyvil by Dyvil.

the class InternalGenericType method resolveType.

@Override
public IType resolveType(MarkerList markers, IContext context) {
    this.arguments.resolveTypes(markers, context);
    if (this.internalName.startsWith("dyvil/tuple/Tuple$Of")) {
        return new TupleType(this.arguments);
    }
    if (this.internalName.startsWith("dyvil/function/Function$Of")) {
        return new LambdaType(this.arguments);
    }
    switch(this.internalName) {
        case "dyvil/ref/ObjectRef":
            return new ReferenceType(ReferenceType.LazyFields.OBJECT_REF_CLASS, this.arguments.get(0));
        case "dyvil/collection/Map":
            return MapType.base(this.arguments.get(0), this.arguments.get(1));
        case "dyvil/collection/MutableMap":
            return MapType.mutable(this.arguments.get(0), this.arguments.get(1));
        case "dyvil/collection/ImmutableMap":
            return MapType.immutable(this.arguments.get(0), this.arguments.get(1));
    }
    final IClass iclass = Package.rootPackage.resolveInternalClass(this.internalName);
    return new ClassGenericType(iclass, this.arguments);
}
Also used : LambdaType(dyvilx.tools.compiler.ast.type.compound.LambdaType) TupleType(dyvilx.tools.compiler.ast.type.compound.TupleType) IClass(dyvilx.tools.compiler.ast.classes.IClass) ReferenceType(dyvilx.tools.compiler.ast.reference.ReferenceType)

Aggregations

ReferenceType (dyvilx.tools.compiler.ast.reference.ReferenceType)4 IClass (dyvilx.tools.compiler.ast.classes.IClass)1 ImplicitReferenceType (dyvilx.tools.compiler.ast.reference.ImplicitReferenceType)1 IType (dyvilx.tools.compiler.ast.type.IType)1 ImplicitNullableType (dyvilx.tools.compiler.ast.type.compound.ImplicitNullableType)1 LambdaType (dyvilx.tools.compiler.ast.type.compound.LambdaType)1 TupleType (dyvilx.tools.compiler.ast.type.compound.TupleType)1 ClassGenericType (dyvilx.tools.compiler.ast.type.generic.ClassGenericType)1 ClassType (dyvilx.tools.compiler.ast.type.raw.ClassType)1 NamedType (dyvilx.tools.compiler.ast.type.raw.NamedType)1 PackageType (dyvilx.tools.compiler.ast.type.raw.PackageType)1 InternalTypeVarType (dyvilx.tools.compiler.ast.type.typevar.InternalTypeVarType)1