Search in sources :

Example 21 with ArgumentList

use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.

the class EnumClassMetadata method updateConstructor.

private void updateConstructor(IConstructor constructor) {
    constructor.getAttributes().addFlag(Modifiers.PRIVATE_PROTECTED);
    // Prepend parameters and set super initializer
    final CodeParameter nameParam = new CodeParameter(constructor, null, Names.name, new ImplicitNullableType(Types.STRING), AttributeList.of(Modifiers.SYNTHETIC));
    final CodeParameter ordParam = new CodeParameter(constructor, null, Names.ordinal, Types.INT, AttributeList.of(Modifiers.SYNTHETIC));
    constructor.getParameters().insert(0, nameParam);
    constructor.getParameters().insert(1, ordParam);
    final IConstructor enumConstructor = Types.ENUM_CLASS.getBody().getConstructor(0);
    final InitializerCall initializer = constructor.getInitializer();
    if (initializer == null) {
        final ArgumentList arguments = new ArgumentList(new FieldAccess(nameParam), new FieldAccess(ordParam));
        final SourcePosition position = constructor.position();
        final InitializerCall init = new InitializerCall(position, true, arguments, this.theClass.getSuperType(), enumConstructor);
        constructor.setInitializer(init);
        return;
    }
    // Prepend access to new parameters
    final ArgumentList arguments = initializer.getArguments();
    arguments.insert(0, new FieldAccess(nameParam));
    arguments.insert(1, new FieldAccess(ordParam));
}
Also used : IConstructor(dyvilx.tools.compiler.ast.constructor.IConstructor) SourcePosition(dyvil.source.position.SourcePosition) ImplicitNullableType(dyvilx.tools.compiler.ast.type.compound.ImplicitNullableType) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) CodeParameter(dyvilx.tools.compiler.ast.parameter.CodeParameter)

Example 22 with ArgumentList

use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.

the class EnumClassMetadata method createFromOrdMethod.

private CodeMethod createFromOrdMethod() {
    // @BytecodeName("valueOf")
    // public static func from(ordinal: int) -> EnumType
    final SourcePosition position = this.theClass.position();
    final IType type = this.theClass.getClassType();
    final CodeMethod method = new CodeMethod(this.theClass, Name.fromRaw("from"), type, AttributeList.of(Modifiers.PUBLIC | Modifiers.STATIC));
    method.setPosition(position);
    method.setInternalName("valueOf");
    final CodeParameter parameter = new CodeParameter(Name.fromRaw("ordinal"), Types.INT);
    method.getParameters().add(parameter);
    // = $VALUES[ordinal]
    final FieldAccess valuesField = new FieldAccess(position, null, Names.$VALUES);
    final SubscriptAccess getCall = new SubscriptAccess(position, valuesField, new ArgumentList(new FieldAccess(parameter)));
    method.setValue(getCall);
    return method;
}
Also used : CodeMethod(dyvilx.tools.compiler.ast.method.CodeMethod) SourcePosition(dyvil.source.position.SourcePosition) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) CodeParameter(dyvilx.tools.compiler.ast.parameter.CodeParameter) IType(dyvilx.tools.compiler.ast.type.IType)

Example 23 with ArgumentList

use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.

the class EnumClassMetadata method createValuesArray.

private IValue createValuesArray() {
    final ArrayExpr arrayExpr = new ArrayExpr();
    arrayExpr.setElementType(this.theClass.getClassType());
    final ClassBody body = this.theClass.getBody();
    if (body != null) {
        final ArgumentList values = arrayExpr.getValues();
        for (IField enumConstant : body.enumConstants()) {
            values.add(new FieldAccess(enumConstant));
        }
    }
    return arrayExpr;
}
Also used : ArrayExpr(dyvilx.tools.compiler.ast.expression.ArrayExpr) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) IField(dyvilx.tools.compiler.ast.field.IField) ClassBody(dyvilx.tools.compiler.ast.classes.ClassBody)

Example 24 with ArgumentList

use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.

the class ColonOperator method withType.

@Override
public IValue withType(IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
    final Annotation annotation = type.getAnnotation(LazyFields.COLON_CONVERTIBLE);
    if (annotation != null) {
        return new LiteralConversion(this, annotation, new ArgumentList(this.left, this.right)).withType(type, typeContext, markers, context);
    }
    if (!Types.isSuperClass(type, TupleType.getTupleClass(2).getClassType())) {
        return null;
    }
    // reset type
    this.type = null;
    final IType leftType = Types.resolveTypeSafely(type, LazyFields.KEY_PARAMETER);
    final IType rightType = Types.resolveTypeSafely(type, LazyFields.VALUE_PARAMETER);
    this.left = TypeChecker.convertValue(this.left, leftType, typeContext, markers, context, TypeChecker.markerSupplier("colon_operator.left.type"));
    this.right = TypeChecker.convertValue(this.right, rightType, typeContext, markers, context, TypeChecker.markerSupplier("colon_operator.right.type"));
    return this;
}
Also used : ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation) IType(dyvilx.tools.compiler.ast.type.IType)

Example 25 with ArgumentList

use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.

the class Deprecation method checkExperimental.

private static void checkExperimental(IMember member, SourcePosition position, MarkerList markers, Annotation annotation) {
    final ArgumentList arguments = annotation.getArguments();
    final MarkerLevel markerLevel = AnnotationUtil.getEnumValue(arguments, EXP_LEVEL_PARAM, MarkerLevel.class);
    if (markerLevel == null || markerLevel == MarkerLevel.IGNORE) {
        return;
    }
    String value = AnnotationUtil.getStringValue(arguments, EXP_VALUE_PARAM);
    final String description = AnnotationUtil.getStringValue(arguments, EXP_DESC_PARAM);
    final Stage stage = AnnotationUtil.getEnumValue(arguments, EXP_STAGE_PARAM, Stage.class);
    assert stage != null;
    final String stageName = Markers.getSemantic("experimental.stage." + stage.name());
    value = replaceMember(member, value).replace("{stage}", stageName);
    final Marker marker = Markers.withText(position, markerLevel, value);
    assert marker != null;
    // Description
    if (description != null && !description.isEmpty()) {
        marker.addInfo(Markers.getSemantic("experimental.description", description));
    }
    // Stage
    marker.addInfo(Markers.getSemantic("experimental.stage", stageName));
    markers.add(marker);
}
Also used : Stage(dyvil.annotation.Experimental.Stage) MarkerLevel(dyvil.util.MarkerLevel) Marker(dyvilx.tools.parsing.marker.Marker) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList)

Aggregations

ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)37 IValue (dyvilx.tools.compiler.ast.expression.IValue)17 IType (dyvilx.tools.compiler.ast.type.IType)10 SourcePosition (dyvil.source.position.SourcePosition)8 CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)7 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)5 ArrayExpr (dyvilx.tools.compiler.ast.expression.ArrayExpr)5 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)5 CodeMethod (dyvilx.tools.compiler.ast.method.CodeMethod)5 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)5 Annotation (dyvilx.tools.compiler.ast.attribute.annotation.Annotation)4 ConstructorCall (dyvilx.tools.compiler.ast.expression.access.ConstructorCall)4 MarkerLevel (dyvil.util.MarkerLevel)3 MethodCall (dyvilx.tools.compiler.ast.expression.access.MethodCall)3 StringValue (dyvilx.tools.compiler.ast.expression.constant.StringValue)3 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)3 Marker (dyvilx.tools.parsing.marker.Marker)3 Reason (dyvil.annotation.Deprecated.Reason)2 Name (dyvil.lang.Name)2 IClass (dyvilx.tools.compiler.ast.classes.IClass)2