Search in sources :

Example 76 with IValue

use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.

the class IOverloadable method getOverloadPriority.

default int getOverloadPriority() {
    final Annotation annotation = this.getAnnotation(Types.OVERLOADPRIORITY_CLASS);
    if (annotation == null) {
        return 0;
    }
    final IValue value = annotation.getArguments().getFirst();
    return value == null ? OverloadPriority.DEFAULT_PRIORITY : value.intValue();
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) Annotation(dyvilx.tools.compiler.ast.attribute.annotation.Annotation)

Example 77 with IValue

use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.

the class StatementList method withType.

@Override
public IValue withType(IType type, ITypeContext typeContext, MarkerList markers, IContext context) {
    if (this.valueCount <= 0) {
        return Types.isVoid(type) ? this : null;
    }
    context = context.push(this);
    final IValue value = this.values[this.valueCount - 1];
    if (Types.isVoid(type) && !value.isStatement()) {
        final IValue applyStatementCall = resolveApplyStatement(markers, context, value);
        if (applyStatementCall != null) {
            this.returnType = type;
            this.values[this.valueCount - 1] = applyStatementCall;
            return this;
        }
    }
    final IValue typed = TypeChecker.convertValue(value, type, typeContext, markers, context, RETURN_MARKER_SUPPLIER);
    context.pop();
    if (typed != null) {
        this.values[this.valueCount - 1] = typed;
        this.returnType = typed.getType();
    }
    return this;
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue)

Example 78 with IValue

use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.

the class StatementList method resolveApplyStatement.

private static IValue resolveApplyStatement(MarkerList markers, IContext context, IValue resolvedValue) {
    final ArgumentList arguments = new ArgumentList(resolvedValue);
    final IValue implicitValue = context.resolveImplicit(null);
    if (implicitValue != null) {
        final IValue call = resolveApplyStatement(markers, context, arguments, implicitValue);
        if (call != null) {
            return call;
        }
    }
    return resolveApplyStatement(markers, context, arguments, null);
}
Also used : IValue(dyvilx.tools.compiler.ast.expression.IValue) ArgumentList(dyvilx.tools.compiler.ast.parameter.ArgumentList)

Example 79 with IValue

use of dyvilx.tools.compiler.ast.expression.IValue in project Dyvil by Dyvil.

the class CompleteCommand method execute.

@Override
public void execute(DyvilREPL repl, String argument) {
    final IContext context = repl.getContext().getContext();
    if (argument == null) {
        // REPL Variables
        this.printREPLMembers(repl, "");
        return;
    }
    final int dotIndex = argument.lastIndexOf('.');
    if (dotIndex <= 0) {
        // REPL Variable Completions
        this.printREPLMembers(repl, Qualifier.qualify(argument));
        return;
    }
    final String expression = argument.substring(0, dotIndex);
    final String memberStart = Qualifier.qualify(argument.substring(dotIndex + 1));
    final MarkerList markers = new MarkerList(Markers.INSTANCE);
    final TokenList tokens = new DyvilLexer(markers, DyvilSymbols.INSTANCE).tokenize(expression);
    new ParserManager(DyvilSymbols.INSTANCE, tokens.iterator(), markers).parse(new ExpressionParser((IValue value) -> {
        value.resolveTypes(markers, context);
        value = value.resolve(markers, context);
        value.checkTypes(markers, context);
        if (!markers.isEmpty()) {
            // Print Errors, if any
            final boolean colors = repl.getCompiler().config.useAnsiColors();
            final StringBuilder buffer = new StringBuilder();
            markers.log(new LineSource(expression), buffer, colors);
            repl.getOutput().println(buffer);
        }
        try {
            this.printCompletions(repl, memberStart, value);
        } catch (Throwable throwable) {
            throwable.printStackTrace(repl.getErrorOutput());
        }
    }));
}
Also used : ParserManager(dyvilx.tools.parsing.ParserManager) MarkerList(dyvilx.tools.parsing.marker.MarkerList) IContext(dyvilx.tools.compiler.ast.context.IContext) IValue(dyvilx.tools.compiler.ast.expression.IValue) LineSource(dyvil.source.LineSource) DyvilLexer(dyvilx.tools.parsing.lexer.DyvilLexer) TokenList(dyvilx.tools.parsing.TokenList) ExpressionParser(dyvilx.tools.compiler.parser.expression.ExpressionParser)

Aggregations

IValue (dyvilx.tools.compiler.ast.expression.IValue)79 IType (dyvilx.tools.compiler.ast.type.IType)20 ArgumentList (dyvilx.tools.compiler.ast.parameter.ArgumentList)17 FieldAccess (dyvilx.tools.compiler.ast.expression.access.FieldAccess)11 SourcePosition (dyvil.source.position.SourcePosition)10 IParameter (dyvilx.tools.compiler.ast.parameter.IParameter)9 ArrayExpr (dyvilx.tools.compiler.ast.expression.ArrayExpr)7 Marker (dyvilx.tools.parsing.marker.Marker)7 IMethod (dyvilx.tools.compiler.ast.method.IMethod)6 AttributeList (dyvilx.tools.compiler.ast.attribute.AttributeList)5 IContext (dyvilx.tools.compiler.ast.context.IContext)5 MethodCall (dyvilx.tools.compiler.ast.expression.access.MethodCall)5 CodeParameter (dyvilx.tools.compiler.ast.parameter.CodeParameter)5 Annotation (dyvilx.tools.compiler.ast.attribute.annotation.Annotation)4 IClass (dyvilx.tools.compiler.ast.classes.IClass)4 Variable (dyvilx.tools.compiler.ast.field.Variable)4 ParameterList (dyvilx.tools.compiler.ast.parameter.ParameterList)4 CombiningContext (dyvilx.tools.compiler.ast.context.CombiningContext)3 IVariable (dyvilx.tools.compiler.ast.field.IVariable)3 CodeMethod (dyvilx.tools.compiler.ast.method.CodeMethod)3