use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class MethodCall method resolveAlternative.
protected IValue resolveAlternative(MarkerList markers, IContext context, boolean report) {
if (this.genericData != null && this.arguments == ArgumentList.EMPTY) {
final IType parentType;
if (this.receiver == null) {
parentType = null;
} else if (this.receiver.isClassAccess()) {
parentType = this.receiver.getType();
} else {
return null;
}
final IType type = new NamedGenericType(this.position, parentType, this.name, this.genericData.getTypes()).resolveType(report ? markers : null, context);
if (type == null) {
return null;
}
return new ClassAccess(this.position, type);
}
final IValue access = new FieldAccess(this.position, this.receiver, this.name).resolveAccess(markers, context);
if (access == null) {
return null;
}
// Field or Class Access available, try to resolve an apply method
final ApplyAccess call = new ApplyAccess(this.position, access, this.arguments);
call.genericData = this.genericData;
return call.resolveCall(markers, context, report);
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class InfixCall method resolveCompound.
protected static IValue resolveCompound(MarkerList markers, IContext context, SourcePosition position, IValue lhs, Name name, ArgumentList arguments) {
final IValue op = new InfixCall(position, lhs, name, arguments).resolveCall(markers, context, false);
if (op == null) {
return null;
}
final SideEffectHelper helper = new SideEffectHelper();
final IValue assignment = lhs.toCompoundAssignment(op, position, markers, context, helper);
if (assignment != null) {
return helper.finish(assignment);
}
return null;
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class AbstractMethod method toString.
@Override
public void toString(@NonNull String indent, @NonNull StringBuilder buffer) {
// Annotations and Modifiers
super.toString(indent, buffer);
// Name
buffer.append("func ").append(this.name);
// Type Parameters
if (this.typeParameters != null) {
this.typeParameters.toString(indent, buffer);
}
// Parameters
final IType thisType = this.getThisType();
this.parameters.toString(thisType == this.enclosingClass.getThisType() ? null : thisType, indent, buffer);
// Exceptions
if (this.exceptions != null && this.exceptions.size() > 0) {
final String throwsIndent;
if (Formatting.getBoolean("method.throws.newline")) {
throwsIndent = Formatting.getIndent("method.throws.indent", indent);
buffer.append('\n').append(throwsIndent).append("throws ");
} else {
throwsIndent = indent;
buffer.append(" throws ");
}
Util.astToString(throwsIndent, this.exceptions.getTypes(), this.exceptions.size(), Formatting.getSeparator("method.throws", ','), buffer);
}
// Type Ascription
if (this.type != null && this.type != Types.UNKNOWN) {
Formatting.appendSeparator(buffer, "method.type_ascription", "->");
this.type.toString(indent, buffer);
}
// Implementation
final IValue value = this.getValue();
if (value != null) {
if (Util.formatStatementList(indent, buffer, value)) {
return;
}
if (Formatting.getBoolean("method.declaration.space_before")) {
buffer.append(' ');
}
buffer.append('=');
String valuePrefix = Formatting.getIndent("method.declaration.indent", indent);
if (Formatting.getBoolean("method.declaration.newline_after")) {
buffer.append('\n').append(valuePrefix);
} else if (Formatting.getBoolean("method.declaration.space_after")) {
buffer.append(' ');
}
value.toString(indent, buffer);
}
if (Formatting.getBoolean("method.semicolon")) {
buffer.append(';');
}
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class ImplicitReferenceType method convertFrom.
@Override
public IValue convertFrom(IValue value, IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
final IValue typedValue = value.withType(this.type, typeContext, markers, context);
if (typedValue == null || !this.isConvertibleFrom(typedValue.getType())) {
return null;
}
final IValue reference = typedValue.toReferenceValue(markers, context);
if (reference != null) {
return reference;
}
markers.add(Markers.semanticError(this.getPosition(), "reference.expression.invalid"));
return typedValue;
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class BindingIfStatement method checkCondition.
@Override
protected void checkCondition(MarkerList markers, IContext context) {
final int size = this.variables.size();
for (int i = 0; i < size; i++) {
final IVariable var = this.variables.get(i);
var.check(markers, this.varContext(i, context));
final IValue value = getOptionalValue(var);
final IType type = value.getType();
if (value.isResolved() && type.isResolved() && !NullableType.isNullable(type)) {
final Marker marker = Markers.semanticError(value.getPosition(), "if.binding.nonnull");
marker.addInfo(Markers.getSemantic("value.type", type));
markers.add(marker);
}
}
super.checkCondition(markers, this.varContext(size, context));
}
Aggregations