Search in sources :

Example 16 with FieldAccess

use of dyvilx.tools.compiler.ast.expression.access.FieldAccess in project Dyvil by Dyvil.

the class Closure method withType.

@Override
public IValue withType(IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
    if (this.resolved) {
        return super.withType(type, typeContext, markers, context);
    }
    final IMethod functionalMethod = type.getFunctionalMethod();
    if (functionalMethod == null) {
        return null;
    }
    final ParameterList parameterList = functionalMethod.getParameters();
    final int parameterCount = parameterList.size();
    final IParameter[] parameters = new IParameter[parameterCount];
    for (int i = 0; i < parameterCount; i++) {
        parameters[i] = new CodeParameter(null, this.position, Name.fromRaw("$" + i), Types.UNKNOWN);
    }
    final LambdaType functionType = type.extract(LambdaType.class);
    if (functionType != null && functionType.isExtension() && parameterCount > 0) {
        this.implicitValue = new FieldAccess(parameters[0]);
    }
    final LambdaExpr lambdaExpr = new LambdaExpr(this.position, parameters, parameterCount);
    lambdaExpr.setValue(this);
    this.resolved = true;
    context = context.push(this);
    final IValue typedLambda = lambdaExpr.withType(type, typeContext, markers, context);
    context.pop();
    return typedLambda;
}
Also used : LambdaType(dyvilx.tools.compiler.ast.type.compound.LambdaType) IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) IValue(dyvilx.tools.compiler.ast.expression.IValue) LambdaExpr(dyvilx.tools.compiler.ast.expression.LambdaExpr) ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList) IMethod(dyvilx.tools.compiler.ast.method.IMethod) FieldAccess(dyvilx.tools.compiler.ast.expression.access.FieldAccess) CodeParameter(dyvilx.tools.compiler.ast.parameter.CodeParameter)

Aggregations

FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)16 IValue (dyvilx.tools.compiler.ast.expression.IValue)11 SourcePosition (dyvil.source.position.SourcePosition)8 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)6 IType (dyvilx.tools.compiler.ast.type.IType)6 Variable (dyvilx.tools.compiler.ast.field.Variable)5 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)5 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)4 CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)4 ConstructorCall (dyvilx.tools.compiler.ast.expression.access.ConstructorCall)3 MethodCall (dyvilx.tools.compiler.ast.expression.access.MethodCall)3 CodeMethod (dyvilx.tools.compiler.ast.method.CodeMethod)3 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)3 StatementList (dyvilx.tools.compiler.ast.statement.StatementList)3 ThisExpr (dyvilx.tools.compiler.ast.expression.ThisExpr)2 FieldAssignment (dyvilx.tools.compiler.ast.expression.access.FieldAssignment)2 IMethod (dyvilx.tools.compiler.ast.method.IMethod)2 BindingIfStatement (dyvilx.tools.compiler.ast.statement.BindingIfStatement)2 VariableStatement (dyvilx.tools.compiler.ast.statement.VariableStatement)2 Reified (dyvil.annotation.Reified)1