blob: b96cb6cb143129bbbf34aabd48001310d0bb6c29 [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
25 clangs PCH file (which contains AST's, or Abstract Syntax Trees). PCH files
26 are created by the following command:
27
28 "clang -emit-pch <sourcefile.langsuffix> -o <sourcefile.ast>".
29
30 If the ast file format ends up diverging from the pch file format, we will
31 need to add a new switch (-emit-ast). For now, the contents are identical.
32
33 Naming Conventions: To avoid namespace pollution, data types are prefixed
34 with "CX" and functions are prefixed with "clang_".
35*/
Steve Naroff3ba83e92009-08-28 15:28:48 +000036typedef void *CXIndex; /* An indexing instance. */
Steve Naroffa6fc61b2009-08-27 19:51:58 +000037
Steve Naroff3ba83e92009-08-28 15:28:48 +000038typedef void *CXTranslationUnit; /* A translation unit instance. */
Steve Naroffa6fc61b2009-08-27 19:51:58 +000039
Steve Naroff3ba83e92009-08-28 15:28:48 +000040typedef void *CXCursor; /* An opaque cursor into the CXTranslationUnit. */
Steve Naroffa6fc61b2009-08-27 19:51:58 +000041
Steve Naroff3ba83e92009-08-28 15:28:48 +000042/* Cursors represent declarations and references (provides line/column info). */
Steve Naroffa6fc61b2009-08-27 19:51:58 +000043enum CXCursorKind {
Steve Naroff00eb51c2009-08-28 12:07:44 +000044 CXCursor_Declaration,
45 CXCursor_Reference,
46 CXCursor_ObjC_ClassRef,
47 CXCursor_ObjC_ProtocolRef,
48 CXCursor_ObjC_MessageRef,
49 CXCursor_ObjC_SelectorRef
Steve Naroffa6fc61b2009-08-27 19:51:58 +000050};
51
Steve Naroff3ba83e92009-08-28 15:28:48 +000052typedef void *CXDecl; /* A specific declaration within a translation unit. */
Steve Naroffa6fc61b2009-08-27 19:51:58 +000053
Steve Naroff3ba83e92009-08-28 15:28:48 +000054enum CXDeclKind { /* The various kinds of declarations. */
Steve Naroffa6fc61b2009-08-27 19:51:58 +000055 CXDecl_any,
56 CXDecl_typedef,
57 CXDecl_enum,
58 CXDecl_enum_constant,
59 CXDecl_record,
60 CXDecl_field,
61 CXDecl_function,
62 CXDecl_variable,
63 CXDecl_parameter,
64 CXDecl_ObjC_interface,
65 CXDecl_ObjC_category,
66 CXDecl_ObjC_protocol,
67 CXDecl_ObjC_property,
68 CXDecl_ObjC_instance_variable,
69 CXDecl_ObjC_instance_method,
70 CXDecl_ObjC_class_method,
71 CXDecl_ObjC_category_implementation,
72 CXDecl_ObjC_class_implementation,
73 CXDecl_ObjC_property_implementation
74};
75
Steve Naroff3ba83e92009-08-28 15:28:48 +000076/* A unique token for looking up "visible" CXDecls from a CXTranslationUnit. */
Steve Naroffa6fc61b2009-08-27 19:51:58 +000077typedef void *CXEntity;
78
79CXIndex clang_createIndex();
80
Steve Naroff3ba83e92009-08-28 15:28:48 +000081CXTranslationUnit clang_createTranslationUnit(
Steve Naroffa6fc61b2009-08-27 19:51:58 +000082 CXIndex, const char *ast_filename
83);
84
85/*
86 Usage: clang_loadTranslationUnit(). Will load the toplevel declarations
87 within a translation unit, issuing a 'callback' for each one.
88
89 void printObjCInterfaceNames(CXTranslationUnit X, CXCursor C) {
90 if (clang_getCursorKind(C) == Cursor_Declaration) {
91 CXDecl D = clang_getCursorDecl(C);
92 if (clang_getDeclKind(D) == CXDecl_ObjC_interface)
93 printf("@interface %s in file %s on line %d column %d\n",
94 clang_getDeclSpelling(D), clang_getCursorSource(C),
95 clang_getCursorLine(C), clang_getCursorColumn(C));
96 }
97 }
98 static void usage {
99 clang_loadTranslationUnit(CXTranslationUnit, printObjCInterfaceNames);
100 }
101*/
102void clang_loadTranslationUnit(
103 CXTranslationUnit, void (*callback)(CXTranslationUnit, CXCursor)
104);
105
106/*
107 Usage: clang_loadDeclaration(). Will load the declaration, issuing a
108 'callback' for each declaration/reference within the respective declaration.
109
110 For interface declarations, this will index the super class, protocols,
111 ivars, methods, etc. For structure declarations, this will index the fields.
112 For functions, this will index the parameters (and body, for function
113 definitions), local declarations/references.
114
115 void getInterfaceDetails(CXDecl X, CXCursor C) {
116 switch (clang_getCursorKind(C)) {
117 case Cursor_ObjC_ClassRef:
118 CXDecl SuperClass = clang_getCursorDecl(C);
119 case Cursor_ObjC_ProtocolRef:
120 CXDecl AdoptsProtocol = clang_getCursorDecl(C);
121 case Cursor_Declaration:
122 CXDecl AnIvarOrMethod = clang_getCursorDecl(C);
123 }
124 }
125 static void usage() {
126 if (clang_getDeclKind(D) == CXDecl_ObjC_interface) {
127 clang_loadDeclaration(D, getInterfaceDetails);
128 }
129 }
130*/
131void clang_loadDeclaration(CXDecl, void (*callback)(CXDecl, CXCursor));
132
Steve Naroff3ba83e92009-08-28 15:28:48 +0000133/*
134 * CXEntity Operations.
135 */
Steve Naroffa6fc61b2009-08-27 19:51:58 +0000136const char *clang_getDeclarationName(CXEntity);
137const char *clang_getURI(CXEntity);
138CXEntity clang_getEntity(const char *URI);
Steve Naroff3ba83e92009-08-28 15:28:48 +0000139/*
140 * CXDecl Operations.
141 */
Steve Naroffa6fc61b2009-08-27 19:51:58 +0000142CXCursor clang_getCursorFromDecl(CXDecl);
143CXEntity clang_getEntityFromDecl(CXDecl);
144enum CXDeclKind clang_getDeclKind(CXDecl);
145const char *clang_getDeclSpelling(CXDecl);
Steve Naroff3ba83e92009-08-28 15:28:48 +0000146/*
147 * CXCursor Operations.
148 */
Steve Naroffa6fc61b2009-08-27 19:51:58 +0000149CXCursor clang_getCursor(CXTranslationUnit, const char *source_name,
150 unsigned line, unsigned column);
151
Steve Naroff3ba83e92009-08-28 15:28:48 +0000152enum CXCursorKind clang_getCursorKind(CXCursor);
Steve Naroffa6fc61b2009-08-27 19:51:58 +0000153
154unsigned clang_getCursorLine(CXCursor);
155unsigned clang_getCursorColumn(CXCursor);
156const char *clang_getCursorSource(CXCursor);
157
Steve Naroff3ba83e92009-08-28 15:28:48 +0000158/*
159 * If CXCursorKind == Cursor_Reference, then this will return the referenced declaration.
160 * If CXCursorKind == Cursor_Declaration, then this will return the declaration.
161 */
Steve Naroffa6fc61b2009-08-27 19:51:58 +0000162CXDecl clang_getCursorDecl(CXCursor);
Ted Kremenek1ca68fb2009-08-26 22:36:44 +0000163
164#ifdef __cplusplus
165}
166#endif
167#endif
168