use of org.eclipse.ceylon.model.typechecker.model.Function in project ceylon by eclipse.
the class DeclarationVisitor method visit.
@Override
public void visit(Tree.MethodDeclaration that) {
super.visit(that);
Tree.SpecifierExpression sie = that.getSpecifierExpression();
Function m = that.getDeclarationModel();
m.setImplemented(sie != null);
if (m.isFormal() && sie != null) {
that.addError("formal method may not have a specification", 1102);
}
Tree.Type type = that.getType();
if (type instanceof Tree.FunctionModifier) {
if (m.isToplevel()) {
if (sie == null) {
type.addError("toplevel function must explicitly specify a return type");
} else {
type.addError("toplevel function must explicitly specify a return type", 200);
}
} else if (mustHaveExplicitType(m)) {
type.addError("shared function must explicitly specify a return type", 200);
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Function in project ceylon by eclipse.
the class DeclarationVisitor method visit.
@Override
public void visit(Tree.MethodDefinition that) {
super.visit(that);
Function m = that.getDeclarationModel();
m.setImplemented(that.getBlock() != null);
Tree.Type type = that.getType();
if (type instanceof Tree.FunctionModifier) {
if (m.isToplevel()) {
type.addError("toplevel function must explicitly specify a return type", 200);
} else if (mustHaveExplicitType(m) && !dynamic) {
type.addError("shared function must explicitly specify a return type", 200);
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Function in project ceylon by eclipse.
the class DeclarationVisitor method visit.
@Override
public void visit(Tree.Constructor that) {
Constructor c = new Constructor();
that.setConstructor(c);
if (scope instanceof Class) {
Class clazz = (Class) scope;
if (that.getIdentifier() == null && clazz.getDefaultConstructor() != null) {
// found an overloaded default constructor
// we'll set up the class overloads later
// when exiting visit(Tree.ClassDefinition)
clazz.setOverloaded(true);
clazz.setAbstraction(true);
}
}
visitDeclaration(that, c, false);
Type at;
Scope realScope = getRealScope(scope);
if (realScope instanceof Class) {
Class clazz = (Class) realScope;
Type ot = clazz.getType();
c.setExtendedType(ot);
at = c.appliedType(ot, NO_TYPE_ARGS);
clazz.setConstructors(true);
if (clazz.isAnonymous()) {
that.addError("anonymous class may not have constructor: '" + clazz.getName() + "' is an anonymous class");
}
} else {
at = null;
that.addError("constructor declaration must occur directly in the body of a class");
}
Function f = new Function();
f.setType(at);
that.setDeclarationModel(f);
visitDeclaration(that, f);
Scope o = enterScope(c);
super.visit(that);
exitScope(o);
f.setImplemented(that.getBlock() != null);
if (that.getParameterList() == null) {
that.addError("missing parameter list in constructor declaration: '" + name(that.getIdentifier()) + "' must have a parameter list", 1000);
} else {
ParameterList model = that.getParameterList().getModel();
model.setFirst(true);
if (model != null) {
c.addParameterList(model);
// TODO: fix this
f.addParameterList(model);
}
}
if (c.isAbstract()) {
if (that.getIdentifier() == null) {
that.addError("default constructor may not be annotated 'abstract'", 1601);
} else if (c.isShared()) {
that.addError("abstract constructor may not be annotated 'shared'", 1610);
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Function 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);
}
use of org.eclipse.ceylon.model.typechecker.model.Function in project ceylon by eclipse.
the class DeclarationVisitor method initFunctionOverload.
// An overloaded function is represented in
// the model with multiple Function objects
private static boolean initFunctionOverload(Function model, Function member, Scope scope, Unit unit) {
Function abstraction;
Function method = (Function) member;
Function newMethod = (Function) model;
newMethod.setOverloaded(true);
if (method.isAbstraction()) {
abstraction = method;
abstraction.getOverloads().add(model);
return abstraction.isActual() && !model.isActual();
} else {
String name = model.getName();
// create the "abstraction"
// for the overloaded method
method.setOverloaded(true);
abstraction = new Function();
abstraction.setAbstraction(true);
abstraction.setType(new UnknownType(unit).getType());
abstraction.setName(name);
abstraction.setShared(true);
abstraction.setActual(method.isActual());
abstraction.setFormal(method.isFormal());
abstraction.setDefault(method.isDefault());
abstraction.setContainer(scope);
abstraction.setScope(scope);
abstraction.setUnit(unit);
abstraction.initOverloads(method, newMethod);
scope.addMember(abstraction);
// put the abstraction first
// TODO: is this hack really necessary?
scope.getMembers().remove(method);
scope.getMembers().add(method);
return true;
}
}
Aggregations