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

Method pullInvoke

src/main/java/wyil/check/FlowTypeCheck.java:2281–2309  ·  view source on GitHub ↗
(Expr.Invoke expr, boolean required, Typing typing, Environment environment)

Source from the content-addressed store, hash-verified

2279 }
2280
2281 private Typing pullInvoke(Expr.Invoke expr, boolean required, Typing typing, Environment environment) {
2282 // Extract link
2283 Decl.Link<Decl.Callable> link = expr.getLink();
2284 // Save argument expressions for later
2285 Tuple<Expr> arguments = expr.getOperands();
2286 final int n = arguments.size();
2287 // Select candidates with matching numbers of arguments
2288 List<Decl.Callable> candidates = select(link.getCandidates(), c -> c.getParameters().size() == n);
2289 // Check this invocation is resolvable
2290 if (!link.isPartiallyResolved() || candidates.size() == 0) {
2291 syntaxError(link.getName(), AMBIGUOUS_CALLABLE, link.getCandidates());
2292 return typing.invalidate();
2293 }
2294 // Allocate space for the signature variables. This is used to identify each row
2295 // in the typing matrix with one of candidates.
2296 typing = typing.push(Type.Any).push(Type.Any).push(Type.Any);
2297 int v_concrete = typing.top();
2298 int v_template = v_concrete - 1;
2299 int v_signature = v_concrete - 2;
2300 // Register a finaliser to resolve this invocation
2301 typing.register(typeInvokeExpression(expr, v_signature, v_template));
2302 // Fork typing into different cases for each overloaded candidate
2303 typing = typing
2304 .project(row -> fork(candidates, c -> initialiseCallableFrame(row, expr, c, v_signature, v_concrete, v_template)));
2305 // >>> Propagate forwards into children
2306 typing = pushExpressions(arguments, (r, i) -> getLambdaParameter(r.get(v_concrete), i), typing, environment);
2307 // Pull back return
2308 return typing.map(row -> row.add(getLambdaReturn(row.get(v_concrete))));
2309 }
2310
2311 private Typing.Row initialiseCallableFrame(Typing.Row row, Expr.Invoke expr, Decl.Callable candidate, int v_signature,
2312 int v_concrete, int v_template) {

Callers 1

pullExpressionMethod · 0.95

Calls 15

selectMethod · 0.95
syntaxErrorMethod · 0.95
typeInvokeExpressionMethod · 0.95
forkMethod · 0.95
pushExpressionsMethod · 0.95
getLambdaParameterMethod · 0.95
getLambdaReturnMethod · 0.95
getCandidatesMethod · 0.80
isPartiallyResolvedMethod · 0.80
invalidateMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected