Search in sources :

Example 6 with CombiningContext

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

the class Property method resolve.

@Override
public void resolve(MarkerList markers, IContext context) {
    super.resolve(markers, context);
    if (this.getter != null) {
        this.getter.resolve(markers, context);
        // Infer Type if necessary
        if (this.type == Types.UNKNOWN) {
            this.type = this.getter.getType();
            if (this.setterParameter != null) {
                this.setterParameter.setType(this.type);
            }
        }
    }
    if (this.type == Types.UNKNOWN) {
        markers.add(Markers.semanticError(this.position, "property.type.infer", this.name));
    }
    if (this.setter != null) {
        this.setter.resolve(markers, context);
    }
    if (this.initializer != null) {
        final IContext context1 = new CombiningContext(this, context);
        final IValue resolved = this.initializer.resolve(markers, context1);
        this.initializer = TypeChecker.convertValue(resolved, Types.VOID, Types.VOID, markers, context1, TypeChecker.markerSupplier("property.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 7 with CombiningContext

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

the class SingleImport method resolveTypes.

@Override
public void resolveTypes(MarkerList markers, IContext context, IImportContext parentContext, int mask) {
    if (this.parent != null) {
        this.parent.resolveTypes(markers, context, parentContext, KindedImport.PARENT);
        parentContext = this.parent.asParentContext();
    }
    boolean resolved = false;
    this.resolver = parentContext;
    this.mask = mask;
    if ((mask & KindedImport.CLASS) != 0) {
        final IClass theClass = parentContext.resolveClass(this.name);
        if (theClass != null) {
            this.asParentContext = theClass;
            resolved = true;
        }
    }
    if ((mask & KindedImport.HEADER) != 0) {
        final IHeaderUnit header = parentContext.resolveHeader(this.name);
        if (header != null) {
            if ((mask & KindedImport.INLINE) != 0 && this.checkInline(markers, context, header)) {
                this.asContext = new CombiningContext(this, header.getContext());
            }
            this.asParentContext = !resolved ? header : new CombiningContext(header, this.asParentContext);
            resolved = true;
        }
    }
    if ((mask & KindedImport.PACKAGE) != 0) {
        final Package thePackage = parentContext.resolvePackage(this.name);
        if (thePackage != null) {
            this.asParentContext = !resolved ? thePackage : new CombiningContext(thePackage, this.asParentContext);
            resolved = true;
        }
    }
    if (!resolved) {
        this.asParentContext = IDefaultContext.DEFAULT;
        if (mask == KindedImport.PARENT) {
            // when resolving as a parent import, the resolve method is never called,
            // so we need the error reporting to happen here.
            this.reportResolve(markers);
        }
    }
// otherwise error later
}
Also used : CombiningContext(dyvilx.tools.compiler.ast.context.CombiningContext) IClass(dyvilx.tools.compiler.ast.classes.IClass) Package(dyvilx.tools.compiler.ast.structure.Package) IHeaderUnit(dyvilx.tools.compiler.ast.header.IHeaderUnit)

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