Search in sources :

Example 31 with IClass

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

the class ClassOperator method toStringBuilder.

@Override
public boolean toStringBuilder(StringBuilder builder) {
    if (this.type.isPrimitive()) {
        builder.append(this.type.getName().qualified);
        return true;
    }
    IClass iClass = this.type.getTheClass();
    if (iClass == null) {
        return false;
    }
    if (iClass.isInterface()) {
        builder.append("interface ");
    } else {
        builder.append("class ");
    }
    builder.append(iClass.getFullName());
    return true;
}
Also used : IClass(dyvilx.tools.compiler.ast.classes.IClass)

Example 32 with IClass

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

the class AbstractConstructor method checkArguments.

@Override
public IType checkArguments(MarkerList markers, SourcePosition position, IContext context, IType type, ArgumentList arguments) {
    final IClass theClass = this.enclosingClass;
    if (!theClass.isTypeParametric()) {
        for (int i = 0, count = this.parameters.size(); i < count; i++) {
            arguments.checkValue(i, this.parameters.get(i), null, position, markers, context);
        }
        return type;
    }
    final IType classType = theClass.getThisType();
    final GenericData genericData = new GenericData(theClass);
    classType.inferTypes(type, genericData);
    genericData.lockAvailable();
    // Check Values and infer Types
    for (int i = 0, count = this.parameters.size(); i < count; i++) {
        arguments.checkValue(i, this.parameters.get(i), genericData, position, markers, context);
    }
    genericData.lockAvailable();
    // Check Type Var Inference and Compatibility
    final TypeParameterList typeParams = theClass.getTypeParameters();
    for (int i = 0, count = typeParams.size(); i < count; i++) {
        final ITypeParameter typeParameter = typeParams.get(i);
        final IType typeArgument = genericData.resolveType(typeParameter);
        if (typeArgument == null) {
            final IType inferredType = typeParameter.getUpperBound();
            markers.add(Markers.semantic(position, "constructor.typevar.infer", theClass.getName(), typeParameter.getName(), inferredType));
            genericData.addMapping(typeParameter, inferredType);
        } else if (!typeParameter.isAssignableFrom(typeArgument, genericData)) {
            final Marker marker = Markers.semanticError(position, "constructor.typevar.incompatible", theClass.getName(), typeParameter.getName());
            marker.addInfo(Markers.getSemantic("type.generic.argument", typeArgument));
            marker.addInfo(Markers.getSemantic("type_parameter.declaration", typeParameter));
            markers.add(marker);
        }
    }
    return classType.getConcreteType(genericData);
}
Also used : TypeParameterList(dyvilx.tools.compiler.ast.generic.TypeParameterList) ITypeParameter(dyvilx.tools.compiler.ast.generic.ITypeParameter) IClass(dyvilx.tools.compiler.ast.classes.IClass) Marker(dyvilx.tools.parsing.marker.Marker) GenericData(dyvilx.tools.compiler.ast.generic.GenericData) IType(dyvilx.tools.compiler.ast.type.IType)

Example 33 with IClass

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

the class ModifierUtil method getFlags.

public static long getFlags(IClassMember member) {
    final int flags = member.getAttributes().flags();
    int javaModifiers = flags & JAVA_MODIFIER_MASK;
    int dyvilModifiers = flags & DYVIL_MODIFIER_MASK;
    if ((flags & PRIVATE_PROTECTED) == PRIVATE_PROTECTED) {
        // for private protected members, move the private modifier
        javaModifiers &= ~PRIVATE;
        dyvilModifiers |= PRIVATE;
    }
    if (member.getElementType() == ElementType.METHOD) {
        if ((flags & STATIC_ABSTRACT) == STATIC_ABSTRACT) {
            // for static abstract methods, move the abstract modifier
            javaModifiers &= ~ABSTRACT;
            dyvilModifiers |= ABSTRACT;
        }
        if ((flags & FINAL) != 0) {
            final IClass enclosingClass = member.getEnclosingClass();
            if (enclosingClass != null && enclosingClass.isInterface()) {
                // for final interface methods, move the final modifier
                javaModifiers &= ~FINAL;
                dyvilModifiers |= FINAL;
            }
        }
    }
    return (long) dyvilModifiers << 32 | javaModifiers;
}
Also used : IClass(dyvilx.tools.compiler.ast.classes.IClass)

Example 34 with IClass

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

the class ModifierUtil method checkMethodModifiers.

public static void checkMethodModifiers(MarkerList markers, IMethod member) {
    final int flags = member.getAttributes().flags();
    final boolean hasValue = member.getValue() != null;
    final boolean isAbstract = (flags & ABSTRACT) != 0;
    final boolean isNative = (flags & NATIVE) != 0;
    // If the method does not have an implementation and is static
    if (isAbstract) {
        if (hasValue) {
            markers.add(Markers.semanticError(member.getPosition(), "modifiers.abstract.implemented", Util.memberNamed(member)));
        }
        if (isNative) {
            markers.add(Markers.semanticError(member.getPosition(), "modifiers.native.abstract", Util.memberNamed(member)));
        }
        final IClass enclosingClass = member.getEnclosingClass();
        if (!enclosingClass.isAbstract()) {
            markers.add(Markers.semanticError(member.getPosition(), "modifiers.abstract.concrete_class", Util.memberNamed(member), enclosingClass.getName()));
        }
        return;
    }
    if (hasValue) {
        if (isNative) {
            markers.add(Markers.semanticError(member.getPosition(), "modifiers.native.implemented", Util.memberNamed(member)));
        }
        return;
    }
    if (!isNative) {
        markers.add(Markers.semanticError(member.getPosition(), "modifiers.unimplemented", Util.memberNamed(member)));
    }
}
Also used : IClass(dyvilx.tools.compiler.ast.classes.IClass)

Example 35 with IClass

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

the class RootPackage method resolveInternalClass.

public IClass resolveInternalClass(String internal) {
    IClass result = this.classCache.get(internal);
    if (result != null) {
        return result;
    }
    Package pack = this;
    int nextIndex;
    int startIndex = 0;
    while ((nextIndex = internal.indexOf('/', startIndex)) >= 0) {
        pack = pack.resolvePackage(internal.substring(startIndex, nextIndex));
        startIndex = nextIndex + 1;
    }
    result = pack.resolveClass(internal.substring(startIndex));
    this.classCache.put(internal, result);
    return result;
}
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