Search in sources :

Example 56 with TypedDeclaration

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

the class ExpressionVisitor method visit.

@Override
public void visit(Tree.BaseMemberExpression that) {
    super.visit(that);
    boolean notIndirectlyInvoked = !that.getIndirectlyInvoked();
    boolean notDirectlyInvoked = !that.getDirectlyInvoked();
    TypedDeclaration member = resolveBaseMemberExpression(that, notIndirectlyInvoked);
    boolean inferrableAnyway = !notDirectlyInvoked && inferrableAnyway(member);
    checkExtendsClauseReference(that, member);
    if (member != null && notDirectlyInvoked || inferrableAnyway) {
        Tree.TypeArguments tal = that.getTypeArguments();
        List<Type> typeArgs;
        if (typeConstructorArgumentsInferrable(member, that)) {
            typeArgs = new TypeArgumentInference(unit).getInferredTypeArgsForFunctionRef(that, null, inferrableAnyway);
        } else if (explicitTypeArguments(member, tal)) {
            typeArgs = getTypeArguments(tal, null, member.getTypeParameters());
        } else {
            typeArgs = new TypeArgumentInference(unit).getInferredTypeArgsForFunctionRef(that, null, inferrableAnyway);
        }
        if (typeArgs != null) {
            tal.setTypeModels(typeArgs);
            visitBaseMemberExpression(that, member, typeArgs, tal, null);
        // otherwise infer type arguments later
        } else if (notDirectlyInvoked) {
            visitGenericBaseMemberReference(that, member);
        // typeArgumentsImplicit(that);
        }
    }
}
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) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 57 with TypedDeclaration

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

the class ExpressionVisitor method visit.

@Override
public void visit(Tree.Return that) {
    super.visit(that);
    if (returnType == null) {
    // misplaced return statements are already handled by ControlFlowVisitor
    // missing return types declarations already handled by TypeVisitor
    // that.addError("could not determine expected return type");
    } else {
        that.setDeclaration(returnDeclaration);
        Tree.Expression e = that.getExpression();
        if (e == null) {
            if (!(returnType instanceof Tree.VoidModifier)) {
                if (returnDeclaration instanceof Function) {
                    that.addError("function must return a value: " + returndesc() + " is not a 'void' function", 12000);
                } else {
                    that.addError("getter must return a value: " + returndesc() + " is a getter");
                }
            }
        } else {
            if (returnType instanceof Tree.VoidModifier) {
                if (returnDeclaration instanceof Function) {
                    that.addError("function may not return a value: " + returndesc() + " is a 'void' function", 13000);
                } else if (returnDeclaration instanceof TypedDeclaration) {
                    that.addError("setter may not return a value: " + returndesc() + " is a setter");
                } else {
                    that.addError("class initializer may not return a value");
                }
            } else {
                Type at = e.getTypeModel();
                if (at != null) {
                    Type et = returnType.getTypeModel();
                    if (returnType instanceof Tree.LocalModifier) {
                        if (returnDeclaration.isActual()) {
                            // & RV.checkRefinedMemberTypeAssignable()
                            if (!isTypeUnknown(et) && !isTypeUnknown(at)) {
                                checkAssignable(at, et, e, "returned expression must be assignable to inferred return type of " + returndesc(), 2100);
                            }
                        } else {
                            inferReturnType(et, at, e);
                        }
                    } else {
                        if (!isTypeUnknown(et) && !isTypeUnknown(at)) {
                            checkAssignable(at, et, e, "returned expression must be assignable to return type of " + returndesc(), 2100);
                        }
                    }
                }
            }
        }
    }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) 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) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 58 with TypedDeclaration

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

the class ExpressionVisitor method resolveBaseMemberExpression.

private TypedDeclaration resolveBaseMemberExpression(Tree.BaseMemberExpression that, boolean error) {
    Tree.Identifier id = that.getIdentifier();
    String name = name(id);
    Scope scope = that.getScope();
    TypedDeclaration member = getTypedDeclaration(scope, name, that.getSignature(), that.getEllipsis(), that.getUnit());
    if (member == null) {
        if (!dynamic && !isNativeForWrongBackend(scope, unit) && error) {
            that.addError("function or value is not defined: '" + name + "'" + correctionMessage(name, scope, unit, cancellable), 100);
            unit.setUnresolvedReferences();
        }
    } else {
        member = (TypedDeclaration) handleAbstractionOrHeader(member, that, error);
        that.setDeclaration(member);
        if (error) {
            if (checkConcreteConstructor(member, that)) {
                checkBaseVisibility(that, member, name);
            }
        }
    }
    return member;
}
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) NativeUtil.declarationScope(org.eclipse.ceylon.compiler.typechecker.util.NativeUtil.declarationScope) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 59 with TypedDeclaration

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

the class ExpressionVisitor method initOriginalDeclaration.

private void initOriginalDeclaration(Tree.Variable that) {
    if (that.getType() instanceof Tree.SyntheticVariable) {
        TypedDeclaration td = (TypedDeclaration) that.getDeclarationModel();
        Tree.BaseMemberExpression bme = (Tree.BaseMemberExpression) that.getSpecifierExpression().getExpression().getTerm();
        TypedDeclaration d = (TypedDeclaration) bme.getDeclaration();
        td.setOriginalDeclaration(d);
    }
}
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) 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)

Example 60 with TypedDeclaration

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

the class ExpressionVisitor method setFunctionType.

private void setFunctionType(Tree.FunctionModifier local, Type et, Tree.TypedDeclaration that, Tree.Expression e) {
    TypedDeclaration dec = that.getDeclarationModel();
    handleUncheckedNulls(local, e, dec);
    Type t = inferrableType(et);
    local.setTypeModel(t);
    dec.setType(t);
}
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)

Aggregations

TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)110 Type (org.eclipse.ceylon.model.typechecker.model.Type)58 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)51 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)50 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)47 Function (org.eclipse.ceylon.model.typechecker.model.Function)34 Value (org.eclipse.ceylon.model.typechecker.model.Value)28 Class (org.eclipse.ceylon.model.typechecker.model.Class)26 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)26 AnalyzerUtil.getTypedDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration)25 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)22 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)21 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)21 AnalyzerUtil.getPackageTypedDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration)20 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)19 JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)18 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)17 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)17 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)16 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)15