Search in sources :

Example 16 with Scope

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

the class ExpressionTransformer method transform.

public JCExpression transform(Tree.Parameter param) {
    // Transform the expression marking that we're inside a defaulted parameter for $this-handling
    // needDollarThis  = true;
    JCExpression expr;
    at(param);
    if (Strategy.hasDefaultParameterValueMethod(param.getParameterModel())) {
        Tree.SpecifierOrInitializerExpression spec = Decl.getDefaultArgument(param);
        Scope container = param.getParameterModel().getModel().getContainer();
        boolean classParameter = container instanceof ClassOrInterface;
        ClassOrInterface oldWithinDefaultParameterExpression = withinDefaultParameterExpression;
        if (classParameter)
            withinDefaultParameterExpression((ClassOrInterface) container);
        if (param instanceof Tree.FunctionalParameterDeclaration) {
            Tree.FunctionalParameterDeclaration fpTree = (Tree.FunctionalParameterDeclaration) param;
            Tree.SpecifierExpression lazy = (Tree.SpecifierExpression) spec;
            Function fp = (Function) fpTree.getParameterModel().getModel();
            expr = CallableBuilder.anonymous(gen(), param, (Function) fpTree.getTypedDeclaration().getDeclarationModel(), lazy.getExpression(), ((Tree.MethodDeclaration) fpTree.getTypedDeclaration()).getParameterLists(), getTypeForFunctionalParameter(fp), true).build();
        } else {
            expr = transformExpression(spec.getExpression(), CodegenUtil.getBoxingStrategy(param.getParameterModel().getModel()), param.getParameterModel().getType());
        }
        if (classParameter)
            withinDefaultParameterExpression(oldWithinDefaultParameterExpression);
    } else {
        expr = makeErroneous(param, "compiler bug: no default parameter value method");
    }
    // needDollarThis = false;
    return expr;
}
Also used : ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) Function(com.redhat.ceylon.model.typechecker.model.Function) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) Scope(com.redhat.ceylon.model.typechecker.model.Scope) JCTree(com.sun.tools.javac.tree.JCTree) Tree(com.redhat.ceylon.compiler.typechecker.tree.Tree)

Example 17 with Scope

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

the class ExpressionTransformer method isRecursiveReference.

// 
// Helper functions
private boolean isRecursiveReference(Tree.StaticMemberOrTypeExpression expr) {
    Declaration decl = expr.getDeclaration();
    Scope s = expr.getScope();
    // do we have decl as our container anywhere in the scope?
    while (s != null && !Decl.equalScopeDecl(s, decl)) {
        s = s.getContainer();
    }
    return Decl.equalScopeDecl(s, decl);
}
Also used : Scope(com.redhat.ceylon.model.typechecker.model.Scope) 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 18 with Scope

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

the class ClassTransformer method typeParametersOfAllContainers.

private java.util.List<TypeParameter> typeParametersOfAllContainers(final ClassOrInterface model, boolean includeModelTypeParameters) {
    java.util.List<java.util.List<TypeParameter>> r = new ArrayList<java.util.List<TypeParameter>>(1);
    Scope s = model.getContainer();
    while (!(s instanceof Package)) {
        if (s instanceof Generic) {
            r.add(0, ((Generic) s).getTypeParameters());
        }
        s = s.getContainer();
    }
    Set<String> names = new HashSet<String>();
    for (TypeParameter tp : model.getTypeParameters()) {
        names.add(tp.getName());
    }
    java.util.List<TypeParameter> result = new ArrayList<TypeParameter>(1);
    for (java.util.List<TypeParameter> tps : r) {
        for (TypeParameter tp : tps) {
            if (names.add(tp.getName())) {
                result.add(tp);
            }
        }
    }
    if (includeModelTypeParameters)
        result.addAll(model.getTypeParameters());
    return result;
}
Also used : TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) Generic(com.redhat.ceylon.model.typechecker.model.Generic) ArrayList(java.util.ArrayList) Scope(com.redhat.ceylon.model.typechecker.model.Scope) ArrayList(java.util.ArrayList) AnnotationList(com.redhat.ceylon.compiler.typechecker.tree.Tree.AnnotationList) List(com.sun.tools.javac.util.List) ParameterList(com.redhat.ceylon.model.typechecker.model.ParameterList) Package(com.redhat.ceylon.model.typechecker.model.Package) HashSet(java.util.HashSet)

Example 19 with Scope

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

the class ClassTransformer method typeParametersForInstantiator.

/**
 * When generating an instantiator method if the inner class has a type
 * parameter with the same name as a type parameter of an outer type, then the
 * instantiator method shouldn't declare its own type parameter of that
 * name -- it should use the captured one. This method filters out the
 * type parameters of the inner class which are the same as type parameters
 * of the outer class so that they can be captured.
 */
private java.util.List<TypeParameter> typeParametersForInstantiator(final Class model) {
    java.util.List<TypeParameter> filtered = new ArrayList<TypeParameter>();
    java.util.List<TypeParameter> tps = model.getTypeParameters();
    if (tps != null) {
        for (TypeParameter tp : tps) {
            boolean omit = false;
            Scope s = model.getContainer();
            while (!(s instanceof Package)) {
                if (s instanceof Generic) {
                    for (TypeParameter outerTp : ((Generic) s).getTypeParameters()) {
                        if (tp.getName().equals(outerTp.getName())) {
                            omit = true;
                        }
                    }
                }
                s = s.getContainer();
            }
            if (!omit) {
                filtered.add(tp);
            }
        }
    }
    return filtered;
}
Also used : TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) Scope(com.redhat.ceylon.model.typechecker.model.Scope) Generic(com.redhat.ceylon.model.typechecker.model.Generic) ArrayList(java.util.ArrayList) Package(com.redhat.ceylon.model.typechecker.model.Package)

Example 20 with Scope

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

the class ClassTransformer method addAtContainer.

private void addAtContainer(ClassDefinitionBuilder classBuilder, TypeDeclaration model) {
    Scope scope = Decl.getNonSkippedContainer((Scope) model);
    Scope declarationScope = Decl.getFirstDeclarationContainer((Scope) model);
    boolean inlineObjectInToplevelAttr = Decl.isTopLevelObjectExpressionType(model);
    if (scope == null || (scope instanceof Package && !inlineObjectInToplevelAttr) && scope == declarationScope)
        return;
    if (scope instanceof ClassOrInterface && scope == declarationScope && !inlineObjectInToplevelAttr && // we do not check for types inside initialiser section which are private and not captured because we treat them as members
    !(model instanceof Interface && Decl.hasLocalNotInitializerAncestor(model))) {
        ClassOrInterface container = (ClassOrInterface) scope;
        List<JCAnnotation> atContainer = makeAtContainer(container.getType());
        classBuilder.annotations(atContainer);
    } else {
        if (model instanceof Interface)
            classBuilder.annotations(makeLocalContainerPath((Interface) model));
        Declaration declarationContainer = getDeclarationContainer(model);
        classBuilder.annotations(makeAtLocalDeclaration(model.getQualifier(), declarationContainer == null));
    }
}
Also used : ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) Scope(com.redhat.ceylon.model.typechecker.model.Scope) 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) MethodDeclaration(com.redhat.ceylon.compiler.typechecker.tree.Tree.MethodDeclaration) AttributeDeclaration(com.redhat.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration) ClassOrInterface(com.redhat.ceylon.model.typechecker.model.ClassOrInterface) LazyInterface(com.redhat.ceylon.model.loader.model.LazyInterface) Interface(com.redhat.ceylon.model.typechecker.model.Interface) JCAnnotation(com.sun.tools.javac.tree.JCTree.JCAnnotation)

Aggregations

Scope (com.redhat.ceylon.model.typechecker.model.Scope)38 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)26 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)22 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)20 Package (com.redhat.ceylon.model.typechecker.model.Package)16 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)14 Interface (com.redhat.ceylon.model.typechecker.model.Interface)10 Class (com.redhat.ceylon.model.typechecker.model.Class)8 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)8 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)7 Type (com.redhat.ceylon.model.typechecker.model.Type)7 ArrayList (java.util.ArrayList)7 Function (com.redhat.ceylon.model.typechecker.model.Function)6 Constructor (com.redhat.ceylon.model.typechecker.model.Constructor)5 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)5 Value (com.redhat.ceylon.model.typechecker.model.Value)5 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)5 JCTree (com.sun.tools.javac.tree.JCTree)4 Generic (com.redhat.ceylon.model.typechecker.model.Generic)3 ParameterList (com.redhat.ceylon.model.typechecker.model.ParameterList)3