Search in sources :

Example 6 with IClass

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

the class CompleteCommand method findInstanceMembers.

private static void findInstanceMembers(IType type, Set<IField> fields, Set<IProperty> properties, Set<IMethod> methods, String start, Set<IClass> dejaVu) {
    final IClass iclass = type.getTheClass();
    if (iclass == null || dejaVu.contains(iclass)) {
        return;
    }
    dejaVu.add(iclass);
    // Add members
    final ParameterList parameterList = iclass.getParameters();
    for (int i = 0, count = parameterList.size(); i < count; i++) {
        checkMember(fields, (IField) parameterList.get(i), start, false);
    }
    findMembers(type, fields, properties, methods, start, false);
    // Recursively scan super types
    final IType superType = iclass.getSuperType();
    if (superType != null) {
        findInstanceMembers(superType.getConcreteType(type), fields, properties, methods, start, dejaVu);
    }
    for (IType interfaceType : iclass.getInterfaces()) {
        findInstanceMembers(interfaceType.getConcreteType(type), fields, properties, methods, start, dejaVu);
    }
}
Also used : ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList) IClass(dyvilx.tools.compiler.ast.classes.IClass) IType(dyvilx.tools.compiler.ast.type.IType)

Example 7 with IClass

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

the class LambdaExpr method isType.

@Override
public boolean isType(IType type) {
    if (this.type != null && Types.isSuperType(type, this.type)) {
        return true;
    }
    final IClass interfaceClass = type.getTheClass();
    if (interfaceClass == null) {
        return false;
    }
    if (interfaceClass == Types.OBJECT_CLASS) {
        return true;
    }
    final IMethod method = interfaceClass.getFunctionalMethod();
    if (method == null) {
        return false;
    }
    final ParameterList methodParameters = method.getParameters();
    final int parameterCount = this.parameters.size();
    if (parameterCount != methodParameters.size()) {
        return false;
    }
    for (int i = 0; i < parameterCount; i++) {
        final IType lambdaParameterType = this.parameters.get(i).getCovariantType();
        if (lambdaParameterType.isUninferred()) {
            continue;
        }
        final IType methodParameterType = methodParameters.get(i).getCovariantType();
        if (!Types.isSuperType(methodParameterType, lambdaParameterType)) {
            return false;
        }
    }
    return true;
}
Also used : IClass(dyvilx.tools.compiler.ast.classes.IClass) IMethod(dyvilx.tools.compiler.ast.method.IMethod) IType(dyvilx.tools.compiler.ast.type.IType)

Example 8 with IClass

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

the class EnumConstant method check.

@Override
public void check(MarkerList markers, IContext context) {
    final IClass enclosingClass = this.getEnclosingClass();
    final IType classType = enclosingClass.getClassType();
    if (!enclosingClass.hasModifier(Modifiers.ENUM_CLASS)) {
        final Marker marker = Markers.semanticError(this.position, "field.enum.class", this.name);
        marker.addInfo(Markers.getSemantic("method.enclosing_class", classType));
        markers.add(marker);
    }
    super.check(markers, context);
}
Also used : IClass(dyvilx.tools.compiler.ast.classes.IClass) Marker(dyvilx.tools.parsing.marker.Marker) IType(dyvilx.tools.compiler.ast.type.IType)

Example 9 with IClass

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

the class Field method writeGet.

@Override
public void writeGet(@NonNull MethodWriter writer, WriteableExpression receiver, int lineNumber) throws BytecodeException {
    this.writeReceiver(writer, receiver);
    final IClass enclosingClass = this.getEnclosingClass();
    final String owner = enclosingClass.getInternalName();
    final String name = this.getInternalName();
    final String desc = this.getDescriptor();
    writer.visitLineNumber(lineNumber);
    switch(this.getAttributes().flags() & (Modifiers.STATIC | Modifiers.LAZY)) {
        case // neither static nor lazy
        0:
            writer.visitFieldInsn(Opcodes.GETFIELD, owner, name, desc);
            return;
        case Modifiers.STATIC:
            writer.visitFieldInsn(Opcodes.GETSTATIC, owner, name, desc);
            return;
        case Modifiers.LAZY:
            writer.visitMethodInsn(this.hasModifier(Modifiers.PRIVATE) ? Opcodes.INVOKESPECIAL : Opcodes.INVOKEVIRTUAL, owner, name + "$lazy", "()" + desc, this.enclosingClass.isInterface());
            return;
        case // both static and lazy
        Modifiers.STATIC | Modifiers.LAZY:
            writer.visitMethodInsn(Opcodes.INVOKESTATIC, owner, name + "$lazy", "()" + desc, enclosingClass.isInterface());
    }
}
Also used : IClass(dyvilx.tools.compiler.ast.classes.IClass)

Example 10 with IClass

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

the class ThisExpr method checkTypes.

@Override
public void checkTypes(MarkerList markers, IContext context) {
    this.type.checkType(markers, context, TypePosition.SUPER_TYPE);
    if (!context.isThisAvailable()) {
        markers.add(Markers.semanticError(this.position, "this.access.static"));
        return;
    }
    if (!this.type.isResolved()) {
        return;
    }
    final IClass theClass = this.type.getTheClass();
    this.getter = context.getAccessibleThis(theClass);
    if (this.getter == null) {
        markers.add(Markers.semanticError(this.position, "this.instance", this.type));
    }
}
Also used : IClass(dyvilx.tools.compiler.ast.classes.IClass)

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