Search in sources :

Example 11 with Value

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

the class MethodOrValueReferenceVisitor method usedIn.

/**
     * Returns 1 if the declaration is captured in the given statements, 0 otherwise.
     */
private int usedIn(List<Statement> stmts) {
    for (Tree.Statement stmt : stmts) {
        // count declarations as usage
        if (stmt instanceof Tree.TypedDeclaration && ((Tree.TypedDeclaration) stmt).getDeclarationModel() == declaration)
            return 1;
        stmt.visit(this);
        if (declaration.isCaptured())
            break;
    }
    boolean used = declaration.isCaptured();
    FunctionOrValue fov = ((FunctionOrValue) declaration);
    fov.setCaptured(false);
    if (fov instanceof Value) {
        Value val = (Value) fov;
        if (val.getSetter() != null)
            val.getSetter().setCaptured(false);
    }
    return used ? 1 : 0;
}
Also used : TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Statement(com.redhat.ceylon.compiler.typechecker.tree.Tree.Statement) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue) Value(com.redhat.ceylon.model.typechecker.model.Value) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue)

Example 12 with Value

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

the class MethodOrValueReferenceVisitor method visitConstructorPlan.

/**
     * Marks declarations as captured if they are used in more than one generated constructor, according
     * to the given plan and knowledge on how we split up constructor delegates.
     */
private void visitConstructorPlan(ConstructorPlan constructorPlan) {
    // if there is no delegation all statements are put in the same method so we can't capture
    if (constructorPlan.delegate == null && !constructorPlan.isDelegate)
        return;
    boolean cs = enterCapturingScope();
    int useCount = usedIn(constructorPlan, false);
    FunctionOrValue fov = ((FunctionOrValue) declaration);
    fov.setCaptured(useCount > 1);
    if (fov instanceof Value) {
        Value val = (Value) fov;
        if (val.getSetter() != null)
            val.getSetter().setCaptured(useCount > 1);
    }
    exitCapturingScope(cs);
}
Also used : FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue) Value(com.redhat.ceylon.model.typechecker.model.Value) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue)

Example 13 with Value

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

the class UnknownTypeCollector method visit.

public void visit(Tree.BaseMemberOrTypeExpression that) {
    super.visit(that);
    Declaration declaration = that.getDeclaration();
    if (declaration == null)
        return;
    if (declaration instanceof Functional) {
        Functional m = (Functional) declaration;
        collectUnknownTypes(m.getType());
        for (ParameterList pl : m.getParameterLists()) {
            for (Parameter p : pl.getParameters()) {
                collectUnknownTypes(p.getType());
            }
        }
    } else if (declaration instanceof Value) {
        Value v = (Value) declaration;
        collectUnknownTypes(v.getType());
    }
}
Also used : Functional(com.redhat.ceylon.model.typechecker.model.Functional) Value(com.redhat.ceylon.model.typechecker.model.Value) ParameterList(com.redhat.ceylon.model.typechecker.model.ParameterList) Parameter(com.redhat.ceylon.model.typechecker.model.Parameter) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Example 14 with Value

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

the class LinkRenderer method processAnnotationParam.

private String processAnnotationParam(String text) {
    if (text.equals("module")) {
        Module mod = getCurrentModule();
        if (mod != null) {
            return processModule(mod);
        }
    }
    if (text.startsWith("module ")) {
        String modName = text.substring(7);
        for (Module m : ceylonDocTool.getTypeChecker().getContext().getModules().getListOfModules()) {
            if (m.getNameAsString().equals(modName)) {
                return processModule(m);
            }
        }
    }
    if (text.equals("package")) {
        Package pkg = getCurrentPackage();
        if (pkg != null) {
            return processPackage(pkg);
        }
    }
    if (text.startsWith("package ")) {
        String pkgName = text.substring(8);
        for (Module m : ceylonDocTool.getTypeChecker().getContext().getModules().getListOfModules()) {
            if (pkgName.startsWith(m.getNameAsString() + ".")) {
                Package pkg = m.getPackage(pkgName);
                if (pkg != null) {
                    return processPackage(pkg);
                }
            }
        }
    }
    if (text.equals("interface")) {
        Interface interf = getCurrentInterface();
        if (interf != null) {
            return processProducedType(interf.getType());
        }
    }
    if (text.equals("class")) {
        Class clazz = getCurrentClass();
        if (clazz != null) {
            return processProducedType(clazz.getType());
        }
    }
    String declName;
    Scope currentScope;
    int pkgSeparatorIndex = text.indexOf("::");
    if (pkgSeparatorIndex == -1) {
        declName = text;
        currentScope = resolveScope(scope);
    } else {
        String pkgName = text.substring(0, pkgSeparatorIndex);
        declName = text.substring(pkgSeparatorIndex + 2, text.length());
        currentScope = ceylonDocTool.getCurrentModule().getPackage(pkgName);
    }
    String[] declNames = declName.split("\\.");
    Declaration currentDecl = null;
    boolean isNested = false;
    for (String currentDeclName : declNames) {
        currentDecl = resolveDeclaration(currentScope, currentDeclName, isNested);
        if (currentDecl != null) {
            if (isValueWithTypeObject(currentDecl)) {
                TypeDeclaration objectType = ((Value) currentDecl).getTypeDeclaration();
                currentScope = objectType;
                currentDecl = objectType;
            } else {
                currentScope = resolveScope(currentDecl);
            }
            isNested = true;
        } else {
            break;
        }
    }
    // we can't link to parameters yet, unless they're toplevel
    if (currentDecl != null && !isParameter(currentDecl)) {
        if (currentDecl instanceof TypeDeclaration) {
            return processProducedType(((TypeDeclaration) currentDecl).getType());
        } else {
            return processTypedDeclaration((TypedDeclaration) currentDecl);
        }
    } else {
        return getUnresolvableLink(text);
    }
}
Also used : Scope(com.redhat.ceylon.model.typechecker.model.Scope) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue) Value(com.redhat.ceylon.model.typechecker.model.Value) Class(com.redhat.ceylon.model.typechecker.model.Class) Package(com.redhat.ceylon.model.typechecker.model.Package) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Module(com.redhat.ceylon.model.typechecker.model.Module) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) Interface(com.redhat.ceylon.model.typechecker.model.Interface) ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface)

Example 15 with Value

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

the class ClassTransformer method refineMethod.

private Function refineMethod(Scope container, TypedReference pr, ClassOrInterface classModel, Function formalMethod, Unit unit) {
    Function refined = new Function();
    refined.setActual(true);
    refined.setShared(formalMethod.isShared());
    refined.setContainer(container);
    // in case there are subclasses
    refined.setDefault(true);
    refined.setDeferred(false);
    refined.setDeprecated(formalMethod.isDeprecated());
    refined.setName(formalMethod.getName());
    refined.setRefinedDeclaration(formalMethod.getRefinedDeclaration());
    refined.setScope(container);
    refined.setType(pr.getType());
    refined.setUnit(unit);
    refined.setUnboxed(formalMethod.getUnboxed());
    refined.setUntrustedType(formalMethod.getUntrustedType());
    refined.setTypeErased(formalMethod.getTypeErased());
    ArrayList<TypeParameter> refinedTp = new ArrayList<TypeParameter>();
    ;
    for (TypeParameter formalTp : formalMethod.getTypeParameters()) {
        refinedTp.add(formalTp);
    }
    refined.setTypeParameters(refinedTp);
    for (ParameterList formalPl : formalMethod.getParameterLists()) {
        ParameterList refinedPl = new ParameterList();
        for (Parameter formalP : formalPl.getParameters()) {
            Parameter refinedP = new Parameter();
            refinedP.setAtLeastOne(formalP.isAtLeastOne());
            refinedP.setDeclaration(refined);
            refinedP.setDefaulted(formalP.isDefaulted());
            refinedP.setDeclaredAnything(formalP.isDeclaredAnything());
            refinedP.setHidden(formalP.isHidden());
            refinedP.setSequenced(formalP.isSequenced());
            refinedP.setName(formalP.getName());
            final TypedReference typedParameter = pr.getTypedParameter(formalP);
            FunctionOrValue paramModel;
            if (formalP.getModel() instanceof Value) {
                Value paramValueModel = refineValue((Value) formalP.getModel(), typedParameter, refined, classModel.getUnit());
                paramValueModel.setInitializerParameter(refinedP);
                paramModel = paramValueModel;
            } else {
                Function paramFunctionModel = refineMethod(refined, typedParameter, classModel, (Function) formalP.getModel(), unit);
                paramFunctionModel.setInitializerParameter(refinedP);
                paramModel = paramFunctionModel;
            }
            refinedP.setModel(paramModel);
            refinedPl.getParameters().add(refinedP);
        }
        refined.addParameterList(refinedPl);
    }
    return refined;
}
Also used : Function(com.redhat.ceylon.model.typechecker.model.Function) TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) TypedReference(com.redhat.ceylon.model.typechecker.model.TypedReference) ArrayList(java.util.ArrayList) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue) JavaBeanValue(com.redhat.ceylon.model.loader.model.JavaBeanValue) Value(com.redhat.ceylon.model.typechecker.model.Value) ParameterList(com.redhat.ceylon.model.typechecker.model.ParameterList) TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) Parameter(com.redhat.ceylon.model.typechecker.model.Parameter) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue)

Aggregations

Value (com.redhat.ceylon.model.typechecker.model.Value)54 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)39 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)28 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)27 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)27 Function (com.redhat.ceylon.model.typechecker.model.Function)25 Type (com.redhat.ceylon.model.typechecker.model.Type)23 Class (com.redhat.ceylon.model.typechecker.model.Class)19 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)19 JavaBeanValue (com.redhat.ceylon.model.loader.model.JavaBeanValue)16 TypedReference (com.redhat.ceylon.model.typechecker.model.TypedReference)15 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)14 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)14 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)13 Parameter (com.redhat.ceylon.model.typechecker.model.Parameter)12 JCTree (com.sun.tools.javac.tree.JCTree)12 AttributeDeclaration (com.redhat.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration)11 FieldValue (com.redhat.ceylon.model.loader.model.FieldValue)11 ParameterList (com.redhat.ceylon.model.typechecker.model.ParameterList)11 JCStatement (com.sun.tools.javac.tree.JCTree.JCStatement)11