Search in sources :

Example 6 with PositionalArgument

use of org.eclipse.ceylon.compiler.typechecker.tree.Tree.PositionalArgument in project ceylon by eclipse.

the class SequenceGenerator method tuple.

static void tuple(final Tree.Tuple that, final GenerateJsVisitor gen) {
    SequencedArgument sarg = that.getSequencedArgument();
    if (sarg == null) {
        gen.out(gen.getClAlias(), "empty()");
    } else {
        final List<PositionalArgument> positionalArguments = sarg.getPositionalArguments();
        final boolean spread = SequenceGenerator.isSpread(positionalArguments);
        int lim = positionalArguments.size() - 1;
        gen.out(gen.getClAlias(), "tpl$([");
        int count = 0;
        for (PositionalArgument expr : positionalArguments) {
            if (!(count == lim && spread)) {
                if (count > 0) {
                    gen.out(",");
                }
                expr.visit(gen);
            }
            count++;
        }
        gen.out("]");
        if (spread) {
            gen.out(",");
            positionalArguments.get(lim).visit(gen);
        }
        gen.out(")");
    }
}
Also used : PositionalArgument(org.eclipse.ceylon.compiler.typechecker.tree.Tree.PositionalArgument) SequencedArgument(org.eclipse.ceylon.compiler.typechecker.tree.Tree.SequencedArgument)

Example 7 with PositionalArgument

use of org.eclipse.ceylon.compiler.typechecker.tree.Tree.PositionalArgument in project ceylon by eclipse.

the class NamedArgumentInvocation method getTransformedArgumentExpression.

@Override
protected JCExpression getTransformedArgumentExpression(int argIndex) {
    PositionalArgument arg = getPositional().getPositionalArguments().get(argIndex);
    // FIXME: I don't like much this weird special case here
    if (arg instanceof Tree.ListedArgument) {
        Tree.Expression expr = ((Tree.ListedArgument) arg).getExpression();
        if (expr.getTerm() instanceof FunctionArgument) {
            FunctionArgument farg = (FunctionArgument) expr.getTerm();
            Type parameterType = getParameterType(argIndex);
            if (isParameterJavaVariadic(argIndex) && parameterType.isSequential()) {
                parameterType = gen.typeFact().getSequentialElementType(parameterType);
            }
            return gen.expressionGen().transform(farg, parameterType);
        }
    }
    // special case for comprehensions which are not expressions
    if (arg instanceof Tree.Comprehension) {
        Type type = getParameterType(argIndex);
        return gen.expressionGen().comprehensionAsSequential((Comprehension) arg, type);
    }
    return gen.expressionGen().transformArg(this, argIndex);
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) Expression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Expression) PositionalArgument(org.eclipse.ceylon.compiler.typechecker.tree.Tree.PositionalArgument) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Comprehension(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Comprehension) FunctionArgument(org.eclipse.ceylon.compiler.typechecker.tree.Tree.FunctionArgument)

Aggregations

PositionalArgument (org.eclipse.ceylon.compiler.typechecker.tree.Tree.PositionalArgument)7 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)6 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)4 Comprehension (org.eclipse.ceylon.compiler.typechecker.tree.Tree.Comprehension)3 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)2 Type (org.eclipse.ceylon.model.typechecker.model.Type)2 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)2 ArrayList (java.util.ArrayList)1 AnalyzerUtil.checkCasesDisjoint (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.checkCasesDisjoint)1 AnalyzerUtil.getTupleType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType)1 AnalyzerUtil.spreadType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType)1 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)1 Expression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.Expression)1 FunctionArgument (org.eclipse.ceylon.compiler.typechecker.tree.Tree.FunctionArgument)1 SequencedArgument (org.eclipse.ceylon.compiler.typechecker.tree.Tree.SequencedArgument)1 Term (org.eclipse.ceylon.compiler.typechecker.tree.Tree.Term)1 TreeUtil.unwrapExpressionUntilTerm (org.eclipse.ceylon.compiler.typechecker.tree.TreeUtil.unwrapExpressionUntilTerm)1 JCCase (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCase)1 JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)1 JCNewClass (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCNewClass)1