use of dyvilx.tools.compiler.ast.type.IType 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;
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class CodeClass method write.
@Override
public void write(ClassWriter writer) throws BytecodeException {
// Header
String signature = this.getSignature();
String superClass = null;
String[] interfaces = this.getInterfaceArray();
if (this.superType != null) {
superClass = this.superType.getInternalName();
}
final long flags = ModifierUtil.getFlags(this);
int modifiers = ModifierUtil.getJavaModifiers(flags);
if ((modifiers & Modifiers.INTERFACE) == 0) {
modifiers |= ASMConstants.ACC_SUPER;
}
writer.visit(ClassFormat.CLASS_VERSION, modifiers, this.getInternalName(), signature, superClass, interfaces);
// Source
writer.visitSource(this.getHeader().getName() + DyvilFileType.DYVIL_EXTENSION, null);
if (this.enclosingClass != null) {
this.writeInnerClassInfo(writer);
}
// Annotations
this.writeAnnotations(writer, flags);
if (this.superType != null) {
IClass iclass = this.superType.getTheClass();
if (iclass != null) {
iclass.writeInnerClassInfo(writer);
}
}
if (this.interfaces != null) {
for (IType type : this.interfaces) {
final IClass iclass = type.getTheClass();
if (iclass != null) {
iclass.writeInnerClassInfo(writer);
}
}
}
// Compute Trait Classes
final Set<IClass> traitClasses;
if ((modifiers & Modifiers.INTERFACE) == 0) {
traitClasses = new ArraySet<>();
this.traitInit = !fillTraitClasses(this, traitClasses, true) && !traitClasses.isEmpty();
} else {
traitClasses = null;
}
for (int i = 0; i < this.compilableCount; i++) {
this.compilables[i].write(writer);
}
this.metadata.write(writer);
this.writeClassParameters(writer);
if (this.body != null) {
this.body.write(writer);
}
this.metadata.writePost(writer);
// Create the static <clinit> method
MethodWriter initWriter = new MethodWriterImpl(writer, writer.visitMethod(Modifiers.STATIC, "<clinit>", "()V", null, null));
initWriter.visitCode();
this.writeStaticInit(initWriter);
initWriter.visitEnd(Types.VOID);
if (traitClasses == null || traitClasses.isEmpty()) {
return;
}
// Create the virtual <traitinit> method
initWriter = new MethodWriterImpl(writer, writer.visitMethod(Modifiers.PROTECTED, TraitMetadata.INIT_NAME, "()V", null, null));
initWriter.visitCode();
initWriter.setLocalType(0, this.getInternalName());
for (IClass traitClass : traitClasses) {
final String internal = traitClass.getInternalName();
// Load 'this'
initWriter.visitVarInsn(Opcodes.ALOAD, 0);
// Invoke the static <traitinit> method of the trait class
initWriter.visitMethodInsn(Opcodes.INVOKESTATIC, internal, TraitMetadata.INIT_NAME, "(L" + internal + ";)V", true);
}
initWriter.visitInsn(Opcodes.RETURN);
initWriter.visitEnd();
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class AnnotationExpr method writeExpression.
@Override
public void writeExpression(MethodWriter writer, IType type) throws BytecodeException {
final StringBuilder descBuilder = new StringBuilder().append('(');
final ArgumentList arguments = this.annotation.getArguments();
final IClass iclass = this.annotation.getType().getTheClass();
final ParameterList parameterList = iclass.getParameters();
final int count = parameterList.size();
String[] parameterNames = new String[count];
for (int i = 0; i < count; i++) {
final IParameter parameter = parameterList.get(i);
final IType parameterType = parameter.getType();
parameterNames[i] = parameter.getInternalName();
parameterType.appendExtendedName(descBuilder);
arguments.writeValue(i, parameter, writer);
}
descBuilder.append(')');
descBuilder.append('L').append(iclass.getInternalName()).append(';');
writer.visitInvokeDynamicInsn("_", descBuilder.toString(), ANNOTATION_METAFACTORY, (Object[]) parameterNames);
if (type != null) {
this.annotation.getType().writeCast(writer, type, this.lineNumber());
}
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class ArrayExpr method getTypeMatch.
@Override
public int getTypeMatch(IType type, IImplicitContext implicitContext) {
final ArrayType arrayType = type.extract(ArrayType.class);
if (arrayType == null) {
if (type.getTheClass() == Types.OBJECT_CLASS) {
return SUBTYPE_MATCH;
}
if (type.getAnnotation(LazyFields.ARRAY_CONVERTIBLE) != null) {
return CONVERSION_MATCH;
}
return MISMATCH;
}
final IType elementType = arrayType.getElementType();
return this.values.getTypeMatch(elementType, implicitContext);
}
use of dyvilx.tools.compiler.ast.type.IType in project Dyvil by Dyvil.
the class ArrayExpr method isType.
@Override
public boolean isType(IType type) {
final ArrayType arrayType = type.extract(ArrayType.class);
if (arrayType == null) {
return type.getTheClass() == Types.OBJECT_CLASS || type.getAnnotation(LazyFields.ARRAY_CONVERTIBLE) != null;
}
final IType elementType = arrayType.getElementType();
return this.values.isType(elementType);
}
Aggregations