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