Search in sources :

Example 1 with ParameterList

use of dyvilx.tools.compiler.ast.parameter.ParameterList in project Dyvil by Dyvil.

the class SimpleMethodVisitor method visitEnd.

@Override
public void visitEnd() {
    if (this.intrinsicData != null && !this.unsupportedInline) {
        this.method.setIntrinsicData(this.intrinsicData);
    }
    int localIndex = this.method.hasModifier(Modifiers.STATIC) ? 0 : 1;
    final ParameterList parameters = this.method.getExternalParameterList();
    for (int i = 0, count = parameters.size(); i < count; i++) {
        final IParameter param = parameters.get(i);
        param.setLocalIndex(localIndex);
        if (param.getName() == null) {
            param.setName(this.getName(localIndex));
        }
        localIndex += param.getLocalSlots();
    }
}
Also used : IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList)

Example 2 with ParameterList

use of dyvilx.tools.compiler.ast.parameter.ParameterList in project Dyvil by Dyvil.

the class CompleteCommand method findInstanceMembers.

private static void findInstanceMembers(IType type, Set<IField> fields, Set<IProperty> properties, Set<IMethod> methods, String start, Set<IClass> dejaVu) {
    final IClass iclass = type.getTheClass();
    if (iclass == null || dejaVu.contains(iclass)) {
        return;
    }
    dejaVu.add(iclass);
    // Add members
    final ParameterList parameterList = iclass.getParameters();
    for (int i = 0, count = parameterList.size(); i < count; i++) {
        checkMember(fields, (IField) parameterList.get(i), start, false);
    }
    findMembers(type, fields, properties, methods, start, false);
    // Recursively scan super types
    final IType superType = iclass.getSuperType();
    if (superType != null) {
        findInstanceMembers(superType.getConcreteType(type), fields, properties, methods, start, dejaVu);
    }
    for (IType interfaceType : iclass.getInterfaces()) {
        findInstanceMembers(interfaceType.getConcreteType(type), fields, properties, methods, start, dejaVu);
    }
}
Also used : ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList) IClass(dyvilx.tools.compiler.ast.classes.IClass) IType(dyvilx.tools.compiler.ast.type.IType)

Example 3 with ParameterList

use of dyvilx.tools.compiler.ast.parameter.ParameterList in project Dyvil by Dyvil.

the class Template method makeMainMethod.

private void makeMainMethod() {
    // func main(args: [String]) -> void = new TemplateName().mainImpl(args)
    final ParameterList params = this.mainMethod.getParameters();
    final CodeParameter argsParam = new CodeParameter(this.mainMethod, null, Name.fromRaw("args"), new ArrayType(Types.STRING));
    params.add(argsParam);
    final IValue newTemplate = new ConstructorCall(null, this.templateClass.getClassType(), ArgumentList.EMPTY);
    this.mainMethod.setValue(new MethodCall(null, newTemplate, Name.fromRaw("mainImpl"), new ArgumentList(new FieldAccess(argsParam))));
}
Also used : ArrayType(dyvilx.tools.compiler.ast.type.compound.ArrayType) IValue(dyvilx.tools.compiler.ast.expression.IValue) ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList) ConstructorCall(dyvilx.tools.compiler.ast.expression.access.ConstructorCall) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList) FieldAccess(dyvilx.tools.compiler.ast.expression.access.FieldAccess) CodeParameter(dyvilx.tools.compiler.ast.parameter.CodeParameter) MethodCall(dyvilx.tools.compiler.ast.expression.access.MethodCall)

Example 4 with ParameterList

use of dyvilx.tools.compiler.ast.parameter.ParameterList in project Dyvil by Dyvil.

the class CaseClasses method writeHashCode.

public static void writeHashCode(MethodWriter writer, IClass theClass) throws BytecodeException {
    writer.visitLdcInsn(31);
    final ParameterList parameters = theClass.getParameters();
    for (int i = 0, count = parameters.size(); i < count; i++) {
        final IDataMember parameter = parameters.get(i);
        // Load the value of the field
        writer.visitVarInsn(ALOAD, 0);
        parameter.writeGet(writer, null, 0);
        // Write the hashing strategy for the parameter
        writeHashCode(writer, parameter.getType());
        // Add the hash to the previous result
        writer.visitInsn(IADD);
        writer.visitLdcInsn(31);
        // Multiply the result by 31
        writer.visitInsn(IMUL);
    }
    writer.visitInsn(IRETURN);
}
Also used : ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList) IDataMember(dyvilx.tools.compiler.ast.field.IDataMember)

Example 5 with ParameterList

use of dyvilx.tools.compiler.ast.parameter.ParameterList in project Dyvil by Dyvil.

the class ClassMetadata method resolveTypesBody.

@Override
public void resolveTypesBody(MarkerList markers, IContext context) {
    // Check if a constructor needs to be generated
    final ClassBody body = this.theClass.getBody();
    if (body == null) {
        return;
    }
    this.checkMembers(body);
    if (body.constructorCount() <= 0) {
        return;
    }
    final ParameterList parameters = this.theClass.getParameters();
    final IConstructor constructor = body.getConstructor(parameters);
    if (constructor != null) {
        this.constructor = constructor;
        this.members |= CONSTRUCTOR;
        return;
    }
    if (parameters.isEmpty()) {
        // Do not generate an empty default constructor if there is any other constructor defined
        this.members |= CONSTRUCTOR;
    }
}
Also used : IConstructor(dyvilx.tools.compiler.ast.constructor.IConstructor) ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList) ClassBody(dyvilx.tools.compiler.ast.classes.ClassBody)

Aggregations

ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)27 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)12 IType (dyvilx.tools.compiler.ast.type.IType)11 TypeParameterList (dyvilx.tools.compiler.ast.generic.TypeParameterList)7 IClass (dyvilx.tools.compiler.ast.classes.IClass)5 IValue (dyvilx.tools.compiler.ast.expression.IValue)5 IConstructor (dyvilx.tools.compiler.ast.constructor.IConstructor)3 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)3 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)3 CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)3 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)2 ThisExpr (dyvilx.tools.compiler.ast.expression.ThisExpr)2 IDataMember (dyvilx.tools.compiler.ast.field.IDataMember)2 Name (dyvil.lang.Name)1 SourcePosition (dyvil.source.position.SourcePosition)1 Label (dyvilx.tools.asm.Label)1 IInstruction (dyvilx.tools.compiler.ast.bytecode.IInstruction)1 VarInstruction (dyvilx.tools.compiler.ast.bytecode.VarInstruction)1 ClassBody (dyvilx.tools.compiler.ast.classes.ClassBody)1 CodeConstructor (dyvilx.tools.compiler.ast.constructor.CodeConstructor)1