use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class Property method resolve.
@Override
public void resolve(MarkerList markers, IContext context) {
super.resolve(markers, context);
if (this.getter != null) {
this.getter.resolve(markers, context);
// Infer Type if necessary
if (this.type == Types.UNKNOWN) {
this.type = this.getter.getType();
if (this.setterParameter != null) {
this.setterParameter.setType(this.type);
}
}
}
if (this.type == Types.UNKNOWN) {
markers.add(Markers.semanticError(this.position, "property.type.infer", this.name));
}
if (this.setter != null) {
this.setter.resolve(markers, context);
}
if (this.initializer != null) {
final IContext context1 = new CombiningContext(this, context);
final IValue resolved = this.initializer.resolve(markers, context1);
this.initializer = TypeChecker.convertValue(resolved, Types.VOID, Types.VOID, markers, context1, TypeChecker.markerSupplier("property.initializer.type"));
}
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class Property method formatGetter.
private static void formatGetter(IMethod getter, String prefix, StringBuilder buffer) {
final String indent = Formatting.getIndent("property.getter.indent", prefix);
final IValue value = getter.getValue();
buffer.append('\n').append(indent);
getter.getAttributes().toInlineString(indent, buffer);
buffer.append("get");
if (value != null) {
if (Util.formatStatementList(indent, buffer, value)) {
return;
}
// Separator
if (Formatting.getBoolean("property.getter.separator.space_before")) {
buffer.append(' ');
}
buffer.append(':');
if (Formatting.getBoolean("property.getter.separator.newline_after")) {
buffer.append('\n').append(indent);
} else if (Formatting.getBoolean("property.getter.separator.space_after")) {
buffer.append(' ');
}
value.toString(indent, buffer);
}
if (Formatting.getBoolean("property.getter.semicolon")) {
buffer.append(';');
}
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class OptionalChainAware method transform.
static IValue transform(OptionalChainAware oca) {
// oca = receiver?.access
// <- oco ->
final IValue oco = oca.getReceiver();
if (oco == null || oco.valueTag() != IValue.OPTIONAL_CHAIN) {
// no transformation needed as it is actually not an optional chain
return oca;
}
final SourcePosition position = oca.getPosition();
final IValue receiver = ((OptionalChainOperator) oco).getReceiver();
// receiver is now the actual receiver of the optional chain operator
BindingIfStatement bindingIf;
if (receiver instanceof BindingIfStatement && (bindingIf = (BindingIfStatement) receiver).getElse() == NullValue.NULL) {
// safe bet that the receiver used to be an optional chain
// Perform the following transformation (the entire statement is the receiver):
// if let $0 = oldReceiver { $0.oldAccess } else null
// becomes
// if (let $0 = oldReceiver, let $1 = $0.oldAccess) { $1.access } else null
final Variable var = newVar(position, bindingIf.getThen());
bindingIf.addVariable(var);
oca.setReceiver(new FieldAccess(var));
bindingIf.setThen(oca);
return bindingIf;
}
// oca = receiver?.access, and receiver is not an optional chain
// receiver?.access
// becomes
// if let $0 = receiver { $0.access } else null
final Variable var = newVar(position, receiver);
bindingIf = new BindingIfStatement(position);
bindingIf.addVariable(var);
oca.setReceiver(new FieldAccess(var));
bindingIf.setThen(oca);
bindingIf.setElse(NullValue.NULL);
return bindingIf;
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class ExternalField method resolveConstantValue.
private void resolveConstantValue() {
if ((this.resolved & RETURN_TYPE) == 0) {
this.resolveReturnType();
}
this.resolved |= CONSTANT_VALUE;
final IValue value = IValue.fromObject(this.constantValue);
if (value != null) {
this.value = value.withType(this.type, null, null, this.getCombiningContext());
}
}
use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.
the class MethodCall method foldConstants.
@Override
public IValue foldConstants() {
if (!this.arguments.isEmpty()) {
IValue argument;
if (this.receiver != null) {
if (this.receiver.isConstant()) {
if (this.arguments.size() == 1 && (argument = this.arguments.getFirst()).isConstant()) {
// Binary Infix Operators
final IValue folded = ConstantFolder.applyInfix(this.receiver, this.name, argument);
if (folded != null) {
return folded;
}
}
} else {
this.receiver = this.receiver.foldConstants();
}
} else if (this.arguments.size() == 1 && (argument = this.arguments.getFirst()).isConstant()) {
// Unary Prefix Operators
final IValue folded = ConstantFolder.applyUnary(this.name, argument);
if (folded != null) {
return folded;
}
}
this.arguments.foldConstants();
return this;
}
if (this.receiver != null) {
if (this.receiver.isConstant()) {
// Unary Postfix Operators (and some Prefix Operators)
final IValue folded = ConstantFolder.applyUnary(this.name, this.receiver);
if (folded != null) {
return folded;
}
}
this.receiver = this.receiver.foldConstants();
}
return this;
}
Aggregations