use of dyvilx.tools.compiler.ast.field.IDataMember in project Dyvil by Dyvil.
the class CaseClasses method writeToString.
public static void writeToString(MethodWriter writer, IClass theClass) throws BytecodeException {
// ----- StringBuilder Constructor -----
writer.visitTypeInsn(NEW, "java/lang/StringBuilder");
writer.visitInsn(DUP);
// Call the StringBuilder(String) constructor with the "[ClassName]("
// argument
writer.visitLdcInsn(theClass.getName() + "(");
writer.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V", false);
// ----- Class Parameters -----
final ParameterList parameters = theClass.getParameters();
for (int i = 0, count = parameters.size(); i < count; i++) {
final IDataMember parameter = parameters.get(i);
IType type = parameter.getType();
// Get the parameter value
writer.visitVarInsn(ALOAD, 0);
parameter.writeGet(writer, null, 0);
writeStringAppend(writer, type);
if (i + 1 < count) {
// Separator Comma
writer.visitLdcInsn(", ");
writer.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
}
}
// ----- Append Closing Parenthesis -----
writer.visitLdcInsn(")");
// Write the call to the StringBuilder#append(String) method
writer.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
// ----- ToString -----
// Write the call to the StringBuilder#toString() method
writer.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false);
// Write the return
writer.visitInsn(ARETURN);
}
use of dyvilx.tools.compiler.ast.field.IDataMember in project Dyvil by Dyvil.
the class FieldAssignment method resolveAsField.
@Override
protected IValue resolveAsField(IValue receiver, MarkerList markers, IContext context) {
final IDataMember field = ICall.resolveField(context, receiver, this.name);
if (field == null) {
return null;
}
this.receiver = receiver;
this.field = field;
this.capture(markers, context);
return this;
}
use of dyvilx.tools.compiler.ast.field.IDataMember in project Dyvil by Dyvil.
the class ExternalClass method resolveField.
@Override
public IDataMember resolveField(Name name) {
final IParameter parameter = this.resolveClassParameter(name);
if (parameter != null) {
return parameter;
}
// Own fields
IDataMember field = this.body.getField(name);
if (field != null) {
return field;
}
this.resolveSuperTypes();
// Inherited Fields
if (this.superType != null) {
field = this.superType.resolveField(name);
if (field != null) {
return field;
}
}
return null;
}
use of dyvilx.tools.compiler.ast.field.IDataMember in project Dyvil by Dyvil.
the class EnumSurrogate method withType.
@Override
public Pattern withType(IType type, MarkerList markers) {
if (this.dataMember == null) {
final IDataMember dataMember = type.resolveField(this.name);
if (dataMember == null) {
return null;
}
this.dataMember = dataMember;
}
return super.withType(type, markers);
}
use of dyvilx.tools.compiler.ast.field.IDataMember in project Dyvil by Dyvil.
the class ObjectSurrogate method resolve.
@Override
public Pattern resolve(MarkerList markers, IContext context) {
if (this.type.typeTag() == IType.NAMED) {
NamedType namedType = (NamedType) this.type;
final Name name = namedType.getName();
IType parent = namedType.getParent();
if (parent != null) {
parent = parent.resolveType(markers, context);
namedType.setParent(parent);
IDataMember dataMember = parent.resolveField(name);
if (dataMember != null) {
return new FieldPattern(this.position, dataMember).resolve(markers, context);
}
} else {
IDataMember dataMember = context.resolveField(name);
if (dataMember != null) {
return new FieldPattern(this.position, dataMember).resolve(markers, context);
}
}
}
this.type = this.type.resolveType(markers, context);
final IClass theClass = this.type.getTheClass();
if (theClass != null && !theClass.hasModifier(Modifiers.OBJECT_CLASS)) {
markers.add(Markers.semanticError(this.position, "pattern.object", theClass.getName()));
}
return this;
}
Aggregations