parseTU: Read a Translation Unit file into memory.

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

Description

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.

Usage

1
2
3
parseTU(filename, language = NA, typedefs = NULL, asText = FALSE)
setLanguage(parser, language = NA)
parseTUOriginalTree(fileName)

Arguments

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 StructDefinition-class for C code rather than C++ClassDefinition-class for C++ code.

typedefs

an optional DefinitionContainer object that can be passed by the caller to initialize the DefinitionContainer within the parser object and which is used to resolve nodes.

parser

the parser object returned from a call to parseTU.

asText

a logical value indicating whether the fileName is the name of a file containing the translation unit (FALSE) or if fileName is the actual contents of the TU ( FALSE) as read from a file by an R command (e.g. readLines)

Details

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.

Value

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.

Author(s)

Duncan Temple Lang <duncan@wald.ucdavis.edu>

References

http://www.omegahat.org/RGccTranslationUnit

See Also

getAllDeclarations getGlobalVariables getFunctions getClassNodes

nodeIterator

Examples

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)

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