Index.h revision 283cae37b03047c14ef918503bc46b08405c3b69
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>
203d31560343856c573376a04558a7111e7afad4f7Chandler Carruth#include <time.h>
2188145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff
22d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#ifdef __cplusplus
23d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenekextern "C" {
24d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#endif
25d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek
2688145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff/* MSVC DLL import/export. */
272e06fc877a633abea3b40a64950c7316dac29ca8John Thompson#ifdef _MSC_VER
282e06fc877a633abea3b40a64950c7316dac29ca8John Thompson  #ifdef _CINDEX_LIB_
292e06fc877a633abea3b40a64950c7316dac29ca8John Thompson    #define CINDEX_LINKAGE __declspec(dllexport)
302e06fc877a633abea3b40a64950c7316dac29ca8John Thompson  #else
312e06fc877a633abea3b40a64950c7316dac29ca8John Thompson    #define CINDEX_LINKAGE __declspec(dllimport)
322e06fc877a633abea3b40a64950c7316dac29ca8John Thompson  #endif
332e06fc877a633abea3b40a64950c7316dac29ca8John Thompson#else
342e06fc877a633abea3b40a64950c7316dac29ca8John Thompson  #define CINDEX_LINKAGE
352e06fc877a633abea3b40a64950c7316dac29ca8John Thompson#endif
362e06fc877a633abea3b40a64950c7316dac29ca8John Thompson
37600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff/*
38600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   Clang indeX abstractions. The backing store for the following API's will be
39b7cd17cfd2970636af0fe9b491bab1acf0009c2fSteve Naroff   clangs AST file (currently based on PCH). AST files are created as follows:
40600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
41b7cd17cfd2970636af0fe9b491bab1acf0009c2fSteve Naroff   "clang -emit-ast <sourcefile.langsuffix> -o <sourcefile.ast>".
42600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
43600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   Naming Conventions: To avoid namespace pollution, data types are prefixed
44600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   with "CX" and functions are prefixed with "clang_".
45600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff*/
4650398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Narofftypedef void *CXIndex;            /* An indexing instance. */
47600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
4850398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Narofftypedef void *CXTranslationUnit;  /* A translation unit instance. */
49600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
5088145034694ed5267fa6fa5febc54fadc02bd479Steve Narofftypedef void *CXFile;    /* A source file */
5189922f86f4e7da383af2a62ef04ad8b93b941220Steve Narofftypedef void *CXDecl;    /* A specific declaration within a translation unit. */
52fb5704295c6137685a7b90b92cd6b958028740c8Steve Narofftypedef void *CXStmt;    /* A specific statement within a function/method */
53600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
54c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff/* Cursors represent declarations, definitions, and references. */
5589922f86f4e7da383af2a62ef04ad8b93b941220Steve Naroffenum CXCursorKind {
5689922f86f4e7da383af2a62ef04ad8b93b941220Steve Naroff /* Declarations */
5789922f86f4e7da383af2a62ef04ad8b93b941220Steve Naroff CXCursor_FirstDecl                     = 1,
58c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_TypedefDecl                   = 2,
59c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_StructDecl                    = 3,
60c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_UnionDecl                     = 4,
61c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ClassDecl                     = 5,
62c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_EnumDecl                      = 6,
63c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_FieldDecl                     = 7,
64c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_EnumConstantDecl              = 8,
65c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_FunctionDecl                  = 9,
66c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_VarDecl                       = 10,
67c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ParmDecl                      = 11,
68c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ObjCInterfaceDecl             = 12,
69c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ObjCCategoryDecl              = 13,
70c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ObjCProtocolDecl              = 14,
71c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ObjCPropertyDecl              = 15,
72c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ObjCIvarDecl                  = 16,
73c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ObjCInstanceMethodDecl        = 17,
74c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ObjCClassMethodDecl           = 18,
75c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_LastDecl                      = 18,
7689922f86f4e7da383af2a62ef04ad8b93b941220Steve Naroff
77c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff /* Definitions */
78c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_FirstDefn                     = 32,
79c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_FunctionDefn                  = 32,
80c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ObjCClassDefn                 = 33,
81c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ObjCCategoryDefn              = 34,
82c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ObjCInstanceMethodDefn        = 35,
83c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_ObjCClassMethodDefn           = 36,
84c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff CXCursor_LastDefn                      = 36,
85c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Naroff
8689922f86f4e7da383af2a62ef04ad8b93b941220Steve Naroff /* References */
87fb5704295c6137685a7b90b92cd6b958028740c8Steve Naroff CXCursor_FirstRef                      = 40, /* Decl references */
88f334b4e3eda5a39f041fe13f805dbb53535daa2fSteve Naroff CXCursor_ObjCSuperClassRef             = 40,
89f334b4e3eda5a39f041fe13f805dbb53535daa2fSteve Naroff CXCursor_ObjCProtocolRef               = 41,
90fb5704295c6137685a7b90b92cd6b958028740c8Steve Naroff CXCursor_ObjCClassRef                  = 42,
91fb5704295c6137685a7b90b92cd6b958028740c8Steve Naroff
92fb5704295c6137685a7b90b92cd6b958028740c8Steve Naroff CXCursor_ObjCSelectorRef               = 43, /* Expression references */
93fb5704295c6137685a7b90b92cd6b958028740c8Steve Naroff CXCursor_ObjCIvarRef                   = 44,
94fb5704295c6137685a7b90b92cd6b958028740c8Steve Naroff CXCursor_VarRef                        = 45,
95fb5704295c6137685a7b90b92cd6b958028740c8Steve Naroff CXCursor_FunctionRef                   = 46,
96fb5704295c6137685a7b90b92cd6b958028740c8Steve Naroff CXCursor_EnumConstantRef               = 47,
97fb5704295c6137685a7b90b92cd6b958028740c8Steve Naroff CXCursor_MemberRef                     = 48,
98fb5704295c6137685a7b90b92cd6b958028740c8Steve Naroff CXCursor_LastRef                       = 48,
9977128ddd3077fc045751a55bb3226802b15d5510Steve Naroff
10077128ddd3077fc045751a55bb3226802b15d5510Steve Naroff /* Error conditions */
10177128ddd3077fc045751a55bb3226802b15d5510Steve Naroff CXCursor_FirstInvalid                  = 70,
10277128ddd3077fc045751a55bb3226802b15d5510Steve Naroff CXCursor_InvalidFile                   = 70,
10377128ddd3077fc045751a55bb3226802b15d5510Steve Naroff CXCursor_NoDeclFound                   = 71,
10477128ddd3077fc045751a55bb3226802b15d5510Steve Naroff CXCursor_NotImplemented                = 72,
10577128ddd3077fc045751a55bb3226802b15d5510Steve Naroff CXCursor_LastInvalid                   = 72
106600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff};
107600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
108735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor/**
109735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * \brief Provides the contents of a file that has not yet been saved to disk.
110735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor *
111735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * Each CXUnsavedFile instance provides the name of a file on the
112735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * system along with the current contents of that file that have not
113735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * yet been saved to disk.
114735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor */
115735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregorstruct CXUnsavedFile {
116735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor  /**
117735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   * \brief The file whose contents have not yet been saved.
118735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   *
119735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   * This file must already exist in the file system.
120735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   */
121735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor  const char *Filename;
122735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor
123735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor  /**
124735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   * \brief A null-terminated buffer containing the unsaved contents
125735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   * of this file.
126735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   */
127735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor  const char *Contents;
128735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor
129735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor  /**
130735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   * \brief The length of the unsaved contents of this buffer, not
131735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   * counting the NULL at the end of the buffer.
132735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor   */
133735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor  unsigned long Length;
134735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor};
135735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor
13689922f86f4e7da383af2a62ef04ad8b93b941220Steve Naroff/* A cursor into the CXTranslationUnit. */
137fb5704295c6137685a7b90b92cd6b958028740c8Steve Naroff
13889922f86f4e7da383af2a62ef04ad8b93b941220Steve Narofftypedef struct {
13989922f86f4e7da383af2a62ef04ad8b93b941220Steve Naroff  enum CXCursorKind kind;
140283cae37b03047c14ef918503bc46b08405c3b69Douglas Gregor  void *data[3];
14189922f86f4e7da383af2a62ef04ad8b93b941220Steve Naroff} CXCursor;
142600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
14350398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff/* A unique token for looking up "visible" CXDecls from a CXTranslationUnit. */
144317238334161d2c72d2432a79827d9a7ee1fc123Ted Kremenektypedef struct {
145317238334161d2c72d2432a79827d9a7ee1fc123Ted Kremenek  CXIndex index;
146317238334161d2c72d2432a79827d9a7ee1fc123Ted Kremenek  void *data;
147317238334161d2c72d2432a79827d9a7ee1fc123Ted Kremenek} CXEntity;
148600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
149ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff/**
150ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff * For functions returning a string that might or might not need
151ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff * to be internally allocated and freed.
152ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff * Use clang_getCString to access the C string value.
153ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff * Use clang_disposeString to free the value.
154ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff * Treat it as an opaque type.
155ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff */
156ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Narofftypedef struct {
157ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff  const char *Spelling;
158ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff  /* A 1 value indicates the clang_ indexing API needed to allocate the string
159ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff     (and it must be freed by clang_disposeString()). */
160ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff  int MustFreeString;
161ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff} CXString;
162ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff
163ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff/* Get C string pointer from a CXString. */
164ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve NaroffCINDEX_LINKAGE const char *clang_getCString(CXString string);
165ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff
166ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff/* Free CXString. */
167ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve NaroffCINDEX_LINKAGE void clang_disposeString(CXString string);
168ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff
169e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff/**
170e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * \brief clang_createIndex() provides a shared context for creating
171e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * translation units. It provides two options:
172e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff *
173e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
174e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * declarations (when loading any new translation units). A "local" declaration
175e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * is one that belongs in the translation unit itself and not in a precompiled
176e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * header that was used by the translation unit. If zero, all declarations
177e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * will be enumerated.
178e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff *
179e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * - displayDiagnostics: when non-zero, diagnostics will be output. If zero,
180e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * diagnostics will be ignored.
181b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
182b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * Here is an example:
183b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
184b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // excludeDeclsFromPCH = 1, displayDiagnostics = 1
185b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   Idx = clang_createIndex(1, 1);
186b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
187b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // IndexTest.pch was produced with the following command:
188b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
189b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
190b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
191b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // This will load all the symbols from 'IndexTest.pch'
192b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0);
193b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   clang_disposeTranslationUnit(TU);
194b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
195b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // This will load all the symbols from 'IndexTest.c', excluding symbols
196b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // from 'IndexTest.pch'.
197b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   char *args[] = { "-Xclang", "-include-pch=IndexTest.pch", 0 };
198b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args);
199b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0);
200b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   clang_disposeTranslationUnit(TU);
201b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
202b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * This process of creating the 'pch', loading it separately, and using it (via
203b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
204b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * (which gives the indexer the same performance benefit as the compiler).
205e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff */
2062e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
207e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff                          int displayDiagnostics);
2088506dde586459887b7e14e23a30af8ac5be5adb6Daniel DunbarCINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
2098506dde586459887b7e14e23a30af8ac5be5adb6Daniel DunbarCINDEX_LINKAGE CXString
2108506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbarclang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
2118506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar
2128506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar/*
2138506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \brief Request that AST's be generated external for API calls which parse
2148506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * source code on the fly, e.g. \see createTranslationUnitFromSourceFile.
2158506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar *
2168506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * Note: This is for debugging purposes only, and may be removed at a later
2178506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * date.
2188506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar *
2198506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param index - The index to update.
2208506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param value - The new flag value.
2218506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar */
2228506dde586459887b7e14e23a30af8ac5be5adb6Daniel DunbarCINDEX_LINKAGE void clang_setUseExternalASTGeneration(CXIndex index,
2238506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar                                                      int value);
224af08ddc8f1c53fed8d8d0ad82aa2a0bb7d654bd1Steve Naroff
225e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff/*
226e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * \brief Create a translation unit from an AST file (-emit-ast).
227e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff */
2282e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(
229e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff  CXIndex, const char *ast_filename
230600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff);
2318506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar
2321374598619f83e6b2de91341a326eae564ece2cbTed Kremenek/**
2331374598619f83e6b2de91341a326eae564ece2cbTed Kremenek * \brief Destroy the specified CXTranslationUnit object.
2341374598619f83e6b2de91341a326eae564ece2cbTed Kremenek */
2352e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
2361374598619f83e6b2de91341a326eae564ece2cbTed Kremenek
2371374598619f83e6b2de91341a326eae564ece2cbTed Kremenek/**
238e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * \brief Return the CXTranslationUnit for a given source file and the provided
239e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * command line arguments one would pass to the compiler.
240e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff *
2418506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * Note: The 'source_filename' argument is optional.  If the caller provides a
2428506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * NULL pointer, the name of the source file is expected to reside in the
2438506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * specified command line arguments.
244139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *
2458506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * Note: When encountered in 'clang_command_line_args', the following options
2468506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * are ignored:
247139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *
248139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *   '-c'
249139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *   '-emit-ast'
250139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *   '-fsyntax-only'
251139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *   '-o <output file>'  (both '-o' and '<output file>' are ignored)
252139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *
2538506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar *
2548506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param source_filename - The name of the source file to load, or NULL if the
2558506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * source file is included in clang_command_line_args.
2561374598619f83e6b2de91341a326eae564ece2cbTed Kremenek */
2572e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
2588506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar  CXIndex CIdx,
2598506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar  const char *source_filename,
2605b7d8e254f6c2855b37b5521c0aee0a560dab237Steve Naroff  int num_clang_command_line_args,
261e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff  const char **clang_command_line_args
2625b7d8e254f6c2855b37b5521c0aee0a560dab237Steve Naroff);
263600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
264600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff/*
265600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   Usage: clang_loadTranslationUnit(). Will load the toplevel declarations
266600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   within a translation unit, issuing a 'callback' for each one.
267600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
268600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   void printObjCInterfaceNames(CXTranslationUnit X, CXCursor C) {
269600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff     if (clang_getCursorKind(C) == Cursor_Declaration) {
270600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff       CXDecl D = clang_getCursorDecl(C);
271600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff       if (clang_getDeclKind(D) == CXDecl_ObjC_interface)
272600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff         printf("@interface %s in file %s on line %d column %d\n",
273600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff                clang_getDeclSpelling(D), clang_getCursorSource(C),
274600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff                clang_getCursorLine(C), clang_getCursorColumn(C));
275600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff     }
276600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   }
277600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   static void usage {
278600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff     clang_loadTranslationUnit(CXTranslationUnit, printObjCInterfaceNames);
2798506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar  }
280600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff*/
2812b8ee6c2994f738e5162ff46b638974870f51662Steve Narofftypedef void *CXClientData;
2822b8ee6c2994f738e5162ff46b638974870f51662Steve Narofftypedef void (*CXTranslationUnitIterator)(CXTranslationUnit, CXCursor,
2832b8ee6c2994f738e5162ff46b638974870f51662Steve Naroff                                          CXClientData);
2848506dde586459887b7e14e23a30af8ac5be5adb6Daniel DunbarCINDEX_LINKAGE void clang_loadTranslationUnit(CXTranslationUnit,
2858506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar                                              CXTranslationUnitIterator,
2868506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar                                              CXClientData);
287600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
288600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff/*
289600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   Usage: clang_loadDeclaration(). Will load the declaration, issuing a
290600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   'callback' for each declaration/reference within the respective declaration.
291600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
292600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   For interface declarations, this will index the super class, protocols,
293600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   ivars, methods, etc. For structure declarations, this will index the fields.
294600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   For functions, this will index the parameters (and body, for function
295600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   definitions), local declarations/references.
296600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
297600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   void getInterfaceDetails(CXDecl X, CXCursor C) {
298600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff     switch (clang_getCursorKind(C)) {
299600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff       case Cursor_ObjC_ClassRef:
300600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff         CXDecl SuperClass = clang_getCursorDecl(C);
301600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff       case Cursor_ObjC_ProtocolRef:
302600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff         CXDecl AdoptsProtocol = clang_getCursorDecl(C);
303600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff       case Cursor_Declaration:
304600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff         CXDecl AnIvarOrMethod = clang_getCursorDecl(C);
305600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff     }
306600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   }
307600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   static void usage() {
308600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff     if (clang_getDeclKind(D) == CXDecl_ObjC_interface) {
309600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff       clang_loadDeclaration(D, getInterfaceDetails);
310600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff     }
311600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   }
312600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff*/
313c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Narofftypedef void (*CXDeclIterator)(CXDecl, CXCursor, CXClientData);
31489922f86f4e7da383af2a62ef04ad8b93b941220Steve Naroff
3152e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE void clang_loadDeclaration(CXDecl, CXDeclIterator, CXClientData);
316600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
31750398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff/*
31888145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff * CXFile Operations.
31988145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff */
32008b0e8daeb683686b876d72674962ad96df21d45Douglas GregorCINDEX_LINKAGE const char *clang_getFileName(CXFile SFile);
32108b0e8daeb683686b876d72674962ad96df21d45Douglas GregorCINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
32288145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff
32388145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff/*
32450398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff * CXEntity Operations.
32550398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff */
326317238334161d2c72d2432a79827d9a7ee1fc123Ted Kremenek
327317238334161d2c72d2432a79827d9a7ee1fc123Ted Kremenek/* clang_getDeclaration() maps from a CXEntity to the matching CXDecl (if any)
328317238334161d2c72d2432a79827d9a7ee1fc123Ted Kremenek *  in a specified translation unit. */
329317238334161d2c72d2432a79827d9a7ee1fc123Ted KremenekCINDEX_LINKAGE CXDecl clang_getDeclaration(CXEntity, CXTranslationUnit);
330317238334161d2c72d2432a79827d9a7ee1fc123Ted Kremenek
33150398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff/*
33250398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff * CXDecl Operations.
33350398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff */
3342e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXCursor clang_getCursorFromDecl(CXDecl);
335317238334161d2c72d2432a79827d9a7ee1fc123Ted KremenekCINDEX_LINKAGE CXEntity clang_getEntityFromDecl(CXIndex, CXDecl);
336ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve NaroffCINDEX_LINKAGE CXString clang_getDeclSpelling(CXDecl);
3372e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_getDeclLine(CXDecl);
3382e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_getDeclColumn(CXDecl);
339c50277f748d13f52bd62a6a2c3bede2cf7d65eeaTed KremenekCINDEX_LINKAGE CXString clang_getDeclUSR(CXDecl);
3406ab9db10c5f89d1db230d227f67ff18f55608e27Ted KremenekCINDEX_LINKAGE const char *clang_getDeclSource(CXDecl); /* deprecate */
34188145034694ed5267fa6fa5febc54fadc02bd479Steve NaroffCINDEX_LINKAGE CXFile clang_getDeclSourceFile(CXDecl);
342699a07d8a0b1579c5178b3baf4bcf9edb6b38108Steve Naroff
343fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenektypedef struct CXSourceLineColumn {
344fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek  unsigned line;
345fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek  unsigned column;
346fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek} CXSourceLineColumn;
347fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek
348fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenektypedef struct CXDeclExtent {
349fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek  CXSourceLineColumn begin;
350fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek  CXSourceLineColumn end;
351fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek} CXSourceExtent;
352fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek
3533aacd53816b4ba78f085c05232ec84f4947222d6Daniel Dunbar/* clang_getDeclExtent() returns the physical extent of a declaration.  The
3543aacd53816b4ba78f085c05232ec84f4947222d6Daniel Dunbar * beginning line/column pair points to the start of the first token in the
355d8210650ed948de65a08a8daf16d291b747717c4Ted Kremenek * declaration, and the ending line/column pair points to the last character in
356d8210650ed948de65a08a8daf16d291b747717c4Ted Kremenek * the last token of the declaration.
357fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek */
3583aacd53816b4ba78f085c05232ec84f4947222d6Daniel DunbarCINDEX_LINKAGE CXSourceExtent clang_getDeclExtent(CXDecl);
359fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek
36050398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff/*
36150398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff * CXCursor Operations.
36250398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff */
3636a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff/**
3646a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff   Usage: clang_getCursor() will translate a source/line/column position
3656a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff   into an AST cursor (to derive semantic information from the source code).
3666a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff */
3678506dde586459887b7e14e23a30af8ac5be5adb6Daniel DunbarCINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit,
3688506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar                                        const char *source_name,
3698506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar                                        unsigned line, unsigned column);
370738855554394a6afcf39cc8345fd22c3756b8dd0Ted Kremenek
371738855554394a6afcf39cc8345fd22c3756b8dd0Ted KremenekCINDEX_LINKAGE CXCursor clang_getNullCursor(void);
372fbcb2b716bee88c754684bd189913ed9f8c09086Ted Kremenek
3732e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
3742e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
3752e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
3762e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_isDefinition(enum CXCursorKind);
3772e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
378600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
379738855554394a6afcf39cc8345fd22c3756b8dd0Ted KremenekCINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
380738855554394a6afcf39cc8345fd22c3756b8dd0Ted Kremenek
3812e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_getCursorLine(CXCursor);
3822e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_getCursorColumn(CXCursor);
383ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve NaroffCINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
38488145034694ed5267fa6fa5febc54fadc02bd479Steve NaroffCINDEX_LINKAGE const char *clang_getCursorSource(CXCursor); /* deprecate */
38588145034694ed5267fa6fa5febc54fadc02bd479Steve NaroffCINDEX_LINKAGE CXFile clang_getCursorSourceFile(CXCursor);
386f334b4e3eda5a39f041fe13f805dbb53535daa2fSteve Naroff
3874ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff/* for debug/testing */
3882e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE const char *clang_getCursorKindSpelling(enum CXCursorKind Kind);
3892e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
3904ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          const char **startBuf,
3914ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          const char **endBuf,
3924ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *startLine,
3934ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *startColumn,
3944ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *endLine,
3954ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *endColumn);
396600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
39750398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff/*
398459789b8d2e3235e2f3342c393b7a78bd73c1347Chris Lattner * If CXCursorKind == Cursor_Reference, then this will return the referenced
399459789b8d2e3235e2f3342c393b7a78bd73c1347Chris Lattner * declaration.
40050398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff * If CXCursorKind == Cursor_Declaration, then this will return the declaration.
40150398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff */
4022e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXDecl clang_getCursorDecl(CXCursor);
403d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek
4040c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
4050c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A semantic string that describes a code-completion result.
4060c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
4070c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * A semantic string that describes the formatting of a code-completion
4080c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * result as a single "template" of text that should be inserted into the
4090c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * source buffer when a particular code-completion result is selected.
4100c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Each semantic string is made up of some number of "chunks", each of which
4110c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * contains some text along with a description of what that text means, e.g.,
4120c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the name of the entity being referenced, whether the text chunk is part of
4130c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the template, or whether it is a "placeholder" that the user should replace
4140c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
4150c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * description of the different kinds of chunks.
4160c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
4170c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregortypedef void *CXCompletionString;
4180c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
4190c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
4200c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A single result of code completion.
4210c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
4220c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregortypedef struct {
4230c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
4240c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief The kind of entity that this completion refers to.
4250c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4260c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * The cursor kind will be a macro, keyword, or a declaration (one of the
4270c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * *Decl cursor kinds), describing the entity that the completion is
4280c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * referring to.
4290c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4300c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \todo In the future, we would like to provide a full cursor, to allow
4310c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * the client to extract additional information from declaration.
4320c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
4330c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  enum CXCursorKind CursorKind;
4340c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
4350c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
4360c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief The code-completion string that describes how to insert this
4370c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * code-completion result into the editing buffer.
4380c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
4390c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionString CompletionString;
4400c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor} CXCompletionResult;
4410c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
4420c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
4430c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Describes a single piece of text within a code-completion string.
4440c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
4450c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Each "chunk" within a code-completion string (\c CXCompletionString) is
4460c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * either a piece of text with a specific "kind" that describes how that text
4470c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * should be interpreted by the client or is another completion string.
4480c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
4490c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorenum CXCompletionChunkKind {
4500c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
4510c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A code-completion string that describes "optional" text that
4520c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * could be a part of the template (but is not required).
4530c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4540c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * The Optional chunk is the only kind of chunk that has a code-completion
4550c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * string for its representation, which is accessible via
4560c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \c clang_getCompletionChunkCompletionString(). The code-completion string
4570c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * describes an additional part of the template that is completely optional.
4580c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * For example, optional chunks can be used to describe the placeholders for
4590c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * arguments that match up with defaulted function parameters, e.g. given:
4600c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4610c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \code
4620c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * void f(int x, float y = 3.14, double z = 2.71828);
4630c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \endcode
4640c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4650c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * The code-completion string for this function would contain:
4660c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - a TypedText chunk for "f".
4670c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - a LeftParen chunk for "(".
4680c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - a Placeholder chunk for "int x"
4690c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - an Optional chunk containing the remaining defaulted arguments, e.g.,
4700c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *       - a Comma chunk for ","
4710c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *       - a Placeholder chunk for "float x"
4720c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *       - an Optional chunk containing the last defaulted argument:
4730c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *           - a Comma chunk for ","
4740c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *           - a Placeholder chunk for "double z"
4750c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - a RightParen chunk for ")"
4760c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4770c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * There are many ways two handle Optional chunks. Two simple approaches are:
4780c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - Completely ignore optional chunks, in which case the template for the
4790c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *     function "f" would only include the first parameter ("int x").
4800c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - Fully expand all optional chunks, in which case the template for the
4810c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *     function "f" would have all of the parameters.
4820c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
4830c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_Optional,
4840c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
4850c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Text that a user would be expected to type to get this
4860c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * code-completion result.
4870c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4880c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * There will be exactly one "typed text" chunk in a semantic string, which
4890c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * will typically provide the spelling of a keyword or the name of a
4900c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * declaration that could be used at the current code point. Clients are
4910c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * expected to filter the code-completion results based on the text in this
4920c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * chunk.
4930c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
4940c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_TypedText,
4950c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
4960c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Text that should be inserted as part of a code-completion result.
4970c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * A "text" chunk represents text that is part of the template to be
4990c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * inserted into user code should this particular code-completion result
5000c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * be selected.
5010c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5020c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_Text,
5030c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5040c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Placeholder text that should be replaced by the user.
5050c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
5060c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * A "placeholder" chunk marks a place where the user should insert text
5070c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * into the code-completion template. For example, placeholders might mark
5080c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * the function parameters for a function declaration, to indicate that the
5090c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * user should provide arguments for each of those parameters. The actual
5100c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * text in a placeholder is a suggestion for the text to display before
5110c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * the user replaces the placeholder with real code.
5120c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5130c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_Placeholder,
5140c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5150c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Informative text that should be displayed but never inserted as
5160c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * part of the template.
5170c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
5180c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * An "informative" chunk contains annotations that can be displayed to
5190c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * help the user decide whether a particular code-completion result is the
5200c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * right option, but which is not part of the actual template to be inserted
5210c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * by code completion.
5220c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5230c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_Informative,
5240c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5250c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Text that describes the current parameter when code-completion is
5260c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * referring to function call, message send, or template specialization.
5270c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
5280c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * A "current parameter" chunk occurs when code-completion is providing
5290c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * information about a parameter corresponding to the argument at the
5300c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * code-completion point. For example, given a function
5310c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
5320c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \code
5330c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * int add(int x, int y);
5340c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \endcode
5350c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
5360c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * and the source code \c add(, where the code-completion point is after the
5370c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * "(", the code-completion string will contain a "current parameter" chunk
5380c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * for "int x", indicating that the current argument will initialize that
5390c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * parameter. After typing further, to \c add(17, (where the code-completion
5400c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * point is after the ","), the code-completion string will contain a
5410c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * "current paremeter" chunk to "int y".
5420c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5430c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_CurrentParameter,
5440c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5450c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A left parenthesis ('('), used to initiate a function call or
5460c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * signal the beginning of a function parameter list.
5470c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5480c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_LeftParen,
5490c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5500c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A right parenthesis (')'), used to finish a function call or
5510c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * signal the end of a function parameter list.
5520c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5530c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_RightParen,
5540c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5550c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A left bracket ('[').
5560c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5570c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_LeftBracket,
5580c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5590c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A right bracket (']').
5600c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5610c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_RightBracket,
5620c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5630c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A left brace ('{').
5640c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5650c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_LeftBrace,
5660c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5670c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A right brace ('}').
5680c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5690c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_RightBrace,
5700c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5710c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A left angle bracket ('<').
5720c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5730c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_LeftAngle,
5740c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5750c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A right angle bracket ('>').
5760c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5770c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_RightAngle,
5780c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5790c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A comma separator (',').
5800c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
581ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor  CXCompletionChunk_Comma,
582ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor  /**
583ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   * \brief Text that specifies the result type of a given result.
584ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   *
585ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   * This special kind of informative chunk is not meant to be inserted into
586ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   * the text buffer. Rather, it is meant to illustrate the type that an
587ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   * expression using the given completion string would have.
588ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   */
58901dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  CXCompletionChunk_ResultType,
59001dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  /**
59101dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   * \brief A colon (':').
59201dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   */
59301dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  CXCompletionChunk_Colon,
59401dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  /**
59501dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   * \brief A semicolon (';').
59601dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   */
59701dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  CXCompletionChunk_SemiColon,
59801dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  /**
59901dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   * \brief An '=' sign.
60001dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   */
60101dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  CXCompletionChunk_Equal,
60201dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  /**
60301dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   * Horizontal space (' ').
60401dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   */
60501dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  CXCompletionChunk_HorizontalSpace,
60601dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  /**
60701dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   * Vertical space ('\n'), after which it is generally a good idea to
60801dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   * perform indentation.
60901dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor   */
61001dfea02d1da297e8b53db8eea3d3cc652acda8dDouglas Gregor  CXCompletionChunk_VerticalSpace
6110c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor};
6120c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
6130c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
6140c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Determine the kind of a particular chunk within a completion string.
6150c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6160c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param completion_string the completion string to query.
6170c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6180c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param chunk_number the 0-based index of the chunk in the completion string.
6190c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6200c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \returns the kind of the chunk at the index \c chunk_number.
6210c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
6220c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas GregorCINDEX_LINKAGE enum CXCompletionChunkKind
6230c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getCompletionChunkKind(CXCompletionString completion_string,
6240c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor                             unsigned chunk_number);
6250c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
6260c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
6270c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Retrieve the text associated with a particular chunk within a
6280c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * completion string.
6290c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6300c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param completion_string the completion string to query.
6310c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6320c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param chunk_number the 0-based index of the chunk in the completion string.
6330c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6340c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \returns the text associated with the chunk at index \c chunk_number.
6350c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
6360c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas GregorCINDEX_LINKAGE const char *
6370c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getCompletionChunkText(CXCompletionString completion_string,
6380c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor                             unsigned chunk_number);
6390c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
6400c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
6410c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Retrieve the completion string associated with a particular chunk
6420c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * within a completion string.
6430c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6440c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param completion_string the completion string to query.
6450c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6460c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param chunk_number the 0-based index of the chunk in the completion string.
6470c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6480c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \returns the completion string associated with the chunk at index
6490c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \c chunk_number, or NULL if that chunk is not represented by a completion
6500c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * string.
6510c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
6520c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas GregorCINDEX_LINKAGE CXCompletionString
6530c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getCompletionChunkCompletionString(CXCompletionString completion_string,
6540c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor                                         unsigned chunk_number);
6550c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
6560c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
6570c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Retrieve the number of chunks in the given code-completion string.
6580c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
6590c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas GregorCINDEX_LINKAGE unsigned
6600c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getNumCompletionChunks(CXCompletionString completion_string);
6610c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
6620c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
663ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \brief Contains the results of code-completion.
664ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor *
665ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * This data structure contains the results of code completion, as
666ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * produced by \c clang_codeComplete. Its contents must be freed by
667ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \c clang_disposeCodeCompleteResults.
668ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor */
669ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregortypedef struct {
670ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor  /**
671ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   * \brief The code-completion results.
672ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   */
673ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor  CXCompletionResult *Results;
674ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor
675ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor  /**
676ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   * \brief The number of code-completion results stored in the
677ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   * \c Results array.
678ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   */
679ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor  unsigned NumResults;
680ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor} CXCodeCompleteResults;
681ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor
682ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor/**
6830c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Perform code completion at a given location in a source file.
6840c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6850c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * This function performs code completion at a particular file, line, and
6860c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * column within source code, providing results that suggest potential
6870c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code snippets based on the context of the completion. The basic model
6880c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * for code completion is that Clang will parse a complete source file,
6890c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * performing syntax checking up to the location where code-completion has
6900c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * been requested. At that point, a special code-completion token is passed
6910c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * to the parser, which recognizes this token and determines, based on the
6920c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * current location in the C/Objective-C/C++ grammar and the state of
6930c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * semantic analysis, what completions to provide. These completions are
694ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * returned via a new \c CXCodeCompleteResults structure.
6950c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6960c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Code completion itself is meant to be triggered by the client when the
6970c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * user types punctuation characters or whitespace, at which point the
6980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code-completion location will coincide with the cursor. For example, if \c p
6990c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * is a pointer, code-completion might be triggered after the "-" and then
7000c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * after the ">" in \c p->. When the code-completion location is afer the ">",
7010c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the completion results will provide, e.g., the members of the struct that
7020c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * "p" points to. The client is responsible for placing the cursor at the
7030c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * beginning of the token currently being typed, then filtering the results
7040c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * based on the contents of the token. For example, when code-completing for
7050c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the expression \c p->get, the client should provide the location just after
7060c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
7070c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * client can filter the results based on the current token text ("get"), only
7080c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * showing those results that start with "get". The intent of this interface
709ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * is to separate the relatively high-latency acquisition of code-completion
7100c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * results from the filtering of results on a per-character basis, which must
7110c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * have a lower latency.
7120c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
7130c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param CIdx the \c CXIndex instance that will be used to perform code
7140c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * completion.
7150c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
7168506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param source_filename the name of the source file that should be parsed to
7178506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * perform code-completion. This source file must be the same as or include the
7188506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * filename described by \p complete_filename, or no code-completion results
7198506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * will be produced.  NOTE: One can also specify NULL for this argument if the
7208506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * source file is included in command_line_args.
7210c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
7220c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param num_command_line_args the number of command-line arguments stored in
7230c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \p command_line_args.
7240c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
7250c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param command_line_args the command-line arguments to pass to the Clang
7260c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * compiler to build the given source file. This should include all of the
7270c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * necessary include paths, language-dialect switches, precompiled header
7280c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * includes, etc., but should not include any information specific to
7290c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code completion.
7300c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
731735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * \param num_unsaved_files the number of unsaved file entries in \p
732735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * unsaved_files.
733735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor *
734735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * \param unsaved_files the files that have not yet been saved to disk
735735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * but may be required for code completion, including the contents of
736735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * those files.
737735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor *
7380c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param complete_filename the name of the source file where code completion
7390c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * should be performed. In many cases, this name will be the same as the
7400c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * source filename. However, the completion filename may also be a file
7410c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * included by the source file, which is required when producing
7420c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code-completion results for a header.
7430c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
7440c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param complete_line the line at which code-completion should occur.
7450c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
7460c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param complete_column the column at which code-completion should occur.
7470c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Note that the column should point just after the syntactic construct that
7480c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * initiated code completion, and not in the middle of a lexical token.
7490c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
750ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \returns if successful, a new CXCodeCompleteResults structure
751ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * containing code-completion results, which should eventually be
752ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * freed with \c clang_disposeCodeCompleteResults(). If code
753ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * completion fails, returns NULL.
754ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor */
755ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas GregorCINDEX_LINKAGE
756ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas GregorCXCodeCompleteResults *clang_codeComplete(CXIndex CIdx,
757ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          const char *source_filename,
758ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          int num_command_line_args,
759ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          const char **command_line_args,
760ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          unsigned num_unsaved_files,
761ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          struct CXUnsavedFile *unsaved_files,
762ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          const char *complete_filename,
763ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          unsigned complete_line,
764ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          unsigned complete_column);
765ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor
766ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor/**
767ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \brief Free the given set of code-completion results.
7680c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
769ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas GregorCINDEX_LINKAGE
770ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregorvoid clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
7710c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
772d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#ifdef __cplusplus
773d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek}
774d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#endif
775d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#endif
776d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek
777