clang

package
v0.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	/**
	 * Used to indicate that the parser should construct a "detailed"
	 * preprocessing record, including all macro definitions and instantiations.
	 *
	 * Constructing a detailed preprocessing record requires more memory
	 * and time to parse, since the information contained in the record
	 * is usually not retained. However, it can be useful for
	 * applications that require more detailed information about the
	 * behavior of the preprocessor.
	 */
	DetailedPreprocessingRecord = clang.TranslationUnit_DetailedPreprocessingRecord
)

*

  • Flags that control the creation of translation units. *
  • The enumerators in this enumeration type are meant to be bitwise
  • ORed together to specify which options should be used when
  • constructing the translation unit.
View Source
const (
	// NULL file handle (invalid/absent File)
	InvalidFile = File(0)
)

Variables

This section is empty.

Functions

func DefaultDiagnosticDisplayOptions

func DefaultDiagnosticDisplayOptions() clang.DiagnosticDisplayOptions

func DisplayName

func DisplayName(entity clang.Cursor) string

*

  • Retrieve the display name for the entity referenced by this cursor. *
  • The display name contains extra information that helps identify the cursor,
  • such as the parameters of a function or template or the arguments of a
  • class template specialization.

func FileName

func FileName(f clang.File) string

*

  • Retrieve the name of a particular source file.

func GoStringAndDispose

func GoStringAndDispose(str clang.String) string

func Mangling

func Mangling(fn Cursor) string

*

  • Retrieve a name for the entity referenced by this cursor.

func PresumedFile

func PresumedFile(loc SourceLocation) string

PresumedFile returns the presumed file name for the given source location.

func RawComment

func RawComment(entity clang.Cursor) string

RawComment returns the raw documentation comment associated with the given cursor, including the comment markers (e.g. "/** ... */" or "///"). It returns an empty string if the cursor has no associated comment.

func String

func String[T stringer](v T) string

String returns the Go string of a value whose String() returns a clang String.

func VisitChildren

func VisitChildren(root Cursor, fn func(cur, parent Cursor) ChildVisitResult) uint

VisitChildren visits the children of a particular cursor, invoking the given visitor function for each child cursor. The traversal may be recursive, depending on the return value of the visitor function.

Types

type ChildVisitResult

type ChildVisitResult = clang.ChildVisitResult

*

  • Describes how the traversal of the children of a particular
  • cursor should proceed after visiting a particular child cursor.
const (
	/**
	 * Terminates the cursor traversal.
	 */
	Break ChildVisitResult = clang.ChildVisit_Break

	/**
	 * Continues the cursor traversal with the next sibling of
	 * the cursor just visited, without visiting its children.
	 */
	Continue ChildVisitResult = clang.ChildVisit_Continue

	/**
	 * Recursively traverse the children of this cursor, using
	 * the same visitor and client data.
	 */
	Recurse ChildVisitResult = clang.ChildVisit_Recurse
)

type Cursor

type Cursor = clang.Cursor

*

  • A cursor representing some element in the abstract syntax tree for
  • a translation unit. *
  • The cursor abstraction unifies the different kinds of entities in a
  • program--declaration, statements, expressions, references to declarations,
  • etc.--under a single "cursor" abstraction with a common set of operations.
  • Common operation for a cursor include: getting the physical location in
  • a source file where the cursor points, getting the name associated with a
  • cursor, and retrieving cursors for any child nodes of a particular cursor. *
  • Cursors can be produced in two specific ways.
  • clang_getTranslationUnitCursor() produces a cursor for a translation unit,
  • from which one can use clang_visitChildren() to explore the rest of the
  • translation unit. clang_getCursor() maps from a physical source location
  • to the entity that resides at that location, allowing one to map from the
  • source code into the AST.

func OverriddenCursors

func OverriddenCursors(cur Cursor) (ret []Cursor, dispose func())

OverriddenCursors returns the set of methods that the given method cursor immediately overrides, computed by libclang via clang_getOverriddenCursors.

For a C++ virtual member function this is the set of virtual member functions with the same signature declared in its (immediate) base classes; with multiple inheritance a method can override several. libclang only reports the immediate overridden methods, so walking the override graph transitively requires calling this again on each result.

The array libclang allocates is released before returning, so the returned slice is a freshly copied, caller-owned []Cursor (empty when there are none).

type Diagnostic

type Diagnostic struct {
	clang.Diagnostic
}

Diagnostic represents a diagnostic message, such as a compiler warning or error.

func (Diagnostic) CategoryText

func (e Diagnostic) CategoryText() string

*

  • Returns the category text for the given diagnostic.

func (Diagnostic) Format

func (e Diagnostic) Format(options clang.DiagnosticDisplayOptions) string

*

  • Format the given diagnostic according to the specified display options.

func (Diagnostic) String

func (e Diagnostic) String() string

*

  • Returns a string that describes the diagnostic.

type File

type File = clang.File

*

  • A particular source file that is part of a translation unit.

type Index

type Index struct {
	clang.Index
}

*

  • An "index" that consists of a set of translation units that would
  • typically be linked together into an executable or library.

func CreateIndex

func CreateIndex(excludeDeclarationsFromPCH, displayDiagnostics int) Index

*

  • Provides a shared context for creating translation units. *
  • It provides two options: *
  • - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
  • declarations (when loading any new translation units). A "local" declaration
  • is one that belongs in the translation unit itself and not in a precompiled
  • header that was used by the translation unit. If zero, all declarations
  • will be enumerated. *
  • This process of creating the 'pch', loading it separately, and using it (via
  • -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
  • (which gives the indexer the same performance benefit as the compiler).

func (Index) ParseTranslationUnit

func (i Index) ParseTranslationUnit(options clang.TranslationUnit_Flags, filename string, args ...string) (ret TranslationUnit, err error)

ParseTranslationUnit parses the given source file and returns the translation unit corresponding to that file.

type SourceLocation

type SourceLocation = clang.SourceLocation

*

  • Identifies a specific source location within a translation
  • unit. *
  • Use clang_getExpansionLocation() or clang_getSpellingLocation()
  • to map a source location to a particular file, line, and column.

type TranslationUnit

type TranslationUnit struct {
	clang.TranslationUnit
}

*

  • A single translation unit, which resides in an index.

func TU

func TU(c Cursor) (ret TranslationUnit)

*

  • Retrieve the translation unit that a cursor originated from.

func (TranslationUnit) Diagnostic

func (u TranslationUnit) Diagnostic(index c.Uint) (ret Diagnostic)

*

  • Retrieve the diagnostic associated with the given index in the translation unit.

func (TranslationUnit) File

func (u TranslationUnit) File(filename string) File

File returns the File object corresponding to the given filename in the translation unit.

func (TranslationUnit) FileContents

func (u TranslationUnit) FileContents(file File) []byte

FileContents returns the contents of the specified file in the translation unit.

func (TranslationUnit) TokenSpelling

func (u TranslationUnit) TokenSpelling(tok clang.Token) string

*

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

func (TranslationUnit) Tokenize

func (u TranslationUnit) Tokenize(extent clang.SourceRange) (ret []clang.Token, dispose func())

Tokenize tokenizes the source code described by the given source range into raw lexical tokens. Call dispose() to free the memory allocated for the tokens after use.

func (TranslationUnit) VisitDiagnostics

func (u TranslationUnit) VisitDiagnostics(fn func(diag Diagnostic))

VisitDiagnostics visits all diagnostics in the translation unit and invokes the given function for each diagnostic.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL