Index.h revision fe6fd3d41a7f48317d6856c9327b6cead32c3498
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;
14089922f86f4e7da383af2a62ef04ad8b93b941220Steve Naroff  CXDecl decl;
141fb5704295c6137685a7b90b92cd6b958028740c8Steve Naroff  CXStmt stmt; /* expression reference */
14289922f86f4e7da383af2a62ef04ad8b93b941220Steve Naroff} CXCursor;
143600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
14450398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff/* A unique token for looking up "visible" CXDecls from a CXTranslationUnit. */
145e56b4baeba5097852e04bc41ca2e0396cf729955Steve Narofftypedef void *CXEntity;
146600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
147ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff/**
148ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff * For functions returning a string that might or might not need
149ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff * to be internally allocated and freed.
150ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff * Use clang_getCString to access the C string value.
151ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff * Use clang_disposeString to free the value.
152ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff * Treat it as an opaque type.
153ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff */
154ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Narofftypedef struct {
155ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff  const char *Spelling;
156ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff  /* A 1 value indicates the clang_ indexing API needed to allocate the string
157ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff     (and it must be freed by clang_disposeString()). */
158ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff  int MustFreeString;
159ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff} CXString;
160ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff
161ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff/* Get C string pointer from a CXString. */
162ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve NaroffCINDEX_LINKAGE const char *clang_getCString(CXString string);
163ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff
164ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff/* Free CXString. */
165ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve NaroffCINDEX_LINKAGE void clang_disposeString(CXString string);
166ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve Naroff
167e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff/**
168e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * \brief clang_createIndex() provides a shared context for creating
169e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * translation units. It provides two options:
170e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff *
171e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * - excludeDeclarationsFromPCH: When non-zero, allows enumeration of "local"
172e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * declarations (when loading any new translation units). A "local" declaration
173e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * is one that belongs in the translation unit itself and not in a precompiled
174e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * header that was used by the translation unit. If zero, all declarations
175e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * will be enumerated.
176e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff *
177e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * - displayDiagnostics: when non-zero, diagnostics will be output. If zero,
178e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * diagnostics will be ignored.
179b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
180b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * Here is an example:
181b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
182b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // excludeDeclsFromPCH = 1, displayDiagnostics = 1
183b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   Idx = clang_createIndex(1, 1);
184b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
185b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // IndexTest.pch was produced with the following command:
186b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // "clang -x c IndexTest.h -emit-ast -o IndexTest.pch"
187b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   TU = clang_createTranslationUnit(Idx, "IndexTest.pch");
188b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
189b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // This will load all the symbols from 'IndexTest.pch'
190b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0);
191b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   clang_disposeTranslationUnit(TU);
192b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
193b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // This will load all the symbols from 'IndexTest.c', excluding symbols
194b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   // from 'IndexTest.pch'.
195b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   char *args[] = { "-Xclang", "-include-pch=IndexTest.pch", 0 };
196b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   TU = clang_createTranslationUnitFromSourceFile(Idx, "IndexTest.c", 2, args);
197b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0);
198b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *   clang_disposeTranslationUnit(TU);
199b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff *
200b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * This process of creating the 'pch', loading it separately, and using it (via
201b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * -include-pch) allows 'excludeDeclsFromPCH' to remove redundant callbacks
202b4ece6377d95e35a8df01cd010d910c34d690f67Steve Naroff * (which gives the indexer the same performance benefit as the compiler).
203e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff */
2042e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXIndex clang_createIndex(int excludeDeclarationsFromPCH,
205e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff                          int displayDiagnostics);
2068506dde586459887b7e14e23a30af8ac5be5adb6Daniel DunbarCINDEX_LINKAGE void clang_disposeIndex(CXIndex index);
2078506dde586459887b7e14e23a30af8ac5be5adb6Daniel DunbarCINDEX_LINKAGE CXString
2088506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbarclang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
2098506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar
2108506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar/*
2118506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \brief Request that AST's be generated external for API calls which parse
2128506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * source code on the fly, e.g. \see createTranslationUnitFromSourceFile.
2138506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar *
2148506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * Note: This is for debugging purposes only, and may be removed at a later
2158506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * date.
2168506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar *
2178506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param index - The index to update.
2188506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param value - The new flag value.
2198506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar */
2208506dde586459887b7e14e23a30af8ac5be5adb6Daniel DunbarCINDEX_LINKAGE void clang_setUseExternalASTGeneration(CXIndex index,
2218506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar                                                      int value);
222af08ddc8f1c53fed8d8d0ad82aa2a0bb7d654bd1Steve Naroff
223e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff/*
224e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * \brief Create a translation unit from an AST file (-emit-ast).
225e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff */
2262e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnit(
227e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff  CXIndex, const char *ast_filename
228600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff);
2298506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar
2301374598619f83e6b2de91341a326eae564ece2cbTed Kremenek/**
2311374598619f83e6b2de91341a326eae564ece2cbTed Kremenek * \brief Destroy the specified CXTranslationUnit object.
2321374598619f83e6b2de91341a326eae564ece2cbTed Kremenek */
2332e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE void clang_disposeTranslationUnit(CXTranslationUnit);
2341374598619f83e6b2de91341a326eae564ece2cbTed Kremenek
2351374598619f83e6b2de91341a326eae564ece2cbTed Kremenek/**
236e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * \brief Return the CXTranslationUnit for a given source file and the provided
237e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff * command line arguments one would pass to the compiler.
238e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff *
2398506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * Note: The 'source_filename' argument is optional.  If the caller provides a
2408506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * NULL pointer, the name of the source file is expected to reside in the
2418506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * specified command line arguments.
242139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *
2438506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * Note: When encountered in 'clang_command_line_args', the following options
2448506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * are ignored:
245139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *
246139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *   '-c'
247139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *   '-emit-ast'
248139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *   '-fsyntax-only'
249139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *   '-o <output file>'  (both '-o' and '<output file>' are ignored)
250139ba86a362593da2e350f881e5c7003917aa5a7Ted Kremenek *
2518506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar *
2528506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param source_filename - The name of the source file to load, or NULL if the
2538506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * source file is included in clang_command_line_args.
2541374598619f83e6b2de91341a326eae564ece2cbTed Kremenek */
2552e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXTranslationUnit clang_createTranslationUnitFromSourceFile(
2568506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar  CXIndex CIdx,
2578506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar  const char *source_filename,
2585b7d8e254f6c2855b37b5521c0aee0a560dab237Steve Naroff  int num_clang_command_line_args,
259e56b4baeba5097852e04bc41ca2e0396cf729955Steve Naroff  const char **clang_command_line_args
2605b7d8e254f6c2855b37b5521c0aee0a560dab237Steve Naroff);
261600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
262600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff/*
263600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   Usage: clang_loadTranslationUnit(). Will load the toplevel declarations
264600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   within a translation unit, issuing a 'callback' for each one.
265600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
266600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   void printObjCInterfaceNames(CXTranslationUnit X, CXCursor C) {
267600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff     if (clang_getCursorKind(C) == Cursor_Declaration) {
268600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff       CXDecl D = clang_getCursorDecl(C);
269600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff       if (clang_getDeclKind(D) == CXDecl_ObjC_interface)
270600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff         printf("@interface %s in file %s on line %d column %d\n",
271600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff                clang_getDeclSpelling(D), clang_getCursorSource(C),
272600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff                clang_getCursorLine(C), clang_getCursorColumn(C));
273600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff     }
274600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   }
275600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   static void usage {
276600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff     clang_loadTranslationUnit(CXTranslationUnit, printObjCInterfaceNames);
2778506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar  }
278600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff*/
2792b8ee6c2994f738e5162ff46b638974870f51662Steve Narofftypedef void *CXClientData;
2802b8ee6c2994f738e5162ff46b638974870f51662Steve Narofftypedef void (*CXTranslationUnitIterator)(CXTranslationUnit, CXCursor,
2812b8ee6c2994f738e5162ff46b638974870f51662Steve Naroff                                          CXClientData);
2828506dde586459887b7e14e23a30af8ac5be5adb6Daniel DunbarCINDEX_LINKAGE void clang_loadTranslationUnit(CXTranslationUnit,
2838506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar                                              CXTranslationUnitIterator,
2848506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar                                              CXClientData);
285600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
286600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff/*
287600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   Usage: clang_loadDeclaration(). Will load the declaration, issuing a
288600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   'callback' for each declaration/reference within the respective declaration.
289600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
290600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   For interface declarations, this will index the super class, protocols,
291600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   ivars, methods, etc. For structure declarations, this will index the fields.
292600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   For functions, this will index the parameters (and body, for function
293600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   definitions), local declarations/references.
294600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
295600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   void getInterfaceDetails(CXDecl X, CXCursor C) {
296600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff     switch (clang_getCursorKind(C)) {
297600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff       case Cursor_ObjC_ClassRef:
298600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff         CXDecl SuperClass = clang_getCursorDecl(C);
299600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff       case Cursor_ObjC_ProtocolRef:
300600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff         CXDecl AdoptsProtocol = clang_getCursorDecl(C);
301600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff       case Cursor_Declaration:
302600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff         CXDecl AnIvarOrMethod = clang_getCursorDecl(C);
303600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff     }
304600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   }
305600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   static void usage() {
306600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff     if (clang_getDeclKind(D) == CXDecl_ObjC_interface) {
307600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff       clang_loadDeclaration(D, getInterfaceDetails);
308600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff     }
309600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff   }
310600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff*/
311c857ea4d22e1e6dd9ede1f0e84d48b157c6924fdSteve Narofftypedef void (*CXDeclIterator)(CXDecl, CXCursor, CXClientData);
31289922f86f4e7da383af2a62ef04ad8b93b941220Steve Naroff
3132e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE void clang_loadDeclaration(CXDecl, CXDeclIterator, CXClientData);
314600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
31550398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff/*
31688145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff * CXFile Operations.
31788145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff */
31808b0e8daeb683686b876d72674962ad96df21d45Douglas GregorCINDEX_LINKAGE const char *clang_getFileName(CXFile SFile);
31908b0e8daeb683686b876d72674962ad96df21d45Douglas GregorCINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
32088145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff
32188145034694ed5267fa6fa5febc54fadc02bd479Steve Naroff/*
32250398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff * CXEntity Operations.
32350398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff */
3242e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE const char *clang_getDeclarationName(CXEntity);
3251b6869a1831ef66b5024dd23160dc9519c99555dTed KremenekCINDEX_LINKAGE const char *clang_getUSR(CXEntity);
3261b6869a1831ef66b5024dd23160dc9519c99555dTed KremenekCINDEX_LINKAGE CXEntity clang_getEntity(const char *USR);
32750398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff/*
32850398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff * CXDecl Operations.
32950398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff */
3302e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXCursor clang_getCursorFromDecl(CXDecl);
3312e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXEntity clang_getEntityFromDecl(CXDecl);
332ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve NaroffCINDEX_LINKAGE CXString clang_getDeclSpelling(CXDecl);
3332e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_getDeclLine(CXDecl);
3342e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_getDeclColumn(CXDecl);
33588145034694ed5267fa6fa5febc54fadc02bd479Steve NaroffCINDEX_LINKAGE const char *clang_getDeclSource(CXDecl); /* deprecate */
33688145034694ed5267fa6fa5febc54fadc02bd479Steve NaroffCINDEX_LINKAGE CXFile clang_getDeclSourceFile(CXDecl);
337699a07d8a0b1579c5178b3baf4bcf9edb6b38108Steve Naroff
338fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenektypedef struct CXSourceLineColumn {
339fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek  unsigned line;
340fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek  unsigned column;
341fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek} CXSourceLineColumn;
342fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek
343fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenektypedef struct CXDeclExtent {
344fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek  CXSourceLineColumn begin;
345fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek  CXSourceLineColumn end;
346fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek} CXSourceExtent;
347fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek
348fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek/* clang_getDeclExtent() returns the physical extent of a declaration.  The beginning
349fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek * line/column pair points to the start of the first token in the declaration, and the
350fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek * ending line/column pair points the start of the last token in the declaration.
351fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek */
352fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted KremenekCXSourceExtent clang_getDeclExtent(CXDecl);
353fe6fd3d41a7f48317d6856c9327b6cead32c3498Ted Kremenek
35450398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff/*
35550398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff * CXCursor Operations.
35650398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff */
3576a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff/**
3586a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff   Usage: clang_getCursor() will translate a source/line/column position
3596a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff   into an AST cursor (to derive semantic information from the source code).
3606a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff */
3618506dde586459887b7e14e23a30af8ac5be5adb6Daniel DunbarCINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit,
3628506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar                                        const char *source_name,
3638506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar                                        unsigned line, unsigned column);
364738855554394a6afcf39cc8345fd22c3756b8dd0Ted Kremenek
365738855554394a6afcf39cc8345fd22c3756b8dd0Ted KremenekCINDEX_LINKAGE CXCursor clang_getNullCursor(void);
366fbcb2b716bee88c754684bd189913ed9f8c09086Ted Kremenek
3672e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
3682e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
3692e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
3702e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_isDefinition(enum CXCursorKind);
3712e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
372600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
373738855554394a6afcf39cc8345fd22c3756b8dd0Ted KremenekCINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
374738855554394a6afcf39cc8345fd22c3756b8dd0Ted Kremenek
3752e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_getCursorLine(CXCursor);
3762e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_getCursorColumn(CXCursor);
377ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve NaroffCINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
37888145034694ed5267fa6fa5febc54fadc02bd479Steve NaroffCINDEX_LINKAGE const char *clang_getCursorSource(CXCursor); /* deprecate */
37988145034694ed5267fa6fa5febc54fadc02bd479Steve NaroffCINDEX_LINKAGE CXFile clang_getCursorSourceFile(CXCursor);
380f334b4e3eda5a39f041fe13f805dbb53535daa2fSteve Naroff
3814ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff/* for debug/testing */
3822e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE const char *clang_getCursorKindSpelling(enum CXCursorKind Kind);
3832e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
3844ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          const char **startBuf,
3854ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          const char **endBuf,
3864ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *startLine,
3874ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *startColumn,
3884ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *endLine,
3894ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *endColumn);
390600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
39150398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff/*
392459789b8d2e3235e2f3342c393b7a78bd73c1347Chris Lattner * If CXCursorKind == Cursor_Reference, then this will return the referenced
393459789b8d2e3235e2f3342c393b7a78bd73c1347Chris Lattner * declaration.
39450398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff * If CXCursorKind == Cursor_Declaration, then this will return the declaration.
39550398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff */
3962e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXDecl clang_getCursorDecl(CXCursor);
397d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek
3980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
3990c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A semantic string that describes a code-completion result.
4000c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
4010c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * A semantic string that describes the formatting of a code-completion
4020c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * result as a single "template" of text that should be inserted into the
4030c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * source buffer when a particular code-completion result is selected.
4040c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Each semantic string is made up of some number of "chunks", each of which
4050c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * contains some text along with a description of what that text means, e.g.,
4060c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the name of the entity being referenced, whether the text chunk is part of
4070c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the template, or whether it is a "placeholder" that the user should replace
4080c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
4090c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * description of the different kinds of chunks.
4100c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
4110c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregortypedef void *CXCompletionString;
4120c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
4130c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
4140c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A single result of code completion.
4150c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
4160c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregortypedef struct {
4170c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
4180c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief The kind of entity that this completion refers to.
4190c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4200c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * The cursor kind will be a macro, keyword, or a declaration (one of the
4210c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * *Decl cursor kinds), describing the entity that the completion is
4220c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * referring to.
4230c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4240c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \todo In the future, we would like to provide a full cursor, to allow
4250c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * the client to extract additional information from declaration.
4260c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
4270c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  enum CXCursorKind CursorKind;
4280c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
4290c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
4300c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief The code-completion string that describes how to insert this
4310c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * code-completion result into the editing buffer.
4320c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
4330c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionString CompletionString;
4340c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor} CXCompletionResult;
4350c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
4360c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
4370c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Describes a single piece of text within a code-completion string.
4380c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
4390c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Each "chunk" within a code-completion string (\c CXCompletionString) is
4400c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * either a piece of text with a specific "kind" that describes how that text
4410c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * should be interpreted by the client or is another completion string.
4420c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
4430c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorenum CXCompletionChunkKind {
4440c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
4450c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A code-completion string that describes "optional" text that
4460c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * could be a part of the template (but is not required).
4470c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4480c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * The Optional chunk is the only kind of chunk that has a code-completion
4490c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * string for its representation, which is accessible via
4500c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \c clang_getCompletionChunkCompletionString(). The code-completion string
4510c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * describes an additional part of the template that is completely optional.
4520c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * For example, optional chunks can be used to describe the placeholders for
4530c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * arguments that match up with defaulted function parameters, e.g. given:
4540c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4550c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \code
4560c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * void f(int x, float y = 3.14, double z = 2.71828);
4570c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \endcode
4580c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4590c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * The code-completion string for this function would contain:
4600c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - a TypedText chunk for "f".
4610c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - a LeftParen chunk for "(".
4620c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - a Placeholder chunk for "int x"
4630c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - an Optional chunk containing the remaining defaulted arguments, e.g.,
4640c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *       - a Comma chunk for ","
4650c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *       - a Placeholder chunk for "float x"
4660c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *       - an Optional chunk containing the last defaulted argument:
4670c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *           - a Comma chunk for ","
4680c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *           - a Placeholder chunk for "double z"
4690c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - a RightParen chunk for ")"
4700c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4710c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * There are many ways two handle Optional chunks. Two simple approaches are:
4720c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - Completely ignore optional chunks, in which case the template for the
4730c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *     function "f" would only include the first parameter ("int x").
4740c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - Fully expand all optional chunks, in which case the template for the
4750c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *     function "f" would have all of the parameters.
4760c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
4770c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_Optional,
4780c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
4790c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Text that a user would be expected to type to get this
4800c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * code-completion result.
4810c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4820c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * There will be exactly one "typed text" chunk in a semantic string, which
4830c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * will typically provide the spelling of a keyword or the name of a
4840c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * declaration that could be used at the current code point. Clients are
4850c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * expected to filter the code-completion results based on the text in this
4860c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * chunk.
4870c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
4880c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_TypedText,
4890c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
4900c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Text that should be inserted as part of a code-completion result.
4910c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4920c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * A "text" chunk represents text that is part of the template to be
4930c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * inserted into user code should this particular code-completion result
4940c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * be selected.
4950c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
4960c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_Text,
4970c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
4980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Placeholder text that should be replaced by the user.
4990c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
5000c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * A "placeholder" chunk marks a place where the user should insert text
5010c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * into the code-completion template. For example, placeholders might mark
5020c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * the function parameters for a function declaration, to indicate that the
5030c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * user should provide arguments for each of those parameters. The actual
5040c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * text in a placeholder is a suggestion for the text to display before
5050c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * the user replaces the placeholder with real code.
5060c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5070c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_Placeholder,
5080c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5090c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Informative text that should be displayed but never inserted as
5100c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * part of the template.
5110c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
5120c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * An "informative" chunk contains annotations that can be displayed to
5130c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * help the user decide whether a particular code-completion result is the
5140c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * right option, but which is not part of the actual template to be inserted
5150c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * by code completion.
5160c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5170c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_Informative,
5180c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5190c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Text that describes the current parameter when code-completion is
5200c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * referring to function call, message send, or template specialization.
5210c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
5220c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * A "current parameter" chunk occurs when code-completion is providing
5230c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * information about a parameter corresponding to the argument at the
5240c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * code-completion point. For example, given a function
5250c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
5260c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \code
5270c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * int add(int x, int y);
5280c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \endcode
5290c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
5300c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * and the source code \c add(, where the code-completion point is after the
5310c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * "(", the code-completion string will contain a "current parameter" chunk
5320c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * for "int x", indicating that the current argument will initialize that
5330c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * parameter. After typing further, to \c add(17, (where the code-completion
5340c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * point is after the ","), the code-completion string will contain a
5350c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * "current paremeter" chunk to "int y".
5360c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5370c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_CurrentParameter,
5380c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5390c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A left parenthesis ('('), used to initiate a function call or
5400c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * signal the beginning of a function parameter list.
5410c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5420c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_LeftParen,
5430c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5440c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A right parenthesis (')'), used to finish a function call or
5450c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * signal the end of a function parameter list.
5460c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5470c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_RightParen,
5480c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5490c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A left bracket ('[').
5500c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5510c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_LeftBracket,
5520c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5530c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A right bracket (']').
5540c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5550c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_RightBracket,
5560c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5570c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A left brace ('{').
5580c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5590c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_LeftBrace,
5600c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5610c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A right brace ('}').
5620c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5630c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_RightBrace,
5640c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5650c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A left angle bracket ('<').
5660c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5670c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_LeftAngle,
5680c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5690c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A right angle bracket ('>').
5700c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5710c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_RightAngle,
5720c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5730c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A comma separator (',').
5740c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
575ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor  CXCompletionChunk_Comma,
576ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor  /**
577ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   * \brief Text that specifies the result type of a given result.
578ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   *
579ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   * This special kind of informative chunk is not meant to be inserted into
580ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   * the text buffer. Rather, it is meant to illustrate the type that an
581ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   * expression using the given completion string would have.
582ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor   */
583ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aaDouglas Gregor  CXCompletionChunk_ResultType
5840c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor};
5850c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
5860c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
5870c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Determine the kind of a particular chunk within a completion string.
5880c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
5890c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param completion_string the completion string to query.
5900c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
5910c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param chunk_number the 0-based index of the chunk in the completion string.
5920c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
5930c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \returns the kind of the chunk at the index \c chunk_number.
5940c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
5950c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas GregorCINDEX_LINKAGE enum CXCompletionChunkKind
5960c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getCompletionChunkKind(CXCompletionString completion_string,
5970c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor                             unsigned chunk_number);
5980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
5990c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
6000c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Retrieve the text associated with a particular chunk within a
6010c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * completion string.
6020c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6030c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param completion_string the completion string to query.
6040c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6050c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param chunk_number the 0-based index of the chunk in the completion string.
6060c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6070c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \returns the text associated with the chunk at index \c chunk_number.
6080c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
6090c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas GregorCINDEX_LINKAGE const char *
6100c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getCompletionChunkText(CXCompletionString completion_string,
6110c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor                             unsigned chunk_number);
6120c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
6130c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
6140c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Retrieve the completion string associated with a particular chunk
6150c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * within a completion string.
6160c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6170c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param completion_string the completion string to query.
6180c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6190c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param chunk_number the 0-based index of the chunk in the completion string.
6200c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6210c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \returns the completion string associated with the chunk at index
6220c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \c chunk_number, or NULL if that chunk is not represented by a completion
6230c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * string.
6240c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
6250c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas GregorCINDEX_LINKAGE CXCompletionString
6260c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getCompletionChunkCompletionString(CXCompletionString completion_string,
6270c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor                                         unsigned chunk_number);
6280c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
6290c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
6300c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Retrieve the number of chunks in the given code-completion string.
6310c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
6320c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas GregorCINDEX_LINKAGE unsigned
6330c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getNumCompletionChunks(CXCompletionString completion_string);
6340c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
6350c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
636ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \brief Contains the results of code-completion.
637ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor *
638ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * This data structure contains the results of code completion, as
639ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * produced by \c clang_codeComplete. Its contents must be freed by
640ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \c clang_disposeCodeCompleteResults.
641ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor */
642ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregortypedef struct {
643ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor  /**
644ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   * \brief The code-completion results.
645ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   */
646ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor  CXCompletionResult *Results;
647ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor
648ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor  /**
649ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   * \brief The number of code-completion results stored in the
650ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   * \c Results array.
651ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   */
652ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor  unsigned NumResults;
653ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor} CXCodeCompleteResults;
654ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor
655ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor/**
6560c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Perform code completion at a given location in a source file.
6570c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6580c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * This function performs code completion at a particular file, line, and
6590c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * column within source code, providing results that suggest potential
6600c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code snippets based on the context of the completion. The basic model
6610c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * for code completion is that Clang will parse a complete source file,
6620c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * performing syntax checking up to the location where code-completion has
6630c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * been requested. At that point, a special code-completion token is passed
6640c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * to the parser, which recognizes this token and determines, based on the
6650c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * current location in the C/Objective-C/C++ grammar and the state of
6660c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * semantic analysis, what completions to provide. These completions are
667ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * returned via a new \c CXCodeCompleteResults structure.
6680c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6690c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Code completion itself is meant to be triggered by the client when the
6700c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * user types punctuation characters or whitespace, at which point the
6710c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code-completion location will coincide with the cursor. For example, if \c p
6720c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * is a pointer, code-completion might be triggered after the "-" and then
6730c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * after the ">" in \c p->. When the code-completion location is afer the ">",
6740c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the completion results will provide, e.g., the members of the struct that
6750c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * "p" points to. The client is responsible for placing the cursor at the
6760c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * beginning of the token currently being typed, then filtering the results
6770c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * based on the contents of the token. For example, when code-completing for
6780c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the expression \c p->get, the client should provide the location just after
6790c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
6800c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * client can filter the results based on the current token text ("get"), only
6810c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * showing those results that start with "get". The intent of this interface
682ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * is to separate the relatively high-latency acquisition of code-completion
6830c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * results from the filtering of results on a per-character basis, which must
6840c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * have a lower latency.
6850c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6860c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param CIdx the \c CXIndex instance that will be used to perform code
6870c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * completion.
6880c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6898506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param source_filename the name of the source file that should be parsed to
6908506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * perform code-completion. This source file must be the same as or include the
6918506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * filename described by \p complete_filename, or no code-completion results
6928506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * will be produced.  NOTE: One can also specify NULL for this argument if the
6938506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * source file is included in command_line_args.
6940c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6950c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param num_command_line_args the number of command-line arguments stored in
6960c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \p command_line_args.
6970c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param command_line_args the command-line arguments to pass to the Clang
6990c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * compiler to build the given source file. This should include all of the
7000c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * necessary include paths, language-dialect switches, precompiled header
7010c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * includes, etc., but should not include any information specific to
7020c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code completion.
7030c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
704735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * \param num_unsaved_files the number of unsaved file entries in \p
705735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * unsaved_files.
706735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor *
707735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * \param unsaved_files the files that have not yet been saved to disk
708735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * but may be required for code completion, including the contents of
709735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * those files.
710735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor *
7110c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param complete_filename the name of the source file where code completion
7120c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * should be performed. In many cases, this name will be the same as the
7130c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * source filename. However, the completion filename may also be a file
7140c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * included by the source file, which is required when producing
7150c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code-completion results for a header.
7160c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
7170c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param complete_line the line at which code-completion should occur.
7180c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
7190c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param complete_column the column at which code-completion should occur.
7200c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Note that the column should point just after the syntactic construct that
7210c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * initiated code completion, and not in the middle of a lexical token.
7220c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
723ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \returns if successful, a new CXCodeCompleteResults structure
724ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * containing code-completion results, which should eventually be
725ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * freed with \c clang_disposeCodeCompleteResults(). If code
726ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * completion fails, returns NULL.
727ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor */
728ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas GregorCINDEX_LINKAGE
729ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas GregorCXCodeCompleteResults *clang_codeComplete(CXIndex CIdx,
730ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          const char *source_filename,
731ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          int num_command_line_args,
732ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          const char **command_line_args,
733ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          unsigned num_unsaved_files,
734ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          struct CXUnsavedFile *unsaved_files,
735ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          const char *complete_filename,
736ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          unsigned complete_line,
737ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          unsigned complete_column);
738ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor
739ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor/**
740ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \brief Free the given set of code-completion results.
7410c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
742ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas GregorCINDEX_LINKAGE
743ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregorvoid clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
7440c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
745d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#ifdef __cplusplus
746d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek}
747d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#endif
748d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#endif
749d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek
750