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));
}
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;
}
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;
}
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;
}
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);
}
Aggregations