Search in sources :

Example 26 with IClass

use of dyvilx.tools.compiler.ast.classes.IClass in project Dyvil by Dyvil.

the class TypeParameter method appendSignature.

@Override
public void appendSignature(StringBuilder buffer) {
    buffer.append(this.name).append(':');
    if (this.upperBounds == null) {
        buffer.append("Ljava/lang/Object;");
        return;
    }
    final IClass theClass = this.upperBounds[0].getTheClass();
    if (theClass != null && theClass.isInterface()) {
        // If the first type is not an interface type, we append two colons
        buffer.append(':');
    }
    this.upperBounds[0].appendSignature(buffer, false);
    for (int i = 1, count = this.upperBounds.length; i < count; i++) {
        buffer.append(':');
        this.upperBounds[i].appendSignature(buffer, false);
    }
}
Also used : IClass(dyvilx.tools.compiler.ast.classes.IClass)

Example 27 with IClass

use of dyvilx.tools.compiler.ast.classes.IClass in project Dyvil by Dyvil.

the class HeaderContext method getVisibility.

@Override
public byte getVisibility(IClassMember member) {
    IClass iclass = member.getEnclosingClass();
    int access = member.getAccessLevel();
    if ((access & Modifiers.INTERNAL) != 0) {
        if (iclass instanceof ExternalClass) {
            return INTERNAL;
        }
        // Clear the INTERNAL bit by ANDing with 0b1111
        access &= 0b1111;
    }
    switch(access) {
        case Modifiers.PUBLIC:
            return VISIBLE;
        case Modifiers.PROTECTED:
        case Modifiers.PACKAGE:
            IHeaderUnit header = iclass.getHeader();
            if (header != null && (header == this || this.pack == header.getPackage())) {
                return VISIBLE;
            }
        // Fallthrough
        case Modifiers.PRIVATE:
        case Modifiers.PRIVATE_PROTECTED:
        default:
            return INVISIBLE;
    }
}
Also used : IClass(dyvilx.tools.compiler.ast.classes.IClass) ExternalClass(dyvilx.tools.compiler.ast.external.ExternalClass)

Example 28 with IClass

use of dyvilx.tools.compiler.ast.classes.IClass in project Dyvil by Dyvil.

the class SpecialIntrinsicData method visitMethodInsn.

private static void visitMethodInsn(MethodWriter writer, int opcode, String owner, String name, String desc) {
    final boolean isInterface;
    switch(opcode) {
        case // invokeINTERFACE -> definitely an interface
        Opcodes.INVOKEINTERFACE:
            isInterface = true;
            break;
        case Opcodes.INVOKESPECIAL:
        case // private or virtual -> can't be an interface
        Opcodes.INVOKEVIRTUAL:
            isInterface = false;
            break;
        // check the class
        case Opcodes.INVOKESTATIC:
        default:
            final IClass iclass = Package.rootPackage.resolveInternalClass(owner);
            isInterface = iclass != null && iclass.isInterface();
            break;
    }
    writer.visitMethodInsn(opcode, owner, name, desc, isInterface);
}
Also used : IClass(dyvilx.tools.compiler.ast.classes.IClass)

Example 29 with IClass

use of dyvilx.tools.compiler.ast.classes.IClass in project Dyvil by Dyvil.

the class TupleSurrogate method writeJumpOnMismatch.

@Override
public void writeJumpOnMismatch(MethodWriter writer, int varIndex, Label target) throws BytecodeException {
    varIndex = Pattern.ensureVar(writer, varIndex);
    final int lineNumber = this.lineNumber();
    final IType tupleType = this.getType();
    final IClass tupleClass = tupleType.getTheClass();
    final TypeParameterList typeParameters = tupleClass.getTypeParameters();
    final String internalTupleClassName = tupleType.getInternalName();
    for (int i = 0; i < this.patternCount; i++) {
        if (this.patterns[i].isWildcard()) {
            // Skip wildcard patterns
            continue;
        }
        writer.visitVarInsn(Opcodes.ALOAD, varIndex);
        writer.visitFieldInsn(Opcodes.GETFIELD, internalTupleClassName, "_" + (i + 1), "Ljava/lang/Object;");
        final IType targetType = Types.resolveTypeSafely(tupleType, typeParameters.get(i));
        Types.OBJECT.writeCast(writer, targetType, lineNumber);
        this.patterns[i].writeJumpOnMismatch(writer, -1, target);
    }
}
Also used : TypeParameterList(dyvilx.tools.compiler.ast.generic.TypeParameterList) IClass(dyvilx.tools.compiler.ast.classes.IClass) IType(dyvilx.tools.compiler.ast.type.IType)

Example 30 with IClass

use of dyvilx.tools.compiler.ast.classes.IClass in project Dyvil by Dyvil.

the class UnapplyPattern method withType.

@Override
public Pattern withType(IType type, MarkerList markers) {
    // PatternType.unapply(_ : MatchedType)
    final IClass matchClass = this.type.getTheClass();
    if (matchClass == null) {
        return null;
    }
    final MethodCall methodCall = new MethodCall(this.position, new ClassAccess(this.type), Names.unapply, new ArgumentList(new DummyValue(type)));
    final IValue resolvedCall = methodCall.resolveCall(MarkerList.BLACKHOLE, matchClass, false);
    return resolvedCall != null && this.withMethod(type, resolvedCall, markers) ? this : null;
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) ClassAccess(dyvilx.tools.compiler.ast.expression.access.ClassAccess) IClass(dyvilx.tools.compiler.ast.classes.IClass) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) MethodCall(dyvilx.tools.compiler.ast.expression.access.MethodCall) DummyValue(dyvilx.tools.compiler.ast.expression.DummyValue)

Aggregations

IClass (dyvilx.tools.compiler.ast.classes.IClass)57 IType (dyvilx.tools.compiler.ast.type.IType)23 Marker (dyvilx.tools.parsing.marker.Marker)9 TypeParameterList (dyvilx.tools.compiler.ast.generic.TypeParameterList)6 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)5 Package (dyvilx.tools.compiler.ast.structure.Package)5 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)4 Name (dyvil.lang.Name)3 IValue (dyvilx.tools.compiler.ast.expression.IValue)3 ITypeParameter (dyvilx.tools.compiler.ast.generic.ITypeParameter)3 IHeaderUnit (dyvilx.tools.compiler.ast.header.IHeaderUnit)3 ClassBody (dyvilx.tools.compiler.ast.classes.ClassBody)2 IConstructor (dyvilx.tools.compiler.ast.constructor.IConstructor)2 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)2 TypeList (dyvilx.tools.compiler.ast.type.TypeList)2 ITypeAlias (dyvilx.tools.compiler.ast.type.alias.ITypeAlias)2 PackageType (dyvilx.tools.compiler.ast.type.raw.PackageType)2 ResolvedTypeVarType (dyvilx.tools.compiler.ast.type.typevar.ResolvedTypeVarType)2 Handle (dyvilx.tools.asm.Handle)1 Annotation (dyvilx.tools.compiler.ast.attribute.annotation.Annotation)1