Search in sources :

Example 26 with IType

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

the class CompleteCommand method findInstanceMembers.

private static void findInstanceMembers(IType type, Set<IField> fields, Set<IProperty> properties, Set<IMethod> methods, String start, Set<IClass> dejaVu) {
    final IClass iclass = type.getTheClass();
    if (iclass == null || dejaVu.contains(iclass)) {
        return;
    }
    dejaVu.add(iclass);
    // Add members
    final ParameterList parameterList = iclass.getParameters();
    for (int i = 0, count = parameterList.size(); i < count; i++) {
        checkMember(fields, (IField) parameterList.get(i), start, false);
    }
    findMembers(type, fields, properties, methods, start, false);
    // Recursively scan super types
    final IType superType = iclass.getSuperType();
    if (superType != null) {
        findInstanceMembers(superType.getConcreteType(type), fields, properties, methods, start, dejaVu);
    }
    for (IType interfaceType : iclass.getInterfaces()) {
        findInstanceMembers(interfaceType.getConcreteType(type), fields, properties, methods, start, dejaVu);
    }
}
Also used : ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList) IClass(dyvilx.tools.compiler.ast.classes.IClass) IType(dyvilx.tools.compiler.ast.type.IType)

Example 27 with IType

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

the class LambdaExpr method inferReturnType.

public void inferReturnType(IType type, IType valueType) {
    if (this.hasImplicitReturnType()) {
        this.returnType = valueType;
    }
    if ((this.flags & LAMBDA_TYPE_INFERRED) != 0 || type.canExtract(LambdaType.class)) {
        this.type = this.makeType();
        return;
    }
    final ITypeContext tempContext = new MapTypeContext();
    final ParameterList methodParams = this.method.getParameters();
    final int size = Math.min(this.parameters.size(), methodParams.size());
    for (int i = 0; i < size; i++) {
        final IParameter lambdaParam = this.parameters.get(i);
        final IParameter methodParam = methodParams.get(i);
        methodParam.getType().inferTypes(lambdaParam.getType(), tempContext);
    }
    this.method.getType().inferTypes(valueType, tempContext);
    final IType classType = this.method.getEnclosingClass().getThisType();
    this.type = classType.getConcreteType(tempContext);
}
Also used : LambdaType(dyvilx.tools.compiler.ast.type.compound.LambdaType) MapTypeContext(dyvilx.tools.compiler.ast.generic.MapTypeContext) ITypeContext(dyvilx.tools.compiler.ast.generic.ITypeContext) IType(dyvilx.tools.compiler.ast.type.IType)

Example 28 with IType

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

the class LambdaExpr method isType.

@Override
public boolean isType(IType type) {
    if (this.type != null && Types.isSuperType(type, this.type)) {
        return true;
    }
    final IClass interfaceClass = type.getTheClass();
    if (interfaceClass == null) {
        return false;
    }
    if (interfaceClass == Types.OBJECT_CLASS) {
        return true;
    }
    final IMethod method = interfaceClass.getFunctionalMethod();
    if (method == null) {
        return false;
    }
    final ParameterList methodParameters = method.getParameters();
    final int parameterCount = this.parameters.size();
    if (parameterCount != methodParameters.size()) {
        return false;
    }
    for (int i = 0; i < parameterCount; i++) {
        final IType lambdaParameterType = this.parameters.get(i).getCovariantType();
        if (lambdaParameterType.isUninferred()) {
            continue;
        }
        final IType methodParameterType = methodParameters.get(i).getCovariantType();
        if (!Types.isSuperType(methodParameterType, lambdaParameterType)) {
            return false;
        }
    }
    return true;
}
Also used : IClass(dyvilx.tools.compiler.ast.classes.IClass) IMethod(dyvilx.tools.compiler.ast.method.IMethod) IType(dyvilx.tools.compiler.ast.type.IType)

Example 29 with IType

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

the class MapExpr method isType.

@Override
public boolean isType(IType type) {
    if (!MapType.MapTypes.MAP_CLASS.isSubClassOf(type)) {
        return this.isConvertibleFrom(type);
    }
    IType keyType = Types.resolveTypeSafely(type, MapType.MapTypes.KEY_VARIABLE);
    IType valueType = Types.resolveTypeSafely(type, MapType.MapTypes.VALUE_VARIABLE);
    return this.keys.isType(keyType) && this.values.isType(valueType);
}
Also used : IType(dyvilx.tools.compiler.ast.type.IType)

Example 30 with IType

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

the class MapExpr method withType.

@Override
public IValue withType(IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
    if (!Types.isSuperClass(type, MapType.MapTypes.IMMUTABLE_MAP_CLASS.getClassType())) {
        final Annotation annotation = type.getTheClass().getAnnotation(LazyTypes.MAP_CONVERTIBLE_CLASS);
        if (annotation == null) {
            return null;
        }
        // [ x : y, ... ] -> Type(x : y, ...))
        final int size = this.keys.size();
        final ArgumentList arguments = new ArgumentList(size);
        for (int i = 0; i < size; i++) {
            arguments.add(new ColonOperator(this.keys.get(i), this.values.get(i)));
        }
        return new LiteralConversion(this, annotation, arguments).withType(type, typeContext, markers, context);
    }
    final int size = this.keys.size();
    final IType keyType = this.keyType = Types.resolveTypeSafely(type, MapType.MapTypes.KEY_VARIABLE);
    final IType valueType = this.valueType = Types.resolveTypeSafely(type, MapType.MapTypes.VALUE_VARIABLE);
    for (int i = 0; i < size; i++) {
        final IValue key = TypeChecker.convertValue(this.keys.get(i), keyType, typeContext, markers, context, KEY_MARKER_SUPPLIER);
        this.keys.set(i, key);
        final IValue value = TypeChecker.convertValue(this.values.get(i), valueType, typeContext, markers, context, VALUE_MARKER_SUPPLIER);
        this.values.set(i, value);
    }
    return this;
}
Also used : ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation) IType(dyvilx.tools.compiler.ast.type.IType)

Aggregations

IType (dyvilx.tools.compiler.ast.type.IType)159 IClass (dyvilx.tools.compiler.ast.classes.IClass)26 Marker (dyvilx.tools.parsing.marker.Marker)23 IValue (dyvilx.tools.compiler.ast.expression.IValue)21 TypeParameterList (dyvilx.tools.compiler.ast.generic.TypeParameterList)13 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)11 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)10 SourcePosition (dyvil.source.position.SourcePosition)9 Annotation (dyvilx.tools.compiler.ast.attribute.annotation.Annotation)9 ITypeParameter (dyvilx.tools.compiler.ast.generic.ITypeParameter)9 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)9 TypeList (dyvilx.tools.compiler.ast.type.TypeList)7 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)6 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)6 IVariable (dyvilx.tools.compiler.ast.field.IVariable)6 ArrayType (dyvilx.tools.compiler.ast.type.compound.ArrayType)6 MethodWriter (dyvilx.tools.compiler.backend.MethodWriter)6 CodeMethod (dyvilx.tools.compiler.ast.method.CodeMethod)5 CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)5 Name (dyvil.lang.Name)4