Search in sources :

Example 11 with CodeParameter

use of dyvilx.tools.compiler.ast.parameter.CodeParameter 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

CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)11 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)7 SourcePosition (dyvil.source.position.SourcePosition)6 IValue (dyvilx.tools.compiler.ast.expression.IValue)5 CodeMethod (dyvilx.tools.compiler.ast.method.CodeMethod)5 IType (dyvilx.tools.compiler.ast.type.IType)5 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)4 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)4 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)3 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)3 Name (dyvil.lang.Name)2 LambdaExpr (dyvilx.tools.compiler.ast.expression.LambdaExpr)2 MethodCall (dyvilx.tools.compiler.ast.expression.access.MethodCall)2 Reified (dyvil.annotation.Reified)1 IConstructor (dyvilx.tools.compiler.ast.constructor.IConstructor)1 CastOperator (dyvilx.tools.compiler.ast.expression.CastOperator)1 ClassOperator (dyvilx.tools.compiler.ast.expression.ClassOperator)1 InstanceOfOperator (dyvilx.tools.compiler.ast.expression.InstanceOfOperator)1 TupleExpr (dyvilx.tools.compiler.ast.expression.TupleExpr)1 ConstructorCall (dyvilx.tools.compiler.ast.expression.access.ConstructorCall)1