Search in sources :

Example 96 with Scope

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

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.AttributeDeclaration that) {
    Value v = new Value();
    that.setDeclarationModel(v);
    Tree.SpecifierOrInitializerExpression sie = that.getSpecifierOrInitializerExpression();
    boolean lazy = sie instanceof Tree.LazySpecifierExpression;
    v.setTransient(lazy);
    v.setImplemented(sie != null);
    visitDeclaration(that, v);
    if (!lazy && v.isVariable() && v.isStatic()) {
        Scope container = v.getContainer();
        if (container instanceof ClassOrInterface) {
            ClassOrInterface ci = (ClassOrInterface) container;
            if (!ci.getTypeParameters().isEmpty()) {
                that.addError("attribute of generic type may not be annotated both 'variable' and 'static'");
            }
        }
    }
    Scope o = null;
    // if (lazy)
    o = enterScope(v);
    super.visit(that);
    // if (lazy)
    exitScope(o);
    if (v.isInterfaceMember() && !v.isFormal() && !v.isNative()) {
        if (sie == null) {
            that.addError("interface attribute must be annotated 'formal'", 1400);
        }
    }
    if (v.isLate()) {
        if (lazy) {
            that.addError("late attribute should specify initial value using '='");
        }
        if (v.isFormal()) {
            that.addError("formal attribute may not be annotated 'late'");
        } else if (v.isDefault()) {
            that.addError("default attribute may not be annotated 'late'");
        } else if (!v.isClassOrInterfaceMember() && !v.isToplevel()) {
            that.addError("block-local value may not be annotated 'late'");
        }
    }
    if (v.isFormal() && sie != null) {
        that.addError("formal attribute may not have a value", 1102);
    }
    Tree.Type type = that.getType();
    if (type instanceof Tree.ValueModifier) {
        if (v.isToplevel()) {
            if (sie == null) {
                type.addError("toplevel value must explicitly specify a type");
            } else {
                type.addError("toplevel value must explicitly specify a type", 200);
            }
        } else if (mustHaveExplicitType(v)) {
            type.addError("shared value must explicitly specify a type", 200);
        }
    }
}
Also used : ModelUtil.getContainingClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getContainingClassOrInterface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) 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) 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)

Example 97 with Scope

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

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.AttributeGetterDefinition that) {
    Value g = new Value();
    g.setTransient(true);
    g.setImplemented(that.getBlock() != null);
    that.setDeclarationModel(g);
    visitDeclaration(that, g);
    Scope o = enterScope(g);
    super.visit(that);
    exitScope(o);
    Tree.Type type = that.getType();
    if (type instanceof Tree.ValueModifier) {
        if (g.isToplevel()) {
            type.addError("toplevel getter must explicitly specify a type", 200);
        } else if (mustHaveExplicitType(g) && !dynamic) {
            type.addError("shared getter must explicitly specify a type", 200);
        }
    }
}
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) 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)

Example 98 with Scope

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

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.AttributeArgument that) {
    Value g = new Value();
    g.setTransient(true);
    g.setImplemented(that.getBlock() != null);
    that.setDeclarationModel(g);
    visitArgument(that, g);
    Scope o = enterScope(g);
    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) Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Example 99 with Scope

use of org.eclipse.ceylon.model.typechecker.model.Scope 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 100 with Scope

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

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.MethodArgument that) {
    Function m = new Function();
    m.setImplemented(that.getBlock() != null);
    that.setDeclarationModel(m);
    visitArgument(that, m);
    Scope o = enterScope(m);
    super.visit(that);
    exitScope(o);
    setParameterLists(m, that.getParameterLists(), that);
    Tree.Type type = that.getType();
    m.setDeclaredVoid(type instanceof Tree.VoidModifier);
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) 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) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Aggregations

Scope (org.eclipse.ceylon.model.typechecker.model.Scope)142 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)71 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)57 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)50 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)44 Type (org.eclipse.ceylon.model.typechecker.model.Type)44 ConditionScope (org.eclipse.ceylon.model.typechecker.model.ConditionScope)35 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)34 Class (org.eclipse.ceylon.model.typechecker.model.Class)33 ModelUtil.getRealScope (org.eclipse.ceylon.model.typechecker.model.ModelUtil.getRealScope)31 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)30 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)26 Value (org.eclipse.ceylon.model.typechecker.model.Value)26 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)25 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)24 Function (org.eclipse.ceylon.model.typechecker.model.Function)23 Package (org.eclipse.ceylon.model.typechecker.model.Package)22 ArrayList (java.util.ArrayList)21 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)20 NativeUtil.declarationScope (org.eclipse.ceylon.compiler.typechecker.util.NativeUtil.declarationScope)15