| lcc {Slcc} | R Documentation |
This parses pre-processed C code (i.e. run through the pre-processor) and calls S functions at different points when C symbols are defined. This allows one to identify C routines, static and global variables, and the definitions of C data structures. This can then be used to create S-level interfaces to these C symbols.
lcc(file, routine=lccHandler(), global=NULL, export=NULL, defSymbol=NULL,
typedef=NULL, enumDecl=NULL, routineDecl=NULL, structDecl = NULL)
file |
the name of the C source code file that has been created by running the C pre-processor on it with the appropriate flags (e.g. -I for include directories, -D for defining pre-processor symbols and constants, etc. |
routine |
either a function which is called by the parser when a C routine is defined, or a list of functions that is assumed to contain functions for all the handlers routine, global, export, defSymbol. The function for handling routines is called each time the parser locates a C routine definition. The S function is called with two arguments: an S representation of the symbol describing the routine and an object identifying the position in the C source (file, row and colum numbers) where the routine is located. The representation of the C routine in S includes information about the name of the routine, whether it is static or not, the number and type of the parameters. |
global |
a function that is called by the parser to announce a non-local variable, which could be static (visible only within this file) or truly global and visible to code in other files. This is called for top-level symbols and static variables within routines. The former includes both regular variables and routines. This function should expect two arguments: an S object defining the symbol that is being registered as a global symbol, and an object giving the location in the C code at which the symbol was defined. This second argument gives the name of the file and the row and column information. |
export |
a function that is called by the parser when a C symbol
is determined to be visible to code in other files.
Not all global variables are exported and so this function is called only for
non-static symbols, and it is called for both variables and routines.
This function should expect two arguments which are the same as those
passed to routine, global and defSymbol.
|
defSymbol |
This handler is called each time a variable is defined, and includes both exported and global variables. |
typedef |
a handler function that is invoked each time
a typedef is found in the C code.
This is called with a symbol giving the name of the new type
and the definition of that type. |
enumDecl |
a function called each time an enumeration is declared in the C code, giving the values and their symbolic names. |
routineDecl |
called when a declaration of a routine is encountered in the C code, allowing one to determine what routines are ``available'' to the code. |
structDecl |
called when a struct is processed by the
C parser. |
The parsing of the C code is done via a modified version of http://www.cs.princeton.edu/software/lcc/{lcc}. This has been changed to allow it to be restarted within an R session, and different handlers are used at the C level to process symbols, etc.
The return value is the list of handlers used in the parsing. If the
default lccHandler() argument is used, this is a list of
functions that provide access to the definitions of the routines,
global and exported variables that have been defined. The functions
routines, globals and exports return named lists
of the symbols in the corresponding groups.
The same handler can be used in different calls and the information
accumulated across source files. This allows one to analyze multiple C
source files in a single operation. Alternatively, one can discard
the information stored in this closure using the reset
function.
One can specify one's own handler functions to process and/or
accumulate the symbol information in a different manner. In this case,
the return value is again the handler list passed to lcc. It is
assumed that this or some other global object provides access to the
collected information.
Duncan Temple Lang (duncan@research.bell-labs.com)
http://www.omegahat.org/Slcc, http://www.cs.princeton.edu/software/lcc/
# get all the symbols
desc <- lcc(system.file("examples", "test.i", package="Slcc"))
names(desc$routines())
names(desc$globals())
# get just the routines, ignoring other symbols
d <- getRoutineHandler()
lcc(system.file("examples", "test.i", package="Slcc"), d$handler)
d$routines()