Search in sources :

Example 31 with Function

use of com.redhat.ceylon.model.typechecker.model.Function in project ceylon-compiler by ceylon.

the class MethodOrValueReferenceVisitor method capture.

private void capture(Tree.Primary that, boolean methodSpecifier) {
    if (that instanceof Tree.MemberOrTypeExpression) {
        final Declaration decl = ((Tree.MemberOrTypeExpression) that).getDeclaration();
        if (!(decl instanceof TypedDeclaration)) {
            return;
        }
        TypedDeclaration d = (TypedDeclaration) decl;
        if (Decl.equal(d, declaration) || (d.isNativeHeader() && d.getOverloads().contains(declaration))) {
            d = declaration;
            if (Decl.isParameter(d)) {
                // a reference from a default argument 
                // expression of the same parameter 
                // list does not capture a parameter
                Scope s = that.getScope();
                boolean sameScope = d.getContainer().equals(s) || (s instanceof Declaration && (Decl.isParameter((Declaration) s) || (s instanceof Value && !((Value) s).isTransient())) && d.getContainer().equals(s.getScope()));
                if (!sameScope || methodSpecifier || inLazySpecifierExpression) {
                    ((FunctionOrValue) d).setCaptured(true);
                }
                // Accessing another instance's member passed to a class initializer
                if (that instanceof Tree.QualifiedMemberExpression) {
                    if (d instanceof TypedDeclaration && ((TypedDeclaration) d).getOtherInstanceAccess()) {
                        ((FunctionOrValue) d).setCaptured(true);
                    }
                }
                if (isCapturableMplParameter(d)) {
                    ((FunctionOrValue) d).setCaptured(true);
                }
            } else if (Decl.isValue(d) || Decl.isGetter(d)) {
                Value v = (Value) d;
                v.setCaptured(true);
                if (Decl.isObjectValue(d)) {
                    v.setSelfCaptured(isSelfCaptured(that, d));
                }
                if (v.getSetter() != null) {
                    v.getSetter().setCaptured(true);
                }
            } else if (d instanceof Function) {
                ((Function) d).setCaptured(true);
            }
        /*if (d.isVariable() && !d.isClassMember() && !d.isToplevel()) {
                    that.addError("access to variable local from capturing scope: " + declaration.getName());
                }*/
        }
    }
}
Also used : TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Function(com.redhat.ceylon.model.typechecker.model.Function) Scope(com.redhat.ceylon.model.typechecker.model.Scope) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue) Value(com.redhat.ceylon.model.typechecker.model.Value) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue)

Example 32 with Function

use of com.redhat.ceylon.model.typechecker.model.Function in project ceylon-compiler by ceylon.

the class ClassOrPackageDoc method writeParameterList.

protected final void writeParameterList(Functional f, Referenceable scope) throws IOException {
    for (ParameterList lists : f.getParameterLists()) {
        write("(");
        boolean first = true;
        for (Parameter param : lists.getParameters()) {
            if (!first) {
                write(", ");
            } else {
                first = false;
            }
            if (param.getModel() instanceof Function) {
                writeFunctionalParameter(param, scope);
            } else {
                linkRenderer().to(param.getType()).useScope(scope).write();
                write(" ");
                around("span class='parameter'", param.getName());
            }
            if (param.isDefaulted()) {
                String defaultValue = getParameterDefaultValue(param);
                if (defaultValue != null) {
                    around("span class='parameter-default-value'", " = ");
                    if (simpleDefaultValues.contains(defaultValue)) {
                        around("span class='parameter-default-value' title='Parameter default value'", defaultValue);
                    } else {
                        around("a class='parameter-default-value' href='#" + f.getName() + "-" + param.getName() + "' title='Go to parameter default value'", "...");
                    }
                }
            }
        }
        write(")");
    }
}
Also used : Function(com.redhat.ceylon.model.typechecker.model.Function) ParameterList(com.redhat.ceylon.model.typechecker.model.ParameterList) TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) Parameter(com.redhat.ceylon.model.typechecker.model.Parameter)

Example 33 with Function

use of com.redhat.ceylon.model.typechecker.model.Function in project ceylon-compiler by ceylon.

the class ParameterDefinitionBuilder method functionalParameters.

static void functionalParameters(StringBuilder sb, ParameterList pl) {
    sb.append('(');
    Iterator<Parameter> parameters = pl.getParameters().iterator();
    while (parameters.hasNext()) {
        Parameter p = parameters.next();
        FunctionOrValue pm = p.getModel();
        sb.append(pm.getName());
        if (p.isSequenced()) {
            if (p.isAtLeastOne()) {
                sb.append('+');
            } else {
                sb.append('*');
            }
        }
        if (pm instanceof Function) {
            Function meth = (Function) pm;
            functionalName(sb, (Function) pm);
        }
        if (parameters.hasNext()) {
            sb.append(',');
        }
    }
    sb.append(')');
}
Also used : Function(com.redhat.ceylon.model.typechecker.model.Function) Parameter(com.redhat.ceylon.model.typechecker.model.Parameter) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue)

Example 34 with Function

use of com.redhat.ceylon.model.typechecker.model.Function in project ceylon-compiler by ceylon.

the class Naming method getMethodNameInternal.

private static String getMethodNameInternal(TypedDeclaration decl) {
    String name;
    if (decl.isClassOrInterfaceMember() && decl instanceof Function) {
        Declaration refined = decl.getRefinedDeclaration();
        if (refined instanceof JavaMethod) {
            return ((JavaMethod) refined).getRealName();
        }
        name = quoteMethodNameIfProperty((Function) decl);
    } else {
        name = decl.getName();
    }
    if (decl.isClassMember() && "readResolve".equals(name) && Strategy.addReadResolve((Class) decl.getContainer())) {
        return quote(name);
    }
    if (decl.isClassMember() && "writeReplace".equals(name) && Strategy.useSerializationProxy((Class) decl.getContainer())) {
        return quote(name);
    }
    // ERASURE
    if (QUOTABLE_METHOD_NAMES.contains(name)) {
        return quote(name);
    } else {
        return quoteIfJavaKeyword(name);
    }
}
Also used : LazyFunction(com.redhat.ceylon.model.loader.model.LazyFunction) Function(com.redhat.ceylon.model.typechecker.model.Function) JavaMethod(com.redhat.ceylon.model.loader.model.JavaMethod) Class(com.redhat.ceylon.model.typechecker.model.Class) LazyClass(com.redhat.ceylon.model.loader.model.LazyClass) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Example 35 with Function

use of com.redhat.ceylon.model.typechecker.model.Function in project ceylon-compiler by ceylon.

the class Naming method quoteMethodNameIfProperty.

private static String quoteMethodNameIfProperty(Function method) {
    String name = method.getName();
    if (!method.isShared()) {
        name = suffixName(Suffix.$priv$, name);
    }
    // Toplevel methods keep their original name because their names might be mangled
    if (method instanceof LazyFunction) {
        return ((LazyFunction) method).getRealName();
    }
    // since local methods have a $getter suffix
    if (!method.isClassOrInterfaceMember())
        return name;
    // do not quote method names if we have a refined constraint
    Function refinedMethod = (Function) method.getRefinedDeclaration();
    if (refinedMethod instanceof JavaMethod) {
        return ((JavaMethod) refinedMethod).getRealName();
    }
    // get/is with at least one more letter, no parameter and non-void type
    if (((name.length() >= 4 && name.startsWith("get")) || name.length() >= 3 && name.startsWith("is")) && method.getFirstParameterList().getParameters().isEmpty() && !AbstractTransformer.isAnything(method.getType()))
        return quote(name);
    // set with one parameter and void type
    if ((name.length() >= 4 && name.startsWith("set")) && method.getFirstParameterList().getParameters().size() == 1 && AbstractTransformer.isAnything(method.getType()))
        return quote(name);
    return name;
}
Also used : LazyFunction(com.redhat.ceylon.model.loader.model.LazyFunction) Function(com.redhat.ceylon.model.typechecker.model.Function) JavaMethod(com.redhat.ceylon.model.loader.model.JavaMethod) LazyFunction(com.redhat.ceylon.model.loader.model.LazyFunction)

Aggregations

Function (com.redhat.ceylon.model.typechecker.model.Function)74 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)35 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)35 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)33 Type (com.redhat.ceylon.model.typechecker.model.Type)33 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)26 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)26 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)25 Value (com.redhat.ceylon.model.typechecker.model.Value)25 Class (com.redhat.ceylon.model.typechecker.model.Class)23 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)22 Parameter (com.redhat.ceylon.model.typechecker.model.Parameter)20 JCTree (com.sun.tools.javac.tree.JCTree)18 TypedReference (com.redhat.ceylon.model.typechecker.model.TypedReference)17 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)17 ArrayList (java.util.ArrayList)14 ParameterList (com.redhat.ceylon.model.typechecker.model.ParameterList)13 ModelUtil.appliedType (com.redhat.ceylon.model.typechecker.model.ModelUtil.appliedType)12 MethodDeclaration (com.redhat.ceylon.compiler.typechecker.tree.Tree.MethodDeclaration)11 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)11