wrapBody method Null safety

void wrapBody(
  1. {List<Statement>? before,
  2. List<Statement>? after,
  3. List<Declaration>? supportingDeclarations}
)

Used to wrap the body of a function, by running some code before or after the original body.

Note that the original function will not have access to code from before or after, and also after will not have access to anything from the scope of the original function body. However, before and after do share the same scope, so after can reference variables defined in before.

You can conceptually think of the wrapping as implemented like this when understanding the semantics:

void someFunction(int x) { void originalFn(int x) { // Copy the original function body here }

// Inject all [before] code here.

// Call function matching the original, capture the return value to
// return later. Note that [ret] should not be available to [after].
var ret = originalFn(x);

// Inject all [after] code here.

return ret; // Return the original return value

}

Note that this means before can modify parameters before they are passed into the original function.

Implementation

void wrapBody(
    {List<Statement>? before,
    List<Statement>? after,
    List<Declaration>? supportingDeclarations});