Search in sources :

Example 21 with Declaration

use of org.eclipse.ceylon.model.typechecker.model.Declaration in project ceylon by eclipse.

the class ExpressionVisitor method createAnonymousFunctionParameters.

/**
 * Iterate over the arguments of an invocation
 * looking for anonymous functions with missing
 * parameter lists, and create the parameter
 * lists from the type of the parameters to
 * which the arguments are assigned.
 */
private void createAnonymousFunctionParameters(Tree.InvocationExpression that) {
    Tree.Primary primary = that.getPrimary();
    Tree.PositionalArgumentList argList = that.getPositionalArgumentList();
    if (argList != null && primary instanceof Tree.MemberOrTypeExpression) {
        Tree.MemberOrTypeExpression mte = (Tree.MemberOrTypeExpression) primary;
        List<Tree.PositionalArgument> args = argList.getPositionalArguments();
        Declaration dec = mte.getDeclaration();
        if (dec instanceof Functional) {
            Functional fun = (Functional) dec;
            ParameterList paramList = fun.getFirstParameterList();
            if (paramList != null) {
                List<Parameter> params = paramList.getParameters();
                for (int i = 0, asz = args.size(), psz = params.size(); i < asz && i < psz; i++) {
                    Tree.PositionalArgument arg = args.get(i);
                    Parameter param = params.get(i);
                    if (arg instanceof Tree.ListedArgument && param != null) {
                        Tree.ListedArgument larg = (Tree.ListedArgument) arg;
                        List<Parameter> fpl = inferrableParameters(param);
                        Tree.Expression ex = larg.getExpression();
                        if (ex != null && fpl != null) {
                            Tree.Term term = ex.getTerm();
                            if (term instanceof Tree.FunctionArgument) {
                                Tree.FunctionArgument anon = (Tree.FunctionArgument) term;
                                createAnonymousFunctionParameters(fpl, term, anon);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : PositionalArgument(org.eclipse.ceylon.compiler.typechecker.tree.Tree.PositionalArgument) AnalyzerUtil.checkCasesDisjoint(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.checkCasesDisjoint) ModelUtil.argumentSatisfiesEnumeratedConstraint(org.eclipse.ceylon.model.typechecker.model.ModelUtil.argumentSatisfiesEnumeratedConstraint) Functional(org.eclipse.ceylon.model.typechecker.model.Functional) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) AnalyzerUtil.getUnspecifiedParameter(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getUnspecifiedParameter) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) AnalyzerUtil.getMatchingParameter(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getMatchingParameter) PositionalArgument(org.eclipse.ceylon.compiler.typechecker.tree.Tree.PositionalArgument) AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) AnalyzerUtil.getPackageTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) ModelUtil.getNativeDeclaration(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getNativeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)

Example 22 with Declaration

use of org.eclipse.ceylon.model.typechecker.model.Declaration in project ceylon by eclipse.

the class ExpressionVisitor method visit.

@Override
public void visit(Tree.Variable that) {
    super.visit(that);
    if (that instanceof CustomTree.GuardedVariable) {
        CustomTree.GuardedVariable gv = (CustomTree.GuardedVariable) that;
        setTypeForGuardedVariable(that, gv.getConditionList(), gv.isReversed());
        Tree.BaseMemberExpression bme = (Tree.BaseMemberExpression) that.getSpecifierExpression().getExpression().getTerm();
        Declaration original = bme.getDeclaration();
        if (original instanceof TypedDeclaration) {
            that.getDeclarationModel().setOriginalDeclaration((TypedDeclaration) original);
        }
    } else {
        Tree.SpecifierExpression se = that.getSpecifierExpression();
        if (se != null) {
            inferType(that, se);
            Tree.Type type = that.getType();
            if (type != null) {
                Type t = type.getTypeModel();
                if (!isTypeUnknown(t)) {
                    checkType(t, se);
                }
            }
        }
    }
}
Also used : AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) ModelUtil.unionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType) AnalyzerUtil.spreadType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType) AnalyzerUtil.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) ModelUtil.genericFunctionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.genericFunctionType) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) TreeUtil.isEffectivelyBaseMemberExpression(org.eclipse.ceylon.compiler.typechecker.tree.TreeUtil.isEffectivelyBaseMemberExpression) AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) AnalyzerUtil.getPackageTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) ModelUtil.getNativeDeclaration(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getNativeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)

Example 23 with Declaration

use of org.eclipse.ceylon.model.typechecker.model.Declaration in project ceylon by eclipse.

the class ExpressionVisitor method visit.

/*private void checkKeyValueType(Tree.Variable key, Tree.Variable value, 
            Tree.SpecifierExpression se) {
        if (key.getType()!=null && value.getType()!=null) {
            Type kt = key.getType().getTypeModel();
            Type vt = value.getType().getTypeModel();
            if (!isTypeUnknown(kt) && !isTypeUnknown(vt)) {
                checkType(unit.getIterableType(unit.getEntryType(kt, vt)), se);
            }
        }
    }*/
@Override
public void visit(Tree.AttributeGetterDefinition that) {
    Value val = that.getDeclarationModel();
    Declaration od = beginReturnDeclaration(val);
    Tree.Type type = that.getType();
    Tree.Type rt = beginReturnScope(type);
    super.visit(that);
    endReturnScope(rt, val);
    endReturnDeclaration(od);
    Setter setter = val.getSetter();
    if (setter != null) {
        setter.getParameter().getModel().setType(val.getType());
    }
    if (type instanceof Tree.LocalModifier) {
        if (isTypeUnknown(type.getTypeModel())) {
            type.addError("getter type could not be inferred");
        }
    }
}
Also used : Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Setter(org.eclipse.ceylon.model.typechecker.model.Setter) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) AnalyzerUtil.getPackageTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) ModelUtil.getNativeDeclaration(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getNativeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)

Example 24 with Declaration

use of org.eclipse.ceylon.model.typechecker.model.Declaration in project ceylon by eclipse.

the class ExpressionVisitor method resetSuperReference.

void resetSuperReference(Tree.QualifiedMemberOrTypeExpression that) {
    // Just for the IDE!
    Tree.Term p = that.getPrimary();
    if (p instanceof Tree.Super) {
        Declaration dec = that.getDeclaration();
        if (dec != null) {
            Tree.Super s = (Tree.Super) p;
            TypeDeclaration td = (TypeDeclaration) dec.getContainer();
            s.setDeclarationModel(td);
        }
    }
}
Also used : CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) AnalyzerUtil.getPackageTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) ModelUtil.getNativeDeclaration(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getNativeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration) AnalyzerUtil.getPackageTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)

Example 25 with Declaration

use of org.eclipse.ceylon.model.typechecker.model.Declaration in project ceylon by eclipse.

the class ExpressionVisitor method checkPositionalArguments.

private void checkPositionalArguments(ParameterList pl, Reference pr, Tree.PositionalArgumentList pal, Tree.InvocationExpression that) {
    List<Tree.PositionalArgument> args = pal.getPositionalArguments();
    List<Parameter> params = pl.getParameters();
    Declaration target = pr.getDeclaration();
    int argCount = args.size();
    int paramsSize = params.size();
    for (int i = 0; i < paramsSize; i++) {
        Parameter param = params.get(i);
        if (i >= argCount) {
            if (isRequired(param)) {
                Node errorNode = that instanceof Tree.Annotation && args.isEmpty() ? that : pal;
                StringBuilder message = new StringBuilder();
                if (i + 1 < paramsSize && isRequired(params.get(i + 1))) {
                    message.append("missing arguments to required parameters '");
                    appendParam(pr, param, message);
                    int count = 1;
                    for (int j = i + 1; j < paramsSize; j++) {
                        Parameter p = params.get(j);
                        if (p.isDefaulted() || p.isSequenced() && !p.isAtLeastOne()) {
                            break;
                        }
                        message.append(", ");
                        appendParam(pr, p, message);
                        count++;
                    }
                    message.append("'").insert(20, " " + count);
                } else {
                    message.append("missing argument to required parameter '");
                    appendParam(pr, param, message);
                    message.append("'");
                }
                message.append(" of '").append(target.getName(unit)).append("'");
                errorNode.addError(message.toString());
                break;
            }
        } else {
            Tree.PositionalArgument arg = args.get(i);
            Type pt = param.getType();
            if (!dynamic && isTypeUnknown(pt)) {
                arg.addError("parameter type could not be determined: " + paramdesc(param) + getTypeUnknownError(pt));
            }
            if (arg instanceof Tree.SpreadArgument) {
                checkSpreadArgument(pr, param, arg, (Tree.SpreadArgument) arg, params.subList(i, paramsSize));
                break;
            } else if (arg instanceof Tree.Comprehension) {
                if (param.isSequenced()) {
                    checkComprehensionPositionalArgument(param, pr, (Tree.Comprehension) arg, param.isAtLeastOne());
                } else {
                    arg.addError("not a variadic parameter: parameter '" + param.getName() + "' of '" + target.getName() + "'");
                }
                break;
            } else {
                if (param.isSequenced()) {
                    checkSequencedPositionalArgument(param, pr, args.subList(i, argCount));
                    // Note: early return!
                    return;
                } else {
                    checkPositionalArgument(param, pr, (Tree.ListedArgument) arg);
                }
            }
        }
    }
    for (int i = paramsSize; i < argCount; i++) {
        Tree.PositionalArgument arg = args.get(i);
        if (arg instanceof Tree.SpreadArgument) {
            if (unit.isEmptyType(arg.getTypeModel())) {
                continue;
            }
        }
        arg.addError("no matching parameter declared by '" + target.getName(unit) + "': '" + target.getName(unit) + "' has " + paramsSize + " parameters", 2000);
    }
    checkJavaAnnotationElements(args, params, target);
}
Also used : Node(org.eclipse.ceylon.compiler.typechecker.tree.Node) PositionalArgument(org.eclipse.ceylon.compiler.typechecker.tree.Tree.PositionalArgument) AnalyzerUtil.checkCasesDisjoint(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.checkCasesDisjoint) ModelUtil.argumentSatisfiesEnumeratedConstraint(org.eclipse.ceylon.model.typechecker.model.ModelUtil.argumentSatisfiesEnumeratedConstraint) ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) ModelUtil.unionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType) AnalyzerUtil.spreadType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType) AnalyzerUtil.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) ModelUtil.genericFunctionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.genericFunctionType) AnalyzerUtil.getUnspecifiedParameter(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getUnspecifiedParameter) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) AnalyzerUtil.getMatchingParameter(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getMatchingParameter) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) PositionalArgument(org.eclipse.ceylon.compiler.typechecker.tree.Tree.PositionalArgument) AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) AnalyzerUtil.getPackageTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) ModelUtil.getNativeDeclaration(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getNativeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)

Aggregations

Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)370 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)309 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)264 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)129 Type (org.eclipse.ceylon.model.typechecker.model.Type)100 Class (org.eclipse.ceylon.model.typechecker.model.Class)78 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)74 Value (org.eclipse.ceylon.model.typechecker.model.Value)73 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)72 Function (org.eclipse.ceylon.model.typechecker.model.Function)71 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)71 AnalyzerUtil.getTypedDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration)63 ArrayList (java.util.ArrayList)61 AnalyzerUtil.getPackageTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration)60 AnalyzerUtil.getTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)60 ModelUtil.getNativeDeclaration (org.eclipse.ceylon.model.typechecker.model.ModelUtil.getNativeDeclaration)57 AnalyzerUtil.getPackageTypedDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration)51 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)50 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)48 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)45