Search in sources :

Example 91 with Function

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

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.MethodDeclaration that) {
    super.visit(that);
    Tree.SpecifierExpression sie = that.getSpecifierExpression();
    Function m = that.getDeclarationModel();
    m.setImplemented(sie != null);
    if (m.isFormal() && sie != null) {
        that.addError("formal method may not have a specification", 1102);
    }
    Tree.Type type = that.getType();
    if (type instanceof Tree.FunctionModifier) {
        if (m.isToplevel()) {
            if (sie == null) {
                type.addError("toplevel function must explicitly specify a return type");
            } else {
                type.addError("toplevel function must explicitly specify a return type", 200);
            }
        } else if (mustHaveExplicitType(m)) {
            type.addError("shared function must explicitly specify a return type", 200);
        }
    }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 92 with Function

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

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.MethodDefinition that) {
    super.visit(that);
    Function m = that.getDeclarationModel();
    m.setImplemented(that.getBlock() != null);
    Tree.Type type = that.getType();
    if (type instanceof Tree.FunctionModifier) {
        if (m.isToplevel()) {
            type.addError("toplevel function must explicitly specify a return type", 200);
        } else if (mustHaveExplicitType(m) && !dynamic) {
            type.addError("shared function must explicitly specify a return type", 200);
        }
    }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 93 with Function

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

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.Constructor that) {
    Constructor c = new Constructor();
    that.setConstructor(c);
    if (scope instanceof Class) {
        Class clazz = (Class) scope;
        if (that.getIdentifier() == null && clazz.getDefaultConstructor() != null) {
            // found an overloaded default constructor
            // we'll set up the class overloads later
            // when exiting visit(Tree.ClassDefinition)
            clazz.setOverloaded(true);
            clazz.setAbstraction(true);
        }
    }
    visitDeclaration(that, c, false);
    Type at;
    Scope realScope = getRealScope(scope);
    if (realScope instanceof Class) {
        Class clazz = (Class) realScope;
        Type ot = clazz.getType();
        c.setExtendedType(ot);
        at = c.appliedType(ot, NO_TYPE_ARGS);
        clazz.setConstructors(true);
        if (clazz.isAnonymous()) {
            that.addError("anonymous class may not have constructor: '" + clazz.getName() + "' is an anonymous class");
        }
    } else {
        at = null;
        that.addError("constructor declaration must occur directly in the body of a class");
    }
    Function f = new Function();
    f.setType(at);
    that.setDeclarationModel(f);
    visitDeclaration(that, f);
    Scope o = enterScope(c);
    super.visit(that);
    exitScope(o);
    f.setImplemented(that.getBlock() != null);
    if (that.getParameterList() == null) {
        that.addError("missing parameter list in constructor declaration: '" + name(that.getIdentifier()) + "' must have a parameter list", 1000);
    } else {
        ParameterList model = that.getParameterList().getModel();
        model.setFirst(true);
        if (model != null) {
            c.addParameterList(model);
            // TODO: fix this
            f.addParameterList(model);
        }
    }
    if (c.isAbstract()) {
        if (that.getIdentifier() == null) {
            that.addError("default constructor may not be annotated 'abstract'", 1601);
        } else if (c.isShared()) {
            that.addError("abstract constructor may not be annotated 'shared'", 1610);
        }
    }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) LazyType(org.eclipse.ceylon.model.typechecker.model.LazyType) UnionType(org.eclipse.ceylon.model.typechecker.model.UnionType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) TypeVisitor.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.TypeVisitor.getTupleType) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) ConditionScope(org.eclipse.ceylon.model.typechecker.model.ConditionScope) ModelUtil.getRealScope(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getRealScope) ModelUtil.isDefaultConstructor(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isDefaultConstructor) ModelUtil.isConstructor(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isConstructor) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) Class(org.eclipse.ceylon.model.typechecker.model.Class) AnalyzerUtil.isVeryAbstractClass(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.isVeryAbstractClass) ModelUtil.isAnonymousClass(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isAnonymousClass)

Example 94 with Function

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

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.MethodArgument that) {
    Function m = new Function();
    m.setImplemented(that.getBlock() != null);
    that.setDeclarationModel(m);
    visitArgument(that, m);
    Scope o = enterScope(m);
    super.visit(that);
    exitScope(o);
    setParameterLists(m, that.getParameterLists(), that);
    Tree.Type type = that.getType();
    m.setDeclaredVoid(type instanceof Tree.VoidModifier);
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) ConditionScope(org.eclipse.ceylon.model.typechecker.model.ConditionScope) ModelUtil.getRealScope(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getRealScope) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 95 with Function

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

the class DeclarationVisitor method initFunctionOverload.

// An overloaded function is represented in
// the model with multiple Function objects
private static boolean initFunctionOverload(Function model, Function member, Scope scope, Unit unit) {
    Function abstraction;
    Function method = (Function) member;
    Function newMethod = (Function) model;
    newMethod.setOverloaded(true);
    if (method.isAbstraction()) {
        abstraction = method;
        abstraction.getOverloads().add(model);
        return abstraction.isActual() && !model.isActual();
    } else {
        String name = model.getName();
        // create the "abstraction"
        // for the overloaded method
        method.setOverloaded(true);
        abstraction = new Function();
        abstraction.setAbstraction(true);
        abstraction.setType(new UnknownType(unit).getType());
        abstraction.setName(name);
        abstraction.setShared(true);
        abstraction.setActual(method.isActual());
        abstraction.setFormal(method.isFormal());
        abstraction.setDefault(method.isDefault());
        abstraction.setContainer(scope);
        abstraction.setScope(scope);
        abstraction.setUnit(unit);
        abstraction.initOverloads(method, newMethod);
        scope.addMember(abstraction);
        // put the abstraction first
        // TODO: is this hack really necessary?
        scope.getMembers().remove(method);
        scope.getMembers().add(method);
        return true;
    }
}
Also used : UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) Function(org.eclipse.ceylon.model.typechecker.model.Function)

Aggregations

Function (org.eclipse.ceylon.model.typechecker.model.Function)167 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)71 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)70 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)69 Type (org.eclipse.ceylon.model.typechecker.model.Type)68 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)62 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)57 Value (org.eclipse.ceylon.model.typechecker.model.Value)50 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)46 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)43 Class (org.eclipse.ceylon.model.typechecker.model.Class)39 ArrayList (java.util.ArrayList)32 ParameterList (org.eclipse.ceylon.model.typechecker.model.ParameterList)29 JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)26 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)23 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)23 TypedReference (org.eclipse.ceylon.model.typechecker.model.TypedReference)23 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)23 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)22 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)21