Search in sources :

Example 1 with VarargsOperator

use of dyvilx.tools.compiler.ast.expression.intrinsic.VarargsOperator in project Dyvil by Dyvil.

the class CaseClassMetadata method createApplyMethod.

private CodeMethod createApplyMethod() {
    // static final func apply<TypeParams...>(classParams...: ClassParamTypes...) -> This
    final SourcePosition position = this.theClass.position();
    final AttributeList attributes = AttributeList.of(Modifiers.PUBLIC | Modifiers.STATIC_FINAL | Modifiers.GENERATED);
    final IType type = this.theClass.getThisType();
    final CodeMethod applyMethod = new CodeMethod(this.theClass, Names.apply, type, attributes);
    applyMethod.setPosition(position);
    applyMethod.getTypeParameters().addAll(this.theClass.getTypeParameters());
    this.copyClassParameters(applyMethod);
    // = new This<TypeParams...>(classParams...)
    final ArgumentList arguments = new ArgumentList();
    for (IParameter param : applyMethod.getParameters()) {
        // no need to check for override class parameters here, since we are dealing with parameters of the
        // apply method
        final IValue access;
        if (param.isVarargs()) {
            access = new VarargsOperator(position, new FieldAccess(param));
        } else {
            access = new FieldAccess(param);
        }
        arguments.add(access);
    }
    // = new This(params...)
    applyMethod.setValue(new ConstructorCall(this.theClass.position(), this.theClass.getThisType(), arguments));
    return applyMethod;
}
Also used : IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) IValue(dyvilx.tools.compiler.ast.expression.IValue) CodeMethod(dyvilx.tools.compiler.ast.method.CodeMethod) AttributeList(dyvilx.tools.compiler.ast.attribute.AttributeList) VarargsOperator(dyvilx.tools.compiler.ast.expression.intrinsic.VarargsOperator) SourcePosition(dyvil.source.position.SourcePosition) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) FieldAccess(dyvilx.tools.compiler.ast.expression.access.FieldAccess) ConstructorCall(dyvilx.tools.compiler.ast.expression.access.ConstructorCall) IType(dyvilx.tools.compiler.ast.type.IType)

Aggregations

SourcePosition (dyvil.source.position.SourcePosition)1 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)1 IValue (dyvilx.tools.compiler.ast.expression.IValue)1 ConstructorCall (dyvilx.tools.compiler.ast.expression.access.ConstructorCall)1 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)1 VarargsOperator (dyvilx.tools.compiler.ast.expression.intrinsic.VarargsOperator)1 CodeMethod (dyvilx.tools.compiler.ast.method.CodeMethod)1 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)1 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)1 IType (dyvilx.tools.compiler.ast.type.IType)1