Search in sources :

Example 16 with Name

use of dyvil.lang.Name in project Dyvil by Dyvil.

the class HeaderContext method putOperator.

private void putOperator(IOperator operator) {
    if (operator.getType() != IOperator.INFIX) {
        return;
    }
    final Name name = operator.getName();
    if (this.infixOperatorMap == null) {
        this.infixOperatorMap = new IdentityHashMap<>();
        this.infixOperatorMap.put(name, operator);
        return;
    }
    final IOperator existing = this.infixOperatorMap.get(name);
    if (existing == null) {
        this.infixOperatorMap.put(name, operator);
    }
}
Also used : IOperator(dyvilx.tools.compiler.ast.expression.operator.IOperator) Name(dyvil.lang.Name)

Example 17 with Name

use of dyvil.lang.Name in project Dyvil by Dyvil.

the class StatementList method addVariable.

protected void addVariable(VariableStatement initializer, MarkerList markers, IContext context) {
    final IVariable variable = initializer.variable;
    final Name variableName = variable.getName();
    // Uninitialized Variables
    if (variable.getValue() == null) {
        variable.setValue(variable.getType().getDefaultValue());
        markers.add(Markers.semanticError(variable.getPosition(), "variable.uninitialized", variableName));
    }
    // Variable Name Shadowing
    final IDataMember dataMember = context.resolveField(variableName);
    if (dataMember != null && dataMember.isLocal() && !variable.hasModifier(Modifiers.GENERATED)) {
        markers.add(Markers.semantic(initializer.getPosition(), "variable.shadow", variableName));
    }
    // Actually add the Variable to the List (this has to happen after checking for shadowed variables)
    this.addVariable(variable);
}
Also used : IVariable(dyvilx.tools.compiler.ast.field.IVariable) IDataMember(dyvilx.tools.compiler.ast.field.IDataMember) Name(dyvil.lang.Name)

Example 18 with Name

use of dyvil.lang.Name 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 19 with Name

use of dyvil.lang.Name in project Dyvil by Dyvil.

the class PropertyReference method checkTypes.

@Override
public void checkTypes(SourcePosition position, MarkerList markers, IContext context) {
    final Name getterName = this.getterMethod.getName();
    final Name setterName = Util.addEq(getterName);
    this.setterMethod = ICall.resolveMethod(context, this.receiver, setterName, new ArgumentList(new WildcardValue(null)));
    if (this.setterMethod == null || this.setterMethod.getParameters().size() != 1) {
        markers.add(Markers.semanticError(position, "reference.property.no_setter", getterName));
    }
}
Also used : WildcardValue(dyvilx.tools.compiler.ast.expression.constant.WildcardValue) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) Name(dyvil.lang.Name)

Example 20 with Name

use of dyvil.lang.Name in project Dyvil by Dyvil.

the class ClassDeclarationParser method parse.

@Override
public void parse(IParserManager pm, IToken token) {
    int type = token.type();
    switch(this.mode) {
        case NAME:
            if (!Tokens.isIdentifier(type)) {
                pm.report(token, "class.identifier");
                return;
            }
            final Name name = token.nameValue();
            if (name.qualified.indexOf('$') >= 0) {
                pm.report(Markers.syntaxError(token, "class.identifier.invalid", name, name.qualified));
            }
            this.theClass = this.consumer.createClass(token.raw(), name, this.classAttributes);
            this.mode = GENERICS;
            return;
        case GENERICS:
            if (type == BaseSymbols.SEMICOLON && token.isInferred() && TypeParser.isGenericStart(token.next())) {
                // allow an implicit semicolon / line break between name and generic argument list
                return;
            }
            if (TypeParser.isGenericStart(token, type)) {
                pm.splitJump(token, 1);
                pm.pushParser(new TypeParameterListParser(this.theClass));
                this.mode = GENERICS_END;
                return;
            }
        // Fallthrough
        case PARAMETERS:
            final Modifier modifier = ModifierParser.parseModifier(token, pm);
            if (modifier != null) {
                this.theClass.getConstructorAttributes().add(modifier);
                return;
            }
            if (type == DyvilSymbols.AT) {
                final Annotation annotation = new CodeAnnotation(token.raw());
                this.theClass.getConstructorAttributes().add(annotation);
                pm.pushParser(new AnnotationParser(annotation));
                return;
            }
            if (type == BaseSymbols.OPEN_PARENTHESIS) {
                pm.pushParser(new ParameterListParser(this.theClass).withFlags(ParameterListParser.ALLOW_PROPERTIES));
                this.mode = PARAMETERS_END;
                return;
            }
        // Fallthrough
        case EXTENDS:
            if (type == DyvilKeywords.EXTENDS) {
                if (this.theClass.isInterface()) {
                    pm.pushParser(new TypeListParser(this));
                    this.mode = BODY;
                    return;
                }
                pm.pushParser(new TypeParser(this));
                this.mode = EXTENDS_PARAMETERS;
                return;
            }
        // Fallthrough
        case IMPLEMENTS:
            if (type == DyvilKeywords.IMPLEMENTS) {
                pm.pushParser(new TypeListParser(this));
                this.mode = BODY;
                if (this.theClass.isInterface()) {
                    pm.report(token, "class.interface.implements");
                    return;
                }
                return;
            }
        // Fallthrough
        case BODY:
            if (type == BaseSymbols.OPEN_CURLY_BRACKET) {
                ClassBody body = new ClassBody(this.theClass);
                this.theClass.setBody(body);
                pm.pushParser(new ClassBodyParser(body), true);
                this.mode = BODY_END;
                return;
            }
            if (BaseSymbols.isTerminator(type)) {
                if (token.isInferred()) {
                    switch(token.next().type()) {
                        case DyvilKeywords.EXTENDS:
                            this.mode = EXTENDS;
                            return;
                        case DyvilKeywords.IMPLEMENTS:
                            this.mode = IMPLEMENTS;
                            return;
                        case BaseSymbols.OPEN_SQUARE_BRACKET:
                            this.mode = GENERICS;
                            return;
                        case BaseSymbols.OPEN_PARENTHESIS:
                            this.mode = PARAMETERS;
                            return;
                    }
                }
                pm.popParser(true);
                this.consumer.addClass(this.theClass);
                return;
            }
            this.mode = BODY_END;
            pm.report(token, "class.body.separator");
            return;
        case GENERICS_END:
            this.mode = PARAMETERS;
            if (TypeParser.isGenericEnd(token, type)) {
                pm.splitJump(token, 1);
                return;
            }
            pm.reparse();
            pm.report(token, "generic.close_angle");
            return;
        case PARAMETERS_END:
            this.mode = EXTENDS;
            if (type != BaseSymbols.CLOSE_PARENTHESIS) {
                pm.reparse();
                pm.report(token, "class.parameters.close_paren");
            }
            return;
        case BODY_END:
            pm.popParser();
            this.consumer.addClass(this.theClass);
            if (type != BaseSymbols.CLOSE_CURLY_BRACKET) {
                pm.reparse();
                pm.report(token, "class.body.close_brace");
            }
            return;
        case EXTENDS_PARAMETERS_END:
            this.mode = IMPLEMENTS;
            if (type != BaseSymbols.CLOSE_PARENTHESIS) {
                pm.reparse();
                pm.report(token, "class.extends.close_paren");
            }
            return;
        case EXTENDS_PARAMETERS:
            if (type == BaseSymbols.OPEN_PARENTHESIS) {
                ArgumentListParser.parseArguments(pm, token.next(), this.theClass::setSuperConstructorArguments);
                this.mode = EXTENDS_PARAMETERS_END;
                return;
            }
            this.mode = IMPLEMENTS;
            pm.reparse();
    }
}
Also used : CodeAnnotation(dyvilx.tools.compiler.ast.attribute.annotation.CodeAnnotation) AnnotationParser(dyvilx.tools.compiler.parser.annotation.AnnotationParser) TypeParser(dyvilx.tools.compiler.parser.type.TypeParser) ParameterListParser(dyvilx.tools.compiler.parser.method.ParameterListParser) TypeParameterListParser(dyvilx.tools.compiler.parser.type.TypeParameterListParser) TypeListParser(dyvilx.tools.compiler.parser.type.TypeListParser) Modifier(dyvilx.tools.compiler.ast.attribute.modifiers.Modifier) TypeParameterListParser(dyvilx.tools.compiler.parser.type.TypeParameterListParser) Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation) CodeAnnotation(dyvilx.tools.compiler.ast.attribute.annotation.CodeAnnotation) Name(dyvil.lang.Name) ClassBody(dyvilx.tools.compiler.ast.classes.ClassBody)

Aggregations

Name (dyvil.lang.Name)33 Annotation (dyvilx.tools.compiler.ast.attribute.annotation.Annotation)4 CodeAnnotation (dyvilx.tools.compiler.ast.attribute.annotation.CodeAnnotation)4 AnnotationParser (dyvilx.tools.compiler.parser.annotation.AnnotationParser)4 TypeParser (dyvilx.tools.compiler.parser.type.TypeParser)4 IClass (dyvilx.tools.compiler.ast.classes.IClass)3 IField (dyvilx.tools.compiler.ast.field.IField)3 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)3 IType (dyvilx.tools.compiler.ast.type.IType)3 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)2 Modifier (dyvilx.tools.compiler.ast.attribute.modifiers.Modifier)2 IValue (dyvilx.tools.compiler.ast.expression.IValue)2 IOperator (dyvilx.tools.compiler.ast.expression.operator.IOperator)2 IDataMember (dyvilx.tools.compiler.ast.field.IDataMember)2 IProperty (dyvilx.tools.compiler.ast.field.IProperty)2 IMethod (dyvilx.tools.compiler.ast.method.IMethod)2 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)2 CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)2 NamedType (dyvilx.tools.compiler.ast.type.raw.NamedType)2 ExpressionParser (dyvilx.tools.compiler.parser.expression.ExpressionParser)2