Search in sources :

Example 1 with VariableStatement

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);
}
Also used : Variable(dyvilx.tools.compiler.ast.field.Variable) VariableStatement(dyvilx.tools.compiler.ast.statement.VariableStatement) StatementList(dyvilx.tools.compiler.ast.statement.StatementList) FieldAccess(dyvilx.tools.compiler.ast.expression.access.FieldAccess)

Example 2 with VariableStatement

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;
}
Also used : Variable(dyvilx.tools.compiler.ast.field.Variable) VariableStatement(dyvilx.tools.compiler.ast.statement.VariableStatement) StatementList(dyvilx.tools.compiler.ast.statement.StatementList) ConstructorCall(dyvilx.tools.compiler.ast.expression.access.ConstructorCall) FieldAccess(dyvilx.tools.compiler.ast.expression.access.FieldAccess) MethodCall(dyvilx.tools.compiler.ast.expression.access.MethodCall)

Aggregations

FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)2 Variable (dyvilx.tools.compiler.ast.field.Variable)2 StatementList (dyvilx.tools.compiler.ast.statement.StatementList)2 VariableStatement (dyvilx.tools.compiler.ast.statement.VariableStatement)2 ConstructorCall (dyvilx.tools.compiler.ast.expression.access.ConstructorCall)1 MethodCall (dyvilx.tools.compiler.ast.expression.access.MethodCall)1