getCursorTokens: Get the text tokens corresponding to a CXCursor

View source: R/clang.R

getCursorTokensR Documentation

Get the text tokens corresponding to a CXCursor

Description

This function allows us to obtain the text in the source code that corresponds to the CXCursor object, e.g. a routine or variable declaration, a call to a routine, etc.

This allows us to obtain additional attributes of a routine such as __inline___, __host__, __device__, etc.

Usage

getCursorTokens(cur)

Arguments

cur

the CXCursor

Value

A character vector containing the tokens. The names of the elements are the types of the tokens, e.g. Punctuation, Identifier, Keyword,

Author(s)

Duncan Temple Lang, with code adapted from Carlos Andrade http://lists.cs.uiuc.edu/pipermail/cfe-dev/2012-June/022601.html

See Also

visitCursor, parseTU

Examples

f = system.file("exampleCode", "fib.c", package = "RCIndex")
r = getRoutines(f)
r$fib
cur = as(r$fib, "CXCursor")
cur[[1]]  # the ParmDecl
cur[[2]] # the body of the routine
cur[[2]][[2]] # the return
cur[[2]][[2]][[1]][[1]] # the BinaryOperator for fib(n-1) + fib(n-2)
getCursorTokens(cur[[2]][[2]][[1]][[1]]) #

bin = cur[[2]][[2]][[1]][[1]]
# get operator
toks = getCursorTokens(bin[[1]])
toks[length(toks)]


omegahat/RClangSimple documentation built on April 25, 2024, 4:18 a.m.