Search in sources :

Example 21 with Function

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

the class AnnotationVisitor method visit.

@Override
public void visit(Tree.Constructor that) {
    super.visit(that);
    Function f = that.getDeclarationModel();
    Unit unit = that.getUnit();
    checkAnnotations(that.getAnnotationList(), unit.getCallableConstructorDeclarationType(), unit.getConstructorMetatype(f.getTypedReference()), that);
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) Unit(org.eclipse.ceylon.model.typechecker.model.Unit)

Example 22 with Function

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

the class ExpressionVisitor method visitGenericQualifiedMemberReference.

private void visitGenericQualifiedMemberReference(Tree.QualifiedMemberExpression that, Type receiverType, TypedDeclaration member) {
    if (member instanceof Function && member.isParameterized()) {
        Function generic = (Function) member;
        Scope scope = that.getScope();
        TypedReference target = receiverType.getTypedMember(member, NO_TYPE_ARGS);
        that.setTarget(target);
        Type functionType = genericFunctionType(generic, scope, member, target, unit);
        that.setTypeModel(functionType);
        checkNotJvm(that, "type functions are not supported on the JVM: '" + member.getName(unit) + "' is generic (specify explicit type arguments)");
    }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) 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) NativeUtil.declarationScope(org.eclipse.ceylon.compiler.typechecker.util.NativeUtil.declarationScope) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) TypedReference(org.eclipse.ceylon.model.typechecker.model.TypedReference)

Example 23 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.FunctionalParameterDeclaration that) {
    Parameter p = new Parameter();
    p.setDeclaration(declaration);
    p.setDefaulted(getSpecifier(that) != null);
    Tree.TypedDeclaration td = that.getTypedDeclaration();
    Tree.Type type = td.getType();
    p.setDeclaredAnything(type instanceof Tree.VoidModifier);
    that.setParameterModel(p);
    super.visit(that);
    Function m = (Function) td.getDeclarationModel();
    p.setModel(m);
    p.setName(m.getName());
    m.setInitializerParameter(p);
    parameterList.getParameters().add(p);
    if (type instanceof Tree.SequencedType) {
        type.addError("functional parameter type may not be variadic");
    }
    if (m.isFormal()) {
        that.addError("parameter may not be annotated 'formal'", 1312);
    }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 24 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.FunctionArgument that) {
    Tree.Type type = that.getType();
    final Function f = new Function();
    f.setName("anonymous#" + fid++);
    f.setAnonymous(true);
    if (type.getToken() != null) {
        f.setDeclaredVoid(type instanceof Tree.VoidModifier);
    } else {
        Tree.Block block = that.getBlock();
        if (block != null) {
            f.setDeclaredVoid(true);
            new Visitor() {

                @Override
                public void visit(Tree.Declaration that) {
                }

                @Override
                public void visit(Tree.TypedArgument that) {
                }

                @Override
                public void visit(Tree.ObjectExpression that) {
                }

                @Override
                public void visit(Tree.FunctionArgument that) {
                }

                @Override
                public void visit(Tree.Return that) {
                    if (that.getExpression() != null) {
                        f.setDeclaredVoid(false);
                    }
                    super.visit(that);
                }
            }.visit(block);
        }
    }
    that.setDeclarationModel(f);
    visitArgument(that, f);
    Scope o = enterScope(f);
    Declaration d = beginDeclaration(f);
    super.visit(that);
    endDeclaration(d);
    exitScope(o);
    setParameterLists(f, that.getParameterLists(), that);
}
Also used : Visitor(org.eclipse.ceylon.compiler.typechecker.tree.Visitor) 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) 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.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Example 25 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.AnyMethod that) {
    Function m = new Function();
    that.setDeclarationModel(m);
    visitDeclaration(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);
    if (type instanceof Tree.ValueModifier) {
        type.addError("functions may not be declared using the keyword value");
    }
    if (type instanceof Tree.DynamicModifier) {
        m.setDynamicallyTyped(true);
    }
}
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)

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