getCallGraph: Compute call graph for a C/C++ routine or method

Description Usage Arguments Value Note Author(s) References See Also Examples

Description

This actually works on arbitrary nodes within the translation unit parser array of nodes. So it can be used for examining code blocks, e.g. body of an if statement or a while loop.

Usage

1
getCallGraph(nodes, defs = getRoutines(nodes), visited = new.env())

Arguments

nodes

the parser or array of nodes, used to lookup the references to other nodes within the defs object.

defs

for the caller, this is the routine returned from getRoutines. In fact, it can also be any node in the parser array, i.e. a GCC::Node.... type.

visited

this is not intended to be supplied by the top-level caller, but rather is passed between the recursive calls to store information about which nodes have already been visited and so are not to be processed again should there be another node that refers to it.

Value

A named vector giving the names of the routines that were found to be called within the routine/language node along with the position in the parser array of nodes so that one can quickly identify the actual declaration/definition.

Note

This does not handle invocations via "function pointers" in the C code. It can be made to understand them, but not know which routine will be called. That is a run-time decision.

Author(s)

Duncan Temple Lang

References

c-tree.texi in the gcc source distribution.

See Also

parseTU

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Not run: 
 filename = system.file("examples", "phast", "msa.c.tu", package = "RGCCTranslationUnit")

 p = parseTU(filename, language = "C")
 routines = getRoutines(p, "msa.c")

 calls = getCallGraph(p, routines$msa_new_from_file)
 names(calls)
 counts = table(names(calls))

## End(Not run)

omegahat/RGCCTranslationUnit documentation built on May 24, 2019, 1:53 p.m.