removeAfterReturn: Remove any code after a top-level 'return' call

removeAfterReturnR Documentation

Remove any code after a top-level return call

Description

This function removes dead code that cannot possible be reached by the interpreter because it comes after an explicit call to return.

One of the purposes of this function is to merely clean and simplify code. We use it to remove extraneous code before compiling R code in the RLLVMCompile package.

Usage

removeAfterReturn(fun, recurse = TRUE)

Arguments

fun

the function whose code we analyze and clean, or an expression or call, i.e. a language object.

recurse

a logical value that controls whether we recursively process each expression or just process the top-level expressions in fun

Value

The modified version of the function with any extraneous code in the body removed.

Author(s)

Duncan Temple Lang

See Also

removeConstIf

Examples

 f =
 function(x) {
     print(x)
     return(x + 1)

     length(x)
 }

duncantl/CodeAnalysis documentation built on April 28, 2024, 6:01 p.m.