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);
}
}
}
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);
}
}
}
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);
}
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);
}
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);
}
Aggregations