use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.
the class ExpressionVisitor method createInferredDynamicParameter.
private void createInferredDynamicParameter(Function m, Parameter pm) {
FunctionOrValue model = pm.getModel();
if (model == null) {
Value value = (Value) model;
value = new Value();
value.setUnit(unit);
value.setName(pm.getName());
pm.setModel(value);
value.setContainer(m);
value.setScope(m);
m.addMember(value);
value.setType(unit.getUnknownType());
// value.setDynamic(true);
value.setDynamicallyTyped(true);
value.setInferred(true);
value.setInitializerParameter(pm);
}
}
use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.
the class ExpressionVisitor method visit.
@Override
public void visit(Tree.AttributeDeclaration that) {
super.visit(that);
Value val = that.getDeclarationModel();
Tree.SpecifierOrInitializerExpression sie = that.getSpecifierOrInitializerExpression();
if (!val.isActual() || // accountForIntermediateRefinements()
isTypeUnknown(val.getType())) {
inferType(that, sie);
}
Tree.Type type = that.getType();
if (type != null) {
Type t = type.getTypeModel();
if (type instanceof Tree.LocalModifier && !isNativeForWrongBackend(val, unit)) {
if (val.isParameter() && !val.isInferred()) {
type.addError("parameter may not have inferred type: '" + val.getName() + "' must declare an explicit type");
} else if (isTypeUnknown(t)) {
if (sie == null) {
type.addError("value must specify an explicit type or definition", 200);
} else if (!hasError(sie)) {
type.addError("value type could not be inferred: '" + val.getName() + "'" + getTypeUnknownError(t));
}
}
}
if (!isTypeUnknown(t)) {
checkType(t, val, sie, 2100);
}
}
Setter setter = val.getSetter();
if (setter != null) {
setter.getParameter().getModel().setType(val.getType());
}
}
use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.
the class ExpressionVisitor method inferParameterTypes.
/**
* Infer parameter types for anonymous functions in a
* positional argument list, and set up references from
* arguments back to parameter models.
*/
private boolean[] inferParameterTypes(Tree.Primary p, Tree.PositionalArgumentList pal, boolean error) {
Type type = p.getTypeModel();
Tree.Term term = unwrapExpressionUntilTerm(p);
if (term instanceof Tree.MemberOrTypeExpression) {
Tree.MemberOrTypeExpression mte = (Tree.MemberOrTypeExpression) term;
Declaration dec = mte.getDeclaration();
if (dec == null || dec.isDynamic()) {
if (type == null || type.isUnknown()) {
inferDynamicParameters(pal);
}
} else if (dec instanceof Functional) {
setupTargetParametersDirectly(pal, mte, dec, error);
return inferParameterTypesDirectly(pal, mte, dec, error);
} else if (dec instanceof Value) {
Value value = (Value) dec;
return inferParameterTypesIndirectly(pal, value.getType(), error);
}
} else {
if (type == null || type.isUnknown()) {
inferDynamicParameters(pal);
} else {
return inferParameterTypesIndirectly(pal, type, error);
}
}
int size = pal.getPositionalArguments().size();
return new boolean[size];
}
use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.
the class DeclarationVisitor method visit.
@Override
public void visit(Tree.Enumerated that) {
Constructor e = new Constructor();
that.setEnumerated(e);
visitDeclaration(that, e, false);
Type at;
if (scope instanceof Class) {
Class clazz = (Class) scope;
Type ot = clazz.getType();
e.setExtendedType(ot);
at = e.appliedType(ot, NO_TYPE_ARGS);
clazz.setEnumerated(true);
if (clazz.isAnonymous()) {
that.addError("anonymous class may not have a value constructor: '" + clazz.getName() + "' is an anonymous class");
} else if (clazz.isAbstract()) {
that.addError("abstract class may not have a value constructor: '" + clazz.getName() + "' is abstract");
} else if (!clazz.getTypeParameters().isEmpty()) {
that.addError("generic class may not have a value constructor: '" + clazz.getName() + "' is generic");
} else if (scope.getContainer() instanceof Interface) {
that.addError("class nested inside an interface may not have a value constructor: '" + clazz.getName() + "' belongs to an interface");
}
} else {
at = null;
that.addError("value constructor declaration must occur directly in the body of a class");
}
Value v = new Value();
v.setType(at);
that.setDeclarationModel(v);
visitDeclaration(that, v);
Scope o = enterScope(e);
super.visit(that);
exitScope(o);
v.setImplemented(that.getBlock() != null);
}
use of org.eclipse.ceylon.model.typechecker.model.Value in project ceylon by eclipse.
the class DeclarationVisitor method visit.
@Override
public void visit(Tree.ObjectArgument that) {
Class c = new Class();
defaultExtendedToBasic(c);
c.setAnonymous(true);
that.setAnonymousClass(c);
visitArgument(that, c);
Value v = new Value();
that.setDeclarationModel(v);
visitArgument(that, v);
Type t = c.getType();
that.getType().setTypeModel(t);
v.setType(t);
Scope o = enterScope(c);
super.visit(that);
exitScope(o);
}
Aggregations