Search in sources :

Example 1 with MemberKind

use of dyvilx.tools.compiler.ast.member.MemberKind in project Dyvil by Dyvil.

the class StatementList method addMethod.

protected void addMethod(MemberStatement memberStatement, MarkerList markers) {
    final IClassMember member = memberStatement.member;
    final MemberKind memberKind = member.getKind();
    if (memberKind != MemberKind.METHOD) {
        markers.add(Markers.semantic(member.getPosition(), "statementlist.declaration.invalid", Util.memberNamed(member)));
        return;
    }
    final IMethod method = (IMethod) member;
    if (this.methods == null) {
        this.methods = new ArrayList<>();
        this.methods.add(method);
        return;
    }
    final Name methodName = method.getName();
    final int parameterCount = method.getParameters().size();
    final String desc = method.getDescriptor();
    for (IMethod candidate : this.methods) {
        if (// same name
        candidate.getName() == methodName && candidate.getParameters().size() == parameterCount && candidate.getDescriptor().equals(desc)) {
            markers.add(Markers.semanticError(memberStatement.getPosition(), "method.duplicate", methodName, desc));
        }
    }
    this.methods.add(method);
}
Also used : MemberKind(dyvilx.tools.compiler.ast.member.MemberKind) IMethod(dyvilx.tools.compiler.ast.method.IMethod) IClassMember(dyvilx.tools.compiler.ast.member.IClassMember) Name(dyvil.lang.Name)

Example 2 with MemberKind

use of dyvilx.tools.compiler.ast.member.MemberKind in project Dyvil by Dyvil.

the class ModifierUtil method checkModifiers.

public static void checkModifiers(IMember member, MarkerList markers) {
    final AttributeList attributes = member.getAttributes();
    final MemberKind memberKind = member.getKind();
    final int defaultAccess = memberKind.getDefaultAccess(member);
    StringBuilder errorBuilder = null;
    for (Attribute modifier : attributes) {
        if (!memberKind.isAttributeAllowed(modifier)) {
            if (errorBuilder == null) {
                errorBuilder = new StringBuilder();
            } else {
                errorBuilder.append(", ");
            }
            modifier.toString(errorBuilder);
        }
        final int visibility = modifier.flags() & Modifiers.VISIBILITY_MODIFIERS;
        if (visibility != 0 && visibility == defaultAccess) {
            markers.add(Markers.semantic(member.getPosition(), "modifiers.visibility.default", Util.memberNamed(member), ModifierUtil.accessModifiersToString(visibility)));
        }
    }
    if (errorBuilder != null) {
        markers.add(Markers.semanticError(member.getPosition(), "modifiers.illegal", Util.memberNamed(member), errorBuilder.toString()));
    }
    if (!attributes.hasAnyFlag(Modifiers.VISIBILITY_MODIFIERS)) {
        // If there is no explicit or implicit visibility modifier already, add the default one
        attributes.addFlag(defaultAccess);
    }
}
Also used : MemberKind(dyvilx.tools.compiler.ast.member.MemberKind) Attribute(dyvilx.tools.compiler.ast.attribute.Attribute) AttributeList(dyvilx.tools.compiler.ast.attribute.AttributeList)

Aggregations

MemberKind (dyvilx.tools.compiler.ast.member.MemberKind)2 Name (dyvil.lang.Name)1 Attribute (dyvilx.tools.compiler.ast.attribute.Attribute)1 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)1 IClassMember (dyvilx.tools.compiler.ast.member.IClassMember)1 IMethod (dyvilx.tools.compiler.ast.method.IMethod)1