Description Usage Arguments Value Author(s) References See Also Examples
This function searches the translation unit for non-local
or top-level C/C++ variables and determines whether
they are constant (i.e. declared with the qualifier const
).
The function then generates C code which can be run and in turn outputs
R code to define R variables with the same values as these C level
constants. This works for simple types.
1 2 3 4 5 | computeGlobalConstants(tu = NULL, gvars = getGlobalVariables(tu, files),
files = character(),
defs = DefinitionContainer(tu),
varsOnly = FALSE, symbolic = FALSE,
access = c("public", "protected"))
|
tu |
the translation unit node/parser, obtained by a call to |
gvars |
the global variable nodes. In some cases, these will
already have been computed and then one only needs to pass these and
not |
files |
a character vector identifying the names of the files
mentioned in the TU nodes in which we are interested, i.e. those
in which the variables of interest are declared/defined.
If |
defs |
the table of resolved nodes and data types and routines.
This is a mutable object of class |
varsOnly |
a logical value which, if |
symbolic |
a logical value indicating whether we want the
values of the constants to be returned as values or symbolically in terms of
other constant variables, e.g. |
access |
a character vector containing any of “public”, “protected” and “private” which is used to filter the constants returned. This is relevant only for C++ code. This specifies whether we want public, protected and/or private global variables. |
An object of S3 class ComputeConstants
.
This is a list with two elements:
cmds |
a character vector with names giving the names of the
global variables and entries giving C/C++ code to calculate the
constant value or an |
filenames |
a character vector that parallels cmds and gives the
names of the header file in which the variable is declared.
This is used when we emit the C code to compute the values of these
constants as R values as we need to include the header files to
ensure the constants are defined and accessible to our generated code.
As with all TU files, we don't have the full path name but merely
the base name of the file and some more computations are warranted
to get the proper access to these files for the |
Duncan Temple Lang
The GCC compiler suite
parseTU
computeGlobalEnumConstants
getCppDefines
1 2 3 4 5 | tu = parseTU(system.file("examples", "globals", "globals.c.tu", package = "RGCCTranslationUnit"))
g = computeGlobalConstants(tu)
names(g)
names(g$cmds)
g$filenames
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.