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

Description Usage Arguments Value Author(s) See Also Examples

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

1
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

1
2
3
4
5
6
7
 f =
 function(x) {
     print(x)
     return(x + 1)

     length(x)
 }

duncantl/CodeAnalysis documentation built on Aug. 11, 2019, 12:35 a.m.