Search in sources :

Example 6 with Backends

use of org.eclipse.ceylon.common.Backends in project ceylon by eclipse.

the class ImportVisitor method visit.

@Override
public void visit(Tree.Import that) {
    Backends scopedBackends = that.getScope().getScopedBackends();
    if (!scopedBackends.none() && !scopedBackends.supports(unit.getSupportedBackends())) {
        return;
    }
    Tree.ImportPath path = that.getImportPath();
    Package importedPackage = importedPackage(path, unit);
    if (importedPackage != null) {
        path.setModel(importedPackage);
        Tree.ImportMemberOrTypeList imtl = that.getImportMemberOrTypeList();
        if (imtl != null) {
            ImportList il = imtl.getImportList();
            il.setImportedScope(importedPackage);
            Set<String> names = new HashSet<String>();
            List<Tree.ImportMemberOrType> list = imtl.getImportMemberOrTypes();
            for (Tree.ImportMemberOrType member : list) {
                names.add(importMember(member, importedPackage, il));
            }
            if (imtl.getImportWildcard() != null) {
                importAllMembers(importedPackage, names, il);
            } else if (list.isEmpty()) {
                imtl.addError("empty import list", 1020);
            }
        }
    }
}
Also used : Backends(org.eclipse.ceylon.common.Backends) ImportList(org.eclipse.ceylon.model.typechecker.model.ImportList) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) AnalyzerUtil.declaredInPackage(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.declaredInPackage) Package(org.eclipse.ceylon.model.typechecker.model.Package) AnalyzerUtil.importedPackage(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.importedPackage) HashSet(java.util.HashSet)

Example 7 with Backends

use of org.eclipse.ceylon.common.Backends in project ceylon by eclipse.

the class ModuleValidator method verifyNative.

private void verifyNative(Module module) {
    for (ImportModule imp : moduleManagerUtil.retrieveModuleImportNodes(module)) {
        Module importedModule;
        Node node;
        if (imp.getImportPath() != null) {
            node = imp.getImportPath();
            importedModule = (Module) imp.getImportPath().getModel();
        } else {
            node = imp.getQuotedLiteral();
            importedModule = moduleManagerUtil.getModuleForNode(node);
            if (importedModule == null)
                continue;
        }
        Backends bs = getNativeBackend(imp.getAnnotationList(), imp.getUnit());
        if (bs.none()) {
            if (importedModule.isNative() && !module.isNative()) {
                node.addError(new ModuleSourceMapper.ModuleDependencyAnalysisError(node, "native import for cross-platform module" + " (mark either the module or the import as native)", 20000));
            }
        } else if (importedModule.isNative() && !bs.supports(importedModule.getNativeBackends())) {
            node.addError(new ModuleSourceMapper.ModuleDependencyAnalysisError(node, "native backend name conflicts with imported module: '\"" + bs + "\"' is not '\"" + importedModule.getNativeBackends().names() + "\"'"));
        }
    }
}
Also used : Backends(org.eclipse.ceylon.common.Backends) Node(org.eclipse.ceylon.compiler.typechecker.tree.Node) ImportModule(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ImportModule) Module(org.eclipse.ceylon.model.typechecker.model.Module) ImportModule(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ImportModule)

Example 8 with Backends

use of org.eclipse.ceylon.common.Backends in project ceylon by eclipse.

the class TypeHierarchyVisitor method getOrBuildType.

/*private void removeTrailing(String trailingString, StringBuilder sb) {
        final int length = sb.length();
        sb.delete(length-trailingString.length(), length);
    }*/
private Type getOrBuildType(TypeDeclaration declaration) {
    Type type = types.get(new TypeDeclKey(declaration));
    if (type == null) {
        type = new Type();
        type.declaration = declaration;
        for (Declaration member : declaration.getMembers()) {
            if (!(member instanceof FunctionOrValue || member instanceof Class) || isConstructor(member) || member.isStatic() || isAbstraction(member)) {
                continue;
            }
            if (declaration.isNative() && member.isNative()) {
                // Make sure we get the right member declaration (the one for the same backend as its container)
                Backends backends = declaration.getNativeBackends();
                member = getNativeDeclaration(member, backends);
                if (member == null) {
                    continue;
                }
            }
            final String name = member.getName();
            Type.Members members = type.membersByName.get(name);
            if (members == null) {
                members = new Type.Members();
                members.name = name;
                type.membersByName.put(name, members);
            }
            if (member.isActual()) {
                members.actuals.add(member);
                if (!member.isFormal()) {
                    members.actualsNonFormals.add(member);
                }
            }
            if (member.isFormal()) {
                members.formals.add(member);
            }
            /*if (!member.isFormal() && member.isInterfaceMember()) {
                    members.concretesOnInterfaces.add(member);
                }*/
            if (member.isDefault()) {
                members.defaults.add(member);
            }
            if (!member.isFormal() && !member.isDefault() && member.isShared()) {
                members.nonFormalsNonDefaults.add(member);
            }
            if (member.isShared()) {
                members.shared.add(member);
            }
        }
        types.put(new TypeDeclKey(declaration), type);
    }
    return type;
}
Also used : IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) UnionType(org.eclipse.ceylon.model.typechecker.model.UnionType) Backends(org.eclipse.ceylon.common.Backends) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) ModelUtil.getNativeDeclaration(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getNativeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Example 9 with Backends

use of org.eclipse.ceylon.common.Backends in project ceylon by eclipse.

the class ExpressionVisitor method handleNativeHeader.

private Declaration handleNativeHeader(Declaration dec, Node that, boolean error) {
    // really nasty workaround to get the "real" scope
    // in which an annotation occurs! (bug #7143)
    Scope scope = (that instanceof Tree.BaseMemberExpression ? ((Tree.BaseMemberExpression) that).getIdentifier() : that).getScope();
    Declaration impl = dec;
    Declaration hdr = null;
    Module ctxModule = unit.getPackage().getModule();
    Module decModule = dec.getUnit().getPackage().getModule();
    Backends decModuleBackends = getModuleBackends(decModule, unit);
    Backends inBackends = scope.getScopedBackends();
    if (dec.isNative()) {
        Backends backends = inBackends.none() ? unit.getSupportedBackends() : inBackends;
        if (dec.isNativeHeader()) {
            hdr = dec;
            impl = getNativeDeclaration(hdr, backends);
        } else {
            Declaration tmp = getNativeHeader(dec);
            if (tmp != dec) {
                hdr = tmp;
                if (hdr != null) {
                    if (backends.none() || !backends.supports(dec.getNativeBackends())) {
                        impl = getNativeDeclaration(hdr, backends);
                    }
                }
            }
        }
    }
    if (error && impl != null && (dec.isToplevel() || dec.isMember()) && declarationScope(scope) != null && (hdr == null || !isImplemented(hdr)) && (ctxModule != decModule && !decModuleBackends.none() || ctxModule == decModule && dec.isNative() && hdr == null) && (inBackends.none() || impl.isNative() && !isForBackend(impl.getNativeBackends(), inBackends) || !decModuleBackends.none() && !isForBackend(decModuleBackends, inBackends))) {
        Declaration d = declarationScope(scope);
        if (!inBackends.none()) {
            that.addError("illegal reference to native declaration '" + dec.getName(unit) + "': native declaration '" + d.getName(unit) + "' has a different backend");
        } else {
            that.addError("illegal reference to native declaration '" + dec.getName(unit) + "': declaration '" + d.getName(unit) + "' is not native (mark it or the module native)", 20010);
        }
    }
    if (dec.isNative()) {
        return inBackends.none() || impl == null ? dec : impl;
    }
    return dec;
}
Also used : NativeUtil.getBackends(org.eclipse.ceylon.compiler.typechecker.util.NativeUtil.getBackends) Backends(org.eclipse.ceylon.common.Backends) NativeUtil.declarationScope(org.eclipse.ceylon.compiler.typechecker.util.NativeUtil.declarationScope) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) 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) ModelUtil.getNativeDeclaration(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getNativeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration) Module(org.eclipse.ceylon.model.typechecker.model.Module) AnalyzerUtil.importedModule(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.importedModule)

Example 10 with Backends

use of org.eclipse.ceylon.common.Backends in project ceylon by eclipse.

the class ExpressionVisitor method getModuleBackends.

private Backends getModuleBackends(Module decModule, Unit unit) {
    Backends bs = decModule.getNativeBackends();
    List<ModuleImport> imports = unit.getPackage().getModule().getImports();
    for (ModuleImport imp : imports) {
        if (imp.getModule().equals(decModule)) {
            if (!imp.getNativeBackends().none()) {
                bs = bs.none() ? imp.getNativeBackends() : bs.supported(imp.getNativeBackends());
            }
            break;
        }
    }
    return bs;
}
Also used : NativeUtil.getBackends(org.eclipse.ceylon.compiler.typechecker.util.NativeUtil.getBackends) Backends(org.eclipse.ceylon.common.Backends) ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport)

Aggregations

Backends (org.eclipse.ceylon.common.Backends)21 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)7 Module (org.eclipse.ceylon.model.typechecker.model.Module)7 HashSet (java.util.HashSet)6 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)6 ModuleImport (org.eclipse.ceylon.model.typechecker.model.ModuleImport)6 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)5 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)4 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 ModuleDependencyInfo (org.eclipse.ceylon.cmr.api.ModuleDependencyInfo)3 AnalyzerUtil.getPackageTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration)3 AnalyzerUtil.getTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)3 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)3 ModelUtil.getNativeDeclaration (org.eclipse.ceylon.model.typechecker.model.ModelUtil.getNativeDeclaration)3 Unit (org.eclipse.ceylon.model.typechecker.model.Unit)3 ModuleInfo (org.eclipse.ceylon.cmr.api.ModuleInfo)2 Backend (org.eclipse.ceylon.common.Backend)2 AnalyzerUtil.getPackageTypedDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration)2