Search in sources :

Example 1 with CombiningContext

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

the class Field method resolveTypes.

@Override
public void resolveTypes(MarkerList markers, IContext context) {
    super.resolveTypes(markers, context);
    if (this.value != null) {
        this.value.resolveTypes(markers, new CombiningContext(this, context));
    }
    if (this.property == null) {
        return;
    }
    copyModifiers(this.attributes, this.property.getAttributes());
    this.property.setEnclosingClass(this.enclosingClass);
    this.property.setType(this.type);
    this.property.resolveTypes(markers, context);
}
Also used : CombiningContext(dyvilx.tools.compiler.ast.context.CombiningContext)

Example 2 with CombiningContext

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

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

the class Property method resolveTypes.

@Override
public void resolveTypes(MarkerList markers, IContext context) {
    super.resolveTypes(markers, context);
    if (this.getter != null) {
        final AttributeList getterAttributes = this.getter.getAttributes();
        // Add <generated> Modifier and copy Property Modifiers
        getterAttributes.addFlag(Modifiers.GENERATED);
        Field.copyModifiers(this.attributes, getterAttributes);
        this.getter.setType(this.type);
        this.getter.resolveTypes(markers, context);
    }
    if (this.setter != null) {
        final AttributeList setterModifiers = this.setter.getAttributes();
        // Add <generated> Modifier and copy Property Modifiers
        setterModifiers.addFlag(Modifiers.GENERATED);
        Field.copyModifiers(this.attributes, setterModifiers);
        this.setterParameter.setPosition(this.setter.getPosition());
        this.setterParameter.setType(this.type);
        this.setter.resolveTypes(markers, context);
    }
    if (this.initializer != null) {
        this.initializer.resolveTypes(markers, new CombiningContext(this, context));
    }
}
Also used : AttributeList(dyvilx.tools.compiler.ast.attribute.AttributeList) CombiningContext(dyvilx.tools.compiler.ast.context.CombiningContext)

Example 4 with CombiningContext

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

the class Initializer 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);
        final IValue resolved = this.value.resolve(markers, context1);
        this.value = TypeChecker.convertValue(resolved, Types.VOID, Types.VOID, markers, context1, TypeChecker.markerSupplier("initializer.type"));
    }
}
Also used : IContext(dyvilx.tools.compiler.ast.context.IContext) IValue(dyvilx.tools.compiler.ast.expression.IValue) CombiningContext(dyvilx.tools.compiler.ast.context.CombiningContext)

Example 5 with CombiningContext

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

the class Types method initHeaders.

public static void initHeaders() {
    LANG_HEADER = Package.dyvil.resolveHeader("Lang");
    BASE_CONTEXT = new CombiningContext(LANG_HEADER.getContext(), Package.rootPackage);
}
Also used : CombiningContext(dyvilx.tools.compiler.ast.context.CombiningContext)

Aggregations

CombiningContext (dyvilx.tools.compiler.ast.context.CombiningContext)7 IContext (dyvilx.tools.compiler.ast.context.IContext)3 IValue (dyvilx.tools.compiler.ast.expression.IValue)3 SourcePosition (dyvil.source.position.SourcePosition)1 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)1 IClass (dyvilx.tools.compiler.ast.classes.IClass)1 ThisExpr (dyvilx.tools.compiler.ast.expression.ThisExpr)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 IHeaderUnit (dyvilx.tools.compiler.ast.header.IHeaderUnit)1 IMethod (dyvilx.tools.compiler.ast.method.IMethod)1 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)1 Package (dyvilx.tools.compiler.ast.structure.Package)1 TypeChecker (dyvilx.tools.compiler.transform.TypeChecker)1