Search in sources :

Example 16 with TypeAlias

use of org.eclipse.ceylon.model.typechecker.model.TypeAlias in project ceylon by eclipse.

the class MetamodelHelper method generateOpenType.

static void generateOpenType(final Tree.MetaLiteral that, final Declaration d, final GenerateJsVisitor gen, boolean compilingLanguageModule) {
    final Module m = d.getUnit().getPackage().getModule();
    final boolean isConstructor = ModelUtil.isConstructor(d) || that instanceof Tree.NewLiteral;
    if (d instanceof TypeParameter == false) {
        if (compilingLanguageModule) {
            gen.out("$init$");
        } else {
            gen.out(gen.getClAlias());
        }
    }
    if (d instanceof org.eclipse.ceylon.model.typechecker.model.Interface) {
        gen.out("OpenInterface$jsint");
    } else if (isConstructor) {
        if (TypeUtils.getConstructor(d).isValueConstructor()) {
            gen.out("OpenValueConstructor$jsint");
        } else {
            gen.out("OpenCallableConstructor$jsint");
        }
    } else if (d instanceof Class) {
        gen.out("openClass$jsint");
    } else if (d instanceof Function) {
        gen.out("OpenFunction$jsint");
    } else if (d instanceof Value) {
        gen.out("OpenValue$jsint");
    } else if (d instanceof org.eclipse.ceylon.model.typechecker.model.IntersectionType) {
        gen.out("OpenIntersection");
    } else if (d instanceof org.eclipse.ceylon.model.typechecker.model.UnionType) {
        gen.out("OpenUnion");
    } else if (d instanceof TypeParameter) {
        generateOpenType(that, ((TypeParameter) d).getDeclaration(), gen, compilingLanguageModule);
        gen.out(".getTypeParameterDeclaration('", d.getName(), "')");
        return;
    } else if (d instanceof org.eclipse.ceylon.model.typechecker.model.NothingType) {
        gen.out("NothingType");
    } else if (d instanceof TypeAlias) {
        gen.out("OpenAlias$jsint(");
        if (compilingLanguageModule) {
            gen.out(")(");
        }
        if (d.isMember()) {
            // Make the chain to the top-level container
            ArrayList<Declaration> parents = new ArrayList<>(2);
            Declaration pd = (Declaration) d.getContainer();
            while (pd != null) {
                parents.add(0, pd);
                pd = pd.isMember() ? (Declaration) pd.getContainer() : null;
            }
            for (Declaration _d : parents) {
                gen.out(gen.getNames().name(_d), ".$$.prototype.");
            }
        }
        gen.out(gen.getNames().name(d), ")");
        return;
    }
    // TODO optimize for local declarations
    if (compilingLanguageModule) {
        gen.out("()");
    }
    gen.out("(", gen.getClAlias());
    final String pkgname = d.getUnit().getPackage().getNameAsString();
    if (Objects.equals(that.getUnit().getPackage().getModule(), d.getUnit().getPackage().getModule())) {
        gen.out("lmp$(ex$,'");
    } else {
        // TODO use $ for language module as well
        gen.out("fmp$('", m.getNameAsString(), "','", m.getVersion(), "','");
    }
    gen.out("ceylon.language".equals(pkgname) ? "$" : pkgname, "'),");
    if (d.isMember() || isConstructor) {
        if (isConstructor) {
            final Class actualClass;
            final String constrName;
            if (d instanceof Class) {
                actualClass = (Class) d;
                constrName = "$c$";
            } else {
                actualClass = (Class) d.getContainer();
                if (d instanceof Constructor && ((Constructor) d).isValueConstructor()) {
                    constrName = gen.getNames().name(actualClass.getDirectMember(d.getName(), null, false));
                } else {
                    constrName = gen.getNames().name(d);
                }
            }
            if (gen.isImported(that.getUnit().getPackage(), actualClass)) {
                gen.out(gen.getNames().moduleAlias(actualClass.getUnit().getPackage().getModule()), ".");
            }
            if (actualClass.isMember()) {
                outputPathToDeclaration(that, actualClass, gen);
            }
            gen.out(gen.getNames().name(actualClass), gen.getNames().constructorSeparator(d), constrName, ")");
            return;
        } else {
            outputPathToDeclaration(that, d, gen);
        }
    }
    if (d instanceof Value || d.isParameter()) {
        if (!d.isMember())
            gen.qualify(that, d);
        if (d.isStatic() && d instanceof Value && ((Value) d).getType().getDeclaration().isAnonymous()) {
            gen.out(gen.getNames().name(d), ")");
        } else {
            gen.out(gen.getNames().getter(d, true), ")");
        }
    } else {
        if (d.isAnonymous()) {
            final String oname = gen.getNames().objectName(d);
            if (d.isToplevel()) {
                gen.qualify(that, d);
            }
            gen.out("$init$", oname);
            if (!d.isToplevel()) {
                gen.out("()");
            }
        } else {
            if (!d.isMember())
                gen.qualify(that, d);
            gen.out(gen.getNames().name(d));
        }
        gen.out(")");
    }
}
Also used : TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) ArrayList(java.util.ArrayList) TypeAlias(org.eclipse.ceylon.model.typechecker.model.TypeAlias) Function(org.eclipse.ceylon.model.typechecker.model.Function) Value(org.eclipse.ceylon.model.typechecker.model.Value) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Module(org.eclipse.ceylon.model.typechecker.model.Module)

Example 17 with TypeAlias

use of org.eclipse.ceylon.model.typechecker.model.TypeAlias in project ceylon by eclipse.

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.TypeAliasDeclaration that) {
    TypeAlias a = new TypeAlias();
    that.setDeclarationModel(a);
    visitDeclaration(that, a);
    Scope o = enterScope(a);
    super.visit(that);
    exitScope(o);
}
Also used : Scope(org.eclipse.ceylon.model.typechecker.model.Scope) ConditionScope(org.eclipse.ceylon.model.typechecker.model.ConditionScope) ModelUtil.getRealScope(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getRealScope) TypeAlias(org.eclipse.ceylon.model.typechecker.model.TypeAlias)

Example 18 with TypeAlias

use of org.eclipse.ceylon.model.typechecker.model.TypeAlias in project ceylon by eclipse.

the class DeclarationVisitor method visit.

public void visit(Tree.TypeConstructor that) {
    TypeAlias ta = new TypeAlias();
    ta.setShared(true);
    ta.setName("Anonymous#" + fid++);
    ta.setAnonymous(true);
    visitElement(that, ta);
    ModelUtil.setVisibleScope(ta);
    Scope o = enterScope(ta);
    Declaration od = beginDeclaration(ta);
    super.visit(that);
    endDeclaration(od);
    exitScope(o);
    ta.setExtendedType(that.getType().getTypeModel());
    that.setDeclarationModel(ta);
    Type pt = ta.getType();
    pt.setTypeConstructor(true);
    that.setTypeModel(pt);
}
Also used : IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) LazyType(org.eclipse.ceylon.model.typechecker.model.LazyType) UnionType(org.eclipse.ceylon.model.typechecker.model.UnionType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) TypeVisitor.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.TypeVisitor.getTupleType) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) ConditionScope(org.eclipse.ceylon.model.typechecker.model.ConditionScope) ModelUtil.getRealScope(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getRealScope) TypeAlias(org.eclipse.ceylon.model.typechecker.model.TypeAlias) 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) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Example 19 with TypeAlias

use of org.eclipse.ceylon.model.typechecker.model.TypeAlias in project ceylon by eclipse.

the class TypeVisitor method visit.

@Override
public void visit(Tree.ExtendedType that) {
    inExtendsOrClassAlias = that.getInvocationExpression() != null;
    super.visit(that);
    inExtendsOrClassAlias = false;
    inheritedType(that.getType());
    checkExtendedTypeExpression(that.getType());
    TypeDeclaration td = (TypeDeclaration) that.getScope();
    if (!td.isAlias()) {
        Tree.SimpleType et = that.getType();
        if (et != null) {
            Type type = et.getTypeModel();
            if (type != null) {
                TypeDeclaration etd = et.getDeclarationModel();
                if (etd != null && !(etd instanceof UnknownType)) {
                    if (etd instanceof Constructor) {
                        type = type.getExtendedType();
                        etd = etd.getExtendedType().getDeclaration();
                    }
                    if (etd == td) {
                    // unnecessary, handled by SupertypeVisitor
                    // et.addError("directly extends itself: '" +
                    // td.getName() + "'");
                    } else if (etd instanceof TypeParameter) {
                        et.addError("directly extends a type parameter: '" + type.getDeclaration().getName(unit) + "'");
                    } else if (etd instanceof Interface) {
                        et.addError("extends an interface: '" + type.getDeclaration().getName(unit) + "'");
                    } else if (etd instanceof TypeAlias) {
                        et.addError("extends a type alias: '" + type.getDeclaration().getName(unit) + "'");
                    } else if (etd instanceof NothingType) {
                        et.addError("extends the bottom type 'Nothing'");
                    } else {
                        td.setExtendedType(type);
                    }
                }
            }
        }
    }
}
Also used : UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) AnalyzerUtil.setTypeConstructor(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.setTypeConstructor) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) AnalyzerUtil.unwrapAliasedTypeConstructor(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.unwrapAliasedTypeConstructor) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) TypeAlias(org.eclipse.ceylon.model.typechecker.model.TypeAlias) AnalyzerUtil.getPackageTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration) ModelUtil.getContainingClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getContainingClassOrInterface) Interface(org.eclipse.ceylon.model.typechecker.model.Interface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType)

Example 20 with TypeAlias

use of org.eclipse.ceylon.model.typechecker.model.TypeAlias in project ceylon by eclipse.

the class TypeVisitor method visit.

@Override
public void visit(Tree.TypeAliasDeclaration that) {
    TypeAlias ta = that.getDeclarationModel();
    ta.setExtendedType(null);
    super.visit(that);
    Tree.TypeSpecifier typeSpecifier = that.getTypeSpecifier();
    if (typeSpecifier == null) {
        that.addError("missing aliased type");
    } else {
        Tree.StaticType et = typeSpecifier.getType();
        if (et == null) {
            that.addError("malformed aliased type");
        } else {
            Type type = et.getTypeModel();
            if (type != null) {
                setTypeConstructor(et, null);
                ta.setExtendedType(type);
            }
        }
    }
}
Also used : NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) TypeAlias(org.eclipse.ceylon.model.typechecker.model.TypeAlias)

Aggregations

TypeAlias (org.eclipse.ceylon.model.typechecker.model.TypeAlias)32 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)23 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)20 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)16 Class (org.eclipse.ceylon.model.typechecker.model.Class)15 Interface (org.eclipse.ceylon.model.typechecker.model.Interface)14 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)13 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)13 Type (org.eclipse.ceylon.model.typechecker.model.Type)12 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)11 Function (org.eclipse.ceylon.model.typechecker.model.Function)10 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)9 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)9 ArrayList (java.util.ArrayList)8 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)8 Value (org.eclipse.ceylon.model.typechecker.model.Value)8 NothingType (org.eclipse.ceylon.model.typechecker.model.NothingType)6 LazyInterface (org.eclipse.ceylon.model.loader.model.LazyInterface)5 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)5 Package (org.eclipse.ceylon.model.typechecker.model.Package)5