Search in sources :

Example 26 with Constructor

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

the class SpecificationVisitor method visit.

@Override
public void visit(Tree.Enumerated that) {
    Value v = that.getDeclarationModel();
    Constructor e = that.getEnumerated();
    if (v == declaration || e == declaration) {
        declare();
        specify();
    }
    super.visit(that);
    if (declaration.getContainer() == e.getContainer() && that == lastConstructor && initedByEveryConstructor) {
        definitely = true;
    }
}
Also used : AnalyzerUtil.getLastConstructor(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getLastConstructor) ModelUtil.isConstructor(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isConstructor) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Value(org.eclipse.ceylon.model.typechecker.model.Value)

Example 27 with Constructor

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

the class SpecificationVisitor method visit.

@Override
public void visit(Tree.Declaration that) {
    boolean oe = endsInReturnThrow;
    boolean of = endsInBreak;
    Tree.Continue olc = lastContinue;
    lastContinue = null;
    endsInReturnThrow = false;
    endsInBreak = false;
    if (isSameDeclaration(that)) {
        loopDepth = 0;
        brokenLoopDepth = 0;
        specificationDisabled = true;
        withinDeclaration = true;
        declare();
        super.visit(that);
        withinDeclaration = false;
        specificationDisabled = false;
        loopDepth = 0;
        brokenLoopDepth = 0;
    } else {
        int l = loopDepth;
        int bl = brokenLoopDepth;
        loopDepth = 0;
        brokenLoopDepth = 0;
        Scope scope = that.getScope();
        boolean constructor = scope instanceof Constructor;
        boolean valueWithInitializer = scope instanceof Value && !((Value) scope).isTransient();
        boolean c = false;
        if (!constructor) {
            c = specificationDisabled;
            specificationDisabled = true;
        }
        boolean d = declared;
        if (valueWithInitializer) {
            super.visit(that);
        } else {
            boolean odefinitely = definitely;
            boolean opossibly = possibly;
            boolean opossiblyExited = possiblyExited;
            boolean odefinitelyExited = definitelyExited;
            boolean odefinitelyByLoopBreaks = definitelyByLoopBreaks;
            boolean opossiblyByLoopBreaks = possiblyByLoopBreaks;
            beginSpecificationScope();
            super.visit(that);
            definitely = odefinitely;
            possibly = opossibly;
            possiblyExited = opossiblyExited;
            definitelyExited = odefinitelyExited;
            definitelyByLoopBreaks = odefinitelyByLoopBreaks;
            possiblyByLoopBreaks = opossiblyByLoopBreaks;
        }
        declared = d;
        if (!constructor) {
            specificationDisabled = c;
        }
        loopDepth = l;
        brokenLoopDepth = bl;
    }
    endsInReturnThrow = oe;
    endsInBreak = of;
    lastContinue = olc;
}
Also used : Scope(org.eclipse.ceylon.model.typechecker.model.Scope) AnalyzerUtil.getLastConstructor(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getLastConstructor) ModelUtil.isConstructor(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isConstructor) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Value(org.eclipse.ceylon.model.typechecker.model.Value) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 28 with Constructor

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

the class SpecificationVisitor method visit.

@Override
public void visit(Tree.Block that) {
    Scope scope = that.getScope();
    if (scope instanceof Constructor) {
        if (definitelyInitedBy.contains(delegatedConstructor)) {
            definitely = true;
        }
        if (possiblyInitedBy.contains(delegatedConstructor)) {
            possibly = true;
        }
        delegatedConstructor = null;
    }
    boolean of = endsInBreak;
    boolean oe = endsInReturnThrow;
    Tree.Continue olc = lastContinue;
    Tree.Statement olcs = lastContinueStatement;
    // rather nasty way of detecting that the continue
    // occurs in another conditional branch of the
    // statement containing this block, even though we
    // did not find it in _this_ branch
    boolean continueInSomeBranchOfCurrentConditional = lastContinue != null && lastContinueStatement == null;
    boolean blockEndsInReturnThrow = blockEndsInReturnThrow(that);
    boolean blockEndsInBreak = blockEndsInBreak(that);
    endsInBreak = endsInBreak || blockEndsInBreak;
    endsInReturnThrow = endsInReturnThrow || blockEndsInReturnThrow;
    Tree.Continue last = null;
    Tree.Statement lastStatement = null;
    for (Tree.Statement st : that.getStatements()) {
        ContinueVisitor cv = new ContinueVisitor(olc);
        st.visit(cv);
        if (cv.node != null) {
            last = cv.node;
            lastStatement = st;
        }
        if (cv.found) {
            olc = null;
            olcs = null;
        }
    }
    if (blockEndsInReturnThrow || blockEndsInBreak || continueInSomeBranchOfCurrentConditional) {
        lastContinue = last;
        lastContinueStatement = lastStatement;
    }
    super.visit(that);
    endsInBreak = of;
    endsInReturnThrow = oe;
    lastContinue = olc;
    lastContinueStatement = olcs;
    if (scope instanceof Constructor) {
        Constructor c = (Constructor) scope;
        if (definitely) {
            definitelyInitedBy.add(c);
        }
        if (possibly) {
            possiblyInitedBy.add(c);
        }
    }
    if (isNonPartialConstructor(scope) && declaration.getContainer() == scope.getContainer()) {
        if (!definitely) {
            initedByEveryConstructor = false;
        }
    }
}
Also used : Scope(org.eclipse.ceylon.model.typechecker.model.Scope) AnalyzerUtil.getLastConstructor(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getLastConstructor) ModelUtil.isConstructor(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isConstructor) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 29 with Constructor

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

the class InheritanceVisitor method checkExtensionOfMemberType.

private void checkExtensionOfMemberType(Node that, TypeDeclaration td, Type type) {
    Type qt = type.getQualifyingType();
    if (qt != null && td instanceof ClassOrInterface) {
        Unit unit = that.getUnit();
        TypeDeclaration d = type.getDeclaration();
        if (d.isStatic() || d instanceof Constructor) {
            checkExtensionOfMemberType(that, td, qt);
        } else {
            Scope s = td;
            while (s != null) {
                s = s.getContainer();
                if (s instanceof TypeDeclaration) {
                    TypeDeclaration otd = (TypeDeclaration) s;
                    if (otd.getType().isSubtypeOf(qt)) {
                        return;
                    }
                }
            }
            that.addError("qualifying type '" + qt.asString(unit) + "' of supertype '" + type.asString(unit) + "' is not an outer type or supertype of any outer type of '" + td.getName(unit) + "'");
        }
    }
}
Also used : ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) Type(org.eclipse.ceylon.model.typechecker.model.Type) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) Unit(org.eclipse.ceylon.model.typechecker.model.Unit) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 30 with Constructor

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

the class InheritanceVisitor method collectCaseValues.

void collectCaseValues(Tree.CaseTypes that, TypeDeclaration td) {
    Unit unit = that.getUnit();
    Set<Declaration> valueSet = new HashSet<Declaration>();
    for (Tree.StaticMemberOrTypeExpression bme : that.getBaseMemberExpressions()) {
        String name = name(bme.getIdentifier());
        TypedDeclaration value = bme instanceof Tree.BaseMemberExpression ? getTypedDeclaration(bme.getScope(), name, null, false, unit) : getPackageTypedDeclaration(name, null, false, unit);
        if (value != null) {
            if (value != null && !valueSet.add(value)) {
                // this error is not really truly necessary
                bme.addError("duplicate case: '" + value.getName(unit) + "' of '" + td.getName() + "'");
            }
            Type type = value.getType();
            if (type != null) {
                TypeDeclaration caseDec = type.getDeclaration();
                if (caseDec instanceof Constructor) {
                    Scope scope = caseDec.getContainer();
                    if (scope instanceof Class) {
                        // enumerated singleton constructors
                        Constructor cons = (Constructor) caseDec;
                        Class c = (Class) scope;
                        if (!c.isToplevel() && !c.isStatic()) {
                            bme.addError("case must be a value constructor of a toplevel or static class: '" + c.getName(unit) + "' is not toplevel");
                        } else if (!cons.getParameterLists().isEmpty()) {
                            bme.addError("case must be a value constructor of a toplevel or static class: '" + cons.getName(unit) + "' is not a value constructor");
                        }
                    /*else if (!c.inherits(unit.getIdentifiableDeclaration())) {
                                bme.addError("case must be a value constructor of an identifiable class: '" + 
                                        c.getName(unit) + 
                                        "' is not a subtype of 'Identifiable'");
                            }*/
                    }
                } else {
                    // enumerated anonymous subclasses
                    if (!caseDec.isObjectClass()) {
                        bme.addError("case must be a toplevel or static anonymous class: '" + value.getName(unit) + "' is not an anonymous class");
                    } else if (!value.isToplevel() && !value.isStatic()) {
                        bme.addError("case must be a toplevel or static anonymous class: '" + value.getName(unit) + "' is neither static nor toplevel");
                    }
                }
                if (checkDirectSubtype(td, bme, type)) {
                    checkAssignable(type, td.getType(), bme, getCaseTypeExplanation(td, type));
                }
            }
        }
    }
}
Also used : AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) Unit(org.eclipse.ceylon.model.typechecker.model.Unit) Type(org.eclipse.ceylon.model.typechecker.model.Type) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Class(org.eclipse.ceylon.model.typechecker.model.Class) AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) HashSet(java.util.HashSet)

Aggregations

Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)95 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)65 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)48 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)47 Type (org.eclipse.ceylon.model.typechecker.model.Type)45 Class (org.eclipse.ceylon.model.typechecker.model.Class)42 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)42 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)27 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)27 Value (org.eclipse.ceylon.model.typechecker.model.Value)27 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)26 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)25 Function (org.eclipse.ceylon.model.typechecker.model.Function)23 ModelUtil.isConstructor (org.eclipse.ceylon.model.typechecker.model.ModelUtil.isConstructor)21 ArrayList (java.util.ArrayList)20 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)19 Interface (org.eclipse.ceylon.model.typechecker.model.Interface)17 AnalyzerUtil.unwrapAliasedTypeConstructor (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.unwrapAliasedTypeConstructor)16 AnalyzerUtil.getPackageTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration)14 AnalyzerUtil.getTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)14