Search in sources :

Example 26 with IMethod

use of dyvilx.tools.compiler.ast.method.IMethod in project Dyvil by Dyvil.

the class Closure method withType.

@Override
public IValue withType(IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
    if (this.resolved) {
        return super.withType(type, typeContext, markers, context);
    }
    final IMethod functionalMethod = type.getFunctionalMethod();
    if (functionalMethod == null) {
        return null;
    }
    final ParameterList parameterList = functionalMethod.getParameters();
    final int parameterCount = parameterList.size();
    final IParameter[] parameters = new IParameter[parameterCount];
    for (int i = 0; i < parameterCount; i++) {
        parameters[i] = new CodeParameter(null, this.position, Name.fromRaw("$" + i), Types.UNKNOWN);
    }
    final LambdaType functionType = type.extract(LambdaType.class);
    if (functionType != null && functionType.isExtension() && parameterCount > 0) {
        this.implicitValue = new FieldAccess(parameters[0]);
    }
    final LambdaExpr lambdaExpr = new LambdaExpr(this.position, parameters, parameterCount);
    lambdaExpr.setValue(this);
    this.resolved = true;
    context = context.push(this);
    final IValue typedLambda = lambdaExpr.withType(type, typeContext, markers, context);
    context.pop();
    return typedLambda;
}
Also used : LambdaType(dyvilx.tools.compiler.ast.type.compound.LambdaType) IParameter(dyvilx.tools.compiler.ast.parameter.IParameter) IValue(dyvilx.tools.compiler.ast.expression.IValue) LambdaExpr(dyvilx.tools.compiler.ast.expression.LambdaExpr) ParameterList(dyvilx.tools.compiler.ast.parameter.ParameterList) IMethod(dyvilx.tools.compiler.ast.method.IMethod) FieldAccess(dyvilx.tools.compiler.ast.expression.access.FieldAccess) CodeParameter(dyvilx.tools.compiler.ast.parameter.CodeParameter)

Example 27 with IMethod

use of dyvilx.tools.compiler.ast.method.IMethod in project Dyvil by Dyvil.

the class HeaderContext method getMethodMatches.

@Override
public void getMethodMatches(MatchList<IMethod> list, IValue receiver, Name name, ArgumentList arguments) {
    // For ordinary headers, this is a no-op, since they (currently) cannot host any free-standing functions
    // The REPL however can, so we need this call
    this.header.getMethodMatches(list, receiver, name, arguments);
    if (list.hasCandidate()) {
        return;
    }
    final ImportDeclaration[] imports = this.header.importDeclarations;
    for (int i = 0; i < this.header.importCount; i++) {
        final IImportContext importContext = imports[i].getContext();
        final MatchList<IMethod> subList = list.emptyCopy();
        importContext.getMethodMatches(subList, receiver, name, arguments);
        list.addAll(subList);
    }
}
Also used : IImportContext(dyvilx.tools.compiler.ast.imports.IImportContext) ImportDeclaration(dyvilx.tools.compiler.ast.imports.ImportDeclaration) IMethod(dyvilx.tools.compiler.ast.method.IMethod)

Example 28 with IMethod

use of dyvilx.tools.compiler.ast.method.IMethod in project Dyvil by Dyvil.

the class CompleteCommand method printCompletions.

private void printCompletions(DyvilREPL repl, String memberStart, IValue value) {
    final IType type = value.getType();
    final boolean statics = value.isClassAccess();
    final IContext context = repl.getContext().getContext();
    final Set<IField> fields = new TreeSet<>(MemberSorter.MEMBER_COMPARATOR);
    final Set<IProperty> properties = new TreeSet<>(MemberSorter.MEMBER_COMPARATOR);
    final Set<IMethod> methods = new TreeSet<>(MemberSorter.METHOD_COMPARATOR);
    final Set<IMethod> extensionMethods = new TreeSet<>(MemberSorter.METHOD_COMPARATOR);
    final Set<IMethod> conversionMethods = new TreeSet<>(MemberSorter.METHOD_COMPARATOR);
    final PrintStream output = repl.getOutput();
    if (statics) {
        output.println(I18n.get("command.complete.type", type));
        findMembers(type, fields, properties, methods, memberStart, true);
        findExtensions(context, type, value, extensionMethods, memberStart, true);
    } else {
        output.println(I18n.get("command.complete.expression", value, type));
        findInstanceMembers(type, fields, properties, methods, memberStart, new IdentityHashSet<>());
        findExtensions(context, type, value, extensionMethods, memberStart, false);
        findConversions(context, type, value, conversionMethods);
    }
    boolean hasOutput = false;
    if (!fields.isEmpty()) {
        hasOutput = true;
        output.println(I18n.get("command.complete.fields"));
        printMembers(output, fields, type);
    }
    if (!properties.isEmpty()) {
        hasOutput = true;
        output.println(I18n.get("command.complete.properties"));
        printMembers(output, properties, type);
    }
    if (!methods.isEmpty()) {
        hasOutput = true;
        output.println(I18n.get("command.complete.methods"));
        printMethods(output, methods, type);
    }
    if (!extensionMethods.isEmpty()) {
        hasOutput = true;
        output.println(I18n.get("command.complete.extensions"));
        printMethods(output, extensionMethods, type);
    }
    if (!conversionMethods.isEmpty()) {
        hasOutput = true;
        output.println(I18n.get("command.complete.conversions"));
        printMethods(output, conversionMethods, type);
    }
    if (!hasOutput) {
        output.println(I18n.get("command.complete.none"));
    }
}
Also used : PrintStream(java.io.PrintStream) IContext(dyvilx.tools.compiler.ast.context.IContext) IProperty(dyvilx.tools.compiler.ast.field.IProperty) TreeSet(dyvil.collection.mutable.TreeSet) IMethod(dyvilx.tools.compiler.ast.method.IMethod) IField(dyvilx.tools.compiler.ast.field.IField) IType(dyvilx.tools.compiler.ast.type.IType)

Example 29 with IMethod

use of dyvilx.tools.compiler.ast.method.IMethod in project Dyvil by Dyvil.

the class CompleteCommand method printMethods.

private static void printMethods(PrintStream out, Set<IMethod> methods, ITypeContext typeContext) {
    for (IMethod method : methods) {
        out.print('\t');
        out.println(Util.methodSignatureToString(method, typeContext));
    }
}
Also used : IMethod(dyvilx.tools.compiler.ast.method.IMethod)

Example 30 with IMethod

use of dyvilx.tools.compiler.ast.method.IMethod in project Dyvil by Dyvil.

the class CompleteCommand method printREPLMembers.

private void printREPLMembers(DyvilREPL repl, String start) {
    final REPLContext replContext = repl.getContext();
    final Set<IField> variables = new TreeSet<>(MemberSorter.MEMBER_COMPARATOR);
    final Set<IMethod> methods = new TreeSet<>(MemberSorter.METHOD_COMPARATOR);
    for (IField variable : replContext.getFields().values()) {
        checkMember(variables, variable, start);
    }
    for (IMethod method : replContext.getMethods()) {
        checkMember(methods, method, start);
    }
    final PrintStream output = repl.getOutput();
    boolean hasOutput = false;
    if (!variables.isEmpty()) {
        hasOutput = true;
        output.println(I18n.get("command.complete.variables"));
        printMembers(output, variables, null);
    }
    if (!methods.isEmpty()) {
        hasOutput = true;
        output.println(I18n.get("command.complete.methods"));
        printMethods(output, methods, null);
    }
    if (!hasOutput) {
        output.println(I18n.get("command.complete.none"));
    }
}
Also used : PrintStream(java.io.PrintStream) TreeSet(dyvil.collection.mutable.TreeSet) REPLContext(dyvilx.tools.repl.context.REPLContext) IMethod(dyvilx.tools.compiler.ast.method.IMethod) IField(dyvilx.tools.compiler.ast.field.IField)

Aggregations

IMethod (dyvilx.tools.compiler.ast.method.IMethod)31 IValue (dyvilx.tools.compiler.ast.expression.IValue)6 IField (dyvilx.tools.compiler.ast.field.IField)4 IProperty (dyvilx.tools.compiler.ast.field.IProperty)4 IType (dyvilx.tools.compiler.ast.type.IType)3 TreeSet (dyvil.collection.mutable.TreeSet)2 Name (dyvil.lang.Name)2 SourcePosition (dyvil.source.position.SourcePosition)2 IContext (dyvilx.tools.compiler.ast.context.IContext)2 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)2 IImportContext (dyvilx.tools.compiler.ast.imports.IImportContext)2 ImportDeclaration (dyvilx.tools.compiler.ast.imports.ImportDeclaration)2 MatchList (dyvilx.tools.compiler.ast.method.MatchList)2 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)2 PrintStream (java.io.PrintStream)2 ClassBody (dyvilx.tools.compiler.ast.classes.ClassBody)1 IClass (dyvilx.tools.compiler.ast.classes.IClass)1 IConstructor (dyvilx.tools.compiler.ast.constructor.IConstructor)1 CombiningContext (dyvilx.tools.compiler.ast.context.CombiningContext)1 IImplicitContext (dyvilx.tools.compiler.ast.context.IImplicitContext)1