Index.h revision ec6762c709726bf2ee5f76c21df81e71a56e6f81
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);
3252e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE const char *clang_getURI(CXEntity);
3262e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXEntity clang_getEntity(const char *URI);
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
33850398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff/*
33950398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff * CXCursor Operations.
34050398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff */
3416a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff/**
3426a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff   Usage: clang_getCursor() will translate a source/line/column position
3436a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff   into an AST cursor (to derive semantic information from the source code).
3446a6de8b4fc944ca1bfa4e47c516d049a0d627b0eSteve Naroff */
3458506dde586459887b7e14e23a30af8ac5be5adb6Daniel DunbarCINDEX_LINKAGE CXCursor clang_getCursor(CXTranslationUnit,
3468506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar                                        const char *source_name,
3478506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar                                        unsigned line, unsigned column);
348738855554394a6afcf39cc8345fd22c3756b8dd0Ted Kremenek
349738855554394a6afcf39cc8345fd22c3756b8dd0Ted KremenekCINDEX_LINKAGE CXCursor clang_getNullCursor(void);
350fbcb2b716bee88c754684bd189913ed9f8c09086Ted Kremenek
3512e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
3522e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
3532e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
3542e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_isDefinition(enum CXCursorKind);
3552e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
356600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
357738855554394a6afcf39cc8345fd22c3756b8dd0Ted KremenekCINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);
358738855554394a6afcf39cc8345fd22c3756b8dd0Ted Kremenek
3592e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_getCursorLine(CXCursor);
3602e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE unsigned clang_getCursorColumn(CXCursor);
361ef0cef6cec8de5fc60e469a93436eed7212e0dc2Steve NaroffCINDEX_LINKAGE CXString clang_getCursorSpelling(CXCursor);
36288145034694ed5267fa6fa5febc54fadc02bd479Steve NaroffCINDEX_LINKAGE const char *clang_getCursorSource(CXCursor); /* deprecate */
36388145034694ed5267fa6fa5febc54fadc02bd479Steve NaroffCINDEX_LINKAGE CXFile clang_getCursorSourceFile(CXCursor);
364f334b4e3eda5a39f041fe13f805dbb53535daa2fSteve Naroff
3654ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff/* for debug/testing */
3662e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE const char *clang_getCursorKindSpelling(enum CXCursorKind Kind);
3672e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE void clang_getDefinitionSpellingAndExtent(CXCursor,
3684ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          const char **startBuf,
3694ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          const char **endBuf,
3704ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *startLine,
3714ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *startColumn,
3724ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *endLine,
3734ade6d6eae934f796ca43c81a5aa185e456dde9bSteve Naroff                                          unsigned *endColumn);
374600866cc7d6d9ec2e27d4b6d6ec461f6463b5ab6Steve Naroff
37550398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff/*
376459789b8d2e3235e2f3342c393b7a78bd73c1347Chris Lattner * If CXCursorKind == Cursor_Reference, then this will return the referenced
377459789b8d2e3235e2f3342c393b7a78bd73c1347Chris Lattner * declaration.
37850398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff * If CXCursorKind == Cursor_Declaration, then this will return the declaration.
37950398199fb10e196a8d92fbf7a062dbe42ed88fdSteve Naroff */
3802e06fc877a633abea3b40a64950c7316dac29ca8John ThompsonCINDEX_LINKAGE CXDecl clang_getCursorDecl(CXCursor);
381d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek
3820c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
3830c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A semantic string that describes a code-completion result.
3840c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
3850c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * A semantic string that describes the formatting of a code-completion
3860c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * result as a single "template" of text that should be inserted into the
3870c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * source buffer when a particular code-completion result is selected.
3880c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Each semantic string is made up of some number of "chunks", each of which
3890c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * contains some text along with a description of what that text means, e.g.,
3900c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the name of the entity being referenced, whether the text chunk is part of
3910c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the template, or whether it is a "placeholder" that the user should replace
3920c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * with actual code,of a specific kind. See \c CXCompletionChunkKind for a
3930c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * description of the different kinds of chunks.
3940c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
3950c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregortypedef void *CXCompletionString;
3960c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
3970c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
3980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief A single result of code completion.
3990c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
4000c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregortypedef struct {
4010c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
4020c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief The kind of entity that this completion refers to.
4030c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4040c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * The cursor kind will be a macro, keyword, or a declaration (one of the
4050c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * *Decl cursor kinds), describing the entity that the completion is
4060c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * referring to.
4070c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4080c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \todo In the future, we would like to provide a full cursor, to allow
4090c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * the client to extract additional information from declaration.
4100c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
4110c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  enum CXCursorKind CursorKind;
4120c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
4130c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
4140c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief The code-completion string that describes how to insert this
4150c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * code-completion result into the editing buffer.
4160c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
4170c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionString CompletionString;
4180c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor} CXCompletionResult;
4190c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
4200c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
4210c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Describes a single piece of text within a code-completion string.
4220c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
4230c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Each "chunk" within a code-completion string (\c CXCompletionString) is
4240c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * either a piece of text with a specific "kind" that describes how that text
4250c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * should be interpreted by the client or is another completion string.
4260c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
4270c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorenum CXCompletionChunkKind {
4280c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
4290c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A code-completion string that describes "optional" text that
4300c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * could be a part of the template (but is not required).
4310c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4320c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * The Optional chunk is the only kind of chunk that has a code-completion
4330c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * string for its representation, which is accessible via
4340c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \c clang_getCompletionChunkCompletionString(). The code-completion string
4350c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * describes an additional part of the template that is completely optional.
4360c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * For example, optional chunks can be used to describe the placeholders for
4370c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * arguments that match up with defaulted function parameters, e.g. given:
4380c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4390c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \code
4400c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * void f(int x, float y = 3.14, double z = 2.71828);
4410c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \endcode
4420c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4430c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * The code-completion string for this function would contain:
4440c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - a TypedText chunk for "f".
4450c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - a LeftParen chunk for "(".
4460c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - a Placeholder chunk for "int x"
4470c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - an Optional chunk containing the remaining defaulted arguments, e.g.,
4480c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *       - a Comma chunk for ","
4490c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *       - a Placeholder chunk for "float x"
4500c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *       - an Optional chunk containing the last defaulted argument:
4510c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *           - a Comma chunk for ","
4520c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *           - a Placeholder chunk for "double z"
4530c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - a RightParen chunk for ")"
4540c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4550c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * There are many ways two handle Optional chunks. Two simple approaches are:
4560c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - Completely ignore optional chunks, in which case the template for the
4570c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *     function "f" would only include the first parameter ("int x").
4580c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *   - Fully expand all optional chunks, in which case the template for the
4590c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *     function "f" would have all of the parameters.
4600c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
4610c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_Optional,
4620c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
4630c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Text that a user would be expected to type to get this
4640c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * code-completion result.
4650c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4660c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * There will be exactly one "typed text" chunk in a semantic string, which
4670c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * will typically provide the spelling of a keyword or the name of a
4680c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * declaration that could be used at the current code point. Clients are
4690c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * expected to filter the code-completion results based on the text in this
4700c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * chunk.
4710c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
4720c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_TypedText,
4730c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
4740c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Text that should be inserted as part of a code-completion result.
4750c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4760c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * A "text" chunk represents text that is part of the template to be
4770c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * inserted into user code should this particular code-completion result
4780c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * be selected.
4790c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
4800c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_Text,
4810c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
4820c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Placeholder text that should be replaced by the user.
4830c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4840c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * A "placeholder" chunk marks a place where the user should insert text
4850c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * into the code-completion template. For example, placeholders might mark
4860c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * the function parameters for a function declaration, to indicate that the
4870c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * user should provide arguments for each of those parameters. The actual
4880c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * text in a placeholder is a suggestion for the text to display before
4890c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * the user replaces the placeholder with real code.
4900c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
4910c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_Placeholder,
4920c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
4930c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Informative text that should be displayed but never inserted as
4940c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * part of the template.
4950c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
4960c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * An "informative" chunk contains annotations that can be displayed to
4970c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * help the user decide whether a particular code-completion result is the
4980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * right option, but which is not part of the actual template to be inserted
4990c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * by code completion.
5000c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5010c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_Informative,
5020c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5030c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief Text that describes the current parameter when code-completion is
5040c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * referring to function call, message send, or template specialization.
5050c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
5060c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * A "current parameter" chunk occurs when code-completion is providing
5070c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * information about a parameter corresponding to the argument at the
5080c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * code-completion point. For example, given a function
5090c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
5100c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \code
5110c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * int add(int x, int y);
5120c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \endcode
5130c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   *
5140c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * and the source code \c add(, where the code-completion point is after the
5150c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * "(", the code-completion string will contain a "current parameter" chunk
5160c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * for "int x", indicating that the current argument will initialize that
5170c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * parameter. After typing further, to \c add(17, (where the code-completion
5180c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * point is after the ","), the code-completion string will contain a
5190c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * "current paremeter" chunk to "int y".
5200c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5210c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_CurrentParameter,
5220c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5230c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A left parenthesis ('('), used to initiate a function call or
5240c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * signal the beginning of a function parameter list.
5250c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5260c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_LeftParen,
5270c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5280c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A right parenthesis (')'), used to finish a function call or
5290c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * signal the end of a function parameter list.
5300c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5310c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_RightParen,
5320c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5330c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A left bracket ('[').
5340c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5350c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_LeftBracket,
5360c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5370c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A right bracket (']').
5380c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5390c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_RightBracket,
5400c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5410c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A left brace ('{').
5420c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5430c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_LeftBrace,
5440c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5450c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A right brace ('}').
5460c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5470c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_RightBrace,
5480c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5490c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A left angle bracket ('<').
5500c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5510c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_LeftAngle,
5520c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5530c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A right angle bracket ('>').
5540c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5550c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_RightAngle,
5560c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  /**
5570c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   * \brief A comma separator (',').
5580c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor   */
5590c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor  CXCompletionChunk_Comma
5600c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor};
5610c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
5620c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
5630c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Determine the kind of a particular chunk within a completion string.
5640c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
5650c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param completion_string the completion string to query.
5660c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
5670c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param chunk_number the 0-based index of the chunk in the completion string.
5680c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
5690c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \returns the kind of the chunk at the index \c chunk_number.
5700c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
5710c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas GregorCINDEX_LINKAGE enum CXCompletionChunkKind
5720c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getCompletionChunkKind(CXCompletionString completion_string,
5730c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor                             unsigned chunk_number);
5740c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
5750c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
5760c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Retrieve the text associated with a particular chunk within a
5770c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * completion string.
5780c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
5790c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param completion_string the completion string to query.
5800c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
5810c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param chunk_number the 0-based index of the chunk in the completion string.
5820c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
5830c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \returns the text associated with the chunk at index \c chunk_number.
5840c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
5850c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas GregorCINDEX_LINKAGE const char *
5860c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getCompletionChunkText(CXCompletionString completion_string,
5870c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor                             unsigned chunk_number);
5880c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
5890c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
5900c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Retrieve the completion string associated with a particular chunk
5910c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * within a completion string.
5920c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
5930c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param completion_string the completion string to query.
5940c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
5950c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param chunk_number the 0-based index of the chunk in the completion string.
5960c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
5970c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \returns the completion string associated with the chunk at index
5980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \c chunk_number, or NULL if that chunk is not represented by a completion
5990c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * string.
6000c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
6010c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas GregorCINDEX_LINKAGE CXCompletionString
6020c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getCompletionChunkCompletionString(CXCompletionString completion_string,
6030c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor                                         unsigned chunk_number);
6040c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
6050c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
6060c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Retrieve the number of chunks in the given code-completion string.
6070c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
6080c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas GregorCINDEX_LINKAGE unsigned
6090c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregorclang_getNumCompletionChunks(CXCompletionString completion_string);
6100c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
6110c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor/**
612ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \brief Contains the results of code-completion.
613ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor *
614ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * This data structure contains the results of code completion, as
615ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * produced by \c clang_codeComplete. Its contents must be freed by
616ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \c clang_disposeCodeCompleteResults.
617ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor */
618ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregortypedef struct {
619ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor  /**
620ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   * \brief The code-completion results.
621ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   */
622ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor  CXCompletionResult *Results;
623ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor
624ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor  /**
625ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   * \brief The number of code-completion results stored in the
626ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   * \c Results array.
627ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor   */
628ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor  unsigned NumResults;
629ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor} CXCodeCompleteResults;
630ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor
631ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor/**
6320c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \brief Perform code completion at a given location in a source file.
6330c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6340c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * This function performs code completion at a particular file, line, and
6350c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * column within source code, providing results that suggest potential
6360c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code snippets based on the context of the completion. The basic model
6370c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * for code completion is that Clang will parse a complete source file,
6380c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * performing syntax checking up to the location where code-completion has
6390c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * been requested. At that point, a special code-completion token is passed
6400c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * to the parser, which recognizes this token and determines, based on the
6410c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * current location in the C/Objective-C/C++ grammar and the state of
6420c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * semantic analysis, what completions to provide. These completions are
643ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * returned via a new \c CXCodeCompleteResults structure.
6440c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6450c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Code completion itself is meant to be triggered by the client when the
6460c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * user types punctuation characters or whitespace, at which point the
6470c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code-completion location will coincide with the cursor. For example, if \c p
6480c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * is a pointer, code-completion might be triggered after the "-" and then
6490c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * after the ">" in \c p->. When the code-completion location is afer the ">",
6500c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the completion results will provide, e.g., the members of the struct that
6510c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * "p" points to. The client is responsible for placing the cursor at the
6520c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * beginning of the token currently being typed, then filtering the results
6530c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * based on the contents of the token. For example, when code-completing for
6540c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the expression \c p->get, the client should provide the location just after
6550c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * the ">" (e.g., pointing at the "g") to this code-completion hook. Then, the
6560c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * client can filter the results based on the current token text ("get"), only
6570c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * showing those results that start with "get". The intent of this interface
658ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * is to separate the relatively high-latency acquisition of code-completion
6590c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * results from the filtering of results on a per-character basis, which must
6600c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * have a lower latency.
6610c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6620c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param CIdx the \c CXIndex instance that will be used to perform code
6630c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * completion.
6640c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6658506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * \param source_filename the name of the source file that should be parsed to
6668506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * perform code-completion. This source file must be the same as or include the
6678506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * filename described by \p complete_filename, or no code-completion results
6688506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * will be produced.  NOTE: One can also specify NULL for this argument if the
6698506dde586459887b7e14e23a30af8ac5be5adb6Daniel Dunbar * source file is included in command_line_args.
6700c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6710c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param num_command_line_args the number of command-line arguments stored in
6720c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \p command_line_args.
6730c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6740c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param command_line_args the command-line arguments to pass to the Clang
6750c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * compiler to build the given source file. This should include all of the
6760c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * necessary include paths, language-dialect switches, precompiled header
6770c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * includes, etc., but should not include any information specific to
6780c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code completion.
6790c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
680735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * \param num_unsaved_files the number of unsaved file entries in \p
681735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * unsaved_files.
682735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor *
683735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * \param unsaved_files the files that have not yet been saved to disk
684735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * but may be required for code completion, including the contents of
685735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor * those files.
686735df88a38e80c1ca70daa889aa516b8b9f54b50Douglas Gregor *
6870c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param complete_filename the name of the source file where code completion
6880c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * should be performed. In many cases, this name will be the same as the
6890c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * source filename. However, the completion filename may also be a file
6900c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * included by the source file, which is required when producing
6910c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * code-completion results for a header.
6920c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6930c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param complete_line the line at which code-completion should occur.
6940c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
6950c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * \param complete_column the column at which code-completion should occur.
6960c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * Note that the column should point just after the syntactic construct that
6970c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor * initiated code completion, and not in the middle of a lexical token.
6980c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor *
699ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \returns if successful, a new CXCodeCompleteResults structure
700ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * containing code-completion results, which should eventually be
701ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * freed with \c clang_disposeCodeCompleteResults(). If code
702ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * completion fails, returns NULL.
703ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor */
704ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas GregorCINDEX_LINKAGE
705ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas GregorCXCodeCompleteResults *clang_codeComplete(CXIndex CIdx,
706ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          const char *source_filename,
707ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          int num_command_line_args,
708ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          const char **command_line_args,
709ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          unsigned num_unsaved_files,
710ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          struct CXUnsavedFile *unsaved_files,
711ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          const char *complete_filename,
712ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          unsigned complete_line,
713ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor                                          unsigned complete_column);
714ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor
715ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor/**
716ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregor * \brief Free the given set of code-completion results.
7170c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor */
718ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas GregorCINDEX_LINKAGE
719ec6762c709726bf2ee5f76c21df81e71a56e6f81Douglas Gregorvoid clang_disposeCodeCompleteResults(CXCodeCompleteResults *Results);
7200c8296dfb495f41d6f0de6fe1d03014ffd063674Douglas Gregor
721d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#ifdef __cplusplus
722d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek}
723d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#endif
724d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek#endif
725d2fa56687f8bd5ac6ebf9d9468d0efd714986a54Ted Kremenek
726