getAncestorByKind: Find the enclosing routine, C++ namespace, or cursor of a...

findAncestorByKindR Documentation

Find the enclosing routine, C++ namespace, or cursor of a given kind

Description

These functions traverse up the AST to find the nearest ancestor cursor with a given cursor kind. This allows us to find the enclosing routine/function, C++ namespace, C++ class, if statement, etc.

Usage

findAncestorByKind(cur, kind)

Arguments

cur

the CXCursor from which to start the search

kind

the cursor kind identifying which type of cursor for which we are looking.

Value

The first matching ancestor CXCursor.

NULL if no ancestor cursor corresponds to the target kind.

Author(s)

Duncan Temple Lang

See Also

createTU

Examples

f = system.file("exampleCode/namespace.cpp", package = "RCIndex")
tu = createTU(f)

k = getCppClasses(tu)

m = k$Foo@methods$doit

ns = findEnclosingNamespace(m)

findEnclosingClass(m)
findAncestorByKind(m, CXCursor_ClassDecl)


c = findAssignTo(tu, "ctr")[[2]]
findEnclosingClass(c)

findEnclosingFunction(c)

omegahat/RClangSimple documentation built on Aug. 17, 2024, 10:23 a.m.