LibClang-3.4.0: Haskell bindings for libclang (a C++ parsing library)

Safe HaskellNone
LanguageHaskell2010

Clang.Location

Contents

Description

Functions for manipulating SourceLocations, which map a location in a translation unit to a location in on-disk or in-memory files.

This module is intended to be imported qualified.

Synopsis

Creating locations

create Source

Arguments

:: ClangBase m 
=> TranslationUnit s'

The translation unit.

-> File s''

The file.

-> Int

The line.

-> Int

The column.

-> ClangT s m (SourceLocation s)

A SourceLocation value representing the location.

Retrieves a SourceLocation representing the given location in the source code.

createForOffset Source

Arguments

:: ClangBase m 
=> TranslationUnit s'

The translation unit.

-> File s''

The file.

-> Int

The offset.

-> ClangT s m (SourceLocation s)

A SourceLocation value representing the location.

Like create, but uses an offset instead of a line and column.

Mapping locations to files

getExpansionLocation :: ClangBase m => SourceLocation s' -> ClangT s m (Maybe (File s), Int, Int, Int) Source

Retrieves the File, line, column, and offset associated with the given location.

If the location points into a macro expansion, retrieves the location of the macro expansion. This may be a position that doesn't exist in the original source.

getPresumedLocation :: ClangBase m => SourceLocation s' -> ClangT s m (ClangString s, Int, Int) Source

Retrieves the File, line, and column associated with the given location, as interpreted by the C preprocessor.

This may differ from the results given by getExpansionLocation because it takes '#line' directives into account, which getExpansionLocation ignores.

getSpellingLocation :: ClangBase m => SourceLocation s' -> ClangT s m (Maybe (File s), Int, Int, Int) Source

Retrieves the File, line, column, and offset associated with the given location.

If the location points into a macro expansion, returns the corresponding position in the original source. This may be where the macro was defined or where it was instantiated, depending on what exactly the location points to.

getFileLocation :: ClangBase m => SourceLocation s' -> ClangT s m (Maybe (File s), Int, Int, Int) Source

Retrieves the File, line, column, and offset associated with the given location.

If the location points into a macro expansion, returns the position where the macro was expanded or the position of the macro argument, if the cursor points at a macro argument.

Analyzing locations

getCursor :: ClangBase m => TranslationUnit s' -> SourceLocation s'' -> ClangT s m (Cursor s) Source

Retrieves an AST cursor at the given source location.

The cursor can be traversed using the functions in Clang.Cursor.

isInSystemHeader :: SourceLocation s' -> Bool Source

Returns True if the given location is inside a system header.

isFromMainFile :: SourceLocation s' -> Bool Source

Returns True if the given location is from the main file of the associated translation unit.