MCPcopy Create free account
hub / github.com/Whiley/WhileyCompiler / pushInvoke

Method pushInvoke

src/main/java/wyil/check/FlowTypeCheck.java:1772–1803  ·  view source on GitHub ↗
(int var, Expr.Invoke expr, Typing typing, Environment environment)

Source from the content-addressed store, hash-verified

1770 }
1771
1772 private Typing pushInvoke(int var, Expr.Invoke expr, Typing typing, Environment environment) {
1773 // Extract link
1774 Decl.Link<Decl.Callable> link = expr.getLink();
1775 // Save argument expressions for later
1776 Tuple<Expr> arguments = expr.getOperands();
1777 final int n = arguments.size();
1778 // Select candidates with matching numbers of arguments
1779 List<Decl.Callable> candidates = select(link.getCandidates(), c -> c.getParameters().size() == n);
1780 // Check this invocation is resolvable
1781 if (!link.isPartiallyResolved() || candidates.size() == 0) {
1782 syntaxError(link.getName(), AMBIGUOUS_CALLABLE, link.getCandidates());
1783 return typing.invalidate();
1784 }
1785 // Allocate space for the signature variables. This is used to identify each row
1786 // in the typing matrix with one of candidates.
1787 typing = typing.push(Type.Any).push(Type.Any).push(Type.Any);
1788 int v_concrete = typing.top();
1789 int v_template = v_concrete - 1;
1790 int v_signature = v_concrete - 2;
1791 // Register a finaliser to resolve this invocation
1792 typing.register(typeInvokeExpression(expr, v_signature, v_template));
1793 // Fork typing into different cases for each overloaded candidate
1794 typing = typing
1795 .project(row -> fork(candidates, c -> initialiseCallableFrame(row, expr, c, v_signature, v_concrete, v_template)));
1796 // <<< Filter return type
1797 Typing nTyping = typing.map(
1798 row -> filterOnSubtype(row, var, row.get(v_concrete).as(Type.Callable.class).getReturn(), environment));
1799 // Sanity check whether valid typing still possible
1800 checkForError(expr, typing, nTyping, var, v_concrete, t -> getLambdaReturn(t));
1801 // >>> Propagate forwards into children
1802 return pushExpressions(arguments, (r, i) -> getLambdaParameter(r.get(v_concrete), i), nTyping, environment);
1803 }
1804
1805 private Typing pushLambdaAccess(int var, Expr.LambdaAccess expr, Typing typing, Environment environment) {
1806 Decl.Link<Decl.Callable> link = expr.getLink();

Callers 1

pushExpressionMethod · 0.95

Calls 15

selectMethod · 0.95
syntaxErrorMethod · 0.95
typeInvokeExpressionMethod · 0.95
forkMethod · 0.95
filterOnSubtypeMethod · 0.95
checkForErrorMethod · 0.95
getLambdaReturnMethod · 0.95
pushExpressionsMethod · 0.95
getLambdaParameterMethod · 0.95
getCandidatesMethod · 0.80
isPartiallyResolvedMethod · 0.80

Tested by

no test coverage detected