blob: 91998037fdd3e72503c6f5628d2e9c729f9d4bb0 [file] [log] [blame]
Ted Kremenek1ca68fb2009-08-26 22:36:44 +00001/*===-- clang-c/Index.h - Indexing Public C Interface -------------*- C -*-===*\
2|* *|
3|* The LLVM Compiler Infrastructure *|
4|* *|
5|* This file is distributed under the University of Illinois Open Source *|
6|* License. See LICENSE.TXT for details. *|
7|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* This header provides a public inferface to a Clang library for extracting *|
11|* high-level symbol information from source files without exposing the full *|
12|* Clang C++ API. *|
13|* *|
14\*===----------------------------------------------------------------------===*/
15
16#ifndef CLANG_C_INDEX_H
17#define CLANG_C_INDEX_H
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
Steve Naroffa6fc61b2009-08-27 19:51:58 +000023/*
24 Clang indeX abstractions. The backing store for the following API's will be
Steve Naroff291065d2009-09-01 17:13:31 +000025 clangs AST file (currently based on PCH). AST files are created as follows:
Steve Naroffa6fc61b2009-08-27 19:51:58 +000026
Steve Naroff291065d2009-09-01 17:13:31 +000027 "clang -emit-ast <sourcefile.langsuffix> -o <sourcefile.ast>".
Steve Naroffa6fc61b2009-08-27 19:51:58 +000028
Steve Naroffa6fc61b2009-08-27 19:51:58 +000029 Naming Conventions: To avoid namespace pollution, data types are prefixed
30 with "CX" and functions are prefixed with "clang_".
31*/
Steve Naroff3ba83e92009-08-28 15:28:48 +000032typedef void *CXIndex; /* An indexing instance. */
Steve Naroffa6fc61b2009-08-27 19:51:58 +000033
Steve Naroff3ba83e92009-08-28 15:28:48 +000034typedef void *CXTranslationUnit; /* A translation unit instance. */
Steve Naroffa6fc61b2009-08-27 19:51:58 +000035
Steve Naroff3ba83e92009-08-28 15:28:48 +000036typedef void *CXDecl; /* A specific declaration within a translation unit. */
Steve Naroffa6fc61b2009-08-27 19:51:58 +000037
Steve Naroffc674c2d2009-08-31 00:59:03 +000038/* Cursors represent declarations and references (provides line/column info). */
39enum CXCursorKind {
40 CXCursor_Invalid = 0,
41
42 /* Declarations */
43 CXCursor_FirstDecl = 1,
44 CXCursor_TypedefDecl = 1,
45 CXCursor_EnumDecl = 2,
46 CXCursor_EnumConstantDecl = 3,
47 CXCursor_RecordDecl = 4, /* struct/union/class */
48 CXCursor_FieldDecl = 5,
49 CXCursor_FunctionDecl = 6,
50 CXCursor_VarDecl = 7,
51 CXCursor_ParmDecl = 8,
52 CXCursor_ObjCInterfaceDecl = 9,
53 CXCursor_ObjCCategoryDecl = 10,
54 CXCursor_ObjCProtocolDecl = 11,
55 CXCursor_ObjCPropertyDecl = 12,
56 CXCursor_ObjCIvarDecl = 13,
57 CXCursor_ObjCMethodDecl = 14,
58 CXCursor_LastDecl = 14,
59
60 /* References */
61 CXCursor_FirstRef = 19,
62 CXCursor_ObjCClassRef = 19,
63 CXCursor_ObjCProtocolRef = 20,
64 CXCursor_ObjCMessageRef = 21,
65 CXCursor_ObjCSelectorRef = 22,
66 CXCursor_LastRef = 23
Steve Naroffa6fc61b2009-08-27 19:51:58 +000067};
68
Steve Naroffc674c2d2009-08-31 00:59:03 +000069/* A cursor into the CXTranslationUnit. */
70typedef struct {
71 enum CXCursorKind kind;
72 CXDecl decl;
73
74 /* FIXME: Handle references. */
75} CXCursor;
76
Steve Naroff3ba83e92009-08-28 15:28:48 +000077/* A unique token for looking up "visible" CXDecls from a CXTranslationUnit. */
Steve Naroffa6fc61b2009-08-27 19:51:58 +000078typedef void *CXEntity;
79
80CXIndex clang_createIndex();
81
Steve Naroff3ba83e92009-08-28 15:28:48 +000082CXTranslationUnit clang_createTranslationUnit(
Steve Naroffa6fc61b2009-08-27 19:51:58 +000083 CXIndex, const char *ast_filename
84);
85
86/*
87 Usage: clang_loadTranslationUnit(). Will load the toplevel declarations
88 within a translation unit, issuing a 'callback' for each one.
89
90 void printObjCInterfaceNames(CXTranslationUnit X, CXCursor C) {
91 if (clang_getCursorKind(C) == Cursor_Declaration) {
92 CXDecl D = clang_getCursorDecl(C);
93 if (clang_getDeclKind(D) == CXDecl_ObjC_interface)
94 printf("@interface %s in file %s on line %d column %d\n",
95 clang_getDeclSpelling(D), clang_getCursorSource(C),
96 clang_getCursorLine(C), clang_getCursorColumn(C));
97 }
98 }
99 static void usage {
100 clang_loadTranslationUnit(CXTranslationUnit, printObjCInterfaceNames);
101 }
102*/
Steve Naroffb836cb72009-09-01 15:55:40 +0000103typedef void *CXClientData;
104typedef void (*CXTranslationUnitIterator)(CXTranslationUnit, CXCursor,
105 CXClientData);
106void clang_loadTranslationUnit(CXTranslationUnit, CXTranslationUnitIterator,
107 CXClientData);
Steve Naroffa6fc61b2009-08-27 19:51:58 +0000108
109/*
110 Usage: clang_loadDeclaration(). Will load the declaration, issuing a
111 'callback' for each declaration/reference within the respective declaration.
112
113 For interface declarations, this will index the super class, protocols,
114 ivars, methods, etc. For structure declarations, this will index the fields.
115 For functions, this will index the parameters (and body, for function
116 definitions), local declarations/references.
117
118 void getInterfaceDetails(CXDecl X, CXCursor C) {
119 switch (clang_getCursorKind(C)) {
120 case Cursor_ObjC_ClassRef:
121 CXDecl SuperClass = clang_getCursorDecl(C);
122 case Cursor_ObjC_ProtocolRef:
123 CXDecl AdoptsProtocol = clang_getCursorDecl(C);
124 case Cursor_Declaration:
125 CXDecl AnIvarOrMethod = clang_getCursorDecl(C);
126 }
127 }
128 static void usage() {
129 if (clang_getDeclKind(D) == CXDecl_ObjC_interface) {
130 clang_loadDeclaration(D, getInterfaceDetails);
131 }
132 }
133*/
Steve Naroffc674c2d2009-08-31 00:59:03 +0000134typedef void (*CXDeclIterator)(CXTranslationUnit, CXDecl, void *clientData);
135
136void clang_loadDeclaration(CXDecl, CXDeclIterator);
Steve Naroffa6fc61b2009-08-27 19:51:58 +0000137
Steve Naroff3ba83e92009-08-28 15:28:48 +0000138/*
139 * CXEntity Operations.
140 */
Steve Naroffa6fc61b2009-08-27 19:51:58 +0000141const char *clang_getDeclarationName(CXEntity);
142const char *clang_getURI(CXEntity);
143CXEntity clang_getEntity(const char *URI);
Steve Naroff3ba83e92009-08-28 15:28:48 +0000144/*
145 * CXDecl Operations.
146 */
Steve Naroffa6fc61b2009-08-27 19:51:58 +0000147CXCursor clang_getCursorFromDecl(CXDecl);
148CXEntity clang_getEntityFromDecl(CXDecl);
Steve Naroffa6fc61b2009-08-27 19:51:58 +0000149const char *clang_getDeclSpelling(CXDecl);
Steve Naroff3ba83e92009-08-28 15:28:48 +0000150/*
151 * CXCursor Operations.
152 */
Steve Naroffa6fc61b2009-08-27 19:51:58 +0000153CXCursor clang_getCursor(CXTranslationUnit, const char *source_name,
154 unsigned line, unsigned column);
155
Steve Naroff3ba83e92009-08-28 15:28:48 +0000156enum CXCursorKind clang_getCursorKind(CXCursor);
Steve Naroffc674c2d2009-08-31 00:59:03 +0000157unsigned clang_isDeclaration(enum CXCursorKind);
Steve Naroffa6fc61b2009-08-27 19:51:58 +0000158
159unsigned clang_getCursorLine(CXCursor);
160unsigned clang_getCursorColumn(CXCursor);
161const char *clang_getCursorSource(CXCursor);
Steve Naroffc674c2d2009-08-31 00:59:03 +0000162const char *clang_getKindSpelling(enum CXCursorKind Kind);
Steve Naroffa6fc61b2009-08-27 19:51:58 +0000163
Steve Naroff3ba83e92009-08-28 15:28:48 +0000164/*
165 * If CXCursorKind == Cursor_Reference, then this will return the referenced declaration.
166 * If CXCursorKind == Cursor_Declaration, then this will return the declaration.
167 */
Steve Naroffa6fc61b2009-08-27 19:51:58 +0000168CXDecl clang_getCursorDecl(CXCursor);
Ted Kremenek1ca68fb2009-08-26 22:36:44 +0000169
170#ifdef __cplusplus
171}
172#endif
173#endif
174