Documentation
¶
Index ¶
- Constants
- func DefaultDiagnosticDisplayOptions() clang.DiagnosticDisplayOptions
- func DisplayName(entity clang.Cursor) string
- func FileName(f clang.File) string
- func GoStringAndDispose(str clang.String) string
- func Mangling(fn Cursor) string
- func PresumedFile(loc SourceLocation) string
- func RawComment(entity clang.Cursor) string
- func String[T stringer](v T) string
- func USR(decl clang.Cursor) string
- func VisitChildren(root Cursor, fn func(cur, parent Cursor) ChildVisitResult) uint
- type ChildVisitResult
- type Cursor
- type Diagnostic
- type File
- type Index
- type RawComments
- type SourceLocation
- type TranslationUnit
- func (u TranslationUnit) Diagnostic(index c.Uint) (ret Diagnostic)
- func (u TranslationUnit) File(filename string) File
- func (u TranslationUnit) FileContents(file File) []byte
- func (u TranslationUnit) TokenSpelling(tok clang.Token) string
- func (u TranslationUnit) Tokenize(extent clang.SourceRange) (ret []clang.Token, dispose func())
- func (u TranslationUnit) VisitDiagnostics(fn func(diag Diagnostic))
Constants ¶
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.
const ( // NULL file handle (invalid/absent File) InvalidFile = File(0) )
Variables ¶
This section is empty.
Functions ¶
func DefaultDiagnosticDisplayOptions ¶
func DefaultDiagnosticDisplayOptions() clang.DiagnosticDisplayOptions
func DisplayName ¶
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 GoStringAndDispose ¶
func PresumedFile ¶
func PresumedFile(loc SourceLocation) string
PresumedFile returns the presumed file name for the given source location.
func RawComment ¶
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 USR ¶ added in v0.9.2
Retrieve a Unified Symbol Resolution (USR) for the entity referenced by the given cursor.
A Unified Symbol Resolution (USR) is a string that identifies a particular entity (function, class, variable, etc.) within a program. USRs can be compared across translation units to determine, e.g., when references in one translation refer to an entity defined in another translation unit.
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.
A value of this enumeration type should be returned by each \c CXCursorVisitor to indicate how clang_visitChildren() proceed.
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 ¶
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 ¶
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
Retrieve the diagnostic category text for a given diagnostic.
func (Diagnostic) Format ¶
func (e Diagnostic) Format(options clang.DiagnosticDisplayOptions) string
Format the given diagnostic in a manner that is suitable for display.
func (Diagnostic) String ¶
func (e Diagnostic) String() string
Retrieve the text of the given diagnostic.
type Index ¶
An "index" that consists of a set of translation units that would typically be linked together into an executable or library.
func CreateIndex ¶
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 RawComments ¶ added in v0.12.0
type RawComments struct {
// A preceding comment counts as the declaration's leading doc only when it sits
// on the line(s) directly above the declaration with no blank line in between;
// a blank line detaches it. The string keeps the original comment markers so it
// can be fed to the same comment-normalizing logic as RawComment. It can be ""
// when there is no such comment.
Preceding string `json:"preceding,omitempty"`
// A trailing comment is considered part of the declaration's documentation
// only when it appears on the line immediately below the declaration with no
// blank line in between.
Trailing string `json:"trailing,omitempty"`
// An inline comment is considered part of the declaration's documentation
// only when it appears on the same line as the declaration.
Inline string `json:"inline,omitempty"`
}
RawComments represents the raw documentation comments associated with a declaration, including preceding, trailing, and inline comments.
func RawCommentsOf ¶ added in v0.12.0
func RawCommentsOf(entity clang.Cursor) (ret RawComments)
RawCommentsOf returns the raw documentation comments associated with the given cursor, including the preceding, trailing, and inline comments. Each comment retains its original markers (e.g., "/** ... */" or "///"). If a particular type of comment is not present, the corresponding field in the returned RawComments struct will be an empty string.
func (*RawComments) Text ¶ added in v0.12.0
func (raw *RawComments) Text() string
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)
Returns the translation unit that a cursor originated from.
func (TranslationUnit) Diagnostic ¶
func (u TranslationUnit) Diagnostic(index c.Uint) (ret Diagnostic)
Retrieve a diagnostic associated with the given 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.