Search in sources :

Example 76 with IType

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

the class IParameter method visitAnnotation.

default AnnotationVisitor visitAnnotation(String internalType) {
    if (this.skipAnnotation(internalType, null)) {
        return null;
    }
    IType type = new InternalType(internalType);
    Annotation annotation = new ExternalAnnotation(type);
    return new AnnotationReader(this, annotation);
}
Also used : InternalType(dyvilx.tools.compiler.ast.type.raw.InternalType) ExternalAnnotation(dyvilx.tools.compiler.ast.attribute.annotation.ExternalAnnotation) AnnotationReader(dyvilx.tools.compiler.backend.visitor.AnnotationReader) Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation) ExternalAnnotation(dyvilx.tools.compiler.ast.attribute.annotation.ExternalAnnotation) IType(dyvilx.tools.compiler.ast.type.IType)

Example 77 with IType

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

the class IParameter method writeDefaultValue.

default void writeDefaultValue(ClassWriter writer) {
    final IValue value = this.getValue();
    assert value != null;
    final ICallableMember method = this.getMethod();
    final IType type = this.getType();
    final String name;
    final int access;
    if (method == null) {
        name = "init$paramDefault$" + this.getInternalName();
        access = Modifiers.STATIC;
    } else {
        name = method.getInternalName() + "$paramDefault$" + this.getInternalName();
        access = (method.getAttributes().flags() & Modifiers.MEMBER_MODIFIERS) | Modifiers.STATIC;
    }
    final String desc = "()" + this.getDescriptor();
    final String signature = "()" + this.getSignature();
    final MethodWriter mw = new MethodWriterImpl(writer, writer.visitMethod(access, name, desc, signature, null));
    mw.visitCode();
    value.writeExpression(mw, type);
    mw.visitEnd(type);
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) MethodWriterImpl(dyvilx.tools.compiler.backend.MethodWriterImpl) MethodWriter(dyvilx.tools.compiler.backend.MethodWriter) ICallableMember(dyvilx.tools.compiler.ast.method.ICallableMember) IType(dyvilx.tools.compiler.ast.type.IType)

Example 78 with IType

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

the class NamedArgumentList method writeValues.

@Override
public void writeValues(MethodWriter writer, ParameterList parameters, int startIndex) throws BytecodeException {
    if (this.hasParameterOrder()) {
        super.writeValues(writer, parameters, startIndex);
        return;
    }
    final int locals = writer.localCount();
    final int paramCount = parameters.size() - startIndex;
    // Step 1: Associate parameters to arguments
    final IParameter[] params = new IParameter[this.size];
    for (int i = 0; i < paramCount; i++) {
        final IParameter param = parameters.get(i + startIndex);
        final int argIndex = this.findIndex(i, param.getLabel());
        if (argIndex >= 0) {
            params[argIndex] = param;
        }
    }
    // Save the local indices in the targets array for later use
    // Maps parameter index -> local index of stored argument
    final int[] targets = new int[paramCount];
    // Fill the array with -1s to mark missing values
    Arrays.fill(targets, -1);
    // Step 2: Write all arguments that already have parameter order
    int argStartIndex = 0;
    for (int i = 0; i < this.size; i++) {
        IParameter param = params[i];
        if (param.getIndex() == startIndex + i) {
            this.values[i].writeExpression(writer, param.getCovariantType());
            targets[i] = -2;
            argStartIndex = i + 1;
        } else {
            break;
        }
    }
    if (argStartIndex < this.size) {
        for (int i = argStartIndex; i < this.size; i++) {
            final IParameter parameter = params[i];
            final IType parameterType = parameter.getCovariantType();
            final IValue value = this.values[i];
            final int localIndex = value.writeStore(writer, parameterType);
            targets[parameter.getIndex() - startIndex] = localIndex;
        }
        // Step 4: Load the local variables in order
        for (int i = 0; i < paramCount; i++) {
            final IParameter parameter = parameters.get(i + startIndex);
            final int target = targets[parameter.getIndex() - startIndex];
            switch(target) {
                case -1:
                case -2:
                    // Value for parameter was already written in Step 2
                    continue;
                default:
                    // Value for parameter exists -> load the variable
                    writer.visitVarInsn(parameter.getCovariantType().getLoadOpcode(), target);
            }
        }
    }
    writer.resetLocals(locals);
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) IType(dyvilx.tools.compiler.ast.type.IType)

Example 79 with IType

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

the class ParameterList method matches.

public boolean matches(ParameterList other) {
    final int len = other.size();
    if (len != this.size) {
        return false;
    }
    for (int i = 0; i < len; i++) {
        final IType thisParameterType = this.parameters[i].getType();
        final IType otherParameterType = other.get(i).getType();
        if (!Types.isSameType(thisParameterType, otherParameterType)) {
            return false;
        }
    }
    return true;
}
Also used : IType(dyvilx.tools.compiler.ast.type.IType)

Example 80 with IType

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

the class InlineIntrinsicData method preWrite.

private void preWrite(MethodWriter writer, IValue instance, ArgumentList arguments, int localCount) {
    if (!this.preProcessed) {
        this.preProcessed = true;
        this.preProcess();
    }
    for (int i = 0; i < this.storedParameters; i++) {
        final IType type = IntrinsicData.writeArgument(writer, this.method, i, instance, arguments);
        writer.visitVarInsn(type.getStoreOpcode(), localCount);
        localCount = writer.localCount();
    }
}
Also used : 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