Search in sources :

Example 1 with IContext

use of dyvilx.tools.compiler.ast.context.IContext in project Dyvil by Dyvil.

the class REPLContext method endEvaluation.

public void endEvaluation() {
    final IContext context = this.getContext();
    this.currentClass.resolveTypes(this.markers, context);
    this.currentClass.resolve(this.markers, context);
    this.currentClass.checkTypes(this.markers, context);
    this.currentClass.check(this.markers, context);
    if (this.markers.getErrors() > 0) {
        this.printErrors();
        this.cleanup();
        return;
    }
    for (int i = this.getCompilationContext().config.getConstantFolding() - 1; i >= 0; i--) {
        this.currentClass.foldConstants();
    }
    this.currentClass.cleanup(this, this.currentClass);
    final Class<?> theClass = this.compileAndLoad();
    for (IMember member : this.members) {
        this.processMember(member, theClass);
    }
    this.printErrors();
    this.cleanup();
}
Also used : IContext(dyvilx.tools.compiler.ast.context.IContext) IMember(dyvilx.tools.compiler.ast.member.IMember)

Example 2 with IContext

use of dyvilx.tools.compiler.ast.context.IContext in project Dyvil by Dyvil.

the class LambdaExpr method withType.

@Override
public IValue withType(IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
    if (!this.isType(type)) {
        return null;
    }
    if (type.getTheClass() == Types.OBJECT_CLASS) {
        type = this.getType();
    }
    if (type != this.type) {
        // If this is not the type initially created and returned by getType(), remove the LAMBDA_TYPE_INFERRED flag
        this.flags &= ~LAMBDA_TYPE_INFERRED;
    }
    this.type = type;
    this.method = type.getFunctionalMethod();
    this.inferTypes(markers);
    final IContext combinedContext = context.push(this);
    if ((this.flags & VALUE_RESOLVED) == 0) {
        this.value = this.value.resolve(markers, combinedContext);
        this.flags |= VALUE_RESOLVED;
    }
    if (this.returnType.isUninferred()) {
        this.returnType = this.value.getType();
    }
    this.value = TypeChecker.convertValue(this.value, this.returnType, this.returnType, markers, combinedContext, LAMBDA_MARKER_SUPPLIER);
    this.inferReturnType(type, this.value.getType());
    if (this.returnType.isUninferred() && this.value.isResolved()) {
        markers.add(Markers.semanticError(this.position, "lambda.return_type.infer"));
    }
    context.pop();
    return this;
}
Also used : IContext(dyvilx.tools.compiler.ast.context.IContext)

Example 3 with IContext

use of dyvilx.tools.compiler.ast.context.IContext 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 4 with IContext

use of dyvilx.tools.compiler.ast.context.IContext in project Dyvil by Dyvil.

the class ExternalClass method resolveGenerics.

private void resolveGenerics() {
    if ((this.resolved & GENERICS) != 0) {
        return;
    }
    this.resolved |= GENERICS;
    final int typeParams;
    if (this.typeParameters == null || (typeParams = this.typeParameters.size()) <= 0) {
        return;
    }
    final IContext context = this.getCombiningContext();
    for (int i = 0; i < typeParams; i++) {
        final ITypeParameter typeParameter = this.typeParameters.get(i);
        typeParameter.resolveTypes(null, context);
    }
}
Also used : IContext(dyvilx.tools.compiler.ast.context.IContext) ITypeParameter(dyvilx.tools.compiler.ast.generic.ITypeParameter)

Example 5 with IContext

use of dyvilx.tools.compiler.ast.context.IContext in project Dyvil by Dyvil.

the class ExternalClass method resolveSuperTypes.

private void resolveSuperTypes() {
    if ((this.resolved & SUPER_TYPES) != 0) {
        return;
    }
    this.resolved |= SUPER_TYPES;
    final IContext context = this.getCombiningContext();
    if (this.superType != null) {
        this.superType = this.superType.resolveType(null, context);
    }
    if (this.interfaces != null) {
        this.interfaces.resolveTypes(null, context);
    }
}
Also used : IContext(dyvilx.tools.compiler.ast.context.IContext)

Aggregations

IContext (dyvilx.tools.compiler.ast.context.IContext)16 IValue (dyvilx.tools.compiler.ast.expression.IValue)5 CombiningContext (dyvilx.tools.compiler.ast.context.CombiningContext)3 SourcePosition (dyvil.source.position.SourcePosition)2 IMember (dyvilx.tools.compiler.ast.member.IMember)2 IMethod (dyvilx.tools.compiler.ast.method.IMethod)2 IType (dyvilx.tools.compiler.ast.type.IType)2 TypeChecker (dyvilx.tools.compiler.transform.TypeChecker)2 MarkerList (dyvilx.tools.parsing.marker.MarkerList)2 NonNull (dyvil.annotation.internal.NonNull)1 TreeSet (dyvil.collection.mutable.TreeSet)1 Modifiers (dyvil.reflect.Modifiers)1 LineSource (dyvil.source.LineSource)1 IClass (dyvilx.tools.compiler.ast.classes.IClass)1 IValueConsumer (dyvilx.tools.compiler.ast.consumer.IValueConsumer)1 ThisExpr (dyvilx.tools.compiler.ast.expression.ThisExpr)1 WriteableExpression (dyvilx.tools.compiler.ast.expression.WriteableExpression)1 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)1 FieldAssignment (dyvilx.tools.compiler.ast.expression.access.FieldAssignment)1 VoidValue (dyvilx.tools.compiler.ast.expression.constant.VoidValue)1