Search in sources :

Example 1 with IParameter

use of dyvilx.tools.compiler.ast.parameter.IParameter in project Dyvil by Dyvil.

the class TypeVarType method checkType.

@Override
public void checkType(MarkerList markers, IContext context, int position) {
    if ((position & TypePosition.REIFY_FLAG) == 0) {
        return;
    }
    final Reified.Type reifiedKind = this.typeParameter.getReifiedKind();
    if (reifiedKind == null) {
        return;
    }
    final IParameter reifyParameter = this.typeParameter.getReifyParameter();
    if (reifyParameter == null) {
        return;
    }
    this.reifyVariableAccess = new FieldAccess(reifyParameter).resolve(markers, context);
    // ensure proper capture
    this.reifyVariableAccess.checkTypes(markers, context);
}
Also used : IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) Reified(dyvil.annotation.Reified) FieldAccess(dyvilx.tools.compiler.ast.expression.access.FieldAccess)

Example 2 with IParameter

use of dyvilx.tools.compiler.ast.parameter.IParameter in project Dyvil by Dyvil.

the class SimpleMethodVisitor method visitEnd.

@Override
public void visitEnd() {
    if (this.intrinsicData != null && !this.unsupportedInline) {
        this.method.setIntrinsicData(this.intrinsicData);
    }
    int localIndex = this.method.hasModifier(Modifiers.STATIC) ? 0 : 1;
    final ParameterList parameters = this.method.getExternalParameterList();
    for (int i = 0, count = parameters.size(); i < count; i++) {
        final IParameter param = parameters.get(i);
        param.setLocalIndex(localIndex);
        if (param.getName() == null) {
            param.setName(this.getName(localIndex));
        }
        localIndex += param.getLocalSlots();
    }
}
Also used : IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList)

Example 3 with IParameter

use of dyvilx.tools.compiler.ast.parameter.IParameter in project Dyvil by Dyvil.

the class SimpleMethodVisitor method visitParameter.

@Override
public void visitParameter(String name, int modifiers) {
    final IParameter parameter = this.method.getExternalParameterList().get(this.parameterIndex);
    if (parameter == null) {
        return;
    }
    this.parameterIndex++;
    if (name != null && !name.isEmpty()) {
        final Name name1 = Name.fromQualified(name);
        parameter.setName(name1);
        parameter.setLabel(name1);
    }
    if (modifiers != 0) {
        if ((modifiers & Modifiers.ACC_VARARGS) != 0) {
            // add the internal bitflag for varargs parameters
            modifiers |= Modifiers.VARARGS;
        }
        parameter.getAttributes().addFlag(modifiers);
    }
}
Also used : IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) Name(dyvil.lang.Name)

Example 4 with IParameter

use of dyvilx.tools.compiler.ast.parameter.IParameter in project Dyvil by Dyvil.

the class Field method resolve.

@Override
public void resolve(MarkerList markers, IContext context) {
    super.resolve(markers, context);
    if (this.value != null) {
        final IContext context1 = new CombiningContext(this, context);
        this.value = this.value.resolve(markers, context1);
        boolean inferType = false;
        if (this.type == Types.UNKNOWN) {
            inferType = true;
            this.type = this.value.getType();
        }
        final TypeChecker.MarkerSupplier markerSupplier = TypeChecker.markerSupplier("field.type.incompatible", "field.type", "value.type", this.name);
        this.value = TypeChecker.convertValue(this.value, this.type, this.type, markers, context1, markerSupplier);
        if (inferType) {
            this.type = this.value.getType();
            if (this.type == Types.UNKNOWN && this.value.isResolved()) {
                markers.add(Markers.semantic(this.position, "field.type.infer", this.name.unqualified));
                this.type = Types.ANY;
            }
        }
    } else if (this.type == Types.UNKNOWN) {
        markers.add(Markers.semantic(this.position, "field.type.infer.novalue", this.name.unqualified));
        this.type = Types.ANY;
    }
    if (this.property == null) {
        return;
    }
    this.property.setType(this.type);
    final IMethod getter = this.property.getGetter();
    final IMethod setter = this.property.getSetter();
    final IValue receiver = this.hasModifier(Modifiers.STATIC) ? null : new ThisExpr(this.enclosingClass.getThisType(), VariableThis.DEFAULT);
    if (getter != null) {
        getter.setType(this.type);
        if (getter.getValue() == null) {
            // get: this.FIELD_NAME
            getter.setValue(new FieldAccess(getter.getPosition(), receiver, this));
        }
    }
    if (setter != null) {
        final IParameter setterParameter = setter.getParameters().get(0);
        setterParameter.setType(this.type);
        if (setter.getValue() == null) {
            final SourcePosition setterPosition = setter.getPosition();
            if (this.hasModifier(Modifiers.FINAL)) {
                markers.add(Markers.semanticError(setterPosition, "field.property.setter.final", this.name));
                // avoid abstract method error
                setter.setValue(new VoidValue(setterPosition));
            } else {
                // set: this.FIELD_NAME = newValue
                setter.setValue(new FieldAssignment(setterPosition, receiver, this, new FieldAccess(setterPosition, null, setterParameter)));
            }
        }
    }
    this.property.resolve(markers, context);
}
Also used : VoidValue(dyvilx.tools.compiler.ast.expression.constant.VoidValue) IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) IContext(dyvilx.tools.compiler.ast.context.IContext) TypeChecker(dyvilx.tools.compiler.transform.TypeChecker) CombiningContext(dyvilx.tools.compiler.ast.context.CombiningContext) FieldAssignment(dyvilx.tools.compiler.ast.expression.access.FieldAssignment) IValue(dyvilx.tools.compiler.ast.expression.IValue) SourcePosition(dyvil.source.position.SourcePosition) IMethod(dyvilx.tools.compiler.ast.method.IMethod) FieldAccess(dyvilx.tools.compiler.ast.expression.access.FieldAccess) ThisExpr(dyvilx.tools.compiler.ast.expression.ThisExpr)

Example 5 with IParameter

use of dyvilx.tools.compiler.ast.parameter.IParameter in project Dyvil by Dyvil.

the class ICall method toLambda.

default IValue toLambda(MarkerList markers, IContext context, int wildcards) {
    SourcePosition position = this.getPosition();
    final IParameter[] parameters = new IParameter[wildcards];
    for (int i = 0; i < wildcards; i++) {
        parameters[i] = new CodeParameter(null, position, Name.fromRaw("wildcard$" + i), Types.UNKNOWN, new AttributeList());
    }
    int parIndex = 0;
    final IValue receiver = this.getReceiver();
    if (receiver != null && receiver.isPartialWildcard()) {
        this.setReceiver(receiver.withLambdaParameter(parameters[parIndex++]));
    }
    final ArgumentList arguments = this.getArguments();
    for (int i = 0, size = arguments.size(); i < size; i++) {
        final IValue argument = arguments.get(i, null);
        if (argument.isPartialWildcard()) {
            arguments.set(i, null, argument.withLambdaParameter(parameters[parIndex++]));
        }
    }
    final LambdaExpr lambdaExpr = new LambdaExpr(position, parameters, wildcards);
    lambdaExpr.setImplicitParameters(true);
    lambdaExpr.setValue(this);
    return lambdaExpr.resolve(markers, context);
}
Also used : IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) IValue(dyvilx.tools.compiler.ast.expression.IValue) AttributeList(dyvilx.tools.compiler.ast.attribute.AttributeList) SourcePosition(dyvil.source.position.SourcePosition) LambdaExpr(dyvilx.tools.compiler.ast.expression.LambdaExpr) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) CodeParameter(dyvilx.tools.compiler.ast.parameter.CodeParameter)

Aggregations

IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)28 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)12 IType (dyvilx.tools.compiler.ast.type.IType)11 IValue (dyvilx.tools.compiler.ast.expression.IValue)9 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)6 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)6 SourcePosition (dyvil.source.position.SourcePosition)5 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)5 IClass (dyvilx.tools.compiler.ast.classes.IClass)4 TypeParameterList (dyvilx.tools.compiler.ast.generic.TypeParameterList)4 LambdaExpr (dyvilx.tools.compiler.ast.expression.LambdaExpr)3 ThisExpr (dyvilx.tools.compiler.ast.expression.ThisExpr)3 CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)3 Name (dyvil.lang.Name)2 AnnotationVisitor (dyvilx.tools.asm.AnnotationVisitor)2 FieldAssignment (dyvilx.tools.compiler.ast.expression.access.FieldAssignment)2 CodeMethod (dyvilx.tools.compiler.ast.method.CodeMethod)2 IMethod (dyvilx.tools.compiler.ast.method.IMethod)2 Reified (dyvil.annotation.Reified)1 MethodVisitor (dyvilx.tools.asm.MethodVisitor)1