use of org.eclipse.ceylon.model.typechecker.model.FunctionOrValue in project ceylon by eclipse.
the class TypeHierarchyVisitor method visit.
@Override
public void visit(Tree.BaseMemberExpression that) {
super.visit(that);
Declaration dec = that.getDeclaration();
if (dec instanceof FunctionOrValue && ((FunctionOrValue) dec).isShortcutRefinement()) {
checkForShortcutRefinement(that, dec);
}
}
use of org.eclipse.ceylon.model.typechecker.model.FunctionOrValue in project ceylon by eclipse.
the class TypeHierarchyVisitor method getOrBuildType.
/*private void removeTrailing(String trailingString, StringBuilder sb) {
final int length = sb.length();
sb.delete(length-trailingString.length(), length);
}*/
private Type getOrBuildType(TypeDeclaration declaration) {
Type type = types.get(new TypeDeclKey(declaration));
if (type == null) {
type = new Type();
type.declaration = declaration;
for (Declaration member : declaration.getMembers()) {
if (!(member instanceof FunctionOrValue || member instanceof Class) || isConstructor(member) || member.isStatic() || isAbstraction(member)) {
continue;
}
if (declaration.isNative() && member.isNative()) {
// Make sure we get the right member declaration (the one for the same backend as its container)
Backends backends = declaration.getNativeBackends();
member = getNativeDeclaration(member, backends);
if (member == null) {
continue;
}
}
final String name = member.getName();
Type.Members members = type.membersByName.get(name);
if (members == null) {
members = new Type.Members();
members.name = name;
type.membersByName.put(name, members);
}
if (member.isActual()) {
members.actuals.add(member);
if (!member.isFormal()) {
members.actualsNonFormals.add(member);
}
}
if (member.isFormal()) {
members.formals.add(member);
}
/*if (!member.isFormal() && member.isInterfaceMember()) {
members.concretesOnInterfaces.add(member);
}*/
if (member.isDefault()) {
members.defaults.add(member);
}
if (!member.isFormal() && !member.isDefault() && member.isShared()) {
members.nonFormalsNonDefaults.add(member);
}
if (member.isShared()) {
members.shared.add(member);
}
}
types.put(new TypeDeclKey(declaration), type);
}
return type;
}
use of org.eclipse.ceylon.model.typechecker.model.FunctionOrValue in project ceylon by eclipse.
the class TypeVisitor method visit.
@Override
public void visit(Tree.InitializerParameter that) {
super.visit(that);
Parameter p = that.getParameterModel();
String name = p.getName();
Declaration a = that.getScope().getDirectMember(name, null, false);
if (a == null) {
// Now done in ExpressionVisitor!
// that.addError("parameter is not defined: '" + p.getName() + "'");
} else if (!isLegalParameter(a)) {
that.addError("parameter is not a reference value or function: '" + name + "' is not a value or function");
} else {
if (a.isFormal()) {
that.addError("parameter is a formal attribute: '" + name + "' is annotated 'formal'", 320);
}
FunctionOrValue mov = (FunctionOrValue) a;
if (mov.getInitializerParameter() != null) {
that.addError("duplicate parameter: '" + name + "' already occurs in the parameter list");
} else {
mov.setInitializerParameter(p);
p.setModel(mov);
}
}
/*if (isGeneric(a)) {
that.addError("parameter declaration is generic: '" +
name + "' may not declare type parameters");
}*/
if (p.isDefaulted()) {
checkDefaultArg(that.getSpecifierExpression(), p);
}
}
use of org.eclipse.ceylon.model.typechecker.model.FunctionOrValue in project ceylon by eclipse.
the class TypeVisitor method visit.
@Override
public void visit(Tree.TypedDeclaration that) {
super.visit(that);
Tree.Type type = that.getType();
TypedDeclaration dec = that.getDeclarationModel();
setType(that, type, dec);
if (dec instanceof FunctionOrValue) {
FunctionOrValue mv = (FunctionOrValue) dec;
if (dec.isLate() && mv.isParameter()) {
that.addError("parameter may not be annotated late");
}
}
// if (type.getTypeModel().isTypeConstructor()) {
// type.addError("type constructor may not occur as the type of a declaration");
// }
}
use of org.eclipse.ceylon.model.typechecker.model.FunctionOrValue in project ceylon by eclipse.
the class ExpressionVisitor method inferParameterTypes.
/**
* Infer parameter types for an anonymous function.
*/
private boolean inferParameterTypes(Reference pr, Parameter param, Tree.Expression e, boolean variadic, boolean error) {
FunctionOrValue model = param.getModel();
if (e != null && model != null) {
Tree.Term term = unwrapExpressionUntilTerm(e.getTerm());
TypedReference tpr = pr.getTypedParameter(param);
if (term instanceof Tree.InvocationExpression) {
Tree.InvocationExpression ie = (Tree.InvocationExpression) term;
Tree.PositionalArgumentList pal = ie.getPositionalArgumentList();
Tree.NamedArgumentList nal = ie.getNamedArgumentList();
if (pal != null && pal.getPositionalArguments().isEmpty() || nal != null && nal.getNamedArguments().isEmpty()) {
term = ie.getPrimary();
}
}
if (term instanceof Tree.FunctionArgument) {
Tree.FunctionArgument anon = (Tree.FunctionArgument) term;
if (model instanceof Functional) {
// and could be removed
return inferParameterTypesFromCallableParameter(pr, param, anon, error);
} else {
Type paramType = tpr.getFullType();
if (variadic) {
paramType = unit.getIteratedType(paramType);
}
paramType = callableFromUnion(paramType);
if (unit.isCallableType(paramType)) {
return inferParameterTypesFromCallableType(paramType, param, anon, error);
}
}
}
}
return true;
}
Aggregations