Search in sources :

Example 1 with IField

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

the class VariablesCommand method execute.

@Override
public void execute(DyvilREPL repl, String args) {
    final Map<Name, IField> fieldMap = repl.getContext().getFields();
    if (fieldMap.isEmpty()) {
        repl.getOutput().println(I18n.get("command.variables.none"));
        return;
    }
    final IField[] fields = fieldMap.toValueArray(IField.class);
    Arrays.sort(fields, MemberSorter.MEMBER_COMPARATOR);
    for (IField field : fields) {
        repl.getOutput().println(Util.memberSignatureToString(field, null));
    }
}
Also used : IField(dyvilx.tools.compiler.ast.field.IField) Name(dyvil.lang.Name)

Example 2 with IField

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

the class ClassBody method addField.

public void addField(IField field) {
    field.setEnclosingClass(this.enclosingClass);
    final int index = this.fieldCount++;
    if (index >= this.fields.length) {
        IField[] temp = new IField[index * 2];
        System.arraycopy(this.fields, 0, temp, 0, index);
        this.fields = temp;
    }
    this.fields[index] = field;
    final IProperty property = field.getProperty();
    if (property != null) {
        this.addToCache(property);
    }
    if (!(field instanceof EnumConstant)) {
        return;
    }
    final EnumConstant enumConst = (EnumConstant) field;
    // set enum constant index
    for (int i = index - 1; i >= 0; i--) {
        final IField fieldI = this.fields[i];
        if (fieldI instanceof EnumConstant) {
            enumConst.setIndex(((EnumConstant) fieldI).getIndex() + 1);
            return;
        }
    }
    enumConst.setIndex(0);
}
Also used : IProperty(dyvilx.tools.compiler.ast.field.IProperty) EnumConstant(dyvilx.tools.compiler.ast.field.EnumConstant) IField(dyvilx.tools.compiler.ast.field.IField)

Example 3 with IField

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

the class ClassBody method resolveImplicit.

public IValue resolveImplicit(IType type) {
    if (type == null) {
        return null;
    }
    IValue candidate = null;
    for (int i = 0; i < this.classCount; i++) {
        final IClass iclass = this.classes[i];
        if (!iclass.isImplicit() || !iclass.isObject() || !Types.isSuperType(type, iclass.getClassType())) {
            continue;
        }
        if (candidate != null) {
            // ambiguous
            return null;
        }
        candidate = new FieldAccess(iclass.getMetadata().getInstanceField());
    }
    for (int i = 0; i < this.fieldCount; i++) {
        final IField field = this.fields[i];
        if (!field.isImplicit() || !Types.isSuperType(type, field.getType())) {
            continue;
        }
        if (candidate != null) {
            // ambiguous
            return null;
        }
        // this<Class> is added automatically later
        candidate = new FieldAccess(field);
    }
    return candidate;
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) FieldAccess(dyvilx.tools.compiler.ast.expression.access.FieldAccess) IField(dyvilx.tools.compiler.ast.field.IField)

Example 4 with IField

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

the class ClassMetadata method checkMembers.

private void checkMembers(ClassBody body) {
    for (int i = 0, count = body.methodCount(); i < count; i++) {
        this.checkMethod(body.getMethod(i));
    }
    for (int i = 0, count = body.propertyCount(); i < count; i++) {
        final IMethod getter = body.getProperty(i).getGetter();
        if (getter != null) {
            this.checkMethod(getter);
        }
    // only check the getter
    }
    for (int i = 0, count = body.fieldCount(); i < count; i++) {
        final IField field = body.getField(i);
        this.checkField(field);
        final IProperty property = field.getProperty();
        final IMethod getter;
        if (property != null && (getter = property.getGetter()) != null) {
            this.checkMethod(getter);
        }
    // only check the getter
    }
}
Also used : IProperty(dyvilx.tools.compiler.ast.field.IProperty) IMethod(dyvilx.tools.compiler.ast.method.IMethod) IField(dyvilx.tools.compiler.ast.field.IField)

Example 5 with IField

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

the class EnumClassMetadata method createValuesArray.

private IValue createValuesArray() {
    final ArrayExpr arrayExpr = new ArrayExpr();
    arrayExpr.setElementType(this.theClass.getClassType());
    final ClassBody body = this.theClass.getBody();
    if (body != null) {
        final ArgumentList values = arrayExpr.getValues();
        for (IField enumConstant : body.enumConstants()) {
            values.add(new FieldAccess(enumConstant));
        }
    }
    return arrayExpr;
}
Also used : ArrayExpr(dyvilx.tools.compiler.ast.expression.ArrayExpr) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) IField(dyvilx.tools.compiler.ast.field.IField) ClassBody(dyvilx.tools.compiler.ast.classes.ClassBody)

Aggregations

IField (dyvilx.tools.compiler.ast.field.IField)9 IProperty (dyvilx.tools.compiler.ast.field.IProperty)4 IMethod (dyvilx.tools.compiler.ast.method.IMethod)4 Name (dyvil.lang.Name)3 TreeSet (dyvil.collection.mutable.TreeSet)2 PrintStream (java.io.PrintStream)2 ClassBody (dyvilx.tools.compiler.ast.classes.ClassBody)1 IContext (dyvilx.tools.compiler.ast.context.IContext)1 ArrayExpr (dyvilx.tools.compiler.ast.expression.ArrayExpr)1 IValue (dyvilx.tools.compiler.ast.expression.IValue)1 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)1 EnumConstant (dyvilx.tools.compiler.ast.field.EnumConstant)1 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)1 IType (dyvilx.tools.compiler.ast.type.IType)1 REPLContext (dyvilx.tools.repl.context.REPLContext)1