Index.h revision 08b0e8daeb683686b876d72674962ad96df21d45
1d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek/*===-- clang-c/Index.h - Indexing Public C Interface -------------*- C -*-===*\
2d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|*                                                                            *|
3d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|*                     The LLVM Compiler Infrastructure                       *|
4d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|*                                                                            *|
5d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* This file is distributed under the University of Illinois Open Source      *|
6d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* License. See LICENSE.TXT for details.                                      *|
7d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|*                                                                            *|
8d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|*===----------------------------------------------------------------------===*|
9d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|*                                                                            *|
10d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* This header provides a public inferface to a Clang library for extracting  *|
11d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* high-level symbol information from source files without exposing the full  *|
12d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|* Clang C++ API.                                                             *|
13d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek|*                                                                            *|
14d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek\*===----------------------------------------------------------------------===*/
15d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek
16d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#ifndef CLANG_C_INDEX_H
17d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#define CLANG_C_INDEX_H
18d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek
1988145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff#include <sys/stat.h>
2088145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff
21d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#ifdef __cplusplus
22d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenekextern "C" {
23d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#endif
24d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek
2588145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff/* MSVC DLL import/export. */
262e06fc877a633abea3b40a64950c7316dac29ca8John Thompson#ifdef _MSC_VER
272e06fc877a633abea3b40a64950c7316dac29ca8John Thompson  #ifdef _CINDEX_LIB_
282e06fc877a633abea3b40a64950c7316dac29ca8John Thompson    #define CINDEX_LINKAGE __declspec(dllexport)
292e06fc877a633abea3b40a64950c7316dac29ca8John Thompson  #else
302e06fc877a633abea3b40a64950c7316dac29ca8John Thompson    #define CINDEX_LINKAGE __declspec(dllimport)
312e06fc877a633abea3b40a64950c7316dac29ca8John Thompson  #endif
322e06fc877a633abea3b40a64950c7316dac29ca8John Thompson#else
332e06fc877a633abea3b40a64950c7316dac29ca8John Thompson  #define CINDEX_LINKAGE
342e06fc877a633abea3b40a64950c7316dac29ca8John Thompson#endif
352e06fc877a633abea3b40a64950c7316dac29ca8John Thompson
36600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff/*
37600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   Clang indeX abstractions. The backing store for the following API's will be
38b7cd17cfd2970636af0fe9b491bab1acf0009c2fSteve Naroff   clangs AST file (currently based on PCH). AST files are created as follows:
39600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
40b7cd17cfd2970636af0fe9b491bab1acf0009c2fSteve Naroff   "clang -emit-ast <sourcefile.langsuffix> -o <sourcefile.ast>".
41600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
42600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   Naming Conventions: To avoid namespace pollution, data types are prefixed
43600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   with "CX" and functions are prefixed with "clang_".
44600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff*/
4550398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Narofftypedef void *CXIndex;            /* An indexing instance. */
46600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
4750398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Narofftypedef void *CXTranslationUnit;  /* A translation unit instance. */
48600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
4988145034694ed5267fa6fa5febc54fadc02bd479Steve Narofftypedef void *CXFile;    /* A source file */
5089922f86f4e7da383af2a62ef04ad8b93b941220Steve Narofftypedef void *CXDecl;    /* A specific declaration within a translation unit. */
51fb5704295c6137685a7b90b92cd6b958028740c8Steve Narofftypedef void *CXStmt;    /* A specific statement within a function/method */
52600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
53c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff/* Cursors represent declarations, definitions, and references. */
5489922f86f4e7da383af2a62ef04ad8b93b941220Steve Naroffenum CXCursorKind {
5589922f86f4e7da383af2a62ef04ad8b93b941220Steve Naroff /* Declarations */
5689922f86f4e7da383af2a62ef04ad8b93b941220Steve Naroff CXCursor_FirstDecl                     = 1,
57c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_TypedefDecl                   = 2,
58c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_StructDecl                    = 3,
59c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_UnionDecl                     = 4,
60c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ClassDecl                     = 5,
61c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_EnumDecl                      = 6,
62c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_FieldDecl                     = 7,
63c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_EnumConstantDecl              = 8,
64c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_FunctionDecl                  = 9,
65c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_VarDecl                       = 10,
66c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ParmDecl                      = 11,
67c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ObjCInterfaceDecl             = 12,
68c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ObjCCategoryDecl              = 13,
69c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ObjCProtocolDecl              = 14,
70c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ObjCPropertyDecl              = 15,
71c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ObjCIvarDecl                  = 16,
72c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ObjCInstanceMethodDecl        = 17,
73c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ObjCClassMethodDecl           = 18,
74c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_LastDecl                      = 18,
7589922f86f4e7da383af2a62ef04ad8b93b941220Steve Naroff
76c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff /* Definitions */
77c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_FirstDefn                     = 32,
78c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_FunctionDefn                  = 32,
79c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ObjCClassDefn                 = 33,
80c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ObjCCategoryDefn              = 34,
81c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ObjCInstanceMethodDefn        = 35,
82c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ObjCClassMethodDefn           = 36,
83c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_LastDefn                      = 36,
84c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff
8589922f86f4e7da383af2a62ef04ad8b93b941220Steve Naroff /* References */
86fb5704295c6137685a7b90b92cd6b958028740c8Steve Naroff CXCursor_FirstRef                      = 40, /* Decl references */
87f334b4e3eda5a39f041fe13f805dbb53535daa2fSteve Naroff CXCursor_ObjCSuperClassRef             = 40,
88f334b4e3eda5a39f041fe13f805dbb53535daa2fSteve Naroff CXCursor_ObjCProtocolRef               = 41,
89fb5704295c6137685a7b90b92cd6b958028740c8Steve Naroff CXCursor_ObjCClassRef                  = 42,
90fb5704295c6137685a7b90b92cd6b958028740c8Steve Naroff
91fb5704295c6137685a7b90b92cd6b958028740c8Steve Naroff CXCursor_ObjCSelectorRef               = 43, /* Expression references */
92fb5704295c6137685a7b90b92cd6b958028740c8Steve Naroff CXCursor_ObjCIvarRef                   = 44,
93fb5704295c6137685a7b90b92cd6b958028740c8Steve Naroff CXCursor_VarRef                        = 45,
94fb5704295c6137685a7b90b92cd6b958028740c8Steve Naroff CXCursor_FunctionRef                   = 46,
95fb5704295c6137685a7b90b92cd6b958028740c8Steve Naroff CXCursor_EnumConstantRef               = 47,
96fb5704295c6137685a7b90b92cd6b958028740c8Steve Naroff CXCursor_MemberRef                     = 48,
97fb5704295c6137685a7b90b92cd6b958028740c8Steve Naroff CXCursor_LastRef                       = 48,
9877128ddd3077fc045751a55bb3226802b15d5510Steve Naroff
9977128ddd3077fc045751a55bb3226802b15d5510Steve Naroff /* Error conditions */
10077128ddd3077fc045751a55bb3226802b15d5510Steve Naroff CXCursor_FirstInvalid                  = 70,
10177128ddd3077fc045751a55bb3226802b15d5510Steve Naroff CXCursor_InvalidFile                   = 70,
10277128ddd3077fc045751a55bb3226802b15d5510Steve Naroff CXCursor_NoDeclFound                   = 71,
10377128ddd3077fc045751a55bb3226802b15d5510Steve Naroff CXCursor_NotImplemented                = 72,
10477128ddd3077fc045751a55bb3226802b15d5510Steve Naroff CXCursor_LastInvalid                   = 72
105600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff};
106600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
10789922f86f4e7da383af2a62ef04ad8b93b941220Steve Naroff/* A cursor into the CXTranslationUnit. */
108fb5704295c6137685a7b90b92cd6b958028740c8Steve Naroff
10989922f86f4e7da383af2a62ef04ad8b93b941220Steve Narofftypedef struct {
11089922f86f4e7da383af2a62ef04ad8b93b941220Steve Naroff  enum CXCursorKind kind;
11189922f86f4e7da383af2a62ef04ad8b93b941220Steve Naroff  CXDecl decl;
112fb5704295c6137685a7b90b92cd6b958028740c8Steve Naroff  CXStmt stmt; /* expression reference */
11389922f86f4e7da383af2a62ef04ad8b93b941220Steve Naroff} CXCursor;
114600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
11550398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff/* A unique token for looking up "visible" CXDecls from a CXTranslationUnit. */
116e56b4baeba5097852e04bc41ca2e0396cf729955Steve Narofftypedef void *CXEntity;
117600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
118e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff/**
119e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * \brief clang_createIndex() provides a shared context for creating
120e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * translation units. It provides two options:
121e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff *
122e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
123e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * declarations (when loading any new translation units). A "local" declaration
124e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * is one that belongs in the translation unit itself and not in a precompiled
125e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * header that was used by the translation unit. If zero, all declarations
126e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * will be enumerated.
127e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff *
128e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * - displayDiagnostics: when non-zero, diagnostics will be output. If zero,
129e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * diagnostics will be ignored.
130b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
131b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * Here is an example:
132b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
133b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // excludeDeclsFromPCH = 1, displayDiagnostics = 1
134b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   Idx = clang_createIndex(1, 1);
135b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
136b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // IndexTest.pch was produced with the following command:
137b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
138b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
139b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
140b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // This will load all the symbols from 'IndexTest.pch'
141b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0);
142b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   clang_disposeTranslationUnit(TU);
143b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
144b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // This will load all the symbols from 'IndexTest.c', excluding symbols
145b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // from 'IndexTest.pch'.
146b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   char *args[] = { "-Xclang", "-include-pch=IndexTest.pch", 0 };
147b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args);
148b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0);
149b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   clang_disposeTranslationUnit(TU);
150b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
151b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * This process of creating the 'pch', loading it separately, and using it (via
152b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
153b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * (which gives the indexer the same performance benefit as the compiler).
154e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff */
1552e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
156e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff                          int displayDiagnostics);
1572e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE void clang_disposeIndex(CXIndex);
158600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
1592e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE const char *clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
160af08ddc8f1c53fed8d8d0ad82aa2a0bb7d654bd1Steve Naroff
161e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff/*
162e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * \brief Create a translation unit from an AST file (-emit-ast).
163e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff */
1642e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(
165e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff  CXIndex, const char *ast_filename
166600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff);
1671374598619f83e6b2de91341a326eae564ece2cbTed Kremenek/**
1681374598619f83e6b2de91341a326eae564ece2cbTed Kremenek * \brief Destroy the specified CXTranslationUnit object.
1691374598619f83e6b2de91341a326eae564ece2cbTed Kremenek */
1702e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
1711374598619f83e6b2de91341a326eae564ece2cbTed Kremenek
1721374598619f83e6b2de91341a326eae564ece2cbTed Kremenek/**
173e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * \brief Return the CXTranslationUnit for a given source file and the provided
174e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * command line arguments one would pass to the compiler.
175e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff *
176139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek * Note: The 'source_filename' argument is optional.  If the caller provides a NULL pointer,
177139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *  the name of the source file is expected to reside in the specified command line arguments.
178139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *
179139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek * Note: When encountered in 'clang_command_line_args', the following options are ignored:
180139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *
181139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *   '-c'
182139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *   '-emit-ast'
183139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *   '-fsyntax-only'
184139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *   '-o <output file>'  (both '-o' and '<output file>' are ignored)
185139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *
1861374598619f83e6b2de91341a326eae564ece2cbTed Kremenek */
1872e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
1885b7d8e254f6c2855b37b5521c0aee0a560dab237Steve Naroff  CXIndex CIdx,
189139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek  const char *source_filename /* specify NULL if the source file is in clang_command_line_args */,
1905b7d8e254f6c2855b37b5521c0aee0a560dab237Steve Naroff  int num_clang_command_line_args,
191e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff  const char **clang_command_line_args
1925b7d8e254f6c2855b37b5521c0aee0a560dab237Steve Naroff);
193600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
194600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff/*
195600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   Usage: clang_loadTranslationUnit(). Will load the toplevel declarations
196600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   within a translation unit, issuing a 'callback' for each one.
197600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
198600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   void printObjCInterfaceNames(CXTranslationUnit X, CXCursor C) {
199600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff     if (clang_getCursorKind(C) == Cursor_Declaration) {
200600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff       CXDecl D = clang_getCursorDecl(C);
201600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff       if (clang_getDeclKind(D) == CXDecl_ObjC_interface)
202600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff         printf("@interface %s in file %s on line %d column %d\n",
203600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff                clang_getDeclSpelling(D), clang_getCursorSource(C),
204600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff                clang_getCursorLine(C), clang_getCursorColumn(C));
205600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff     }
206600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   }
207600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   static void usage {
208600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff     clang_loadTranslationUnit(CXTranslationUnit, printObjCInterfaceNames);
209600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   }
210600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff*/
2112b8ee6c2994f738e5162ff46b638974870f51662Steve Narofftypedef void *CXClientData;
2122b8ee6c2994f738e5162ff46b638974870f51662Steve Narofftypedef void (*CXTranslationUnitIterator)(CXTranslationUnit, CXCursor,
2132b8ee6c2994f738e5162ff46b638974870f51662Steve Naroff                                          CXClientData);
2142e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE void clang_loadTranslationUnit(CXTranslationUnit, CXTranslationUnitIterator,
2152b8ee6c2994f738e5162ff46b638974870f51662Steve Naroff                               CXClientData);
216600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
217600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff/*
218600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   Usage: clang_loadDeclaration(). Will load the declaration, issuing a
219600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   'callback' for each declaration/reference within the respective declaration.
220600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
221600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   For interface declarations, this will index the super class, protocols,
222600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   ivars, methods, etc. For structure declarations, this will index the fields.
223600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   For functions, this will index the parameters (and body, for function
224600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   definitions), local declarations/references.
225600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
226600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   void getInterfaceDetails(CXDecl X, CXCursor C) {
227600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff     switch (clang_getCursorKind(C)) {
228600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff       case Cursor_ObjC_ClassRef:
229600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff         CXDecl SuperClass = clang_getCursorDecl(C);
230600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff       case Cursor_ObjC_ProtocolRef:
231600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff         CXDecl AdoptsProtocol = clang_getCursorDecl(C);
232600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff       case Cursor_Declaration:
233600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff         CXDecl AnIvarOrMethod = clang_getCursorDecl(C);
234600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff     }
235600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   }
236600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   static void usage() {
237600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff     if (clang_getDeclKind(D) == CXDecl_ObjC_interface) {
238600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff       clang_loadDeclaration(D, getInterfaceDetails);
239600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff     }
240600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   }
241600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff*/
242c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Narofftypedef void (*CXDeclIterator)(CXDecl, CXCursor, CXClientData);
24389922f86f4e7da383af2a62ef04ad8b93b941220Steve Naroff
2442e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE void clang_loadDeclaration(CXDecl, CXDeclIterator, CXClientData);
245600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
24650398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff/*
24788145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff * CXFile Operations.
24888145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff */
24908b0e8daeb683686b876d72674962ad96df21d45Douglas GregorCINDEX_LINKAGE const char *clang_getFileName(CXFile SFile);
25008b0e8daeb683686b876d72674962ad96df21d45Douglas GregorCINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
25188145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff
25288145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff/*
25350398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff * CXEntity Operations.
25450398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff */
2552e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE const char *clang_getDeclarationName(CXEntity);
2562e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE const char *clang_getURI(CXEntity);
2572e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXEntity clang_getEntity(const char *URI);
25850398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff/*
25950398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff * CXDecl Operations.
26050398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff */
2612e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXCursor clang_getCursorFromDecl(CXDecl);
2622e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXEntity clang_getEntityFromDecl(CXDecl);
2632e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE const char *clang_getDeclSpelling(CXDecl);
2642e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_getDeclLine(CXDecl);
2652e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_getDeclColumn(CXDecl);
26688145034694ed5267fa6fa5febc54fadc02bd479Steve NaroffCINDEX_LINKAGE const char *clang_getDeclSource(CXDecl); /* deprecate */
26788145034694ed5267fa6fa5febc54fadc02bd479Steve NaroffCINDEX_LINKAGE CXFile clang_getDeclSourceFile(CXDecl);
268699a07d8a0b1579c5178b3baf4bcf9edb6b38108Steve Naroff
26950398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff/*
27050398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff * CXCursor Operations.
27150398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff */
2726a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff/**
2736a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff   Usage: clang_getCursor() will translate a source/line/column position
2746a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff   into an AST cursor (to derive semantic information from the source code).
2756a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff */
2762e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit, const char *source_name,
277fbcb2b716bee88c754684bd189913ed9f8c09086Ted Kremenek                         unsigned line, unsigned column);
278fbcb2b716bee88c754684bd189913ed9f8c09086Ted Kremenek
2792e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
2802e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
2812e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
2822e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_isDefinition(enum CXCursorKind);
2832e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
284600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
2852e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_getCursorLine(CXCursor);
2862e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_getCursorColumn(CXCursor);
2872e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE const char *clang_getCursorSpelling(CXCursor);
28888145034694ed5267fa6fa5febc54fadc02bd479Steve NaroffCINDEX_LINKAGE const char *clang_getCursorSource(CXCursor); /* deprecate */
28988145034694ed5267fa6fa5febc54fadc02bd479Steve NaroffCINDEX_LINKAGE CXFile clang_getCursorSourceFile(CXCursor);
290f334b4e3eda5a39f041fe13f805dbb53535daa2fSteve Naroff
2914ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff/* for debug/testing */
2922e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE const char *clang_getCursorKindSpelling(enum CXCursorKind Kind);
2932e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
2944ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          const char **startBuf,
2954ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          const char **endBuf,
2964ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *startLine,
2974ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *startColumn,
2984ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *endLine,
2994ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *endColumn);
300600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
30150398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff/*
302459789b8d2e3235e2f3342c393b7a78bd73c1347Chris Lattner * If CXCursorKind == Cursor_Reference, then this will return the referenced
303459789b8d2e3235e2f3342c393b7a78bd73c1347Chris Lattner * declaration.
30450398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff * If CXCursorKind == Cursor_Declaration, then this will return the declaration.
30550398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff */
3062e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXDecl clang_getCursorDecl(CXCursor);
307d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek
308d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#ifdef __cplusplus
309d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek}
310d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#endif
311d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#endif
312d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek
313