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.

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.

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

Return immediate cursors of the given cursor.

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

Return a child cursor vector of the given cursor.

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.

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.

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.

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

Return the arguments of a command.

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

Convert an HTML tag to its string representation.

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

Convert a comment into an XML document.

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

Return the attributes of an HTML tag.

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

Return the getCanonicalCursor cursor corresponding to the given cursor.

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.

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

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

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

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

Clang.getCompileCommandsMethod
getCompileCommands(db::CLCompilationDatabase)

Get all compile commands from a compilation database.

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.

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).

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.

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.

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

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

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

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

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.

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.

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.

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.

Clang.getCursorTypeMethod
getCursorType(c::CXCursor) -> CXType
getCursorType(c::CLCursor) -> CLType

Return the type of a CXCursor (if any). To get the cursor from a type, see getTypeDeclaration.

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

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

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.

Clang.getFieldDeclBitWidthMethod
getFieldDeclBitWidth(c::CLFieldDecl) -> Int

Return the bit width of a bit field declaration as an integer.

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

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

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

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

Clang.getNumArgumentsMethod
getNumArguments(t::Union{CXType,CLFunctionNoProto,CLFunctionProto}) -> Int

Return the number of non-variadic parameters associated with a function type. Wrapper for libclang's clang_getNumArgTypes.

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

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

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.

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.

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.

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

Return the paragraph argument of a given command.

Clang.getParamNameMethod
getParamName(c::ParamCommand) -> String

Return the name of a parameter.

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

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

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

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

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.

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

Get source code for the cursor.

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

Return the tag name of a HTML tag.

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

Get the text content assiciated with the node.

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

Return a source range that covers the given token.

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

Return the source location of the given token.

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

Returns the translation unit that a cursor originated from.

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

Return the cursor that represents the given translation unit.

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.

Clang.get_file_line_columnMethod
get_file_line_column(c::Union{CXCursor,CLCursor}) -> (String, Int, Int)

Return file name, line and column number.

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

Return the complete file and path name of the given file

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.

Clang.get_function_argsMethod
get_function_args(cursor::CLCursor) -> Vector{CLCursor}

Return function arguments for a given cursor.

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

Determine whether the given cursor has any attributes.

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.

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.

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

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

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

Return true if the given cursor kind represents an attribute.

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

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

Clang.isConstQualifiedTypeMethod
isConstQualifiedType(t::Union{CXType,CLType}) -> Bool

Determine whether a CXType has the "const" qualifier set, without looking through typedefs that may have added "const" at a different level. Wrapper for libclang's clang_isConstQualifiedType.

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.

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

Return true if the given cursor kind represents a declaration.

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

Return true if the given cursor kind represents an expression.

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

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

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

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

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

Return true if the type is a valid type.

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.

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

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

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

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

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

Return true if cursor is null.

Clang.isPODTypeMethod
isPODType(t::Union{CXType,CLType}) -> Bool

Return true if the CXType is a plain old data type. Wrapper for libclang's clang_isPODType.

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.

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.

Clang.isRestrictQualifiedTypeMethod
isRestrictQualifiedType(t::Union{CXType,CLType}) -> Bool

Determine whether a CXType has the "restrict" qualifier set, without looking through typedefs that may have added "restrict" at a different level. Wrapper for libclang's clang_isRestrictQualifiedType.

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

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

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

Return true if the given cursor kind represents a statement.

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

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

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).

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

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

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

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

Clang.isVolatileQualifiedTypeMethod
isVolatileQualifiedType(t::Union{CXType,CLType}) -> Bool

Determine whether a CXType has the "volatile" qualifier set, without looking through typedefs that may have added "volatile" at a different level. Wrapper for libclang's clang_isVolatileQualifiedType.

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.

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

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

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

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.

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

Return the kind of a comment.

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

Return the kind of the given cursor.

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

Return the kind of the given token.

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

Return the kind of the given type.

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

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

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.

Clang.parse_headersFunction
parse_headers(
    index::Index,
    headers::Vector{String},
    args::Vector{String}=[],
    flags=CXTranslationUnit_None,
) -> Vector{TranslationUnit}

Return a TranslationUnit vector for the given headers.

See also parse_header.

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.

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

Return the spelling of a given CXTypeKind.

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.

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

Return the original translation unit source file name.

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

Return a name for the entity referenced by this cursor.

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.

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

Return a TokenList from the given cursor.

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

Return the integer value of an enum constant declaration.

Clang.CLCompilationDatabaseMethod
CLCompilationDatabase(path::AbstractString)

Creates a compilation database from the database found in directory path.

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.
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.