Search in sources :

Example 6 with ConstructorCall

use of dyvilx.tools.compiler.ast.expression.access.ConstructorCall 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)

Example 7 with ConstructorCall

use of dyvilx.tools.compiler.ast.expression.access.ConstructorCall in project Dyvil by Dyvil.

the class EnumConstant method resolve.

@Override
public void resolve(MarkerList markers, IContext context) {
    final ArgumentList arguments = new ArgumentList(new StringValue(this.name.unqualified), new IntValue(this.index));
    if (this.value != null) {
        if (this.value.valueTag() == IValue.TUPLE) {
            arguments.addAll(((TupleExpr) this.value).getValues());
        } else {
            arguments.add(this.value);
        }
    }
    this.value = new ConstructorCall(this.position, this.enclosingClass.getClassType(), arguments);
    super.resolve(markers, context);
}
Also used : ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) StringValue(dyvilx.tools.compiler.ast.expression.constant.StringValue) ConstructorCall(dyvilx.tools.compiler.ast.expression.access.ConstructorCall) IntValue(dyvilx.tools.compiler.ast.expression.constant.IntValue)

Aggregations

ConstructorCall (dyvilx.tools.compiler.ast.expression.access.ConstructorCall)7 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)4 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)3 IValue (dyvilx.tools.compiler.ast.expression.IValue)2 MethodCall (dyvilx.tools.compiler.ast.expression.access.MethodCall)2 IType (dyvilx.tools.compiler.ast.type.IType)2 SourcePosition (dyvil.source.position.SourcePosition)1 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)1 IConstructor (dyvilx.tools.compiler.ast.constructor.IConstructor)1 AbstractCall (dyvilx.tools.compiler.ast.expression.access.AbstractCall)1 ClassConstructorCall (dyvilx.tools.compiler.ast.expression.access.ClassConstructorCall)1 IntValue (dyvilx.tools.compiler.ast.expression.constant.IntValue)1 StringValue (dyvilx.tools.compiler.ast.expression.constant.StringValue)1 VarargsOperator (dyvilx.tools.compiler.ast.expression.intrinsic.VarargsOperator)1 Field (dyvilx.tools.compiler.ast.field.Field)1 IField (dyvilx.tools.compiler.ast.field.IField)1 Variable (dyvilx.tools.compiler.ast.field.Variable)1 CodeMethod (dyvilx.tools.compiler.ast.method.CodeMethod)1 IMethod (dyvilx.tools.compiler.ast.method.IMethod)1 CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)1