use of dyvilx.tools.compiler.ast.parameter.CodeParameter in project Dyvil by Dyvil.
the class Property method initSetter.
@Override
public IMethod initSetter() {
if (this.setter != null) {
return this.setter;
}
final Name name = Name.from(this.name.unqualified + "_=", this.name.qualified + "_$eq");
this.setter = new CodeMethod(this.enclosingClass, name, Types.VOID);
this.setter.setPosition(this.position);
this.setterParameter = new CodeParameter(this.setter, this.position, Names.newValue, this.type);
this.setter.getParameters().add(this.setterParameter);
return this.setter;
}
use of dyvilx.tools.compiler.ast.parameter.CodeParameter in project Dyvil by Dyvil.
the class ICall method toLambda.
default IValue toLambda(MarkerList markers, IContext context, int wildcards) {
SourcePosition position = this.getPosition();
final IParameter[] parameters = new IParameter[wildcards];
for (int i = 0; i < wildcards; i++) {
parameters[i] = new CodeParameter(null, position, Name.fromRaw("wildcard$" + i), Types.UNKNOWN, new AttributeList());
}
int parIndex = 0;
final IValue receiver = this.getReceiver();
if (receiver != null && receiver.isPartialWildcard()) {
this.setReceiver(receiver.withLambdaParameter(parameters[parIndex++]));
}
final ArgumentList arguments = this.getArguments();
for (int i = 0, size = arguments.size(); i < size; i++) {
final IValue argument = arguments.get(i, null);
if (argument.isPartialWildcard()) {
arguments.set(i, null, argument.withLambdaParameter(parameters[parIndex++]));
}
}
final LambdaExpr lambdaExpr = new LambdaExpr(position, parameters, wildcards);
lambdaExpr.setImplicitParameters(true);
lambdaExpr.setValue(this);
return lambdaExpr.resolve(markers, context);
}
use of dyvilx.tools.compiler.ast.parameter.CodeParameter in project Dyvil by Dyvil.
the class Template method makeMainMethod.
private void makeMainMethod() {
// func main(args: [String]) -> void = new TemplateName().mainImpl(args)
final ParameterList params = this.mainMethod.getParameters();
final CodeParameter argsParam = new CodeParameter(this.mainMethod, null, Name.fromRaw("args"), new ArrayType(Types.STRING));
params.add(argsParam);
final IValue newTemplate = new ConstructorCall(null, this.templateClass.getClassType(), ArgumentList.EMPTY);
this.mainMethod.setValue(new MethodCall(null, newTemplate, Name.fromRaw("mainImpl"), new ArgumentList(new FieldAccess(argsParam))));
}
use of dyvilx.tools.compiler.ast.parameter.CodeParameter 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;
}
use of dyvilx.tools.compiler.ast.parameter.CodeParameter in project Dyvil by Dyvil.
the class EnumClassMetadata method createFromNameMethod.
private CodeMethod createFromNameMethod() {
// @BytecodeName("valueOf")
// public static func from(name: String) -> 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("name"), Types.STRING);
method.getParameters().add(parameter);
// = Enum.valueOf(class<EnumType>, name)
final MethodCall valueOfCall = new MethodCall(position, new ClassAccess(Types.ENUM), Name.fromRaw("valueOf"), new ArgumentList(new ClassOperator(this.theClass.getClassType()), new FieldAccess(parameter)));
method.setValue(valueOfCall);
return method;
}
Aggregations