[erlang-questions] Core Erlang: Associating Function Names to Function Bodies

Christopher Meiklejohn christopher.meiklejohn@REDACTED
Sun Mar 10 18:02:18 CET 2019

As part of a static analysis I'm writing, I'm trying to associate
function names with their function bodies so I can provide information
about the calling functions to users as part of the completed
analysis.  However, I'm running into difficulty performing this

The problem I'm running into is the following:

1.) In the Core Erlang AST, named functions are defined by associating
a c_var node in the form of {Function, Arity} to a subtree containing
the c_fun function body.
2.) Also, in the Core Erlang AST, calls to functions are also
represented as c_var nodes in the form of {Function, Arity}.

The cerl_trees:fold, mapfold all perform postorder traversals.  With a
postorder traversal, there may be an arbitrary distance in the fold
between when a function is defined and where it is given a name.  With
reverse postorder, my understanding is that these nodes would be
directly next to each other, which would make the mapping easier.

My initial approach was to attempt to, when a c_var node was found in
the proper form, store a candidate name for the next function that's
found and perform the association that way.  The problem that arises
from this approach is that there can be an arbitrary number of c_var
nodes for function invocations between the definition of the function
and it's actual body.  The same can also happen for any functions that
occur in between as well.

Therefore, my analysis incorrectly associates function bodies to
function names for any function that calls another function in the
body -- incorrectly thinking that the nearest c_var node containing a
function name is it's associated name.

I assume this must have been done for a previous analysis performed on
Erlang, but I haven't found anything.  Would a reverse postorder
traversal make this easier?  Is there a better way to identify the
mapping between c_var nodes and c_funs that are being assigned to
them?  Has this been done before?

Thanks for the advice,

More information about the erlang-questions mailing list