Search in sources :

Example 1 with ImplicitNullableType

use of dyvilx.tools.compiler.ast.type.compound.ImplicitNullableType in project Dyvil by Dyvil.

the class PostfixType method resolveType.

@Override
public IType resolveType(MarkerList markers, IContext context) {
    final String unqualified = this.name.unqualified;
    final IType argument = this.arguments.get(0);
    if (unqualified.length() == 1) {
        switch(unqualified.charAt(0)) {
            case '?':
                return NullableType.apply(argument).resolveType(markers, context);
            case '!':
                return new ImplicitNullableType(argument).resolveType(markers, context);
            case '*':
                return new ReferenceType(argument).resolveType(markers, context);
            case '^':
                return new ImplicitReferenceType(argument).resolveType(markers, context);
        }
    }
    return super.resolveType(markers, context);
}
Also used : ImplicitNullableType(dyvilx.tools.compiler.ast.type.compound.ImplicitNullableType) ImplicitReferenceType(dyvilx.tools.compiler.ast.reference.ImplicitReferenceType) ImplicitReferenceType(dyvilx.tools.compiler.ast.reference.ImplicitReferenceType) ReferenceType(dyvilx.tools.compiler.ast.reference.ReferenceType) IType(dyvilx.tools.compiler.ast.type.IType)

Example 2 with ImplicitNullableType

use of dyvilx.tools.compiler.ast.type.compound.ImplicitNullableType in project Dyvil by Dyvil.

the class EnumClassMetadata method updateConstructor.

private void updateConstructor(IConstructor constructor) {
    constructor.getAttributes().addFlag(Modifiers.PRIVATE_PROTECTED);
    // Prepend parameters and set super initializer
    final CodeParameter nameParam = new CodeParameter(constructor, null, Names.name, new ImplicitNullableType(Types.STRING), AttributeList.of(Modifiers.SYNTHETIC));
    final CodeParameter ordParam = new CodeParameter(constructor, null, Names.ordinal, Types.INT, AttributeList.of(Modifiers.SYNTHETIC));
    constructor.getParameters().insert(0, nameParam);
    constructor.getParameters().insert(1, ordParam);
    final IConstructor enumConstructor = Types.ENUM_CLASS.getBody().getConstructor(0);
    final InitializerCall initializer = constructor.getInitializer();
    if (initializer == null) {
        final ArgumentList arguments = new ArgumentList(new FieldAccess(nameParam), new FieldAccess(ordParam));
        final SourcePosition position = constructor.position();
        final InitializerCall init = new InitializerCall(position, true, arguments, this.theClass.getSuperType(), enumConstructor);
        constructor.setInitializer(init);
        return;
    }
    // Prepend access to new parameters
    final ArgumentList arguments = initializer.getArguments();
    arguments.insert(0, new FieldAccess(nameParam));
    arguments.insert(1, new FieldAccess(ordParam));
}
Also used : IConstructor(dyvilx.tools.compiler.ast.constructor.IConstructor) SourcePosition(dyvil.source.position.SourcePosition) ImplicitNullableType(dyvilx.tools.compiler.ast.type.compound.ImplicitNullableType) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) CodeParameter(dyvilx.tools.compiler.ast.parameter.CodeParameter)

Aggregations

ImplicitNullableType (dyvilx.tools.compiler.ast.type.compound.ImplicitNullableType)2 SourcePosition (dyvil.source.position.SourcePosition)1 IConstructor (dyvilx.tools.compiler.ast.constructor.IConstructor)1 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)1 CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)1 ImplicitReferenceType (dyvilx.tools.compiler.ast.reference.ImplicitReferenceType)1 ReferenceType (dyvilx.tools.compiler.ast.reference.ReferenceType)1 IType (dyvilx.tools.compiler.ast.type.IType)1