Search in sources :

Example 16 with IClass

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

the class ConstructorCall method check.

@Override
public void check(MarkerList markers, IContext context) {
    this.type.check(markers, context);
    this.arguments.check(markers, context);
    if (this.type.hasTag(IType.ARRAY)) {
        return;
    }
    if (this.constructor != null) {
        final IClass iclass = this.type.getTheClass();
        if (iclass.isInterface()) {
            markers.add(Markers.semanticError(this.position, "constructor.access.abstract", this.type));
        }
        this.constructor.checkCall(markers, this.position, context, this.arguments);
    }
}
Also used : IClass(dyvilx.tools.compiler.ast.classes.IClass)

Example 17 with IClass

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

the class CodeTypeParameter method resolveTypes.

@Override
public void resolveTypes(MarkerList markers, IContext context) {
    this.attributes.resolveTypes(markers, context, this);
    if (this.lowerBound != null) {
        this.lowerBound = this.lowerBound.resolveType(markers, context);
    }
    this.upperBound = this.upperBound.resolveType(markers, context);
    this.upperBounds = getUpperBounds(this.upperBound);
    // The first upper bound is meant to be a class bound.
    IType type = this.upperBounds[0];
    IClass typeClass = type.getTheClass();
    if (typeClass != null && !typeClass.isInterface()) {
        // If the first type is a class type (not an interface), it becomes the erasure type.
        this.erasure = type;
    }
    // Check if the remaining upper bounds are interfaces
    for (int i = 1, count = this.upperBounds.length; i < count; i++) {
        type = this.upperBounds[i];
        typeClass = type.getTheClass();
        if (typeClass != null && !typeClass.isInterface()) {
            final Marker marker = Markers.semanticError(type.getPosition(), "type_parameter.bound.class");
            marker.addInfo(Markers.getSemantic("class.declaration", Util.classSignatureToString(typeClass)));
            markers.add(marker);
        }
    }
}
Also used : IClass(dyvilx.tools.compiler.ast.classes.IClass) Marker(dyvilx.tools.parsing.marker.Marker) IType(dyvilx.tools.compiler.ast.type.IType)

Example 18 with IClass

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

the class ConstructorCallParser method parseBody.

/**
 * Creates the body and initializes parsing for anonymous classes.
 *
 * @param pm
 * 	the current parsing context manager.
 */
private void parseBody(IParserManager pm) {
    final ClassConstructorCall classConstructorCall = this.call.toClassConstructor();
    this.call = classConstructorCall;
    final IClass nestedClass = classConstructorCall.getNestedClass();
    final ClassBody body = nestedClass.getBody();
    pm.pushParser(new ClassBodyParser(body), true);
    this.mode = ANONYMOUS_CLASS_END;
}
Also used : ClassBodyParser(dyvilx.tools.compiler.parser.classes.ClassBodyParser) IClass(dyvilx.tools.compiler.ast.classes.IClass) ClassConstructorCall(dyvilx.tools.compiler.ast.expression.access.ClassConstructorCall) ClassBody(dyvilx.tools.compiler.ast.classes.ClassBody)

Example 19 with IClass

use of dyvilx.tools.compiler.ast.classes.IClass 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 20 with IClass

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

the class Annotation method resolve.

@Override
public void resolve(MarkerList markers, IContext context) {
    this.arguments.resolve(markers, context);
    final IClass theClass;
    if (this.type == null || (theClass = this.type.getTheClass()) == null) {
        return;
    }
    final ParameterList parameterList = theClass.getParameters();
    for (int i = 0, count = parameterList.size(); i < count; i++) {
        final IParameter parameter = parameterList.get(i);
        final IType parameterType = parameter.getType();
        final IValue value = this.arguments.get(parameter);
        if (value == null) {
            if (parameter.getValue() == null) {
                markers.add(Markers.semanticError(this.getPosition(), "annotation.parameter.missing", this.type, parameter.getName()));
            }
            continue;
        }
        IValue typedValue = value.withType(parameterType, parameterType, markers, context);
        if (typedValue == null) {
            markers.add(TypeChecker.typeError(value, parameterType, parameterType, "annotation.parameter.type", parameter.getName()));
            continue;
        }
        typedValue = IValue.toAnnotationConstant(typedValue, markers, context);
        if (typedValue != value) {
            this.arguments.set(i, parameter.getLabel(), typedValue);
        }
    }
}
Also used : IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) IValue(dyvilx.tools.compiler.ast.expression.IValue) ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList) IClass(dyvilx.tools.compiler.ast.classes.IClass) IType(dyvilx.tools.compiler.ast.type.IType)

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