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);
}
}
}
}
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() + "\"'"));
}
}
}
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;
}
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;
}
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;
}
Aggregations