use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class ArgumentList method checkVarargsValue.
protected static boolean checkVarargsValue(IValue[] values, int startIndex, int endIndex, IParameter param, GenericData genericData, MarkerList markers, IContext context) {
final IValue value = values[startIndex];
if (value.checkVarargs(true)) {
values[startIndex] = convertValue(value, param, genericData, markers, context);
return false;
}
final int count = endIndex - startIndex;
final ArrayExpr arrayExpr = newArrayExpr(values, startIndex, count);
final IValue converted = convertValue(arrayExpr, param, genericData, markers, context);
values[startIndex] = converted;
return true;
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class CodeParameter method resolve.
@Override
public void resolve(MarkerList markers, IContext context) {
super.resolve(markers, context);
if (this.type == Types.UNKNOWN) {
markers.add(Markers.semanticError(this.position, "parameter.type.infer", this.name));
}
if (this.value == null) {
return;
}
this.attributes.addFlag(Modifiers.DEFAULT);
IValue value = this.value.resolve(markers, context);
final String kindName = this.getKind().getName();
final TypeChecker.MarkerSupplier markerSupplier = TypeChecker.markerSupplier(kindName + ".type.incompatible", kindName + ".type", "value.type", this.name);
value = TypeChecker.convertValue(value, this.type, null, markers, context, markerSupplier);
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class IParameter method writeDefaultValue.
default void writeDefaultValue(ClassWriter writer) {
final IValue value = this.getValue();
assert value != null;
final ICallableMember method = this.getMethod();
final IType type = this.getType();
final String name;
final int access;
if (method == null) {
name = "init$paramDefault$" + this.getInternalName();
access = Modifiers.STATIC;
} else {
name = method.getInternalName() + "$paramDefault$" + this.getInternalName();
access = (method.getAttributes().flags() & Modifiers.MEMBER_MODIFIERS) | Modifiers.STATIC;
}
final String desc = "()" + this.getDescriptor();
final String signature = "()" + this.getSignature();
final MethodWriter mw = new MethodWriterImpl(writer, writer.visitMethod(access, name, desc, signature, null));
mw.visitCode();
value.writeExpression(mw, type);
mw.visitEnd(type);
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class NamedArgumentList method writeValues.
@Override
public void writeValues(MethodWriter writer, ParameterList parameters, int startIndex) throws BytecodeException {
if (this.hasParameterOrder()) {
super.writeValues(writer, parameters, startIndex);
return;
}
final int locals = writer.localCount();
final int paramCount = parameters.size() - startIndex;
// Step 1: Associate parameters to arguments
final IParameter[] params = new IParameter[this.size];
for (int i = 0; i < paramCount; i++) {
final IParameter param = parameters.get(i + startIndex);
final int argIndex = this.findIndex(i, param.getLabel());
if (argIndex >= 0) {
params[argIndex] = param;
}
}
// Save the local indices in the targets array for later use
// Maps parameter index -> local index of stored argument
final int[] targets = new int[paramCount];
// Fill the array with -1s to mark missing values
Arrays.fill(targets, -1);
// Step 2: Write all arguments that already have parameter order
int argStartIndex = 0;
for (int i = 0; i < this.size; i++) {
IParameter param = params[i];
if (param.getIndex() == startIndex + i) {
this.values[i].writeExpression(writer, param.getCovariantType());
targets[i] = -2;
argStartIndex = i + 1;
} else {
break;
}
}
if (argStartIndex < this.size) {
for (int i = argStartIndex; i < this.size; i++) {
final IParameter parameter = params[i];
final IType parameterType = parameter.getCovariantType();
final IValue value = this.values[i];
final int localIndex = value.writeStore(writer, parameterType);
targets[parameter.getIndex() - startIndex] = localIndex;
}
// Step 4: Load the local variables in order
for (int i = 0; i < paramCount; i++) {
final IParameter parameter = parameters.get(i + startIndex);
final int target = targets[parameter.getIndex() - startIndex];
switch(target) {
case -1:
case -2:
// Value for parameter was already written in Step 2
continue;
default:
// Value for parameter exists -> load the variable
writer.visitVarInsn(parameter.getCovariantType().getLoadOpcode(), target);
}
}
}
writer.resetLocals(locals);
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class HeaderContext method resolveImplicit.
@Override
public IValue resolveImplicit(IType type) {
final IValue headerValue = this.header.resolveImplicit(type);
if (headerValue != null) {
return headerValue;
}
IValue candidate = null;
for (int i = 0; i < this.header.importCount; i++) {
final IValue value = this.header.importDeclarations[i].getContext().resolveImplicit(type);
if (value == null) {
continue;
}
if (candidate != null) {
// ambiguous
return null;
}
candidate = value;
}
return candidate;
}
Aggregations