Skip to content

Commit

Permalink
cleanups after eclipse-archived#7190
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking authored and Voiteh committed Mar 23, 2020
1 parent f18e568 commit 127e00a
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,8 @@ private void checkAnnotations(
// references are only resolved when we get to the
// containing InvocationExpression, and I did not want
// to add a whole new Visitor just for overloading errors
@Override public void visit(Tree.MemberOrTypeExpression that) {
@Override
public void visit(Tree.MemberOrTypeExpression that) {
super.visit(that);
Declaration dec = that.getDeclaration();
if (!that.getStaticMethodReferencePrimary()
Expand Down Expand Up @@ -1224,6 +1225,20 @@ && isAbstraction(dec)) {
}
}

//Note: this simply doesn't belong here at all, since it has
// nothing at all to do with annotations, but it has to
// happen after ExpressionVisitor because parameter
// lists are only inferred when we get to the containing
// InvocationExpression, and I did not want to add a
// whole new Visitor just for this
@Override
public void visit(Tree.FunctionArgument that) {
if (that.getParameterLists().isEmpty()) {
that.addError("missing parameter list: the parameter list of the anonymous function could not be inferred");
}
super.visit(that);
}

@Override
public void visit(Tree.TypeConstraint that) {
Tree.SatisfiedTypes sts = that.getSatisfiedTypes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static com.redhat.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.notAssignableMessage;
import static com.redhat.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType;
import static com.redhat.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.unwrapAliasedTypeConstructor;
import static com.redhat.ceylon.compiler.typechecker.parser.CeylonLexer.LIDENTIFIER;
import static com.redhat.ceylon.compiler.typechecker.tree.TreeUtil.eliminateParensAndWidening;
import static com.redhat.ceylon.compiler.typechecker.tree.TreeUtil.hasError;
import static com.redhat.ceylon.compiler.typechecker.tree.TreeUtil.hasUncheckedNulls;
Expand Down Expand Up @@ -79,10 +80,10 @@
import java.util.Set;

import org.antlr.runtime.CommonToken;
import org.antlr.runtime.Token;

import com.redhat.ceylon.common.Backend;
import com.redhat.ceylon.common.Backends;
import com.redhat.ceylon.compiler.typechecker.parser.CeylonLexer;
import com.redhat.ceylon.compiler.typechecker.tree.CustomTree;
import com.redhat.ceylon.compiler.typechecker.tree.Node;
import com.redhat.ceylon.compiler.typechecker.tree.Tree;
Expand Down Expand Up @@ -3324,14 +3325,23 @@ else if (op instanceof Tree.SpreadOp) {

}

private void createAnonymousFunctionParameters(Tree.InvocationExpression that) {
Tree.Primary prim = that.getPrimary();
/**
* Iterate over the arguments of an invocation
* looking for anonymous functions with missing
* parameter lists, and create the parameter
* lists from the type of the parameters to
* which the arguments are assigned.
*/
private void createAnonymousFunctionParameters(
Tree.InvocationExpression that) {
Tree.Primary primary = that.getPrimary();
Tree.PositionalArgumentList argList =
that.getPositionalArgumentList();
if (argList!=null &&
prim instanceof Tree.MemberOrTypeExpression) {
primary instanceof Tree.MemberOrTypeExpression) {
Tree.MemberOrTypeExpression mte =
(Tree.MemberOrTypeExpression) prim;
(Tree.MemberOrTypeExpression)
primary;
List<Tree.PositionalArgument> args =
argList.getPositionalArguments();
Declaration dec = mte.getDeclaration();
Expand All @@ -3348,53 +3358,23 @@ private void createAnonymousFunctionParameters(Tree.InvocationExpression that) {
i<asz && i<psz; i++) {
Tree.PositionalArgument arg =
args.get(i);
FunctionOrValue param =
params.get(i).getModel();
if (arg instanceof Tree.ListedArgument) {
Parameter param = params.get(i);
if (arg instanceof Tree.ListedArgument
&& param!=null) {
Tree.ListedArgument larg =
(Tree.ListedArgument) arg;
List<Parameter> fpl =
inferrableParameters(param);
Tree.Expression ex = larg.getExpression();
Tree.Expression ex =
larg.getExpression();
if (ex!=null && fpl!=null) {
Tree.Term term = ex.getTerm();
if (term instanceof Tree.FunctionArgument) {
Tree.FunctionArgument anon =
(Tree.FunctionArgument) term;
Function model = anon.getDeclarationModel();
if (anon.getParameterLists().isEmpty()) {
Tree.ParameterList pl =
new Tree.ParameterList(null);
ParameterList mpl = new ParameterList();
for (Parameter p: fpl) {
Tree.InitializerParameter ip =
new Tree.InitializerParameter(null);
CommonToken token =
new CommonToken(CeylonLexer.LIDENTIFIER,
p.getName());
token.setStartIndex(term.getStartIndex());
token.setLine(term.getToken().getLine());
token.setCharPositionInLine(term.getToken().getCharPositionInLine());
Tree.Identifier id =
new Tree.Identifier(token);
ip.setIdentifier(id);
pl.addParameter(ip);
ip.setUnit(unit);
ip.setScope(model);
id.setUnit(unit);
id.setScope(model);
Parameter mp = new Parameter();
mp.setDeclaration(model);
mp.setName(p.getName());
ip.setParameterModel(mp);
mpl.getParameters().add(mp);
pl.setModel(mpl);
}
pl.setUnit(unit);
pl.setScope(model);
model.addParameterList(mpl);
anon.addParameterList(pl);
}
(Tree.FunctionArgument)
term;
createAnonymousFunctionParameters(
fpl, term, anon);
}
}
}
Expand All @@ -3404,17 +3384,71 @@ private void createAnonymousFunctionParameters(Tree.InvocationExpression that) {
}
}

private List<Parameter> inferrableParameters(FunctionOrValue param) {
if (param instanceof Function) {
Function fun = (Function) param;
/**
* Create the parameter list of the given
* anonymous function with a missing argument
* list, from the given parameter list of a
* functional parameter to which it is assigned.
*/
private void createAnonymousFunctionParameters(
List<Parameter> parameters, Tree.Term term,
Tree.FunctionArgument anon) {
Function model = anon.getDeclarationModel();
if (anon.getParameterLists().isEmpty()) {
Tree.ParameterList pl =
new Tree.ParameterList(null);
ParameterList mpl = new ParameterList();
for (Parameter parameter: parameters) {
Tree.InitializerParameter ip =
new Tree.InitializerParameter(null);
CommonToken token =
new CommonToken(LIDENTIFIER,
parameter.getName());
token.setStartIndex(term.getStartIndex());
Token tok = term.getToken();
token.setLine(tok.getLine());
token.setCharPositionInLine(
tok.getCharPositionInLine());
Tree.Identifier id =
new Tree.Identifier(token);
ip.setIdentifier(id);
pl.addParameter(ip);
ip.setUnit(unit);
ip.setScope(model);
id.setUnit(unit);
id.setScope(model);
Parameter mp = new Parameter();
mp.setDeclaration(model);
mp.setName(parameter.getName());
ip.setParameterModel(mp);
mpl.getParameters().add(mp);
pl.setModel(mpl);
}
pl.setUnit(unit);
pl.setScope(model);
model.addParameterList(mpl);
anon.addParameterList(pl);
}
}

/**
* Get the parameters of a callable parameter, or, if
* the given parameter is a value parameter of type
* X(Y), a single faked parameter with the name 'it'.
*/
private List<Parameter> inferrableParameters(Parameter param) {
FunctionOrValue model = param.getModel();
if (model instanceof Function) {
Function fun = (Function) model;
ParameterList fpl = fun.getFirstParameterList();
return fpl==null ? null : fpl.getParameters();
}
else if (param instanceof Value) {
else if (model instanceof Value) {
Type type = param.getType();
if (type!=null && type.isCallable()) {
int min = unit.getTupleMinimumLength(unit.getCallableTuple(type));
int max = unit.getTupleMaximumLength(unit.getCallableTuple(type));
Type tup = unit.getCallableTuple(type);
int min = unit.getTupleMinimumLength(tup);
int max = unit.getTupleMaximumLength(tup);
if (min==1 || max==1) {
Parameter p = new Parameter();
p.setName("it");
Expand Down

0 comments on commit 127e00a

Please sign in to comment.