use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.
the class Intrinsics method readComplex.
private static IntrinsicData readComplex(IMethod method, int insnCount, int[] ints, ArrayExpr stringArray) {
String[] strings;
if (stringArray != null) {
final ArgumentList values = stringArray.getValues();
// Convert string constants to an array
final int stringCount = values.size();
strings = new String[stringCount];
for (int i = 0; i < stringCount; i++) {
strings[i] = values.get(i).stringValue();
}
} else {
strings = null;
}
// Convert jump instructions into a label array
final boolean[] labels = new boolean[insnCount + 1];
for (int i = 0, length = ints.length; i < length; i++) {
final int opcode = ints[i];
if (Opcodes.isFieldOrMethodOpcode(opcode)) {
i += 3;
} else if (Opcodes.isJumpOpcode(opcode)) {
final int target = ints[i + 1];
labels[target] = true;
i += 1;
}
}
return new SpecialIntrinsicData(method, ints, strings, labels);
}
use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.
the class UnapplyPattern method withType.
@Override
public Pattern withType(IType type, MarkerList markers) {
// PatternType.unapply(_ : MatchedType)
final IClass matchClass = this.type.getTheClass();
if (matchClass == null) {
return null;
}
final MethodCall methodCall = new MethodCall(this.position, new ClassAccess(this.type), Names.unapply, new ArgumentList(new DummyValue(type)));
final IValue resolvedCall = methodCall.resolveCall(MarkerList.BLACKHOLE, matchClass, false);
return resolvedCall != null && this.withMethod(type, resolvedCall, markers) ? this : null;
}
use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.
the class PropertyReference method checkTypes.
@Override
public void checkTypes(SourcePosition position, MarkerList markers, IContext context) {
final Name getterName = this.getterMethod.getName();
final Name setterName = Util.addEq(getterName);
this.setterMethod = ICall.resolveMethod(context, this.receiver, setterName, new ArgumentList(new WildcardValue(null)));
if (this.setterMethod == null || this.setterMethod.getParameters().size() != 1) {
markers.add(Markers.semanticError(position, "reference.property.no_setter", getterName));
}
}
use of dyvilx.tools.compiler.ast.parameter.ArgumentList 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;
}
use of dyvilx.tools.compiler.ast.parameter.ArgumentList in project Dyvil by Dyvil.
the class CaseClassMetadata method createUnapplyAnyMethod.
private CodeMethod createUnapplyAnyMethod() {
// static final func unapply<TypeParams...>(value: any) -> (T...)?
final SourcePosition position = this.theClass.position();
final AttributeList attributes = AttributeList.of(Modifiers.PUBLIC | Modifiers.STATIC_FINAL | Modifiers.GENERATED);
final IType type = NullableType.apply(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, Types.NULLABLE_ANY);
unapply.getParameters().add(parameter);
// = (param is This) ? unapply(param as This) : null
final InstanceOfOperator isOperator = new InstanceOfOperator(new FieldAccess(parameter), this.theClass.getClassType());
final CastOperator castOperator = new CastOperator(new FieldAccess(parameter), this.theClass.getThisType());
final IValue call = new MethodCall(position, null, Names.unapply, new ArgumentList(castOperator));
final IfStatement ifStatement = new IfStatement(isOperator, call, new NullValue());
unapply.setValue(ifStatement);
return unapply;
}
Aggregations