Search in sources :

Example 56 with IType

use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.

the class ObjectClassMetadata method createInstanceField.

private Field createInstanceField() {
    final int flags = Modifiers.PUBLIC | Modifiers.CONST | (this.theClass.isImplicit() ? Modifiers.IMPLICIT : 0);
    final IType classType = this.theClass.getClassType();
    final Field field = new Field(this.theClass, Names.instance, classType, AttributeList.of(flags));
    final ConstructorCall call = new ConstructorCall(this.theClass.position(), classType, ArgumentList.EMPTY);
    field.setValue(call);
    return field;
}
Also used : IField(dyvilx.tools.compiler.ast.field.IField) Field(dyvilx.tools.compiler.ast.field.Field) ConstructorCall(dyvilx.tools.compiler.ast.expression.access.ConstructorCall) IType(dyvilx.tools.compiler.ast.type.IType)

Example 57 with IType

use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.

the class CodeClass method write.

@Override
public void write(ClassWriter writer) throws BytecodeException {
    // Header
    String signature = this.getSignature();
    String superClass = null;
    String[] interfaces = this.getInterfaceArray();
    if (this.superType != null) {
        superClass = this.superType.getInternalName();
    }
    final long flags = ModifierUtil.getFlags(this);
    int modifiers = ModifierUtil.getJavaModifiers(flags);
    if ((modifiers & Modifiers.INTERFACE) == 0) {
        modifiers |= ASMConstants.ACC_SUPER;
    }
    writer.visit(ClassFormat.CLASS_VERSION, modifiers, this.getInternalName(), signature, superClass, interfaces);
    // Source
    writer.visitSource(this.getHeader().getName() + DyvilFileType.DYVIL_EXTENSION, null);
    if (this.enclosingClass != null) {
        this.writeInnerClassInfo(writer);
    }
    // Annotations
    this.writeAnnotations(writer, flags);
    if (this.superType != null) {
        IClass iclass = this.superType.getTheClass();
        if (iclass != null) {
            iclass.writeInnerClassInfo(writer);
        }
    }
    if (this.interfaces != null) {
        for (IType type : this.interfaces) {
            final IClass iclass = type.getTheClass();
            if (iclass != null) {
                iclass.writeInnerClassInfo(writer);
            }
        }
    }
    // Compute Trait Classes
    final Set<IClass> traitClasses;
    if ((modifiers & Modifiers.INTERFACE) == 0) {
        traitClasses = new ArraySet<>();
        this.traitInit = !fillTraitClasses(this, traitClasses, true) && !traitClasses.isEmpty();
    } else {
        traitClasses = null;
    }
    for (int i = 0; i < this.compilableCount; i++) {
        this.compilables[i].write(writer);
    }
    this.metadata.write(writer);
    this.writeClassParameters(writer);
    if (this.body != null) {
        this.body.write(writer);
    }
    this.metadata.writePost(writer);
    // Create the static <clinit> method
    MethodWriter initWriter = new MethodWriterImpl(writer, writer.visitMethod(Modifiers.STATIC, "<clinit>", "()V", null, null));
    initWriter.visitCode();
    this.writeStaticInit(initWriter);
    initWriter.visitEnd(Types.VOID);
    if (traitClasses == null || traitClasses.isEmpty()) {
        return;
    }
    // Create the virtual <traitinit> method
    initWriter = new MethodWriterImpl(writer, writer.visitMethod(Modifiers.PROTECTED, TraitMetadata.INIT_NAME, "()V", null, null));
    initWriter.visitCode();
    initWriter.setLocalType(0, this.getInternalName());
    for (IClass traitClass : traitClasses) {
        final String internal = traitClass.getInternalName();
        // Load 'this'
        initWriter.visitVarInsn(Opcodes.ALOAD, 0);
        // Invoke the static <traitinit> method of the trait class
        initWriter.visitMethodInsn(Opcodes.INVOKESTATIC, internal, TraitMetadata.INIT_NAME, "(L" + internal + ";)V", true);
    }
    initWriter.visitInsn(Opcodes.RETURN);
    initWriter.visitEnd();
}
Also used : MethodWriterImpl(dyvilx.tools.compiler.backend.MethodWriterImpl) MethodWriter(dyvilx.tools.compiler.backend.MethodWriter) IType(dyvilx.tools.compiler.ast.type.IType)

Example 58 with IType

use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.

the class AnnotationExpr method writeExpression.

@Override
public void writeExpression(MethodWriter writer, IType type) throws BytecodeException {
    final StringBuilder descBuilder = new StringBuilder().append('(');
    final ArgumentList arguments = this.annotation.getArguments();
    final IClass iclass = this.annotation.getType().getTheClass();
    final ParameterList parameterList = iclass.getParameters();
    final int count = parameterList.size();
    String[] parameterNames = new String[count];
    for (int i = 0; i < count; i++) {
        final IParameter parameter = parameterList.get(i);
        final IType parameterType = parameter.getType();
        parameterNames[i] = parameter.getInternalName();
        parameterType.appendExtendedName(descBuilder);
        arguments.writeValue(i, parameter, writer);
    }
    descBuilder.append(')');
    descBuilder.append('L').append(iclass.getInternalName()).append(';');
    writer.visitInvokeDynamicInsn("_", descBuilder.toString(), ANNOTATION_METAFACTORY, (Object[]) parameterNames);
    if (type != null) {
        this.annotation.getType().writeCast(writer, type, this.lineNumber());
    }
}
Also used : IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList) IClass(dyvilx.tools.compiler.ast.classes.IClass) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) IType(dyvilx.tools.compiler.ast.type.IType)

Example 59 with IType

use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.

the class ArrayExpr method getTypeMatch.

@Override
public int getTypeMatch(IType type, IImplicitContext implicitContext) {
    final ArrayType arrayType = type.extract(ArrayType.class);
    if (arrayType == null) {
        if (type.getTheClass() == Types.OBJECT_CLASS) {
            return SUBTYPE_MATCH;
        }
        if (type.getAnnotation(LazyFields.ARRAY_CONVERTIBLE) != null) {
            return CONVERSION_MATCH;
        }
        return MISMATCH;
    }
    final IType elementType = arrayType.getElementType();
    return this.values.getTypeMatch(elementType, implicitContext);
}
Also used : ArrayType(dyvilx.tools.compiler.ast.type.compound.ArrayType) IType(dyvilx.tools.compiler.ast.type.IType)

Example 60 with IType

use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.

the class ArrayExpr method isType.

@Override
public boolean isType(IType type) {
    final ArrayType arrayType = type.extract(ArrayType.class);
    if (arrayType == null) {
        return type.getTheClass() == Types.OBJECT_CLASS || type.getAnnotation(LazyFields.ARRAY_CONVERTIBLE) != null;
    }
    final IType elementType = arrayType.getElementType();
    return this.values.isType(elementType);
}
Also used : ArrayType(dyvilx.tools.compiler.ast.type.compound.ArrayType) IType(dyvilx.tools.compiler.ast.type.IType)

Aggregations

IType (dyvilx.tools.compiler.ast.type.IType)159 IClass (dyvilx.tools.compiler.ast.classes.IClass)26 Marker (dyvilx.tools.parsing.marker.Marker)23 IValue (dyvilx.tools.compiler.ast.expression.IValue)21 TypeParameterList (dyvilx.tools.compiler.ast.generic.TypeParameterList)13 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)11 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)10 SourcePosition (dyvil.source.position.SourcePosition)9 Annotation (dyvilx.tools.compiler.ast.attribute.annotation.Annotation)9 ITypeParameter (dyvilx.tools.compiler.ast.generic.ITypeParameter)9 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)9 TypeList (dyvilx.tools.compiler.ast.type.TypeList)7 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)6 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)6 IVariable (dyvilx.tools.compiler.ast.field.IVariable)6 ArrayType (dyvilx.tools.compiler.ast.type.compound.ArrayType)6 MethodWriter (dyvilx.tools.compiler.backend.MethodWriter)6 CodeMethod (dyvilx.tools.compiler.ast.method.CodeMethod)5 CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)5 Name (dyvil.lang.Name)4