Search in sources :

Example 6 with ControlBlock

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

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.Variable that) {
    if (that instanceof CustomTree.GuardedVariable) {
        ConditionScope cb = new ConditionScope();
        cb.setId(id++);
        that.setScope(cb);
        visitElement(that, cb);
        enterScope(cb);
    }
    Tree.SpecifierExpression se = that.getSpecifierExpression();
    if (se != null) {
        Scope s = scope;
        if (scope instanceof ControlBlock) {
            ControlBlock block = (ControlBlock) scope;
            if (!block.isLet()) {
                scope = scope.getContainer();
            }
        }
        se.visit(this);
        scope = s;
    }
    Tree.Type type = that.getType();
    Value v = new Value();
    that.setDeclarationModel(v);
    visitDeclaration(that, v, !(type instanceof Tree.SyntheticVariable));
    ModelUtil.setVisibleScope(v);
    if (type != null) {
        type.visit(this);
    }
    Tree.Identifier identifier = that.getIdentifier();
    if (identifier != null) {
        identifier.visit(this);
    }
    // TODO: scope should be the variable, not the
    // containing control structure:
    Tree.AnnotationList al = that.getAnnotationList();
    if (al != null) {
        al.visit(this);
    }
    List<Tree.ParameterList> pls = that.getParameterLists();
    for (Tree.ParameterList pl : pls) {
        pl.visit(this);
    }
    if (pls.isEmpty()) {
        if (type instanceof Tree.FunctionModifier) {
            type.addError("variables with no parameters may not be declared using the keyword 'function'");
        }
        if (type instanceof Tree.VoidModifier) {
            type.addError("variables with no parameters may not be declared using the keyword 'void'");
        }
    } else {
        Tree.ParameterList pl = pls.get(0);
        pl.addUnsupportedError("variables with parameter lists are not yet supported");
        if (type instanceof Tree.ValueModifier) {
            type.addError("variables with parameters may not be declared using the keyword 'value'");
        }
    }
    that.setScope(scope);
    that.setUnit(unit);
}
Also used : ControlBlock(org.eclipse.ceylon.model.typechecker.model.ControlBlock) 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) ConditionScope(org.eclipse.ceylon.model.typechecker.model.ConditionScope) Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList)

Example 7 with ControlBlock

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

the class DeclarationVisitor method checkForDuplicateDeclaration.

private static void checkForDuplicateDeclaration(Tree.Declaration that, Declaration model, Scope scope) {
    String name = model.getName();
    Unit unit = model.getUnit();
    if (name != null) {
        if (model instanceof Setter) {
            Setter setter = (Setter) model;
            checkGetterForSetter(that, setter, scope);
        } else {
            // this isn't the correct scope for declaration
            // which follow an assertion, since it misses
            // condition scopes, so use the argument scope
            // Scope scope = model.getContainer();
            boolean isControl;
            do {
                Declaration member = scope.getDirectMember(name, null, false);
                if (member != null && member != model) {
                    boolean dup = false;
                    boolean possibleOverloadedMethod = member instanceof Function && model instanceof Function && scope instanceof ClassOrInterface && !member.isNative() && member.isShared() && model.isShared();
                    boolean legalOverloadedMethod = possibleOverloadedMethod;
                    if (legalOverloadedMethod) {
                        // anticipate that it might be
                        // an overloaded method - then
                        // further checking happens in
                        // RefinementVisitor
                        initFunctionOverload((Function) model, (Function) member, scope, unit);
                    } else if (canBeNative(member) && canBeNative(model) && model.isNative()) {
                    // just to make sure no error
                    // gets reported
                    } else {
                        dup = true;
                        if (possibleOverloadedMethod) {
                            // it as overloading anyway
                            if (initFunctionOverload((Function) model, (Function) member, scope, unit)) {
                                that.addError("duplicate declaration: the name '" + name + "' is not unique in this scope");
                            }
                        } else {
                            that.addError("duplicate declaration: the name '" + name + "' is not unique in this scope");
                        }
                    }
                    if (dup) {
                        unit.getDuplicateDeclarations().add(member);
                    }
                }
                isControl = scope instanceof ControlBlock;
                scope = scope.getContainer();
            } while (isControl);
        }
    }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) ModelUtil.getContainingClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getContainingClassOrInterface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) ControlBlock(org.eclipse.ceylon.model.typechecker.model.ControlBlock) Setter(org.eclipse.ceylon.model.typechecker.model.Setter) 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) Unit(org.eclipse.ceylon.model.typechecker.model.Unit)

Example 8 with ControlBlock

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

the class DefiniteAssignmentVisitor method visit.

public void visit(Tree.AnyAttribute that) {
    ControlBlock prevControlBlock = forBlock;
    forBlock = null;
    super.visit(that);
    forBlock = prevControlBlock;
}
Also used : ControlBlock(org.eclipse.ceylon.model.typechecker.model.ControlBlock)

Example 9 with ControlBlock

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

the class DefiniteAssignmentVisitor method visit.

public void visit(Tree.ForStatement that) {
    ControlBlock prevControlBlock = forBlock;
    forBlock = that.getForClause().getControlBlock();
    that.getForClause().visit(this);
    if (that.getElseClause() != null) {
        elseBlock = that.getElseClause().getControlBlock();
        that.getElseClause().visit(this);
        elseBlock = null;
    }
    if (prevControlBlock != null) {
        Set<Value> specifiedValues = forBlock.getSpecifiedValues();
        if (specifiedValues != null) {
            for (Declaration decl : new ArrayList<Value>(specifiedValues)) {
                if (!prevControlBlock.equals(tracked.get(decl))) {
                    addSpecified(decl, prevControlBlock);
                    specifiedValues.remove(decl);
                }
            }
        }
    }
    forBlock = prevControlBlock;
}
Also used : ControlBlock(org.eclipse.ceylon.model.typechecker.model.ControlBlock) Value(org.eclipse.ceylon.model.typechecker.model.Value) ArrayList(java.util.ArrayList) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Example 10 with ControlBlock

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

the class DefiniteAssignmentVisitor method visit.

public void visit(Tree.AnyMethod that) {
    ControlBlock prevControlBlock = forBlock;
    forBlock = null;
    super.visit(that);
    checkForCycle(that, that.getDeclarationModel(), (AnnotationInvocation) that.getDeclarationModel().getAnnotationConstructor(), new HashSet<Declaration>());
    forBlock = prevControlBlock;
}
Also used : ControlBlock(org.eclipse.ceylon.model.typechecker.model.ControlBlock) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Aggregations

ControlBlock (org.eclipse.ceylon.model.typechecker.model.ControlBlock)10 ConditionScope (org.eclipse.ceylon.model.typechecker.model.ConditionScope)4 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)4 ModelUtil.getRealScope (org.eclipse.ceylon.model.typechecker.model.ModelUtil.getRealScope)4 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)4 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)3 Value (org.eclipse.ceylon.model.typechecker.model.Value)3 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)2 ArrayList (java.util.ArrayList)1 AnalyzerUtil.getPackageTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration)1 AnalyzerUtil.getTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)1 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)1 Function (org.eclipse.ceylon.model.typechecker.model.Function)1 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)1 ModelUtil.getContainingClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ModelUtil.getContainingClassOrInterface)1 ParameterList (org.eclipse.ceylon.model.typechecker.model.ParameterList)1 Setter (org.eclipse.ceylon.model.typechecker.model.Setter)1 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)1 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)1 Unit (org.eclipse.ceylon.model.typechecker.model.Unit)1