2009-08-27 06:36:44 +08:00
|
|
|
/*===-- clang-c/Index.h - Indexing Public C Interface -------------*- C -*-===*\
|
|
|
|
|* *|
|
|
|
|
|* The LLVM Compiler Infrastructure *|
|
|
|
|
|* *|
|
|
|
|
|* This file is distributed under the University of Illinois Open Source *|
|
|
|
|
|* License. See LICENSE.TXT for details. *|
|
|
|
|
|* *|
|
|
|
|
|*===----------------------------------------------------------------------===*|
|
|
|
|
|* *|
|
|
|
|
|* This header provides a public inferface to a Clang library for extracting *|
|
|
|
|
|* high-level symbol information from source files without exposing the full *|
|
|
|
|
|* Clang C++ API. *|
|
|
|
|
|* *|
|
|
|
|
\*===----------------------------------------------------------------------===*/
|
|
|
|
|
|
|
|
#ifndef CLANG_C_INDEX_H
|
|
|
|
#define CLANG_C_INDEX_H
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2009-08-28 03:51:58 +08:00
|
|
|
/*
|
|
|
|
Clang indeX abstractions. The backing store for the following API's will be
|
|
|
|
clangs PCH file (which contains AST's, or Abstract Syntax Trees). PCH files
|
|
|
|
are created by the following command:
|
|
|
|
|
2009-08-31 22:26:51 +08:00
|
|
|
"clang -S -Xclang -emit-pch <sourcefile.langsuffix> -o <sourcefile.ast>".
|
2009-08-28 03:51:58 +08:00
|
|
|
|
|
|
|
If the ast file format ends up diverging from the pch file format, we will
|
|
|
|
need to add a new switch (-emit-ast). For now, the contents are identical.
|
|
|
|
|
|
|
|
Naming Conventions: To avoid namespace pollution, data types are prefixed
|
|
|
|
with "CX" and functions are prefixed with "clang_".
|
|
|
|
*/
|
2009-08-28 23:28:48 +08:00
|
|
|
typedef void *CXIndex; /* An indexing instance. */
|
2009-08-28 03:51:58 +08:00
|
|
|
|
2009-08-28 23:28:48 +08:00
|
|
|
typedef void *CXTranslationUnit; /* A translation unit instance. */
|
2009-08-28 03:51:58 +08:00
|
|
|
|
2009-08-31 08:59:03 +08:00
|
|
|
typedef void *CXDecl; /* A specific declaration within a translation unit. */
|
2009-08-28 03:51:58 +08:00
|
|
|
|
2009-08-28 23:28:48 +08:00
|
|
|
/* Cursors represent declarations and references (provides line/column info). */
|
2009-08-31 08:59:03 +08:00
|
|
|
enum CXCursorKind {
|
|
|
|
CXCursor_Invalid = 0,
|
|
|
|
|
|
|
|
/* Declarations */
|
|
|
|
CXCursor_FirstDecl = 1,
|
|
|
|
CXCursor_TypedefDecl = 1,
|
|
|
|
CXCursor_EnumDecl = 2,
|
|
|
|
CXCursor_EnumConstantDecl = 3,
|
|
|
|
CXCursor_RecordDecl = 4, /* struct/union/class */
|
|
|
|
CXCursor_FieldDecl = 5,
|
|
|
|
CXCursor_FunctionDecl = 6,
|
|
|
|
CXCursor_VarDecl = 7,
|
|
|
|
CXCursor_ParmDecl = 8,
|
|
|
|
CXCursor_ObjCInterfaceDecl = 9,
|
|
|
|
CXCursor_ObjCCategoryDecl = 10,
|
|
|
|
CXCursor_ObjCProtocolDecl = 11,
|
|
|
|
CXCursor_ObjCPropertyDecl = 12,
|
|
|
|
CXCursor_ObjCIvarDecl = 13,
|
|
|
|
CXCursor_ObjCMethodDecl = 14,
|
|
|
|
CXCursor_LastDecl = 14,
|
|
|
|
|
|
|
|
/* References */
|
|
|
|
CXCursor_FirstRef = 19,
|
|
|
|
CXCursor_ObjCClassRef = 19,
|
|
|
|
CXCursor_ObjCProtocolRef = 20,
|
|
|
|
CXCursor_ObjCMessageRef = 21,
|
|
|
|
CXCursor_ObjCSelectorRef = 22,
|
|
|
|
CXCursor_LastRef = 23
|
2009-08-28 03:51:58 +08:00
|
|
|
};
|
|
|
|
|
2009-08-31 08:59:03 +08:00
|
|
|
/* A cursor into the CXTranslationUnit. */
|
|
|
|
typedef struct {
|
|
|
|
enum CXCursorKind kind;
|
|
|
|
CXDecl decl;
|
|
|
|
|
|
|
|
/* FIXME: Handle references. */
|
|
|
|
} CXCursor;
|
2009-08-28 03:51:58 +08:00
|
|
|
|
2009-08-28 23:28:48 +08:00
|
|
|
/* A unique token for looking up "visible" CXDecls from a CXTranslationUnit. */
|
2009-08-28 03:51:58 +08:00
|
|
|
typedef void *CXEntity;
|
|
|
|
|
|
|
|
CXIndex clang_createIndex();
|
|
|
|
|
2009-08-28 23:28:48 +08:00
|
|
|
CXTranslationUnit clang_createTranslationUnit(
|
2009-08-28 03:51:58 +08:00
|
|
|
CXIndex, const char *ast_filename
|
|
|
|
);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Usage: clang_loadTranslationUnit(). Will load the toplevel declarations
|
|
|
|
within a translation unit, issuing a 'callback' for each one.
|
|
|
|
|
|
|
|
void printObjCInterfaceNames(CXTranslationUnit X, CXCursor C) {
|
|
|
|
if (clang_getCursorKind(C) == Cursor_Declaration) {
|
|
|
|
CXDecl D = clang_getCursorDecl(C);
|
|
|
|
if (clang_getDeclKind(D) == CXDecl_ObjC_interface)
|
|
|
|
printf("@interface %s in file %s on line %d column %d\n",
|
|
|
|
clang_getDeclSpelling(D), clang_getCursorSource(C),
|
|
|
|
clang_getCursorLine(C), clang_getCursorColumn(C));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static void usage {
|
|
|
|
clang_loadTranslationUnit(CXTranslationUnit, printObjCInterfaceNames);
|
|
|
|
}
|
|
|
|
*/
|
2009-08-31 08:59:03 +08:00
|
|
|
typedef void (*CXTranslationUnitIterator)(CXTranslationUnit, CXCursor);
|
|
|
|
void clang_loadTranslationUnit(CXTranslationUnit, CXTranslationUnitIterator);
|
2009-08-28 03:51:58 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
Usage: clang_loadDeclaration(). Will load the declaration, issuing a
|
|
|
|
'callback' for each declaration/reference within the respective declaration.
|
|
|
|
|
|
|
|
For interface declarations, this will index the super class, protocols,
|
|
|
|
ivars, methods, etc. For structure declarations, this will index the fields.
|
|
|
|
For functions, this will index the parameters (and body, for function
|
|
|
|
definitions), local declarations/references.
|
|
|
|
|
|
|
|
void getInterfaceDetails(CXDecl X, CXCursor C) {
|
|
|
|
switch (clang_getCursorKind(C)) {
|
|
|
|
case Cursor_ObjC_ClassRef:
|
|
|
|
CXDecl SuperClass = clang_getCursorDecl(C);
|
|
|
|
case Cursor_ObjC_ProtocolRef:
|
|
|
|
CXDecl AdoptsProtocol = clang_getCursorDecl(C);
|
|
|
|
case Cursor_Declaration:
|
|
|
|
CXDecl AnIvarOrMethod = clang_getCursorDecl(C);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static void usage() {
|
|
|
|
if (clang_getDeclKind(D) == CXDecl_ObjC_interface) {
|
|
|
|
clang_loadDeclaration(D, getInterfaceDetails);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
2009-08-31 08:59:03 +08:00
|
|
|
typedef void (*CXDeclIterator)(CXTranslationUnit, CXDecl, void *clientData);
|
|
|
|
|
|
|
|
void clang_loadDeclaration(CXDecl, CXDeclIterator);
|
2009-08-28 03:51:58 +08:00
|
|
|
|
2009-08-28 23:28:48 +08:00
|
|
|
/*
|
|
|
|
* CXEntity Operations.
|
|
|
|
*/
|
2009-08-28 03:51:58 +08:00
|
|
|
const char *clang_getDeclarationName(CXEntity);
|
|
|
|
const char *clang_getURI(CXEntity);
|
|
|
|
CXEntity clang_getEntity(const char *URI);
|
2009-08-28 23:28:48 +08:00
|
|
|
/*
|
|
|
|
* CXDecl Operations.
|
|
|
|
*/
|
2009-08-28 03:51:58 +08:00
|
|
|
CXCursor clang_getCursorFromDecl(CXDecl);
|
|
|
|
CXEntity clang_getEntityFromDecl(CXDecl);
|
|
|
|
const char *clang_getDeclSpelling(CXDecl);
|
2009-08-28 23:28:48 +08:00
|
|
|
/*
|
|
|
|
* CXCursor Operations.
|
|
|
|
*/
|
2009-08-28 03:51:58 +08:00
|
|
|
CXCursor clang_getCursor(CXTranslationUnit, const char *source_name,
|
|
|
|
unsigned line, unsigned column);
|
|
|
|
|
2009-08-28 23:28:48 +08:00
|
|
|
enum CXCursorKind clang_getCursorKind(CXCursor);
|
2009-08-31 08:59:03 +08:00
|
|
|
unsigned clang_isDeclaration(enum CXCursorKind);
|
2009-08-28 03:51:58 +08:00
|
|
|
|
|
|
|
unsigned clang_getCursorLine(CXCursor);
|
|
|
|
unsigned clang_getCursorColumn(CXCursor);
|
|
|
|
const char *clang_getCursorSource(CXCursor);
|
2009-08-31 08:59:03 +08:00
|
|
|
const char *clang_getKindSpelling(enum CXCursorKind Kind);
|
2009-08-28 03:51:58 +08:00
|
|
|
|
2009-08-28 23:28:48 +08:00
|
|
|
/*
|
|
|
|
* If CXCursorKind == Cursor_Reference, then this will return the referenced declaration.
|
|
|
|
* If CXCursorKind == Cursor_Declaration, then this will return the declaration.
|
|
|
|
*/
|
2009-08-28 03:51:58 +08:00
|
|
|
CXDecl clang_getCursorDecl(CXCursor);
|
2009-08-27 06:36:44 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|