use of dyvilx.tools.compiler.ast.statement.VariableStatement in project Dyvil by Dyvil.
the class SideEffectHelper method processValue.
public IValue processValue(IValue value) {
if (value == null || !value.hasSideEffects()) {
return value;
}
if (this.statementList == null) {
this.statementList = new StatementList();
}
final Variable variable = new Variable(value.getPosition(), Name.fromRaw("sideEffect$" + this.registered), value.getType());
variable.setValue(value);
this.statementList.add(new VariableStatement(variable));
this.statementList.addVariable(variable);
this.registered++;
return new FieldAccess(value.getPosition(), null, variable);
}
use of dyvilx.tools.compiler.ast.statement.VariableStatement in project Dyvil by Dyvil.
the class FuncDirective method convertBlock.
protected static StatementList convertBlock(StatementList block) {
final StatementList value = new StatementList();
// new StringWriter()
final ConstructorCall newStringWriter = new ConstructorCall(null, Template.LazyTypes.StringWriter, ArgumentList.EMPTY);
// let writer = new StringWriter()
final Variable writer = new Variable(Name.fromRaw("writer"), Template.LazyTypes.Writer, newStringWriter);
writer.getAttributes().addFlag(Modifiers.FINAL | Modifiers.GENERATED);
// { let writer = new StringWriter; { ... }; writer.toString }
value.add(new VariableStatement(writer));
value.add(block);
value.add(new MethodCall(null, new FieldAccess(writer), Names.toString));
return value;
}
Aggregations