Search in sources :

Example 1 with SequencedArgument

use of org.eclipse.ceylon.compiler.typechecker.tree.Tree.SequencedArgument 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 2 with SequencedArgument

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

the class ClassTransformer method transformAnnotationParameterDefault.

private JCExpression transformAnnotationParameterDefault(Tree.Parameter p) {
    Tree.SpecifierOrInitializerExpression defaultArgument = Decl.getDefaultArgument(p);
    Tree.Expression defaultExpression = defaultArgument.getExpression();
    Tree.Term term = defaultExpression.getTerm();
    JCExpression defaultLiteral = null;
    if (term instanceof Tree.Literal && !(term instanceof Tree.QuotedLiteral)) {
        defaultLiteral = expressionGen().transform((Tree.Literal) term);
    } else if (term instanceof Tree.BaseMemberExpression) {
        Tree.BaseMemberExpression bme = (Tree.BaseMemberExpression) term;
        Declaration decl = bme.getDeclaration();
        if (isBooleanTrue(decl)) {
            defaultLiteral = makeBoolean(true);
        } else if (isBooleanFalse(decl)) {
            defaultLiteral = makeBoolean(false);
        } else if (typeFact().isEmptyType(bme.getTypeModel())) {
            defaultLiteral = make().NewArray(null, null, List.<JCExpression>nil());
        } else if (Decl.isAnonCaseOfEnumeratedType(bme)) {
            defaultLiteral = makeClassLiteral(bme.getTypeModel());
        } else {
            defaultLiteral = make().Literal(bme.getDeclaration().getQualifiedNameString());
        }
    } else if (term instanceof Tree.MemberOrTypeExpression) {
        Tree.MemberOrTypeExpression mte = (Tree.MemberOrTypeExpression) term;
        defaultLiteral = make().Literal(mte.getDeclaration().getQualifiedNameString());
    } else if (term instanceof Tree.SequenceEnumeration) {
        Tree.SequenceEnumeration seq = (Tree.SequenceEnumeration) term;
        SequencedArgument sequencedArgument = seq.getSequencedArgument();
        defaultLiteral = makeArrayInitializer(sequencedArgument);
    } else if (term instanceof Tree.Tuple) {
        Tree.Tuple seq = (Tree.Tuple) term;
        SequencedArgument sequencedArgument = seq.getSequencedArgument();
        defaultLiteral = makeArrayInitializer(sequencedArgument);
    } else if (term instanceof Tree.InvocationExpression) {
        // Allow invocations of annotation constructors, so long as they're
        // themselves being invoked with permitted arguments
        Tree.InvocationExpression invocation = (Tree.InvocationExpression) term;
        try {
            defaultLiteral = AnnotationInvocationVisitor.transform(expressionGen(), invocation);
        } catch (BugException e) {
            defaultLiteral = e.makeErroneous(this, invocation);
        }
    } else if (term instanceof Tree.MemberLiteral) {
        defaultLiteral = expressionGen().makeMetaLiteralStringLiteralForAnnotation((Tree.MemberLiteral) term);
    } else if (term instanceof Tree.TypeLiteral) {
        defaultLiteral = expressionGen().makeMetaLiteralStringLiteralForAnnotation((Tree.TypeLiteral) term);
    }
    if (defaultLiteral == null) {
        defaultLiteral = makeErroneous(p, "compiler bug: " + p.getParameterModel().getName() + " has an unsupported defaulted parameter expression");
    }
    return defaultLiteral;
}
Also used : BaseMemberExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.BaseMemberExpression) JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) JCPrimitiveTypeTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCPrimitiveTypeTree) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) BaseMemberExpression(org.eclipse.ceylon.compiler.typechecker.tree.Tree.BaseMemberExpression) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) MethodDeclaration(org.eclipse.ceylon.compiler.typechecker.tree.Tree.MethodDeclaration) SequencedArgument(org.eclipse.ceylon.compiler.typechecker.tree.Tree.SequencedArgument)

Example 3 with SequencedArgument

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

the class NamedArgumentInvocation method buildVars.

/**
 * Constructs the vars used in the Let expression
 */
private void buildVars() {
    if (getPrimaryDeclaration() == null) {
        return;
    }
    boolean prev = gen.expressionGen().withinInvocation(false);
    java.util.List<Tree.NamedArgument> namedArguments = namedArgumentList.getNamedArguments();
    SequencedArgument sequencedArgument = namedArgumentList.getSequencedArgument();
    java.util.List<ParameterList> paramLists = ((Functional) getPrimaryDeclaration()).getParameterLists();
    java.util.List<Parameter> declaredParams = paramLists.get(0).getParameters();
    appendVarsForNamedArguments(namedArguments, declaredParams);
    appendVarsForReifiedTypeArguments();
    if (sequencedArgument != null)
        appendVarsForSequencedArguments(sequencedArgument, declaredParams);
    boolean hasDefaulted = appendVarsForDefaulted(declaredParams);
    DefaultParameterMethodOwner owner = Strategy.defaultParameterMethodOwner(getPrimaryDeclaration());
    if (hasDefaulted && owner != DefaultParameterMethodOwner.STATIC && owner != DefaultParameterMethodOwner.OUTER && owner != DefaultParameterMethodOwner.OUTER_COMPANION) {
        vars.prepend(makeThis());
    }
    gen.expressionGen().withinInvocation(prev);
}
Also used : Functional(org.eclipse.ceylon.model.typechecker.model.Functional) DefaultParameterMethodOwner(org.eclipse.ceylon.compiler.java.codegen.Strategy.DefaultParameterMethodOwner) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) SequencedArgument(org.eclipse.ceylon.compiler.typechecker.tree.Tree.SequencedArgument)

Aggregations

SequencedArgument (org.eclipse.ceylon.compiler.typechecker.tree.Tree.SequencedArgument)3 DefaultParameterMethodOwner (org.eclipse.ceylon.compiler.java.codegen.Strategy.DefaultParameterMethodOwner)1 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)1 BaseMemberExpression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.BaseMemberExpression)1 MethodDeclaration (org.eclipse.ceylon.compiler.typechecker.tree.Tree.MethodDeclaration)1 PositionalArgument (org.eclipse.ceylon.compiler.typechecker.tree.Tree.PositionalArgument)1 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)1 JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)1 JCPrimitiveTypeTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCPrimitiveTypeTree)1 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)1 Functional (org.eclipse.ceylon.model.typechecker.model.Functional)1 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)1 ParameterList (org.eclipse.ceylon.model.typechecker.model.ParameterList)1 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)1 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)1