Search in sources :

Example 21 with FunctionOrValue

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

the class TypeHierarchyVisitor method visit.

@Override
public void visit(Tree.BaseMemberExpression that) {
    super.visit(that);
    Declaration dec = that.getDeclaration();
    if (dec instanceof FunctionOrValue && ((FunctionOrValue) dec).isShortcutRefinement()) {
        checkForShortcutRefinement(that, dec);
    }
}
Also used : TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) ModelUtil.getNativeDeclaration(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getNativeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Example 22 with FunctionOrValue

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

the class TypeHierarchyVisitor method getOrBuildType.

/*private void removeTrailing(String trailingString, StringBuilder sb) {
        final int length = sb.length();
        sb.delete(length-trailingString.length(), length);
    }*/
private Type getOrBuildType(TypeDeclaration declaration) {
    Type type = types.get(new TypeDeclKey(declaration));
    if (type == null) {
        type = new Type();
        type.declaration = declaration;
        for (Declaration member : declaration.getMembers()) {
            if (!(member instanceof FunctionOrValue || member instanceof Class) || isConstructor(member) || member.isStatic() || isAbstraction(member)) {
                continue;
            }
            if (declaration.isNative() && member.isNative()) {
                // Make sure we get the right member declaration (the one for the same backend as its container)
                Backends backends = declaration.getNativeBackends();
                member = getNativeDeclaration(member, backends);
                if (member == null) {
                    continue;
                }
            }
            final String name = member.getName();
            Type.Members members = type.membersByName.get(name);
            if (members == null) {
                members = new Type.Members();
                members.name = name;
                type.membersByName.put(name, members);
            }
            if (member.isActual()) {
                members.actuals.add(member);
                if (!member.isFormal()) {
                    members.actualsNonFormals.add(member);
                }
            }
            if (member.isFormal()) {
                members.formals.add(member);
            }
            /*if (!member.isFormal() && member.isInterfaceMember()) {
                    members.concretesOnInterfaces.add(member);
                }*/
            if (member.isDefault()) {
                members.defaults.add(member);
            }
            if (!member.isFormal() && !member.isDefault() && member.isShared()) {
                members.nonFormalsNonDefaults.add(member);
            }
            if (member.isShared()) {
                members.shared.add(member);
            }
        }
        types.put(new TypeDeclKey(declaration), type);
    }
    return type;
}
Also used : IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) UnionType(org.eclipse.ceylon.model.typechecker.model.UnionType) Backends(org.eclipse.ceylon.common.Backends) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) ModelUtil.getNativeDeclaration(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getNativeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Example 23 with FunctionOrValue

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

the class TypeVisitor method visit.

@Override
public void visit(Tree.InitializerParameter that) {
    super.visit(that);
    Parameter p = that.getParameterModel();
    String name = p.getName();
    Declaration a = that.getScope().getDirectMember(name, null, false);
    if (a == null) {
    // Now done in ExpressionVisitor!
    // that.addError("parameter is not defined: '" + p.getName() + "'");
    } else if (!isLegalParameter(a)) {
        that.addError("parameter is not a reference value or function: '" + name + "' is not a value or function");
    } else {
        if (a.isFormal()) {
            that.addError("parameter is a formal attribute: '" + name + "' is annotated 'formal'", 320);
        }
        FunctionOrValue mov = (FunctionOrValue) a;
        if (mov.getInitializerParameter() != null) {
            that.addError("duplicate parameter: '" + name + "' already occurs in the parameter list");
        } else {
            mov.setInitializerParameter(p);
            p.setModel(mov);
        }
    }
    /*if (isGeneric(a)) {
            that.addError("parameter declaration is generic: '" + 
                    name + "' may not declare type parameters");
        }*/
    if (p.isDefaulted()) {
        checkDefaultArg(that.getSpecifierExpression(), p);
    }
}
Also used : Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) 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) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) ModelUtil.getNativeDeclaration(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getNativeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Example 24 with FunctionOrValue

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

the class TypeVisitor method visit.

@Override
public void visit(Tree.TypedDeclaration that) {
    super.visit(that);
    Tree.Type type = that.getType();
    TypedDeclaration dec = that.getDeclarationModel();
    setType(that, type, dec);
    if (dec instanceof FunctionOrValue) {
        FunctionOrValue mv = (FunctionOrValue) dec;
        if (dec.isLate() && mv.isParameter()) {
            that.addError("parameter may not be annotated late");
        }
    }
// if (type.getTypeModel().isTypeConstructor()) {
// type.addError("type constructor may not occur as the type of a declaration");
// }
}
Also used : AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Example 25 with FunctionOrValue

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

the class ExpressionVisitor method inferParameterTypes.

/**
 * Infer parameter types for an anonymous function.
 */
private boolean inferParameterTypes(Reference pr, Parameter param, Tree.Expression e, boolean variadic, boolean error) {
    FunctionOrValue model = param.getModel();
    if (e != null && model != null) {
        Tree.Term term = unwrapExpressionUntilTerm(e.getTerm());
        TypedReference tpr = pr.getTypedParameter(param);
        if (term instanceof Tree.InvocationExpression) {
            Tree.InvocationExpression ie = (Tree.InvocationExpression) term;
            Tree.PositionalArgumentList pal = ie.getPositionalArgumentList();
            Tree.NamedArgumentList nal = ie.getNamedArgumentList();
            if (pal != null && pal.getPositionalArguments().isEmpty() || nal != null && nal.getNamedArguments().isEmpty()) {
                term = ie.getPrimary();
            }
        }
        if (term instanceof Tree.FunctionArgument) {
            Tree.FunctionArgument anon = (Tree.FunctionArgument) term;
            if (model instanceof Functional) {
                // and could be removed
                return inferParameterTypesFromCallableParameter(pr, param, anon, error);
            } else {
                Type paramType = tpr.getFullType();
                if (variadic) {
                    paramType = unit.getIteratedType(paramType);
                }
                paramType = callableFromUnion(paramType);
                if (unit.isCallableType(paramType)) {
                    return inferParameterTypesFromCallableType(paramType, param, anon, error);
                }
            }
        }
    }
    return true;
}
Also used : Functional(org.eclipse.ceylon.model.typechecker.model.Functional) 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) TypedReference(org.eclipse.ceylon.model.typechecker.model.TypedReference) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Aggregations

FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)65 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)28 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)27 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)26 Type (org.eclipse.ceylon.model.typechecker.model.Type)25 Value (org.eclipse.ceylon.model.typechecker.model.Value)24 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)22 Function (org.eclipse.ceylon.model.typechecker.model.Function)22 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)21 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)19 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)13 ArrayList (java.util.ArrayList)12 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)11 TypedReference (org.eclipse.ceylon.model.typechecker.model.TypedReference)10 AnalyzerUtil.getTupleType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType)9 AnalyzerUtil.spreadType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType)9 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)9 ModelUtil.genericFunctionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.genericFunctionType)9 ModelUtil.intersectionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType)9 ModelUtil.unionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType)9