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));
}
}
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);
}
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;
}
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
}
}
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;
}
Aggregations