Search in sources :

Example 36 with IType

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

the class TupleExpr method writeExpression.

@Override
public void writeExpression(MethodWriter writer, IType type) throws BytecodeException {
    final IType thisType = this.getType();
    final String internal = thisType.getInternalName();
    writer.visitTypeInsn(Opcodes.NEW, internal);
    writer.visitInsn(Opcodes.DUP);
    final int arity = this.values.size();
    for (int i = 0; i < arity; i++) {
        this.values.get(i).writeExpression(writer, Types.OBJECT);
    }
    final String desc = TupleType.getConstructorDescriptor(arity);
    writer.visitMethodInsn(Opcodes.INVOKESPECIAL, internal, "<init>", desc, false);
    if (type != null) {
        thisType.writeCast(writer, type, this.lineNumber());
    }
}
Also used : IType(dyvilx.tools.compiler.ast.type.IType)

Example 37 with IType

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

the class ExternalClass method getMethodMatches.

@Override
public void getMethodMatches(MatchList<IMethod> list, IValue receiver, Name name, ArgumentList arguments) {
    this.resolveGenerics();
    /*
		Note: unlike AbstractClass.getMethodMatches, this does not check the Class Parameter Properties, because
		External classes do not have any class parameters with associated properties
		*/
    this.body.getMethodMatches(list, receiver, name, arguments);
    if (list.hasCandidate()) {
        return;
    }
    this.resolveSuperTypes();
    if (this.superType != null) {
        this.superType.getMethodMatches(list, receiver, name, arguments);
    }
    if (list.hasCandidate() || this.interfaces == null) {
        return;
    }
    for (IType type : this.interfaces) {
        type.getMethodMatches(list, receiver, name, arguments);
    }
}
Also used : IType(dyvilx.tools.compiler.ast.type.IType)

Example 38 with IType

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

the class ExternalClass method visitField.

public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
    IType type = ClassFormat.readFieldType(signature == null ? desc : signature);
    if (this.classParameters != null && this.classParameters.contains(name)) {
        final ClassParameter param = new ExternalClassParameter(this, Name.fromQualified(name), desc, type, readModifiers(access));
        this.parameters.add(param);
        return new SimpleFieldVisitor(param);
    }
    final ExternalField field = new ExternalField(this, Name.fromQualified(name), desc, type, readModifiers(access));
    if (value != null) {
        field.setConstantValue(value);
    }
    this.body.addDataMember(field);
    return new SimpleFieldVisitor(field);
}
Also used : ClassParameter(dyvilx.tools.compiler.ast.parameter.ClassParameter) IType(dyvilx.tools.compiler.ast.type.IType)

Example 39 with IType

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

the class ClassConstructorCall method resolveCall.

@Override
public IValue resolveCall(MarkerList markers, IContext context, boolean report) {
    if (!this.type.isResolved()) {
        return this;
    }
    final IClass theClass = this.type.getTheClass();
    if (theClass == null) {
        return this;
    }
    final IType type = theClass.isInterface() ? Types.OBJECT : this.type;
    final MatchList<IConstructor> candidates = this.resolveCandidates(context, type);
    if (candidates.hasCandidate()) {
        this.checkArguments(markers, context, candidates.getBestMember());
        return this;
    }
    if (report) {
        reportResolve(markers, candidates, this.position, type, this.arguments);
        return this;
    }
    return null;
}
Also used : IConstructor(dyvilx.tools.compiler.ast.constructor.IConstructor) IClass(dyvilx.tools.compiler.ast.classes.IClass) IType(dyvilx.tools.compiler.ast.type.IType)

Example 40 with IType

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

the class ConstructorCall method resolveArrayConstructor.

private void resolveArrayConstructor(MarkerList markers, IContext context, ArrayType arrayType) {
    final IType elementType = arrayType.getElementType();
    if (elementType.hasTag(IType.TYPE_VAR)) {
        markers.add(Markers.semanticError(this.position, "constructor.access.array.typevar", elementType));
    }
    final int len = this.arguments.size();
    final int dims = 1 + getDimensions(arrayType.getElementType());
    if (len > dims) {
        final Marker marker = Markers.semanticError(this.position, "constructor.access.array.length");
        marker.addInfo(Markers.getSemantic("type.dimensions", dims));
        marker.addInfo(Markers.getSemantic("constructor.access.array.count", len));
        markers.add(marker);
        return;
    }
    for (int i = 0; i < len; i++) {
        final IValue value = this.arguments.get(i, null);
        final IValue typed = TypeChecker.convertValue(value, Types.INT, ITypeContext.DEFAULT, markers, context, TypeChecker.markerSupplier("constructor.access.array.type"));
        this.arguments.set(i, null, typed);
    }
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) Marker(dyvilx.tools.parsing.marker.Marker) 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