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

Safe HaskellNone
LanguageHaskell2010

Clang

Contents

Description

LibClang is a Haskell binding to the libclang library, a compiler front-end for C-family languages. It allows you to produce and walk an AST, get a list of diagnostic warnings and errors, perform code completion, and more.

Your starting point for using LibClang should be this module, which exports the ClangT monad and the functions you'll need to start analyzing source code. The other modules in this library, such as Clang.Cursor and Clang.Type, are meant to be imported qualified, and provide the functions you'll need to get more detailed information about the AST.

Synopsis

Parsing

parseSourceFile Source

Arguments

:: ClangBase m 
=> FilePath

Source filename

-> [String]

Clang-compatible compilation arguments

-> (forall s. TranslationUnit s -> ClangT s m a)

Callback

-> m (Maybe a) 

Parses a source file using libclang and allows you to analyze the resulting AST using a callback.

More flexible alternatives to parseSourceFile are available in Clang.Index and Clang.TranslationUnit.

Traversing the AST

type CursorList s = Vector (Cursor s) Source

getChildren :: ClangBase m => Cursor s' -> ClangT s m (CursorList s) Source

Gets an CursorList of the children of this Cursor.

getDescendants :: ClangBase m => Cursor s' -> ClangT s m (CursorList s) Source

Gets an CursorList of all descendants of this Cursor. If you are planning on visiting all the descendants anyway, this is often more efficient than calling getChildren repeatedly. The descendants are listed according to a preorder traversal of the AST.

getDeclarations :: ClangBase m => TranslationUnit s' -> ClangT s m (CursorList s) Source

Gets an CursorList of all declarations in this TranslationUnit.

getReferences :: ClangBase m => TranslationUnit s' -> ClangT s m (CursorList s) Source

Gets an CursorList of all references in this TranslationUnit.

getDeclarationsAndReferences :: ClangBase m => TranslationUnit s' -> ClangT s m (CursorList s, CursorList s) Source

Gets two CursorLists, one containing all declarations in this TranslationUnit, and another containing all references. If you need both lists, this is more efficient than calling getDeclarations and getReferences individually, as it only traverses the AST once.

getParentedDescendants :: ClangBase m => Cursor s' -> ClangT s m (ParentedCursorList s) Source

Like getDescendants, but each descendant is annotated with its parent AST node. This provides enough information to replicate the preorder traversal of the AST, but maintains the performance benefits relative to getChildren.

getParentedDeclarations :: ClangBase m => TranslationUnit s' -> ClangT s m (ParentedCursorList s) Source

Like getDeclarations, but each declaration is annotated with its parent AST node.

getParentedReferences :: ClangBase m => TranslationUnit s' -> ClangT s m (ParentedCursorList s) Source

Like getReferences, but each reference is annotated with its parent AST node.

getParentedDeclarationsAndReferences :: ClangBase m => TranslationUnit s' -> ClangT s m (ParentedCursorList s, ParentedCursorList s) Source

Like getDeclarationsAndReferences, but each reference is annotated with its parent AST node.

Traversing inclusions

type InclusionList s = Vector (Inclusion s) Source

getInclusions :: ClangBase m => TranslationUnit s' -> ClangT s m (InclusionList s) Source

Gets all inclusions in this TranslationUnit.

The ClangT monad

data ClangT s m a Source

Instances

MonadBase b m => MonadBase b (ClangT s m) Source 
MonadTrans (ClangT s) Source 
Monad m => Monad (ClangT s m) Source 
Functor m => Functor (ClangT s m) Source 
Applicative m => Applicative (ClangT s m) Source 
MonadIO m => MonadIO (ClangT s m) Source 
ClangBase m => MonadResource (ClangT s m) Source 
MonadThrow m => MonadThrow (ClangT s m) Source 

type Clang s a = ClangT s IO a Source

Clang is a specialization of the ClangT monad to IO, provided as a convenience. If you have a more complicated monad stack, you may find it useful to define your own Clang-like type synonym.

type ClangBase m = MonadResourceBase m Source

class ClangValue v where Source

Minimal complete definition

Nothing

Methods

fromOuterScope :: ClangBase m => v s' -> ClangT s m (v s) Source

Promotes a value from an outer scope to the current inner scope. The value's lifetime remains that of the outer scope. This is never necessary, but it may allow you to write code more naturally in some situations, since it can occasionally be inconvenient that variables from different scopes are different types.

class ClangValueList v where Source

Minimal complete definition

Nothing

Methods

listFromOuterScope :: ClangBase m => Vector (v s') -> ClangT s m (Vector (v s)) Source

Promotes a list from an outer scope to the current inner scope. The list's lifetime remains that of the outer scope. This is never necessary, but it may allow you to write code more naturally in some situations, since it can occasionally be inconvenient that variables from different scopes are different types.

clangScope :: ClangBase m => (forall s. ClangT s m a) -> ClangT s' m a Source

Runs a monadic computation with libclang and frees all the resources allocated by that computation immediately.

Clang AST types

data CursorKind Source

Constructors

UnexposedDeclCursor 
StructDeclCursor 
UnionDeclCursor 
ClassDeclCursor 
EnumDeclCursor 
FieldDeclCursor 
EnumConstantDeclCursor 
FunctionDeclCursor 
VarDeclCursor 
ParmDeclCursor 
ObjCInterfaceDeclCursor 
ObjCCategoryDeclCursor 
ObjCProtocolDeclCursor 
ObjCPropertyDeclCursor 
ObjCIvarDeclCursor 
ObjCInstanceMethodDeclCursor 
ObjCClassMethodDeclCursor 
ObjCImplementationDeclCursor 
ObjCCategoryImplDeclCursor 
TypedefDeclCursor 
CXXMethodCursor 
NamespaceCursor 
LinkageSpecCursor 
ConstructorCursor 
DestructorCursor 
ConversionFunctionCursor 
TemplateTypeParameterCursor 
NonTypeTemplateParameterCursor 
TemplateTemplateParameterCursor 
FunctionTemplateCursor 
ClassTemplateCursor 
ClassTemplatePartialSpecializationCursor 
NamespaceAliasCursor 
UsingDirectiveCursor 
UsingDeclarationCursor 
TypeAliasDeclCursor 
ObjCSynthesizeDeclCursor 
ObjCDynamicDeclCursor 
CXXAccessSpecifierCursor 
ObjCSuperClassRefCursor 
ObjCProtocolRefCursor 
ObjCClassRefCursor 
TypeRefCursor 
CXXBaseSpecifierCursor 
TemplateRefCursor 
NamespaceRefCursor 
MemberRefCursor 
LabelRefCursor 
OverloadedDeclRefCursor 
VariableRefCursor 
InvalidFileCursor 
NoDeclFoundCursor 
NotImplementedCursor 
InvalidCodeCursor 
UnexposedExprCursor 
DeclRefExprCursor 
MemberRefExprCursor 
CallExprCursor 
ObjCMessageExprCursor 
BlockExprCursor 
IntegerLiteralCursor 
FloatingLiteralCursor 
ImaginaryLiteralCursor 
StringLiteralCursor 
CharacterLiteralCursor 
ParenExprCursor 
UnaryOperatorCursor 
ArraySubscriptExprCursor 
BinaryOperatorCursor 
CompoundAssignOperatorCursor 
ConditionalOperatorCursor 
CStyleCastExprCursor 
CompoundLiteralExprCursor 
InitListExprCursor 
AddrLabelExprCursor 
StmtExprCursor 
GenericSelectionExprCursor 
GNUNullExprCursor 
CXXStaticCastExprCursor 
CXXDynamicCastExprCursor 
CXXReinterpretCastExprCursor 
CXXConstCastExprCursor 
CXXFunctionalCastExprCursor 
CXXTypeidExprCursor 
CXXBoolLiteralExprCursor 
CXXNullPtrLiteralExprCursor 
CXXThisExprCursor 
CXXThrowExprCursor 
CXXNewExprCursor 
CXXDeleteExprCursor 
UnaryExprCursor 
ObjCStringLiteralCursor 
ObjCEncodeExprCursor 
ObjCSelectorExprCursor 
ObjCProtocolExprCursor 
ObjCBridgedCastExprCursor 
PackExpansionExprCursor 
SizeOfPackExprCursor 
LambdaExprCursor 
ObjCBoolLiteralExprCursor 
ObjCSelfExprCursor 
UnexposedStmtCursor 
LabelStmtCursor 
CompoundStmtCursor 
CaseStmtCursor 
DefaultStmtCursor 
IfStmtCursor 
SwitchStmtCursor 
WhileStmtCursor 
DoStmtCursor 
ForStmtCursor 
GotoStmtCursor 
IndirectGotoStmtCursor 
ContinueStmtCursor 
BreakStmtCursor 
ReturnStmtCursor 
AsmStmtCursor 
ObjCAtTryStmtCursor 
ObjCAtCatchStmtCursor 
ObjCAtFinallyStmtCursor 
ObjCAtThrowStmtCursor 
ObjCAtSynchronizedStmtCursor 
ObjCAutoreleasePoolStmtCursor 
ObjCForCollectionStmtCursor 
CXXCatchStmtCursor 
CXXTryStmtCursor 
CXXForRangeStmtCursor 
SEHTryStmtCursor 
SEHExceptStmtCursor 
SEHFinallyStmtCursor 
MSAsmStmtCursor 
NullStmtCursor 
DeclStmtCursor 
OMPParallelDirectiveCursor 
TranslationUnitCursor 
UnexposedAttrCursor 
IBActionAttrCursor 
IBOutletAttrCursor 
IBOutletCollectionAttrCursor 
CXXFinalAttrCursor 
CXXOverrideAttrCursor 
AnnotateAttrCursor 
AsmLabelAttrCursor 
PackedAttrCursor 
PreprocessingDirectiveCursor 
MacroDefinitionCursor 
MacroExpansionCursor 
InclusionDirectiveCursor 
ModuleImportDeclCursor 

data File s Source

Instances

data UnsavedFile Source

A representation of an unsaved file and its contents.

newtype Module s Source

Constructors

Module 

Fields

unModule :: Ptr ()