use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class OptionalChainAware method newVar.
/**
* Creates a new variable for use in binding if statements. The lhs automatically gets wrapped in an optional unwrap
* operator.
*/
static Variable newVar(SourcePosition position, IValue lhs) {
final IValue value = new OptionalUnwrapOperator(lhs, true);
final Variable var = new Variable(position, null, value.getType(), AttributeList.of(Modifiers.FINAL));
var.setValue(value);
return var;
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class ConstructorCall method resolveArrayConstructor.
private void resolveArrayConstructor(MarkerList markers, IContext context, ArrayType arrayType) {
final IType elementType = arrayType.getElementType();
if (elementType.hasTag(IType.TYPE_VAR)) {
markers.add(Markers.semanticError(this.position, "constructor.access.array.typevar", elementType));
}
final int len = this.arguments.size();
final int dims = 1 + getDimensions(arrayType.getElementType());
if (len > dims) {
final Marker marker = Markers.semanticError(this.position, "constructor.access.array.length");
marker.addInfo(Markers.getSemantic("type.dimensions", dims));
marker.addInfo(Markers.getSemantic("constructor.access.array.count", len));
markers.add(marker);
return;
}
for (int i = 0; i < len; i++) {
final IValue value = this.arguments.get(i, null);
final IValue typed = TypeChecker.convertValue(value, Types.INT, ITypeContext.DEFAULT, markers, context, TypeChecker.markerSupplier("constructor.access.array.type"));
this.arguments.set(i, null, typed);
}
}
use of dyvilx.tools.compiler.ast.expression.IValue 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.expression.IValue in project Dyvil by Dyvil.
the class CaptureParameter method getDefaultValue.
@Override
public IValue getDefaultValue(IContext context) {
final IValue access = new FieldAccess(this.variable) {
@Override
public void writeExpression(MethodWriter writer, IType type) throws BytecodeException {
this.field.writeGetRaw(writer, this.receiver, this.lineNumber());
}
}.resolve(MarkerList.BLACKHOLE, context);
// ensures proper capture
access.checkTypes(MarkerList.BLACKHOLE, context);
return access;
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class VarargsOperator method withType.
@Override
public IValue withType(IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
final IValue typed = this.value.withType(type, typeContext, markers, context);
if (typed == null) {
return null;
}
this.value = typed;
return this;
}
Aggregations