Clang API Reference

Clang._cxstring_to_stringMethod

Free and convert a CXString to String. Note this function will free the given CXString so ensure it is not called twice.

source
Clang.annotateTokensMethod
annotateTokens(tu::TranslationUnit, tokens, token_num, cursors)

Annotate the given set of tokens by providing cursors for each token that can be mapped to a specific entity within the abstract syntax tree.

source
Clang.childrenMethod
children(cursor::CXCursor) -> Vector{CXCursor}
children(cursor::CLCursor) -> Vector{CLCursor}

Return immediate cursors of the given cursor.

source
Clang.fieldsMethod
fields(ty::CXType) -> Vector{CXCursor}
fields(ty::CLType) -> Vector{CLCursor}

Return a child cursor vector of the given cursor.

source
Clang.fileMethod
file(c::CLCursor) -> CLFile

Return the file referenced by the input cursor.

source
Clang.getAlignOfMethod
getAlignOf(t::CXType) -> Int
getAlignOf(t::CLType) -> Int

Return the alignment of a type in bytes as per C++[expr.alignof] standard.

It returns a minus number for layout errors, please convert the result to a CXTypeLayoutError to see what the error is.

source
Clang.getArgTypeMethod
getArgType(t::CXType, i::Unsigned) -> CXType
getArgType(t::Union{CLFunctionNoProto,CLFunctionProto}, i::Integer) -> CLType

Return the type of a parameter of a function type. Wrapper for libclang's clang_getArgType.

source
Clang.getArgumentMethod
getArgument(c::CXCursor, i::Integer) -> CXCursor
getArgument(c::Union{CLFunctionDecl,CLCXXMethod,CLConstructor,CLFunctionTemplate}, i::Integer) -> CLCursor

Return the argument cursor of a function or method.

source
Clang.getArgumentsMethod
getArguments(c::Union{BlockCommand, InlineCommand}) -> Vector{String}

Return the arguments of a command.

source
Clang.getAsStringMethod
getAsString(c::Union{CXComment, HTMLStartTag, HTMLEndTag})

Convert an HTML tag to its string representation.

source
Clang.getAsXMLMethod
getAsXML(c::Union{CXComment, FullComment})

Convert a comment into an XML document.

source
Clang.getAttributesMethod
getAttributes(c::Union{CXComment, HTMLStartTag}) -> Vector{Pair{String, String}}

Return the attributes of an HTML tag.

source
Clang.getCanonicalCursorMethod
getCanonicalCursor(c::CXCursor) -> CXCursor
getCanonicalCursor(c::CLCursor) -> CLCursor

Return the getCanonicalCursor cursor corresponding to the given cursor.

source
Clang.getCanonicalTypeMethod
getCanonicalType(t::CXType) -> CXType
getCanonicalType(t::CLType) -> CLType

Return the canonical type for a CXType.

Clang's type system explicitly models typedefs and all the ways a specific type can be represented. The canonical type is the underlying type with all the "sugar" removed. For example, if 'T' is a typedef for 'int', the canonical type for 'T' would be 'int'. Wrapper for libclang's clang_getCanonicalType.

source
Clang.getCommandNameMethod
getCommandName(c::InlineCommand) -> String
getCommandName(c::BlockCommand) -> String

Return the command name of a command, e.g. "brief" for \brief blah.

source
Clang.getCompileCommandsMethod
getCompileCommands(db::CLCompilationDatabase, file::AbstractString)

Get all compile commands for a file given its complete path.

source
Clang.getCursorDefinitionMethod
getCursorDefinition(c::CXCursor) -> CXCursor
getCursorDefinition(c::CLCursor) -> CLCursor

For a cursor that is either a reference to or a declaration of some entity, retrieve a cursor that describes the definition of that entity.

source
Clang.getCursorExtentMethod
getCursorExtent(c::Union{CXCursor,CLCursor}) -> CXSourceRange

Return the physical extent of the source construct referenced by the given cursor.

The extent of a cursor starts with the file/line/column pointing at the first character within the source construct that the cursor refers to and ends with the last character within that source construct. For a declaration, the extent covers the declaration itself. For a reference, the extent covers the location of the reference (e.g., where the referenced entity was actually used).

source
Clang.getCursorLanguageMethod
getCursorLanguage(c::Union{CXCursor,CLCursor}) -> CXLanguageKind

Return the language of the entity referred to by a given cursor. Return CXLanguage_Invalid if the input cursor is not a decl. Note that, this function has limitations, for example, it cannot distinguish C++ structs from C structs, in both cases, it returns CXLanguage_C.

source
Clang.getCursorLexicalParentMethod
getCursorLexicalParent(c::CXCursor) -> CXCursor
getCursorLexicalParent(c::CLCursor) -> CLCursor

Return the lexical parent of the given cursor. Please checkout libclang's doc to know more.

source
Clang.getCursorLinkageMethod
getCursorLinkage(c::Union{CXCursor,CLCursor}) -> CXLinkageKind

Return the linkage of the entity referred to by a given cursor.

source
Clang.getCursorLocationMethod
getCursorLocation(c::Union{CXCursor,CLCursor}) -> CXSourceLocation

Return the physical location of the source constructor referenced by the given cursor.

source
Clang.getCursorReferencedMethod
getCursorReferenced(c::CXCursor) -> CXCursor
getCursorReferenced(c::CLCursor) -> CLCursor

For a cursor that is a reference, retrieve a cursor representing the entity that it references.

source
Clang.getCursorResultTypeMethod
getCursorResultType(c::CXCursor) -> CXType
getCursorResultType(c::Union{CLFunctionDecl,CLCXXMethod}) -> CLType

Return the return type associated with a given cursor. This only returns a valid type if the cursor refers to a function or method.

source
Clang.getCursorResultTypeMethod
getCursorResultType(t::CXType) -> CXType
getCursorResultType(t::Union{CLFunctionNoProto,CLFunctionProto}) -> CLType

Return the return type associated with a function type. Wrapper for libclang's clang_getResultType.

source
Clang.getCursorSemanticParentMethod
getCursorSemanticParent(c::CXCursor) -> CXCursor
getCursorSemanticParent(c::CLCursor) -> CLCursor

Return the semantic parent of the given cursor. Please checkout libclang's doc to know more.

source
Clang.getDirectionMethod
getDirection(c::Union{CXComment, ParamCommand})

Return the parameter passing direction ([in], [out], [in,out]) or missing if the direction is not specified.

source
Clang.getElementTypeMethod
getElementType(t::CXType) -> CXType
getElementType(t::Union{CLVector,CLConstantArray,CLIncompleteArray,CLVariableArray,CLDependentSizedArray,CLComplex}) -> CLType

Return the element type of an array, complex, or vector type. Wrapper for libclang's clang_getElementType.

source
Clang.getIncludedFileMethod
getIncludedFile(c::Union{CXCursor,CLCursor}) -> CXFile

Return the file that is included by the given inclusion directive cursor.

source
Clang.getIndexMethod
getIndex(c::Union{CXComment, ParamCommand})

Return zero-based parameter index in function prototype or missing if the parameter is invalid.

source
Clang.getNumArgumentsMethod
getNumArguments(c::Union{CXCursor,CLCursor}) -> Int

Return the number of non-variadic arguments associated with a given cursor.

source
Clang.getNumElementsMethod
getNumElements(t::Union{CXType,CLVector,CLConstantArray,CLIncompleteArray,CLVariableArray,CLDependentSizedArray}) -> Int

Return the number of elements of an array or vector type. Wrapper for libclang's clang_getNumElements.

source
Clang.getOffsetOfMethod
getOffsetOf(t::CXType, s) -> Int
getOffsetOf(t::CLType, s::AbstractString) -> Int

Return the offset of a field named S in a record of type T in bits as it would be returned by offsetof as per C++11[18.2p4].

It returns a minus number for layout errors, please convert the result to a CXTypeLayoutError to see what the error is.

source
Clang.getOffsetOfFieldMethod
getOffsetOfField(c::Union{CXCursor,CLCursor}) -> Int

Return the offset of the field represented by the cursor in bits as it would be returned by offsetof as per C++11[18.2p4]. It returns a minus number for layout errors, please convert the result to a CXTypeLayoutError to see what the error is.

source
Clang.getParagraphMethod
getParagraph(c::CXComment)
getParagraph(c::BlockCommand)

Return the paragraph argument of a given command.

source
Clang.getParsedCommentMethod
getParsedComment(c::CXCursor) -> CXComment
getParsedComment(c::CLCursor) -> CLComment

Return the parsed AST of doxygen comment associated with the given node.

source
Clang.getRenderKindMethod
getRenderKind(c::Union{CXComment, InlineCommand}) -> CXCommentInlineCommandRenderKind

Return the most appropriate rendering mode, chosen on command semantics in Doxygen.

source
Clang.getSizeOfMethod
getSizeOf(t::CXType) -> Int
getSizeOf(t::CLType) -> Int

Return the size of a type in bytes as per C++[expr.sizeof] standard,

It returns a minus number for layout errors, please convert the result to a CXTypeLayoutError to see what the error is.

source
Clang.getSourceCodeMethod
getSourceCode(cursor::Union{CXCursor, CLCursor}) -> String

Get source code for the cursor.

source
Clang.getTagNameMethod
getTagName(c::Union{CXComment, HTMLStartTag, HTMLEndTag})

Return the tag name of a HTML tag.

source
Clang.getTextMethod
getText(c::Text) -> String
getText(c::VerbatimBlockLine) -> String
getText(c::VerbatimLine) -> String

Get the text content assiciated with the node.

source
Clang.getTokenExtentMethod
getTokenExtent(tu::Union{CXTranslationUnit,TranslationUnit}, t::Union{CXToken,CLToken}) -> CXSourceRange

Return a source range that covers the given token.

source
Clang.getTokenLocationMethod
getTokenLocation(tu::Union{CXTranslationUnit,TranslationUnit}, t::Union{CXToken,CLToken}) -> CXSourceLocation

Return the source location of the given token.

source
Clang.getTranslationUnitMethod
getTranslationUnit(c::Union{CXCursor,CLCursor}) -> CXTranslationUnit

Returns the translation unit that a cursor originated from.

source
Clang.getTranslationUnitCursorMethod
getTranslationUnitCursor(tu::TranslationUnit) -> CLCursor
getTranslationUnitCursor(tu::CXTranslationUnit) -> CXCursor

Return the cursor that represents the given translation unit.

source
Clang.get_elaborated_cursorMethod
get_elaborated_cursor(ty::CLType) -> CLCursor
get_elaborated_cursor(ty::CXType) -> CXCursor

Return the cursor of the elaborated type that is referenced by the input type. The input type can be a pointer/array. This function returns clang_getNullCursor if the input type is not refer to an elaborated type.

source
Clang.get_filenameMethod
get_filename(x::CXFile) -> String

Return the complete file and path name of the given file

source
Clang.get_filenameMethod
get_filename(c::Union{CXCursor,CLCursor}) -> String

Return the complete file and path name of the given file referenced by the input cursor.

source
Clang.hasAttrsMethod
hasAttrs(c::Union{CXCursor,CLCursor}) -> Bool

Determine whether the given cursor has any attributes.

source
Clang.has_elaborated_referenceMethod
has_elaborated_reference(ty::CLType) -> Bool
has_elaborated_reference(ty::CXType) -> Bool

Return true if the type is an elaborated type or the type indirectly refers to an elaborated type.

source
Clang.has_elaborated_tag_referenceMethod
has_elaborated_tag_reference(ty::CLType) -> Bool
has_elaborated_tag_reference(ty::CXType) -> Bool

Return true if the type is an elaborated tag type or the type indirectly refers to an elaborated tag type.

source
Clang.has_function_referenceMethod
has_function_reference(ty::CLType) -> Bool
has_function_reference(ty::CXType) -> Bool

Return true if the type is a function or the type indirectly refers to a function.

source
Clang.isAnonymousMethod
isAnonymous(c::Union{CXCursor,CLCursor}) -> Bool

Return true if the given cursor represents an anonymous record declaration(C++).

source
Clang.isAttributeMethod
isAttribute(k::CXcursorKind) -> Bool
isAttribute(c::CLCursor) -> Bool

Return true if the given cursor kind represents an attribute.

source
Clang.isBitFieldMethod
isBitField(c::Union{CXCursor,CLCursor}) -> Bool

Return true if the cursor specifies a Record member that is a bitfield.

source
Clang.isCursorDefinitionMethod
isCursorDefinition(c::Union{CXCursor,CLCursor}) -> Bool

Return true if the declaration pointed to by this cursor is also a definition of that entity.

source
Clang.isDeclarationMethod
isDeclaration(k::CXcursorKind) -> Bool
isDeclaration(c::CLCursor) -> Bool

Return true if the given cursor kind represents a declaration.

source
Clang.isExpressionMethod
isExpression(k::CXcursorKind) -> Bool
isExpression(c::CLCursor) -> Bool

Return true if the given cursor kind represents an expression.

source
Clang.isFunctionInlinedMethod
isFunctionInlined(c::Union{CXCursor,CLCursor}) -> Bool

Determine whether a CXCursor that is a function declaration, is an inline declaration.

source
Clang.isInvalidMethod
isInvalid(k::CXcursorKind) -> Bool
isInvalid(c::CLCursor) -> Bool

Return true if the given cursor kind represents an valid cursor.

source
Clang.isInvalidMethod
isInvalid(t::CXType) -> Bool
isInvalid(t::CLType) -> Bool

Return true if the type is a valid type.

source
Clang.isInvalidDeclarationMethod
isInvalidDeclaration(x::CXcursorKind) -> Bool

Return true if the given declaration is invalid. A declaration is invalid if it could not be parsed successfully.

source
Clang.isMacroBuiltinMethod
isMacroBuiltin(c::Union{CXCursor,CLCursor}) -> Bool

Determine whether a CXCursor that is a macro, is a builtin one.

source
Clang.isMacroFunctionLikeMethod
isMacroFunctionLike(c::Union{CXCursor,CLCursor}) -> Bool

Determine whether a CXCursor that is a macro, is function like.

source
Clang.isNullMethod
isNull(c::Union{CXCursor,CLCursor}) -> Bool

Return true if cursor is null.

source
Clang.isPreprocessingMethod
isPreprocessing(k::CXcursorKind) -> Bool
isPreprocessing(c::CLCursor) -> Bool

Return true if the given cursor kind represents a preprocessing element, such as a preprocessor directive or macro instantiation.

source
Clang.isReferenceMethod
isReference(k::CXcursorKind) -> Bool
isReference(c::CLCursor) -> Bool

Return true if the given cursor kind represents a simple reference. Note that other kinds of cursors (such as expressions) can also refer to other cursors. Use getCursorReferenced to determine whether a particular cursor refers to another entity.

source
Clang.isSelfClosingMethod
isSelfClosing(c::Union{CXComment, HTMLStartTag})

Return whether a tag is self-closing (for example, <br />).

source
Clang.isStatementMethod
isStatement(k::CXcursorKind) -> Bool
isStatement(c::CLCursor) -> Bool

Return true if the given cursor kind represents a statement.

source
Clang.isTranslationUnitMethod
isTranslationUnit(k::CXcursorKind) -> Bool
isTranslationUnit(c::CLCursor) -> Bool

Return true if the given cursor kind represents a translation unit.

source
Clang.isUnexposedMethod
isUnexposed(k::CXcursorKind) -> Bool

Return true if the given cursor kind represents a currently unexposed piece of the AST (e.g., CXCursor_UnexposedStmt).

source
Clang.isVariadicMethod
isVariadic(c::Union{CXCursor,CLCursor}) -> Bool

Return true if the given cursor is a variadic function or method.

source
Clang.isVirtualBaseMethod
isVirtualBase(c::Union{CXCursor,CLCursor}) -> Bool

Return true if the base class specified by the cursor with kind CX_CXXBaseSpecifier is virtual.

source
Clang.isWhiteSpaceMethod
isWhiteSpace(c::Union{CXComment, CLComment}) -> Bool

Return whether a CXParagraph or CXText is contains only white space. Return false for other kinds of comment.

source
Clang.is_forward_declarationMethod
is_forward_declaration(x::CLCursor) -> Bool

Return true if the cursor is a forward declaration. Reference: https://joshpeterson.github.io/identifying-a-forward-declaration-with-libclang

source
Clang.is_typedef_anonMethod
is_typedef_anon(current::CLCursor, next::CLCursor) -> Bool

Return true if the current cursor is a typedef anonymous struct/enum.

source
Clang.kindMethod
kind(c::CLCursor) -> CXCursorKind

Return the kind of the given cursor. Note this method directly reads CXCursor's kind field, which won't invoke additional clang_getCursorKind function calls.

source
Clang.kindMethod
kind(c::Union{CXComment, CXComment}) -> CXCommentKind

Return the kind of a comment.

source
Clang.kindMethod
kind(c::CXCursor) -> CXCursorKind

Return the kind of the given cursor.

source
Clang.kindMethod
kind(t::CXToken) -> CXTokenKind
kind(t::CLToken) -> CXTokenKind

Return the kind of the given token.

source
Clang.kindMethod
kind(t::CXType) -> CXTypeKind
kind(t::CLType) -> CXTypeKind

Return the kind of the given type.

source
Clang.nameMethod
name(x::CLFile) -> String

Return the complete file and path name of the given file

source
Clang.nameMethod
name(c::Union{CXCursor,CLCursor}) -> String

Return the display name for the entity referenced by this cursor.

source
Clang.parse_headerFunction
parse_header(
    index::Index,
    header::AbstractString,
    args::Vector{String}=[],
    flags=CXTranslationUnit_None,
) -> TranslationUnit

Return the TranslationUnit for a given header. This is the main entry point for parsing.

Arguments

  • header::AbstractString: the header file to parse.
  • index::Index: CXIndex pointer (pass to avoid re-allocation).
  • args::Vector{String}: compiler switches as string array, eg: ["-x", "c++", "-fno-elide-type"].
  • flags: bitwise OR of CXTranslationUnit_Flags.

See also parse_headers.

source
Clang.searchMethod
search(cursors::Vector{CLCursor}, ismatch::Function) -> Vector{CLCursor}

Return vector of CLCursors that match predicate. ismatch is a function that accepts a CLCursor argument.

source
Clang.spellingMethod
spelling(kind::CXTypeKind) -> String

Return the spelling of a given CXTypeKind.

source
Clang.spellingMethod
spelling(tu::TranslationUnit, t::CLToken) -> String
spelling(tu::TranslationUnit, t::CXToken) -> String
spelling(tu::CXTranslationUnit, t::CXToken) -> String

Return the spelling of the given token. The spelling of a token is the textual representation of that token, e.g., the text of an identifier or keyword.

source
Clang.spellingMethod
spelling(tu::TranslationUnit) -> String

Return the original translation unit source file name.

source
Clang.spellingMethod
spelling(c::Union{CXCursor,CLCursor}) -> String

Return a name for the entity referenced by this cursor.

source
Clang.spellingMethod
spelling(t::Union{CXType,CLType}) -> String

Pretty-print the underlying type using the rules of the language of the translation unit from which it came. If the type is invalid, an empty string is returned. Wrapper for libclang's clang_getTypeSpelling.

source
Clang.tokenizeMethod
tokenize(c::Union{CXCursor,CLCursor}) -> TokenList

Return a TokenList from the given cursor.

source
Clang.unique_idMethod
unique_id(file::CLFile) -> CXFileUniqueID

Return the unique id of the given file.

source
Clang.valueMethod
value(c::CLCursor) -> Integer

Return the integer value of an enum constant declaration.

source
Clang.IndexType
Index(exclude_decls_from_PCH, display_diagnostics)

Provide a shared context for creating translation units.

Arguments

  • exclude_decls_from_PCH: whether we only want to see "local" declarations (that did not come from a previous precompiled header). If false, we want to see all declarations.
  • display_diagnostics: whether to display diagnostics.
source
Clang.TranslationUnitType
TranslationUnit(idx, source, args)
TranslationUnit(idx, source, args, unsavedFiles, options)

Parse the given source file and the translation unit corresponding to that file.

source