Search in sources :

Example 1 with AttributeList

use of dyvilx.tools.compiler.ast.attribute.AttributeList in project Dyvil by Dyvil.

the class REPLContext method initMember.

private void initMember(IClassMember member) {
    member.setEnclosingClass(this.currentClass);
    // Ensure public & static
    final AttributeList modifiers = member.getAttributes();
    if ((modifiers.flags() & Modifiers.VISIBILITY_MODIFIERS) == 0) {
        modifiers.addFlag(Modifiers.PUBLIC);
    }
    modifiers.addFlag(Modifiers.STATIC);
}
Also used : AttributeList(dyvilx.tools.compiler.ast.attribute.AttributeList)

Example 2 with AttributeList

use of dyvilx.tools.compiler.ast.attribute.AttributeList in project Dyvil by Dyvil.

the class VarDirectiveParser method parse.

@Override
public void parse(IParserManager pm, IToken token) {
    final int type = token.type();
    switch(this.mode) {
        case KEYWORD:
            AttributeList attributes = new AttributeList();
            switch(type) {
                case GenSrcSymbols.VAR:
                    break;
                case GenSrcSymbols.CONST:
                case GenSrcSymbols.LET:
                    attributes.addFlag(Modifiers.FINAL);
                    break;
                default:
                    pm.report(token, "var.declarator");
                    return;
            }
            this.mode = OPEN_PAREN;
            return;
        case OPEN_PAREN:
            if (type != BaseSymbols.OPEN_PARENTHESIS) {
                this.directives.add(this.varDirective);
                pm.popParser(true);
                return;
            }
            pm.pushParser(new DataMemberParser<>(this).withFlags(DataMemberParser.PARSE_VALUE));
            this.mode = CLOSE_PAREN;
            return;
        case CLOSE_PAREN:
            if (type != BaseSymbols.CLOSE_PARENTHESIS) {
                pm.report(token, "var.close_paren");
                return;
            }
            this.mode = BODY;
            return;
        case BODY:
            if (type != BaseSymbols.OPEN_CURLY_BRACKET) {
                this.directives.add(this.varDirective);
                pm.popParser(true);
                return;
            }
            final StatementList body = new StatementList();
            pm.pushParser(new BlockParser(body));
            this.varDirective.setBlock(body);
            this.mode = BODY_END;
            return;
        case BODY_END:
            assert type == BaseSymbols.CLOSE_CURLY_BRACKET;
            this.directives.add(this.varDirective);
            pm.popParser();
    }
}
Also used : AttributeList(dyvilx.tools.compiler.ast.attribute.AttributeList) DataMemberParser(dyvilx.tools.compiler.parser.classes.DataMemberParser) StatementList(dyvilx.tools.compiler.ast.statement.StatementList)

Example 3 with AttributeList

use of dyvilx.tools.compiler.ast.attribute.AttributeList in project Dyvil by Dyvil.

the class Property method resolveTypes.

@Override
public void resolveTypes(MarkerList markers, IContext context) {
    super.resolveTypes(markers, context);
    if (this.getter != null) {
        final AttributeList getterAttributes = this.getter.getAttributes();
        // Add <generated> Modifier and copy Property Modifiers
        getterAttributes.addFlag(Modifiers.GENERATED);
        Field.copyModifiers(this.attributes, getterAttributes);
        this.getter.setType(this.type);
        this.getter.resolveTypes(markers, context);
    }
    if (this.setter != null) {
        final AttributeList setterModifiers = this.setter.getAttributes();
        // Add <generated> Modifier and copy Property Modifiers
        setterModifiers.addFlag(Modifiers.GENERATED);
        Field.copyModifiers(this.attributes, setterModifiers);
        this.setterParameter.setPosition(this.setter.getPosition());
        this.setterParameter.setType(this.type);
        this.setter.resolveTypes(markers, context);
    }
    if (this.initializer != null) {
        this.initializer.resolveTypes(markers, new CombiningContext(this, context));
    }
}
Also used : AttributeList(dyvilx.tools.compiler.ast.attribute.AttributeList) CombiningContext(dyvilx.tools.compiler.ast.context.CombiningContext)

Example 4 with AttributeList

use of dyvilx.tools.compiler.ast.attribute.AttributeList in project Dyvil by Dyvil.

the class ICall method toLambda.

default IValue toLambda(MarkerList markers, IContext context, int wildcards) {
    SourcePosition position = this.getPosition();
    final IParameter[] parameters = new IParameter[wildcards];
    for (int i = 0; i < wildcards; i++) {
        parameters[i] = new CodeParameter(null, position, Name.fromRaw("wildcard$" + i), Types.UNKNOWN, new AttributeList());
    }
    int parIndex = 0;
    final IValue receiver = this.getReceiver();
    if (receiver != null && receiver.isPartialWildcard()) {
        this.setReceiver(receiver.withLambdaParameter(parameters[parIndex++]));
    }
    final ArgumentList arguments = this.getArguments();
    for (int i = 0, size = arguments.size(); i < size; i++) {
        final IValue argument = arguments.get(i, null);
        if (argument.isPartialWildcard()) {
            arguments.set(i, null, argument.withLambdaParameter(parameters[parIndex++]));
        }
    }
    final LambdaExpr lambdaExpr = new LambdaExpr(position, parameters, wildcards);
    lambdaExpr.setImplicitParameters(true);
    lambdaExpr.setValue(this);
    return lambdaExpr.resolve(markers, context);
}
Also used : IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) IValue(dyvilx.tools.compiler.ast.expression.IValue) AttributeList(dyvilx.tools.compiler.ast.attribute.AttributeList) SourcePosition(dyvil.source.position.SourcePosition) LambdaExpr(dyvilx.tools.compiler.ast.expression.LambdaExpr) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) CodeParameter(dyvilx.tools.compiler.ast.parameter.CodeParameter)

Example 5 with AttributeList

use of dyvilx.tools.compiler.ast.attribute.AttributeList in project Dyvil by Dyvil.

the class PropertyBodyParser method configureMethod.

private void configureMethod(IMethod method, IToken token) {
    method.setPosition(token.raw());
    method.setAttributes(this.attributes);
    this.attributes = new AttributeList();
}
Also used : AttributeList(dyvilx.tools.compiler.ast.attribute.AttributeList)

Aggregations

AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)20 SourcePosition (dyvil.source.position.SourcePosition)7 IValue (dyvilx.tools.compiler.ast.expression.IValue)6 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)6 IType (dyvilx.tools.compiler.ast.type.IType)6 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)5 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)4 CodeMethod (dyvilx.tools.compiler.ast.method.CodeMethod)4 CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)4 Name (dyvil.lang.Name)2 LambdaExpr (dyvilx.tools.compiler.ast.expression.LambdaExpr)2 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)2 StatementList (dyvilx.tools.compiler.ast.statement.StatementList)2 ArrayType (dyvilx.tools.compiler.ast.type.compound.ArrayType)2 IToken (dyvilx.tools.parsing.token.IToken)2 Reified (dyvil.annotation.Reified)1 Modifiers (dyvil.reflect.Modifiers)1 Opcodes (dyvil.reflect.Opcodes)1 AnnotatableVisitor (dyvilx.tools.asm.AnnotatableVisitor)1 AnnotationVisitor (dyvilx.tools.asm.AnnotationVisitor)1