use of org.eclipse.ceylon.model.typechecker.model.Declaration in project ceylon by eclipse.
the class ExpressionVisitor method inferParameterTypes.
/**
* Infer parameter types for anonymous functions in a
* named argument list, and set up references from
* arguments back to parameter models.
*/
private void inferParameterTypes(Tree.Primary p, Tree.NamedArgumentList nal) {
Tree.Term term = unwrapExpressionUntilTerm(p);
if (term instanceof Tree.MemberOrTypeExpression) {
Tree.MemberOrTypeExpression mte = (Tree.MemberOrTypeExpression) term;
Declaration dec = mte.getDeclaration();
if (dec instanceof Functional) {
inferParameterTypesDirectly(nal, mte, dec);
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Declaration in project ceylon by eclipse.
the class ExpressionVisitor method setupTargetParametersDirectly.
/**
* Sets references from arguments back to parameters
* in a direct invocation with positional arguments,
* special casing "coercion points" generated by the
* model loader.
*/
private void setupTargetParametersDirectly(Tree.PositionalArgumentList pal, Tree.MemberOrTypeExpression mte, Declaration dec, boolean error) {
// coercion point and use that instead
if (!error && isOverloadedVersion(dec) && !dec.isCoercionPoint()) {
Declaration abstraction = dec.getContainer().getDirectMember(dec.getName(), null, false);
if (abstraction.isAbstraction()) {
List<Declaration> overloads = abstraction.getOverloads();
if (overloads.size() == 2) {
for (Declaration overload : overloads) {
if (overload.isCoercionPoint()) {
dec = overload;
break;
}
}
}
}
}
List<Tree.PositionalArgument> args = pal.getPositionalArguments();
int argCount = args.size();
Functional fun = (Functional) dec;
List<ParameterList> pls = fun.getParameterLists();
if (!pls.isEmpty()) {
List<Parameter> params = pls.get(0).getParameters();
Reference reference = getInvokedProducedReference(dec, mte);
int paramsSize = params.size();
for (int i = 0, j = 0; i < argCount && j < paramsSize; i++) {
Parameter param = params.get(j);
Tree.PositionalArgument arg = args.get(i);
arg.setParameter(param);
if (arg instanceof Tree.ListedArgument) {
Tree.ListedArgument la = (Tree.ListedArgument) arg;
setupTargetParameters(reference, param, la.getExpression());
}
if (!param.isSequenced()) {
j++;
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Declaration 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.Declaration in project ceylon by eclipse.
the class DeclarationVisitor method beginDeclaration.
private Declaration beginDeclaration(Declaration innerDec) {
Declaration outerDec = declaration;
declaration = innerDec;
return outerDec;
}
use of org.eclipse.ceylon.model.typechecker.model.Declaration in project ceylon by eclipse.
the class DeclarationVisitor method visit.
@Override
public void visit(Tree.TypedArgument that) {
Declaration d = beginDeclaration(that.getDeclarationModel());
super.visit(that);
endDeclaration(d);
}
Aggregations