Package com.redhat.ceylon.compiler.typechecker.model

Examples of com.redhat.ceylon.compiler.typechecker.model.ProducedType


                for (Tree.PositionalArgument arg : argList.getPositionalArguments()) {
                    fillInParams &= arg.getParameter() == null;
                }
                if (fillInParams) {
                    //Get the callable and try to assign params from there
                    ProducedType callable = that.getPrimary().getTypeModel().getSupertype(
                            that.getUnit().getCallableDeclaration());
                    if (callable != null) {
                        //This is a tuple with the arguments to the callable
                        //(can be union with empty if first param is defaulted)
                        ProducedType callableArgs = callable.getTypeArgumentList().get(1);
                        boolean isUnion=false;
                        if (callableArgs.getDeclaration() instanceof UnionType) {
                            if (callableArgs.getCaseTypes().size() == 2) {
                                callableArgs = callableArgs.minus(gen.getTypeUtils().empty.getType());
                            }
                            isUnion=callableArgs.getDeclaration() instanceof UnionType;
                        }
                        //This is the type of the first argument
                        boolean isSequenced = !(isUnion || gen.getTypeUtils().tuple.equals(callableArgs.getDeclaration()));
                        ProducedType argtype = isUnion ? callableArgs :
                            callableArgs.getDeclaration() instanceof TypeParameter ? callableArgs :
                            callableArgs.getTypeArgumentList().get(
                                isSequenced ? 0 : 1);
                        Parameter p = null;
                        int c = 0;
                        for (Tree.PositionalArgument arg : argList.getPositionalArguments()) {
                            if (p == null) {
                                p = new Parameter();
                                p.setName("arg"+c);
                                p.setDeclaration(that.getPrimary().getTypeModel().getDeclaration());
                                Value v = new Value();
                                v.setContainer(that.getPositionalArgumentList().getScope());
                                v.setType(argtype);
                                p.setModel(v);
                                if (callableArgs == null || isSequenced) {
                                    p.setSequenced(true);
                                } else if (!isSequenced) {
                                    ProducedType next = isUnion ? null : callableArgs.getTypeArgumentList().get(2);
                                    if (next != null && next.getSupertype(gen.getTypeUtils().tuple) == null) {
                                        //It's not a tuple, so no more regular parms. It can be:
                                        //empty|tuple if defaulted params
                                        //empty if no more params
                                        //sequential if sequenced param
                                        if (next.getDeclaration() instanceof UnionType) {
                                            //empty|tuple
                                            callableArgs = next.minus(gen.getTypeUtils().empty.getType());
                                            isSequenced = !gen.getTypeUtils().tuple.equals(callableArgs.getDeclaration());
                                            argtype = callableArgs.getTypeArgumentList().get(isSequenced ? 0 : 1);
                                        } else {
                                            //we'll bet on sequential (if it's empty we don't care anyway)
                                            argtype = next;
View Full Code Here


            final boolean forceSequenced, final boolean generateVars) {
        if (!args.isEmpty()) {
            final List<String> argvars = new ArrayList<String>(args.size());
            boolean first=true;
            boolean opened=false;
            ProducedType sequencedType=null;
            for (Tree.PositionalArgument arg : args) {
                Tree.Expression expr;
                final Parameter pd = arg.getParameter();
                if (arg instanceof Tree.ListedArgument) {
                    if (!first) gen.out(",");
                    expr = ((Tree.ListedArgument) arg).getExpression();
                    ProducedType exprType = expr.getTypeModel();
                    boolean dyncheck = gen.isInDynamicBlock() && pd != null && !Util.isTypeUnknown(pd.getType())
                            && exprType.containsUnknowns();
                    if (forceSequenced || (pd != null && pd.isSequenced())) {
                        if (dyncheck) {
                            //We don't have a real type so get the one declared in the parameter
                            exprType = pd.getType();
                        }
                        if (sequencedType == null) {
                            sequencedType=exprType;
                        } else {
                            ArrayList<ProducedType> cases = new ArrayList<ProducedType>(2);
                            Util.addToUnion(cases, sequencedType);
                            Util.addToUnion(cases, exprType);
                            if (cases.size() > 1) {
                                UnionType ut = new UnionType(that.getUnit());
                                ut.setCaseTypes(cases);
                                sequencedType = ut.getType();
                            } else {
                                sequencedType = cases.get(0);
                            }
                        }
                        if (!opened) {
                            if (generateVars) {
                                final String argvar = names.createTempVariable();
                                argvars.add(argvar);
                                gen.out(argvar, "=");
                            }
                            gen.out("[");
                        }
                        opened=true;
                    } else if (generateVars) {
                        final String argvar = names.createTempVariable();
                        argvars.add(argvar);
                        gen.out(argvar, "=");
                    }
                    final int boxType = pd==null?0:gen.boxUnboxStart(expr.getTerm(), pd.getModel());
                    if (dyncheck) {
                        Map<TypeParameter,ProducedType> targs = null;
                        if (primary instanceof Tree.MemberOrTypeExpression) {
                            targs = ((Tree.MemberOrTypeExpression)primary).getTarget().getTypeArguments();
                        }
                        TypeUtils.generateDynamicCheck(expr, pd.getType(), gen, false, targs);
                    } else {
                        arg.visit(gen);
                    }
                    if (boxType == 4) {
                        gen.out(",");
                        //Add parameters
                        describeMethodParameters(expr.getTerm());
                        gen.out(",");
                        TypeUtils.printTypeArguments(arg, arg.getTypeModel().getTypeArguments(), gen, false,
                                arg.getTypeModel().getVarianceOverrides());
                    }
                    gen.boxUnboxEnd(boxType);
                } else if (arg instanceof Tree.SpreadArgument || arg instanceof Tree.Comprehension) {
                    if (arg instanceof Tree.SpreadArgument) {
                        expr = ((Tree.SpreadArgument) arg).getExpression();
                    } else {
                        expr = null;
                    }
                    if (opened) {
                        SequenceGenerator.closeSequenceWithReifiedType(that,
                                gen.getTypeUtils().wrapAsIterableArguments(sequencedType), gen);
                        gen.out(".chain(");
                        sequencedType=null;
                    } else if (!first) {
                        gen.out(",");
                    }
                    if (arg instanceof Tree.SpreadArgument) {
                        TypedDeclaration td = pd == null ? null : pd.getModel();
                        int boxType = gen.boxUnboxStart(expr.getTerm(), td);
                        if (boxType == 4) {
                            arg.visit(gen);
                            gen.out(",");
                            describeMethodParameters(expr.getTerm());
                            gen.out(",");
                            TypeUtils.printTypeArguments(arg, arg.getTypeModel().getTypeArguments(), gen, false,
                                    arg.getTypeModel().getVarianceOverrides());
                        } else if (pd == null) {
                            if (gen.isInDynamicBlock() && primary instanceof Tree.MemberOrTypeExpression
                                    && ((Tree.MemberOrTypeExpression)primary).getDeclaration() == null
                                    && arg.getTypeModel() != null && arg.getTypeModel().getDeclaration().inherits((gen.getTypeUtils().tuple))) {
                                //Spread dynamic parameter
                                ProducedType tupleType = arg.getTypeModel();
                                ProducedType targ = tupleType.getTypeArgumentList().get(2);
                                arg.visit(gen);
                                gen.out(".$_get(0)");
                                int i = 1;
                                while (!targ.getDeclaration().inherits(gen.getTypeUtils().empty)) {
                                    gen.out(",");
                                    arg.visit(gen);
                                    gen.out(".$_get("+(i++)+")");
                                    targ = targ.getTypeArgumentList().get(2);
                                }
                            } else {
                                arg.visit(gen);
                            }
                        } else if (pd.isSequenced()) {
                            arg.visit(gen);
                        } else {
                            final String specialSpreadVar = gen.getNames().createTempVariable();
                            gen.out("(", specialSpreadVar, "=");
                            args.get(args.size()-1).visit(gen);
                            gen.out(".sequence(),");
                            if (pd.isDefaulted()) {
                                gen.out(gen.getClAlias(), "nn$(",
                                        specialSpreadVar, ".$_get(0))?", specialSpreadVar,
                                        ".$_get(0):undefined)");
                            } else {
                                gen.out(specialSpreadVar, ".$_get(0))");
                            }
                            //Find out if there are more params
                            final List<Parameter> moreParams;
                            final Declaration pdd = pd.getDeclaration();
                            boolean found = false;
                            if (pdd instanceof Method) {
                                moreParams = ((Method)pdd).getParameterLists().get(0).getParameters();
                            } else if (pdd instanceof com.redhat.ceylon.compiler.typechecker.model.Class) {
                                moreParams = ((com.redhat.ceylon.compiler.typechecker.model.Class)pdd).getParameterList().getParameters();
                            } else {
                                //Check the parameters of the primary (obviously a callable, so this is a Tuple)
                                List<Parameter> cparms = gen.getTypeUtils().convertTupleToParameters(
                                        primary.getTypeModel().getTypeArgumentList().get(1));
                                cparms.remove(0);
                                moreParams = cparms;
                                found = true;
                            }
                            if (moreParams != null) {
                                int c = 1;
                                for (Parameter restp : moreParams) {
                                    if (found) {
                                        final String cs=Integer.toString(c++);
                                        if (restp.isDefaulted()) {
                                            gen.out(",", gen.getClAlias(), "nn$(", specialSpreadVar,
                                                    ".$_get(", cs, "))?", specialSpreadVar, ".$_get(", cs, "):undefined");
                                        } else {
                                            gen.out(",", specialSpreadVar, ".$_get(", cs, ")");
                                        }
                                    } else {
                                        found = restp.equals(pd);
                                    }
                                }
                            }
                        }
                        gen.boxUnboxEnd(boxType);
                    } else {
                        ((Tree.Comprehension)arg).visit(gen);
                    }
                    if (opened) {
                        gen.out(",");
                        if (expr == null) {
                            //it's a comprehension
                            TypeUtils.printTypeArguments(that,
                                    gen.getTypeUtils().wrapAsIterableArguments(arg.getTypeModel()), gen, false, null);
                        } else {
                            ProducedType spreadType = TypeUtils.findSupertype(gen.getTypeUtils().sequential,
                                    expr.getTypeModel());
                            if (spreadType == null) {
                                //Go directly to Iterable
                                spreadType = TypeUtils.findSupertype(gen.getTypeUtils().iterable, expr.getTypeModel());
                            }
                            TypeUtils.printTypeArguments(that, spreadType.getTypeArguments(), gen, false,
                                    spreadType.getVarianceOverrides());
                        }
                        gen.out(")");
                    }
                    if (arg instanceof Tree.Comprehension) {
                        break;
View Full Code Here

                first = false;
            } else {
                gen.out(",");
            }
            gen.out(e.getKey().getName(), "$", e.getKey().getDeclaration().getName(), ":");
            final ProducedType pt = e.getValue();
            if (pt == null) {
                gen.out("'", e.getKey().getName(), "'");
            } else if (!outputTypeList(node, pt, gen, skipSelfDecl)) {
                boolean hasParams = pt.getTypeArgumentList() != null && !pt.getTypeArgumentList().isEmpty();
                boolean closeBracket = false;
                final TypeDeclaration d = pt.getDeclaration();
                if (d instanceof TypeParameter) {
                    resolveTypeParameter(node, (TypeParameter)d, gen, skipSelfDecl);
                } else {
                    closeBracket = pt.getDeclaration() instanceof TypeAlias==false;
                    if (closeBracket)gen.out("{t:");
                    outputQualifiedTypename(node,
                            node != null && gen.isImported(node.getUnit().getPackage(), pt.getDeclaration()),
                            pt, gen, skipSelfDecl);
                }
                if (hasParams) {
                    gen.out(",a:");
                    printTypeArguments(node, pt.getTypeArguments(), gen, skipSelfDecl, pt.getVarianceOverrides());
                }
                SiteVariance siteVariance = overrides == null ? null : overrides.get(e.getKey());
                if (siteVariance != null) {
                    gen.out(",", MetamodelGenerator.KEY_US_VARIANCE, ":");
                    if (siteVariance == SiteVariance.IN) {
View Full Code Here

            gen.out("{t:'u");
            subs = d.getCaseTypes();
        } else if ("ceylon.language::Tuple".equals(d.getQualifiedNameString())) {
            gen.out("{t:'T");
            subs = node.getUnit().getTupleElementTypes(pt);
            final ProducedType lastType = subs.get(subs.size()-1);
            if (node.getUnit().getSequenceDeclaration().equals(lastType.getDeclaration())
                    || node.getUnit().getSequentialDeclaration().equals(lastType.getDeclaration())) {
                //Non-empty, non-tuple tail; union it with its type parameter
                UnionType utail = new UnionType(node.getUnit());
                utail.setCaseTypes(Arrays.asList(lastType.getTypeArgumentList().get(0), lastType));
                subs.remove(subs.size()-1);
                subs.add(utail.getType());
            }
        } else {
            return false;
View Full Code Here

        } else {
            //it has to be a method, right?
            //We need to find the index of the parameter where the argument occurs
            //...and it could be null...
            int plistCount = -1;
            ProducedType type = null;
            for (Iterator<ParameterList> iter0 = ((Method)tp.getContainer()).getParameterLists().iterator();
                    type == null && iter0.hasNext();) {
                plistCount++;
                for (Iterator<Parameter> iter1 = iter0.next().getParameters().iterator();
                        type == null && iter1.hasNext();) {
                    if (type == null) {
                        type = typeContainsTypeParameter(iter1.next().getType(), tp);
                    }
                }
            }
            //The ProducedType that we find corresponds to a parameter, whose type can be:
            //A type parameter in the method, in which case we just use the argument's type (may be null)
            //A component of a union/intersection type, in which case we just use the argument's type (may be null)
            //A type argument of the argument's type, in which case we must get the reified generic from the argument
            if (tp.getContainer() == parent) {
                gen.out("$$$mptypes.", tp.getName(), "$", tp.getDeclaration().getName());
            } else {
                gen.out("/*METHOD TYPEPARM plist ", Integer.toString(plistCount), "#",
                        tp.getName(), "*/'", type.getProducedTypeQualifiedName(), "'");
            }
        }
    }
View Full Code Here

                        }
                    }
                    gen.out(",", MetamodelGenerator.KEY_DEFAULT,":1");
                }
            } else if (tdecl.inherits(gen.getTypeUtils().sequential)) {
                ProducedType _t2 = _tuple.getSupertype(gen.getTypeUtils().sequential);
                //Handle Sequence, for nonempty variadic parameters
                metamodelTypeNameOrList(gen.getCurrentPackage(), _t2.getTypeArgumentList().get(0), gen);
                gen.out(",seq:1");
                _tuple = gen.getTypeUtils().empty.getType();
            } else if (tdecl instanceof UnionType) {
                metamodelTypeNameOrList(gen.getCurrentPackage(), _tuple, gen);
                tdecl = gen.getTypeUtils().empty; _tuple=null;
View Full Code Here

        if (md == null) {
            expr.addUnexpectedError("Left term of intersection operator should have method named " + methodName);
            return null;
        }
        Map<TypeParameter, ProducedType> targs = expr.getRightTerm().getTypeModel().getTypeArguments();
        ProducedType otherType = null;
        for (TypeParameter tp : targs.keySet()) {
            if (tp.getName().equals(rightTpName)) {
                otherType = targs.get(tp);
                break;
            }
View Full Code Here

        super.visit(that);
    }
    @Override
    public void visit(AnyAttribute that) {
        //local vars
      ProducedType t = that.getDeclarationModel().getType();
      if (t!=null) {
        retrieveDocs(t.getDeclaration().getAnnotations(),
            that.getType().getLocation());
      }
        super.visit(that);
    }
View Full Code Here

            if (md.getSpecifierExpression() != null) {
                md.getSpecifierExpression().visit(this);
            }
        }
        else {
            ProducedType t = that.getDeclarationModel().getType();
            if (t!=null) {
              retrieveDocs(t.getDeclaration().getAnnotations(),
                  that.getType().getLocation());
            }
        }
        super.visit(that);
    }
View Full Code Here

            Assert.assertNotNull(b.getSatisfiedTypes());
            Assert.assertEquals("satisfied types for " + n,
                    a.getSatisfiedTypes().size(), b.getSatisfiedTypes().size());
            Iterator<ProducedType> bsats = b.getSatisfiedTypes().iterator();
            for (ProducedType satA : a.getSatisfiedTypes()) {
                ProducedType satB = bsats.next();
                compareTypes(satA, satB, null);
            }
        }
    }
View Full Code Here

TOP

Related Classes of com.redhat.ceylon.compiler.typechecker.model.ProducedType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.