Search in sources :

Example 6 with IDataMember

use of dyvilx.tools.compiler.ast.field.IDataMember in project Dyvil by Dyvil.

the class CaseClasses method writeToString.

public static void writeToString(MethodWriter writer, IClass theClass) throws BytecodeException {
    // ----- StringBuilder Constructor -----
    writer.visitTypeInsn(NEW, "java/lang/StringBuilder");
    writer.visitInsn(DUP);
    // Call the StringBuilder(String) constructor with the "[ClassName]("
    // argument
    writer.visitLdcInsn(theClass.getName() + "(");
    writer.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V", false);
    // ----- Class Parameters -----
    final ParameterList parameters = theClass.getParameters();
    for (int i = 0, count = parameters.size(); i < count; i++) {
        final IDataMember parameter = parameters.get(i);
        IType type = parameter.getType();
        // Get the parameter value
        writer.visitVarInsn(ALOAD, 0);
        parameter.writeGet(writer, null, 0);
        writeStringAppend(writer, type);
        if (i + 1 < count) {
            // Separator Comma
            writer.visitLdcInsn(", ");
            writer.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
        }
    }
    // ----- Append Closing Parenthesis -----
    writer.visitLdcInsn(")");
    // Write the call to the StringBuilder#append(String) method
    writer.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
    // ----- ToString -----
    // Write the call to the StringBuilder#toString() method
    writer.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false);
    // Write the return
    writer.visitInsn(ARETURN);
}
Also used : ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList) IDataMember(dyvilx.tools.compiler.ast.field.IDataMember) IType(dyvilx.tools.compiler.ast.type.IType)

Example 7 with IDataMember

use of dyvilx.tools.compiler.ast.field.IDataMember in project Dyvil by Dyvil.

the class FieldAssignment method resolveAsField.

@Override
protected IValue resolveAsField(IValue receiver, MarkerList markers, IContext context) {
    final IDataMember field = ICall.resolveField(context, receiver, this.name);
    if (field == null) {
        return null;
    }
    this.receiver = receiver;
    this.field = field;
    this.capture(markers, context);
    return this;
}
Also used : IDataMember(dyvilx.tools.compiler.ast.field.IDataMember)

Example 8 with IDataMember

use of dyvilx.tools.compiler.ast.field.IDataMember in project Dyvil by Dyvil.

the class ExternalClass method resolveField.

@Override
public IDataMember resolveField(Name name) {
    final IParameter parameter = this.resolveClassParameter(name);
    if (parameter != null) {
        return parameter;
    }
    // Own fields
    IDataMember field = this.body.getField(name);
    if (field != null) {
        return field;
    }
    this.resolveSuperTypes();
    // Inherited Fields
    if (this.superType != null) {
        field = this.superType.resolveField(name);
        if (field != null) {
            return field;
        }
    }
    return null;
}
Also used : IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) IDataMember(dyvilx.tools.compiler.ast.field.IDataMember)

Example 9 with IDataMember

use of dyvilx.tools.compiler.ast.field.IDataMember in project Dyvil by Dyvil.

the class EnumSurrogate method withType.

@Override
public Pattern withType(IType type, MarkerList markers) {
    if (this.dataMember == null) {
        final IDataMember dataMember = type.resolveField(this.name);
        if (dataMember == null) {
            return null;
        }
        this.dataMember = dataMember;
    }
    return super.withType(type, markers);
}
Also used : IDataMember(dyvilx.tools.compiler.ast.field.IDataMember)

Example 10 with IDataMember

use of dyvilx.tools.compiler.ast.field.IDataMember in project Dyvil by Dyvil.

the class ObjectSurrogate method resolve.

@Override
public Pattern resolve(MarkerList markers, IContext context) {
    if (this.type.typeTag() == IType.NAMED) {
        NamedType namedType = (NamedType) this.type;
        final Name name = namedType.getName();
        IType parent = namedType.getParent();
        if (parent != null) {
            parent = parent.resolveType(markers, context);
            namedType.setParent(parent);
            IDataMember dataMember = parent.resolveField(name);
            if (dataMember != null) {
                return new FieldPattern(this.position, dataMember).resolve(markers, context);
            }
        } else {
            IDataMember dataMember = context.resolveField(name);
            if (dataMember != null) {
                return new FieldPattern(this.position, dataMember).resolve(markers, context);
            }
        }
    }
    this.type = this.type.resolveType(markers, context);
    final IClass theClass = this.type.getTheClass();
    if (theClass != null && !theClass.hasModifier(Modifiers.OBJECT_CLASS)) {
        markers.add(Markers.semanticError(this.position, "pattern.object", theClass.getName()));
    }
    return this;
}
Also used : NamedType(dyvilx.tools.compiler.ast.type.raw.NamedType) IClass(dyvilx.tools.compiler.ast.classes.IClass) IDataMember(dyvilx.tools.compiler.ast.field.IDataMember) Name(dyvil.lang.Name) IType(dyvilx.tools.compiler.ast.type.IType)

Aggregations

IDataMember (dyvilx.tools.compiler.ast.field.IDataMember)10 Name (dyvil.lang.Name)2 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)2 IType (dyvilx.tools.compiler.ast.type.IType)2 SourcePosition (dyvil.source.position.SourcePosition)1 IClass (dyvilx.tools.compiler.ast.classes.IClass)1 StringInterpolationExpr (dyvilx.tools.compiler.ast.expression.StringInterpolationExpr)1 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)1 EnumValue (dyvilx.tools.compiler.ast.expression.constant.EnumValue)1 StringValue (dyvilx.tools.compiler.ast.expression.constant.StringValue)1 IVariable (dyvilx.tools.compiler.ast.field.IVariable)1 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)1 NamedType (dyvilx.tools.compiler.ast.type.raw.NamedType)1