Description Usage Arguments Details Value Author(s) References See Also Examples
This function provides a high-level interface to the Perl tools to process a translation unit graph and bring it into memory. The result is a Perl array of GCC::Node node types that describe the entities within the original source code. This array can be indexed by position from within R and the individual nodes can be processed in various ways.
This function tolerates mis-specified file names
allowing one to specify the name of the C/C++ source file
or one with a ".tu" extension instead of the
".t00.tu" extension generated by more modern/up-to-date
versions of GCC. In other words,
if the TU file is named abc.cc.tu
,
the caller can specify the file name as
abc.cc
, abc.cc.tu
or
abc.cc.t00.tu
. This forces the function to determine
which extension is being used and not the caller.
One can set the source language as "C" or "C++" when creating the
parser with parseTU
, but setLanguage
also allows one
to set it after the parser has been created and the parsing performed.
parseTUOriginalTree
reads the type of file generated with the
gcc/g++ command line flag -fdump-tree-original-raw which results in a
file with multiple, separate TUs for each routine in the original
source. Each TU has its own set of nodes, numbered starting from 1 and
so must be treated separately.
This function returns a list of objects obtained by calling
parseTU
on each of the separate sub-TUs using asText = TRUE
.
1 2 3 | parseTU(filename, language = NA, typedefs = NULL, asText = FALSE)
setLanguage(parser, language = NA)
parseTUOriginalTree(fileName)
|
filename, fileName |
the name of the file containing the translation unit. |
language |
a string such as "C" or "C++" which tells the parser
and, more specifically, code that uses the contents of parsed nodes
that the original code from which the translation unit was generated
was actually C code even if g++ was used to generate the tu file.
This influences how, for example, structs are resolved,
being |
typedefs |
an optional |
parser |
the parser object returned from a call to
|
asText |
a logical value indicating whether the |
This uses the Perl GCCTranslationUnit module to read the translation
unit
and uses the RSPerl
package to initiate this action
and provide access to the resulting array.
A reference to a Perl array
which is of class GCC::TranslationUnit::Parser
.
This S3-style class has methods in R that make it
easier to work with and treat more like a regular R
list. It allows indexing by
position
or node name
(taking into account the first element) ,
and provides lapply/sapply methods for
looping over the elements and applying a function to each node.
See GCC::TranslationUnit::Parser-class
for more information.
Duncan Temple Lang <duncan@wald.ucdavis.edu>
http://www.omegahat.org/RGccTranslationUnit
getAllDeclarations
getGlobalVariables
getFunctions
getClassNodes
1 2 3 4 5 6 7 | tu = parseTU(system.file("examples", "myFun.cpp.tu", package = "RGCCTranslationUnit"))
tu = parseTU(system.file("examples", "foo.c", package = "RGCCTranslationUnit"), language = "C")
# Number of nodes in the translation unit
.PerlLength(tu)
class(tu)
getRoutines(tu)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.