Search in sources :

Example 1 with Field

use of dyvilx.tools.compiler.ast.field.Field in project Dyvil by Dyvil.

the class ObjectClassMetadata method createInstanceField.

private Field createInstanceField() {
    final int flags = Modifiers.PUBLIC | Modifiers.CONST | (this.theClass.isImplicit() ? Modifiers.IMPLICIT : 0);
    final IType classType = this.theClass.getClassType();
    final Field field = new Field(this.theClass, Names.instance, classType, AttributeList.of(flags));
    final ConstructorCall call = new ConstructorCall(this.theClass.position(), classType, ArgumentList.EMPTY);
    field.setValue(call);
    return field;
}
Also used : IField(dyvilx.tools.compiler.ast.field.IField) Field(dyvilx.tools.compiler.ast.field.Field) ConstructorCall(dyvilx.tools.compiler.ast.expression.access.ConstructorCall) IType(dyvilx.tools.compiler.ast.type.IType)

Example 2 with Field

use of dyvilx.tools.compiler.ast.field.Field in project Dyvil by Dyvil.

the class ObjectClassMetadata method resolveTypesGenerate.

@Override
public void resolveTypesGenerate(MarkerList markers, IContext context) {
    super.resolveTypesGenerate(markers, context);
    if ((this.members & CONSTRUCTOR) == 0) {
        this.constructor.setAttributes(AttributeList.of(Modifiers.PRIVATE | Modifiers.GENERATED));
    }
    if ((this.members & INSTANCE_FIELD) == 0) {
        final Field field = this.createInstanceField();
        this.instanceField = field;
        this.theClass.createBody().addDataMember(field);
    } else {
        markers.add(Markers.semanticError(this.instanceField.getPosition(), "class.object.field", this.theClass.getName()));
    }
}
Also used : IField(dyvilx.tools.compiler.ast.field.IField) Field(dyvilx.tools.compiler.ast.field.Field)

Example 3 with Field

use of dyvilx.tools.compiler.ast.field.Field in project Dyvil by Dyvil.

the class EnumClassMetadata method createValuesField.

private Field createValuesField() {
    final SourcePosition position = this.theClass.position();
    final ArrayType type = new ArrayType(this.theClass.getClassType(), Mutability.IMMUTABLE);
    final AttributeList attributes = AttributeList.of(Modifiers.PRIVATE | Modifiers.CONST | Modifiers.SYNTHETIC);
    final Field field = new Field(this.theClass, position, Names.$VALUES, type, attributes);
    field.setValue(this.createValuesArray());
    return field;
}
Also used : ArrayType(dyvilx.tools.compiler.ast.type.compound.ArrayType) IField(dyvilx.tools.compiler.ast.field.IField) Field(dyvilx.tools.compiler.ast.field.Field) AttributeList(dyvilx.tools.compiler.ast.attribute.AttributeList) SourcePosition(dyvil.source.position.SourcePosition)

Aggregations

Field (dyvilx.tools.compiler.ast.field.Field)3 IField (dyvilx.tools.compiler.ast.field.IField)3 SourcePosition (dyvil.source.position.SourcePosition)1 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)1 ConstructorCall (dyvilx.tools.compiler.ast.expression.access.ConstructorCall)1 IType (dyvilx.tools.compiler.ast.type.IType)1 ArrayType (dyvilx.tools.compiler.ast.type.compound.ArrayType)1