use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class SideEffectHelper method processArguments.
public ArgumentList processArguments(ArgumentList arguments) {
final ArgumentList copy = arguments.copy();
for (int i = 0, count = arguments.size(); i < count; i++) {
final IValue value = arguments.get(i, null);
copy.set(i, null, this.processValue(value));
}
return copy;
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class TypeChecker method convertValueDirect.
private static IValue convertValueDirect(IValue value, IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
final IValue typedValue = value.withType(type, typeContext, markers, context);
if (typedValue != null) {
return typedValue;
}
final IValue converted1 = type.convertFrom(value, value.getType(), typeContext, markers, context);
if (converted1 != null) {
return converted1;
}
final IValue converted2 = value.getType().convertTo(value, type, typeContext, markers, context);
if (converted2 != null) {
return converted2;
}
final IMethod converter = IContext.resolveImplicits(context, value, type).getBestMember();
if (converter == null) {
return null;
}
return new LiteralConversion(value, converter);
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class AnnotationMetadata method readRetention.
private void readRetention() {
final Annotation retention = this.theClass.getAnnotation(Annotation.LazyFields.RETENTION_CLASS);
if (retention == null) {
return;
}
final IValue value = retention.getArguments().get(0, Names.value);
if (!(value instanceof EnumValue)) {
return;
}
try {
final String name = ((EnumValue) value).getName().qualified;
this.retention = RetentionPolicy.valueOf(name);
} catch (IllegalArgumentException ignored) {
// Problematic RetentionPolicy annotation - do not handle this
}
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class AnnotationMetadata method readTargets.
private void readTargets() {
final Annotation target = this.theClass.getAnnotation(Annotation.LazyFields.TARGET_CLASS);
if (target == null) {
return;
}
this.targets = EnumSet.noneOf(ElementType.class);
final IValue argument = target.getArguments().get(0, Names.value);
if (!(argument instanceof ArrayExpr)) {
return;
}
final ArgumentList values = ((ArrayExpr) argument).getValues();
final int size = values.size();
for (int i = 0; i < size; i++) {
final INamed value = (INamed) values.get(i);
try {
this.targets.add(ElementType.valueOf(value.getName().qualified));
} catch (IllegalArgumentException ignored) {
// Problematic Target annotation - do not handle this
}
}
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class CaseClassMetadata method createUnapplyMethod.
private CodeMethod createUnapplyMethod() {
// static final func unapply<TypeParams...>(value: This) -> (T...)
final SourcePosition position = this.theClass.position();
final AttributeList attributes = AttributeList.of(Modifiers.PUBLIC | Modifiers.STATIC_FINAL | Modifiers.GENERATED);
final IType type = this.getUnapplyReturnType();
final CodeMethod unapply = new CodeMethod(this.theClass, Names.unapply, type, attributes);
unapply.setPosition(position);
unapply.getTypeParameters().addAll(this.theClass.getTypeParameters());
final CodeParameter parameter = new CodeParameter(unapply, position, Names.value, this.theClass.getThisType());
unapply.getParameters().add(parameter);
// = (value.classParams...)
final TupleExpr tupleExpr = new TupleExpr(position);
final ArgumentList arguments = tupleExpr.getValues();
for (IParameter param : this.theClass.getParameters()) {
// value
final FieldAccess thisAccess = new FieldAccess(position, null, parameter);
// value.classParam
final IValue fieldAccess;
if (param.isOverride()) {
// if the class parameter is marked as 'override', we have to resolve it from a super-class
// the easiest way to do this is by name
fieldAccess = new FieldAccess(position, thisAccess, param.getName());
} else {
fieldAccess = new FieldAccess(position, thisAccess, param);
}
arguments.add(fieldAccess);
}
unapply.setValue(tupleExpr);
return unapply;
}
Aggregations