Bug Summary

File:build/llvm-toolchain-snapshot-16~++20220929111209+ac2e2d659819/clang/tools/c-index-test/c-index-test.c
Warning:line 2154, column 9
Null pointer passed to 1st parameter expecting 'nonnull'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name c-index-test.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/llvm-toolchain-snapshot-16~++20220929111209+ac2e2d659819/build-llvm/tools/clang/stage2-bins -resource-dir /usr/lib/llvm-16/lib/clang/16.0.0 -isystem /usr/include/libxml2 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I tools/clang/tools/c-index-test -I /build/llvm-toolchain-snapshot-16~++20220929111209+ac2e2d659819/clang/tools/c-index-test -I /build/llvm-toolchain-snapshot-16~++20220929111209+ac2e2d659819/clang/include -I tools/clang/include -I include -I /build/llvm-toolchain-snapshot-16~++20220929111209+ac2e2d659819/llvm/include -D _FORTIFY_SOURCE=2 -D NDEBUG -U NDEBUG -internal-isystem /usr/lib/llvm-16/lib/clang/16.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/build/llvm-toolchain-snapshot-16~++20220929111209+ac2e2d659819/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fmacro-prefix-map=/build/llvm-toolchain-snapshot-16~++20220929111209+ac2e2d659819/= -fcoverage-prefix-map=/build/llvm-toolchain-snapshot-16~++20220929111209+ac2e2d659819/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fcoverage-prefix-map=/build/llvm-toolchain-snapshot-16~++20220929111209+ac2e2d659819/= -O2 -Wno-unused-command-line-argument -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-comment -std=gnu89 -fconst-strings -fdebug-compilation-dir=/build/llvm-toolchain-snapshot-16~++20220929111209+ac2e2d659819/build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/llvm-toolchain-snapshot-16~++20220929111209+ac2e2d659819/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/llvm-toolchain-snapshot-16~++20220929111209+ac2e2d659819/= -ferror-limit 19 -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2022-09-29-125212-15910-1 -x c /build/llvm-toolchain-snapshot-16~++20220929111209+ac2e2d659819/clang/tools/c-index-test/c-index-test.c
1/* c-index-test.c */
2
3#include "clang/Config/config.h"
4#include "clang-c/Index.h"
5#include "clang-c/CXCompilationDatabase.h"
6#include "clang-c/BuildSystem.h"
7#include "clang-c/Documentation.h"
8#include <ctype.h>
9#include <stdlib.h>
10#include <stdio.h>
11#include <string.h>
12#include <assert.h>
13
14#ifdef CLANG_HAVE_LIBXML1
15#include <libxml/parser.h>
16#include <libxml/relaxng.h>
17#include <libxml/xmlerror.h>
18#endif
19
20#ifdef _WIN32
21# include <direct.h>
22#else
23# include <unistd.h>
24#endif
25
26extern int indextest_core_main(int argc, const char **argv);
27extern int indextest_perform_shell_execution(const char *command_line);
28
29/******************************************************************************/
30/* Utility functions. */
31/******************************************************************************/
32
33#ifdef _MSC_VER
34char *basename(const char* path)
35{
36 char* base1 = (char*)strrchr(path, '/');
37 char* base2 = (char*)strrchr(path, '\\');
38 if (base1 && base2)
39 return((base1 > base2) ? base1 + 1 : base2 + 1);
40 else if (base1)
41 return(base1 + 1);
42 else if (base2)
43 return(base2 + 1);
44
45 return((char*)path);
46}
47char *dirname(char* path)
48{
49 char* base1 = (char*)strrchr(path, '/');
50 char* base2 = (char*)strrchr(path, '\\');
51 if (base1 && base2)
52 if (base1 > base2)
53 *base1 = 0;
54 else
55 *base2 = 0;
56 else if (base1)
57 *base1 = 0;
58 else if (base2)
59 *base2 = 0;
60
61 return path;
62}
63#else
64extern char *basename(const char *);
65extern char *dirname(char *);
66#endif
67
68/** Return the default parsing options. */
69static unsigned getDefaultParsingOptions(void) {
70 unsigned options = CXTranslationUnit_DetailedPreprocessingRecord;
71
72 if (getenv("CINDEXTEST_EDITING"))
73 options |= clang_defaultEditingTranslationUnitOptions();
74 if (getenv("CINDEXTEST_COMPLETION_CACHING"))
75 options |= CXTranslationUnit_CacheCompletionResults;
76 if (getenv("CINDEXTEST_COMPLETION_NO_CACHING"))
77 options &= ~CXTranslationUnit_CacheCompletionResults;
78 if (getenv("CINDEXTEST_SKIP_FUNCTION_BODIES"))
79 options |= CXTranslationUnit_SkipFunctionBodies;
80 if (getenv("CINDEXTEST_COMPLETION_BRIEF_COMMENTS"))
81 options |= CXTranslationUnit_IncludeBriefCommentsInCodeCompletion;
82 if (getenv("CINDEXTEST_CREATE_PREAMBLE_ON_FIRST_PARSE"))
83 options |= CXTranslationUnit_CreatePreambleOnFirstParse;
84 if (getenv("CINDEXTEST_KEEP_GOING"))
85 options |= CXTranslationUnit_KeepGoing;
86 if (getenv("CINDEXTEST_LIMIT_SKIP_FUNCTION_BODIES_TO_PREAMBLE"))
87 options |= CXTranslationUnit_LimitSkipFunctionBodiesToPreamble;
88 if (getenv("CINDEXTEST_INCLUDE_ATTRIBUTED_TYPES"))
89 options |= CXTranslationUnit_IncludeAttributedTypes;
90 if (getenv("CINDEXTEST_VISIT_IMPLICIT_ATTRIBUTES"))
91 options |= CXTranslationUnit_VisitImplicitAttributes;
92 if (getenv("CINDEXTEST_IGNORE_NONERRORS_FROM_INCLUDED_FILES"))
93 options |= CXTranslationUnit_IgnoreNonErrorsFromIncludedFiles;
94
95 return options;
96}
97
98static void ModifyPrintingPolicyAccordingToEnv(CXPrintingPolicy Policy) {
99 struct Mapping {
100 const char *name;
101 enum CXPrintingPolicyProperty property;
102 };
103 struct Mapping mappings[] = {
104 {"CINDEXTEST_PRINTINGPOLICY_INDENTATION", CXPrintingPolicy_Indentation},
105 {"CINDEXTEST_PRINTINGPOLICY_SUPPRESSSPECIFIERS",
106 CXPrintingPolicy_SuppressSpecifiers},
107 {"CINDEXTEST_PRINTINGPOLICY_SUPPRESSTAGKEYWORD",
108 CXPrintingPolicy_SuppressTagKeyword},
109 {"CINDEXTEST_PRINTINGPOLICY_INCLUDETAGDEFINITION",
110 CXPrintingPolicy_IncludeTagDefinition},
111 {"CINDEXTEST_PRINTINGPOLICY_SUPPRESSSCOPE",
112 CXPrintingPolicy_SuppressScope},
113 {"CINDEXTEST_PRINTINGPOLICY_SUPPRESSUNWRITTENSCOPE",
114 CXPrintingPolicy_SuppressUnwrittenScope},
115 {"CINDEXTEST_PRINTINGPOLICY_SUPPRESSINITIALIZERS",
116 CXPrintingPolicy_SuppressInitializers},
117 {"CINDEXTEST_PRINTINGPOLICY_CONSTANTARRAYSIZEASWRITTEN",
118 CXPrintingPolicy_ConstantArraySizeAsWritten},
119 {"CINDEXTEST_PRINTINGPOLICY_ANONYMOUSTAGLOCATIONS",
120 CXPrintingPolicy_AnonymousTagLocations},
121 {"CINDEXTEST_PRINTINGPOLICY_SUPPRESSSTRONGLIFETIME",
122 CXPrintingPolicy_SuppressStrongLifetime},
123 {"CINDEXTEST_PRINTINGPOLICY_SUPPRESSLIFETIMEQUALIFIERS",
124 CXPrintingPolicy_SuppressLifetimeQualifiers},
125 {"CINDEXTEST_PRINTINGPOLICY_SUPPRESSTEMPLATEARGSINCXXCONSTRUCTORS",
126 CXPrintingPolicy_SuppressTemplateArgsInCXXConstructors},
127 {"CINDEXTEST_PRINTINGPOLICY_BOOL", CXPrintingPolicy_Bool},
128 {"CINDEXTEST_PRINTINGPOLICY_RESTRICT", CXPrintingPolicy_Restrict},
129 {"CINDEXTEST_PRINTINGPOLICY_ALIGNOF", CXPrintingPolicy_Alignof},
130 {"CINDEXTEST_PRINTINGPOLICY_UNDERSCOREALIGNOF",
131 CXPrintingPolicy_UnderscoreAlignof},
132 {"CINDEXTEST_PRINTINGPOLICY_USEVOIDFORZEROPARAMS",
133 CXPrintingPolicy_UseVoidForZeroParams},
134 {"CINDEXTEST_PRINTINGPOLICY_TERSEOUTPUT", CXPrintingPolicy_TerseOutput},
135 {"CINDEXTEST_PRINTINGPOLICY_POLISHFORDECLARATION",
136 CXPrintingPolicy_PolishForDeclaration},
137 {"CINDEXTEST_PRINTINGPOLICY_HALF", CXPrintingPolicy_Half},
138 {"CINDEXTEST_PRINTINGPOLICY_MSWCHAR", CXPrintingPolicy_MSWChar},
139 {"CINDEXTEST_PRINTINGPOLICY_INCLUDENEWLINES",
140 CXPrintingPolicy_IncludeNewlines},
141 {"CINDEXTEST_PRINTINGPOLICY_MSVCFORMATTING",
142 CXPrintingPolicy_MSVCFormatting},
143 {"CINDEXTEST_PRINTINGPOLICY_CONSTANTSASWRITTEN",
144 CXPrintingPolicy_ConstantsAsWritten},
145 {"CINDEXTEST_PRINTINGPOLICY_SUPPRESSIMPLICITBASE",
146 CXPrintingPolicy_SuppressImplicitBase},
147 {"CINDEXTEST_PRINTINGPOLICY_FULLYQUALIFIEDNAME",
148 CXPrintingPolicy_FullyQualifiedName},
149 };
150
151 unsigned i;
152 for (i = 0; i < sizeof(mappings) / sizeof(struct Mapping); i++) {
153 char *value = getenv(mappings[i].name);
154 if (value) {
155 clang_PrintingPolicy_setProperty(Policy, mappings[i].property,
156 (unsigned)strtoul(value, 0L, 10));
157 }
158 }
159}
160
161/** Returns 0 in case of success, non-zero in case of a failure. */
162static int checkForErrors(CXTranslationUnit TU);
163
164static void describeLibclangFailure(enum CXErrorCode Err) {
165 switch (Err) {
166 case CXError_Success:
167 fprintf(stderr, "Success\n")__fprintf_chk (stderr, 2 - 1, "Success\n");
168 return;
169
170 case CXError_Failure:
171 fprintf(stderr, "Failure (no details available)\n")__fprintf_chk (stderr, 2 - 1, "Failure (no details available)\n"
)
;
172 return;
173
174 case CXError_Crashed:
175 fprintf(stderr, "Failure: libclang crashed\n")__fprintf_chk (stderr, 2 - 1, "Failure: libclang crashed\n");
176 return;
177
178 case CXError_InvalidArguments:
179 fprintf(stderr, "Failure: invalid arguments passed to a libclang routine\n")__fprintf_chk (stderr, 2 - 1, "Failure: invalid arguments passed to a libclang routine\n"
)
;
180 return;
181
182 case CXError_ASTReadError:
183 fprintf(stderr, "Failure: AST deserialization error occurred\n")__fprintf_chk (stderr, 2 - 1, "Failure: AST deserialization error occurred\n"
)
;
184 return;
185 }
186}
187
188static void PrintExtent(FILE *out, unsigned begin_line, unsigned begin_column,
189 unsigned end_line, unsigned end_column) {
190 fprintf(out, "[%d:%d - %d:%d]", begin_line, begin_column,__fprintf_chk (out, 2 - 1, "[%d:%d - %d:%d]", begin_line, begin_column
, end_line, end_column)
191 end_line, end_column)__fprintf_chk (out, 2 - 1, "[%d:%d - %d:%d]", begin_line, begin_column
, end_line, end_column)
;
192}
193
194static unsigned CreateTranslationUnit(CXIndex Idx, const char *file,
195 CXTranslationUnit *TU) {
196 enum CXErrorCode Err = clang_createTranslationUnit2(Idx, file, TU);
197 if (Err != CXError_Success) {
198 fprintf(stderr, "Unable to load translation unit from '%s'!\n", file)__fprintf_chk (stderr, 2 - 1, "Unable to load translation unit from '%s'!\n"
, file)
;
199 describeLibclangFailure(Err);
200 *TU = 0;
201 return 0;
202 }
203 return 1;
204}
205
206void free_remapped_files(struct CXUnsavedFile *unsaved_files,
207 int num_unsaved_files) {
208 int i;
209 for (i = 0; i != num_unsaved_files; ++i) {
210 free((char *)unsaved_files[i].Filename);
211 free((char *)unsaved_files[i].Contents);
212 }
213 free(unsaved_files);
214}
215
216static int parse_remapped_files_with_opt(const char *opt_name,
217 int argc, const char **argv,
218 int start_arg,
219 struct CXUnsavedFile **unsaved_files,
220 int *num_unsaved_files) {
221 int i;
222 int arg;
223 int prefix_len = strlen(opt_name);
224 int arg_indices[20];
225 *unsaved_files = 0;
226 *num_unsaved_files = 0;
227
228 /* Count the number of remapped files. */
229 for (arg = start_arg; arg < argc; ++arg) {
230 if (strncmp(argv[arg], opt_name, prefix_len))
231 continue;
232
233 assert(*num_unsaved_files < (int)(sizeof(arg_indices)/sizeof(int)))((void) sizeof ((*num_unsaved_files < (int)(sizeof(arg_indices
)/sizeof(int))) ? 1 : 0), __extension__ ({ if (*num_unsaved_files
< (int)(sizeof(arg_indices)/sizeof(int))) ; else __assert_fail
("*num_unsaved_files < (int)(sizeof(arg_indices)/sizeof(int))"
, "clang/tools/c-index-test/c-index-test.c", 233, __extension__
__PRETTY_FUNCTION__); }))
;
234 arg_indices[*num_unsaved_files] = arg;
235 ++*num_unsaved_files;
236 }
237
238 if (*num_unsaved_files == 0)
239 return 0;
240
241 *unsaved_files
242 = (struct CXUnsavedFile *)malloc(sizeof(struct CXUnsavedFile) *
243 *num_unsaved_files);
244 assert(*unsaved_files)((void) sizeof ((*unsaved_files) ? 1 : 0), __extension__ ({ if
(*unsaved_files) ; else __assert_fail ("*unsaved_files", "clang/tools/c-index-test/c-index-test.c"
, 244, __extension__ __PRETTY_FUNCTION__); }))
;
245 for (i = 0; i != *num_unsaved_files; ++i) {
246 struct CXUnsavedFile *unsaved = *unsaved_files + i;
247 const char *arg_string = argv[arg_indices[i]] + prefix_len;
248 int filename_len;
249 char *filename;
250 char *contents;
251 FILE *to_file;
252 const char *sep = strchr(arg_string, ',');
253 if (!sep) {
254 fprintf(stderr,__fprintf_chk (stderr, 2 - 1, "error: %sfrom:to argument is missing comma\n"
, opt_name)
255 "error: %sfrom:to argument is missing comma\n", opt_name)__fprintf_chk (stderr, 2 - 1, "error: %sfrom:to argument is missing comma\n"
, opt_name)
;
256 free_remapped_files(*unsaved_files, i);
257 *unsaved_files = 0;
258 *num_unsaved_files = 0;
259 return -1;
260 }
261
262 /* Open the file that we're remapping to. */
263 to_file = fopen(sep + 1, "rb");
264 if (!to_file) {
265 fprintf(stderr, "error: cannot open file %s that we are remapping to\n",__fprintf_chk (stderr, 2 - 1, "error: cannot open file %s that we are remapping to\n"
, sep + 1)
266 sep + 1)__fprintf_chk (stderr, 2 - 1, "error: cannot open file %s that we are remapping to\n"
, sep + 1)
;
267 free_remapped_files(*unsaved_files, i);
268 *unsaved_files = 0;
269 *num_unsaved_files = 0;
270 return -1;
271 }
272
273 /* Determine the length of the file we're remapping to. */
274 fseek(to_file, 0, SEEK_END2);
275 unsaved->Length = ftell(to_file);
276 fseek(to_file, 0, SEEK_SET0);
277
278 /* Read the contents of the file we're remapping to. */
279 contents = (char *)malloc(unsaved->Length + 1);
280 assert(contents)((void) sizeof ((contents) ? 1 : 0), __extension__ ({ if (contents
) ; else __assert_fail ("contents", "clang/tools/c-index-test/c-index-test.c"
, 280, __extension__ __PRETTY_FUNCTION__); }))
;
281 if (fread(contents, 1, unsaved->Length, to_file) != unsaved->Length) {
282 fprintf(stderr, "error: unexpected %s reading 'to' file %s\n",__fprintf_chk (stderr, 2 - 1, "error: unexpected %s reading 'to' file %s\n"
, (feof(to_file) ? "EOF" : "error"), sep + 1)
283 (feof(to_file) ? "EOF" : "error"), sep + 1)__fprintf_chk (stderr, 2 - 1, "error: unexpected %s reading 'to' file %s\n"
, (feof(to_file) ? "EOF" : "error"), sep + 1)
;
284 fclose(to_file);
285 free_remapped_files(*unsaved_files, i);
286 free(contents);
287 *unsaved_files = 0;
288 *num_unsaved_files = 0;
289 return -1;
290 }
291 contents[unsaved->Length] = 0;
292 unsaved->Contents = contents;
293
294 /* Close the file. */
295 fclose(to_file);
296
297 /* Copy the file name that we're remapping from. */
298 filename_len = sep - arg_string;
299 filename = (char *)malloc(filename_len + 1);
300 assert(filename)((void) sizeof ((filename) ? 1 : 0), __extension__ ({ if (filename
) ; else __assert_fail ("filename", "clang/tools/c-index-test/c-index-test.c"
, 300, __extension__ __PRETTY_FUNCTION__); }))
;
301 memcpy(filename, arg_string, filename_len);
302 filename[filename_len] = 0;
303 unsaved->Filename = filename;
304 }
305
306 return 0;
307}
308
309static int parse_remapped_files(int argc, const char **argv, int start_arg,
310 struct CXUnsavedFile **unsaved_files,
311 int *num_unsaved_files) {
312 return parse_remapped_files_with_opt("-remap-file=", argc, argv, start_arg,
313 unsaved_files, num_unsaved_files);
314}
315
316static int parse_remapped_files_with_try(int try_idx,
317 int argc, const char **argv,
318 int start_arg,
319 struct CXUnsavedFile **unsaved_files,
320 int *num_unsaved_files) {
321 struct CXUnsavedFile *unsaved_files_no_try_idx;
322 int num_unsaved_files_no_try_idx;
323 struct CXUnsavedFile *unsaved_files_try_idx;
324 int num_unsaved_files_try_idx;
325 int ret;
326 char opt_name[32];
327
328 ret = parse_remapped_files(argc, argv, start_arg,
329 &unsaved_files_no_try_idx, &num_unsaved_files_no_try_idx);
330 if (ret)
331 return ret;
332
333 sprintf(opt_name, "-remap-file-%d=", try_idx)__builtin___sprintf_chk (opt_name, 2 - 1, __builtin_object_size
(opt_name, 2 > 1), "-remap-file-%d=", try_idx)
;
334 ret = parse_remapped_files_with_opt(opt_name, argc, argv, start_arg,
335 &unsaved_files_try_idx, &num_unsaved_files_try_idx);
336 if (ret)
337 return ret;
338
339 if (num_unsaved_files_no_try_idx == 0) {
340 *unsaved_files = unsaved_files_try_idx;
341 *num_unsaved_files = num_unsaved_files_try_idx;
342 return 0;
343 }
344 if (num_unsaved_files_try_idx == 0) {
345 *unsaved_files = unsaved_files_no_try_idx;
346 *num_unsaved_files = num_unsaved_files_no_try_idx;
347 return 0;
348 }
349
350 *num_unsaved_files = num_unsaved_files_no_try_idx + num_unsaved_files_try_idx;
351 *unsaved_files
352 = (struct CXUnsavedFile *)realloc(unsaved_files_no_try_idx,
353 sizeof(struct CXUnsavedFile) *
354 *num_unsaved_files);
355 assert(*unsaved_files)((void) sizeof ((*unsaved_files) ? 1 : 0), __extension__ ({ if
(*unsaved_files) ; else __assert_fail ("*unsaved_files", "clang/tools/c-index-test/c-index-test.c"
, 355, __extension__ __PRETTY_FUNCTION__); }))
;
356 memcpy(*unsaved_files + num_unsaved_files_no_try_idx,
357 unsaved_files_try_idx, sizeof(struct CXUnsavedFile) *
358 num_unsaved_files_try_idx);
359 free(unsaved_files_try_idx);
360 return 0;
361}
362
363static const char *parse_comments_schema(int argc, const char **argv) {
364 const char *CommentsSchemaArg = "-comments-xml-schema=";
365 const char *CommentSchemaFile = NULL((void*)0);
366
367 if (argc == 0)
368 return CommentSchemaFile;
369
370 if (!strncmp(argv[0], CommentsSchemaArg, strlen(CommentsSchemaArg)))
371 CommentSchemaFile = argv[0] + strlen(CommentsSchemaArg);
372
373 return CommentSchemaFile;
374}
375
376/******************************************************************************/
377/* Pretty-printing. */
378/******************************************************************************/
379
380static const char *FileCheckPrefix = "CHECK";
381
382static void PrintCString(const char *CStr) {
383 if (CStr != NULL((void*)0) && CStr[0] != '\0') {
384 for ( ; *CStr; ++CStr) {
385 const char C = *CStr;
386 switch (C) {
387 case '\n': printf("\\n")__printf_chk (2 - 1, "\\n"); break;
388 case '\r': printf("\\r")__printf_chk (2 - 1, "\\r"); break;
389 case '\t': printf("\\t")__printf_chk (2 - 1, "\\t"); break;
390 case '\v': printf("\\v")__printf_chk (2 - 1, "\\v"); break;
391 case '\f': printf("\\f")__printf_chk (2 - 1, "\\f"); break;
392 default: putchar(C); break;
393 }
394 }
395 }
396}
397
398static void PrintCStringWithPrefix(const char *Prefix, const char *CStr) {
399 printf(" %s=[", Prefix)__printf_chk (2 - 1, " %s=[", Prefix);
400 PrintCString(CStr);
401 printf("]")__printf_chk (2 - 1, "]");
402}
403
404static void PrintCXStringAndDispose(CXString Str) {
405 PrintCString(clang_getCString(Str));
406 clang_disposeString(Str);
407}
408
409static void PrintCXStringWithPrefix(const char *Prefix, CXString Str) {
410 PrintCStringWithPrefix(Prefix, clang_getCString(Str));
411}
412
413static void PrintCXStringWithPrefixAndDispose(const char *Prefix,
414 CXString Str) {
415 PrintCStringWithPrefix(Prefix, clang_getCString(Str));
416 clang_disposeString(Str);
417}
418
419static void PrintRange(CXSourceRange R, const char *str) {
420 CXFile begin_file, end_file;
421 unsigned begin_line, begin_column, end_line, end_column;
422
423 clang_getSpellingLocation(clang_getRangeStart(R),
424 &begin_file, &begin_line, &begin_column, 0);
425 clang_getSpellingLocation(clang_getRangeEnd(R),
426 &end_file, &end_line, &end_column, 0);
427 if (!begin_file || !end_file)
428 return;
429
430 if (str)
431 printf(" %s=", str)__printf_chk (2 - 1, " %s=", str);
432 PrintExtent(stdoutstdout, begin_line, begin_column, end_line, end_column);
433}
434
435static enum DisplayType {
436 DisplayType_Spelling,
437 DisplayType_DisplayName,
438 DisplayType_Pretty
439} wanted_display_type = DisplayType_Spelling;
440
441static void printVersion(const char *Prefix, CXVersion Version) {
442 if (Version.Major < 0)
443 return;
444 printf("%s%d", Prefix, Version.Major)__printf_chk (2 - 1, "%s%d", Prefix, Version.Major);
445
446 if (Version.Minor < 0)
447 return;
448 printf(".%d", Version.Minor)__printf_chk (2 - 1, ".%d", Version.Minor);
449
450 if (Version.Subminor < 0)
451 return;
452 printf(".%d", Version.Subminor)__printf_chk (2 - 1, ".%d", Version.Subminor);
453}
454
455struct CommentASTDumpingContext {
456 int IndentLevel;
457};
458
459static void DumpCXCommentInternal(struct CommentASTDumpingContext *Ctx,
460 CXComment Comment) {
461 unsigned i;
462 unsigned e;
463 enum CXCommentKind Kind = clang_Comment_getKind(Comment);
464
465 Ctx->IndentLevel++;
466 for (i = 0, e = Ctx->IndentLevel; i != e; ++i)
467 printf(" ")__printf_chk (2 - 1, " ");
468
469 printf("(")__printf_chk (2 - 1, "(");
470 switch (Kind) {
471 case CXComment_Null:
472 printf("CXComment_Null")__printf_chk (2 - 1, "CXComment_Null");
473 break;
474 case CXComment_Text:
475 printf("CXComment_Text")__printf_chk (2 - 1, "CXComment_Text");
476 PrintCXStringWithPrefixAndDispose("Text",
477 clang_TextComment_getText(Comment));
478 if (clang_Comment_isWhitespace(Comment))
479 printf(" IsWhitespace")__printf_chk (2 - 1, " IsWhitespace");
480 if (clang_InlineContentComment_hasTrailingNewline(Comment))
481 printf(" HasTrailingNewline")__printf_chk (2 - 1, " HasTrailingNewline");
482 break;
483 case CXComment_InlineCommand:
484 printf("CXComment_InlineCommand")__printf_chk (2 - 1, "CXComment_InlineCommand");
485 PrintCXStringWithPrefixAndDispose(
486 "CommandName",
487 clang_InlineCommandComment_getCommandName(Comment));
488 switch (clang_InlineCommandComment_getRenderKind(Comment)) {
489 case CXCommentInlineCommandRenderKind_Normal:
490 printf(" RenderNormal")__printf_chk (2 - 1, " RenderNormal");
491 break;
492 case CXCommentInlineCommandRenderKind_Bold:
493 printf(" RenderBold")__printf_chk (2 - 1, " RenderBold");
494 break;
495 case CXCommentInlineCommandRenderKind_Monospaced:
496 printf(" RenderMonospaced")__printf_chk (2 - 1, " RenderMonospaced");
497 break;
498 case CXCommentInlineCommandRenderKind_Emphasized:
499 printf(" RenderEmphasized")__printf_chk (2 - 1, " RenderEmphasized");
500 break;
501 case CXCommentInlineCommandRenderKind_Anchor:
502 printf(" RenderAnchor")__printf_chk (2 - 1, " RenderAnchor");
503 break;
504 }
505 for (i = 0, e = clang_InlineCommandComment_getNumArgs(Comment);
506 i != e; ++i) {
507 printf(" Arg[%u]=", i)__printf_chk (2 - 1, " Arg[%u]=", i);
508 PrintCXStringAndDispose(
509 clang_InlineCommandComment_getArgText(Comment, i));
510 }
511 if (clang_InlineContentComment_hasTrailingNewline(Comment))
512 printf(" HasTrailingNewline")__printf_chk (2 - 1, " HasTrailingNewline");
513 break;
514 case CXComment_HTMLStartTag: {
515 unsigned NumAttrs;
516 printf("CXComment_HTMLStartTag")__printf_chk (2 - 1, "CXComment_HTMLStartTag");
517 PrintCXStringWithPrefixAndDispose(
518 "Name",
519 clang_HTMLTagComment_getTagName(Comment));
520 NumAttrs = clang_HTMLStartTag_getNumAttrs(Comment);
521 if (NumAttrs != 0) {
522 printf(" Attrs:")__printf_chk (2 - 1, " Attrs:");
523 for (i = 0; i != NumAttrs; ++i) {
524 printf(" ")__printf_chk (2 - 1, " ");
525 PrintCXStringAndDispose(clang_HTMLStartTag_getAttrName(Comment, i));
526 printf("=")__printf_chk (2 - 1, "=");
527 PrintCXStringAndDispose(clang_HTMLStartTag_getAttrValue(Comment, i));
528 }
529 }
530 if (clang_HTMLStartTagComment_isSelfClosing(Comment))
531 printf(" SelfClosing")__printf_chk (2 - 1, " SelfClosing");
532 if (clang_InlineContentComment_hasTrailingNewline(Comment))
533 printf(" HasTrailingNewline")__printf_chk (2 - 1, " HasTrailingNewline");
534 break;
535 }
536 case CXComment_HTMLEndTag:
537 printf("CXComment_HTMLEndTag")__printf_chk (2 - 1, "CXComment_HTMLEndTag");
538 PrintCXStringWithPrefixAndDispose(
539 "Name",
540 clang_HTMLTagComment_getTagName(Comment));
541 if (clang_InlineContentComment_hasTrailingNewline(Comment))
542 printf(" HasTrailingNewline")__printf_chk (2 - 1, " HasTrailingNewline");
543 break;
544 case CXComment_Paragraph:
545 printf("CXComment_Paragraph")__printf_chk (2 - 1, "CXComment_Paragraph");
546 if (clang_Comment_isWhitespace(Comment))
547 printf(" IsWhitespace")__printf_chk (2 - 1, " IsWhitespace");
548 break;
549 case CXComment_BlockCommand:
550 printf("CXComment_BlockCommand")__printf_chk (2 - 1, "CXComment_BlockCommand");
551 PrintCXStringWithPrefixAndDispose(
552 "CommandName",
553 clang_BlockCommandComment_getCommandName(Comment));
554 for (i = 0, e = clang_BlockCommandComment_getNumArgs(Comment);
555 i != e; ++i) {
556 printf(" Arg[%u]=", i)__printf_chk (2 - 1, " Arg[%u]=", i);
557 PrintCXStringAndDispose(
558 clang_BlockCommandComment_getArgText(Comment, i));
559 }
560 break;
561 case CXComment_ParamCommand:
562 printf("CXComment_ParamCommand")__printf_chk (2 - 1, "CXComment_ParamCommand");
563 switch (clang_ParamCommandComment_getDirection(Comment)) {
564 case CXCommentParamPassDirection_In:
565 printf(" in")__printf_chk (2 - 1, " in");
566 break;
567 case CXCommentParamPassDirection_Out:
568 printf(" out")__printf_chk (2 - 1, " out");
569 break;
570 case CXCommentParamPassDirection_InOut:
571 printf(" in,out")__printf_chk (2 - 1, " in,out");
572 break;
573 }
574 if (clang_ParamCommandComment_isDirectionExplicit(Comment))
575 printf(" explicitly")__printf_chk (2 - 1, " explicitly");
576 else
577 printf(" implicitly")__printf_chk (2 - 1, " implicitly");
578 PrintCXStringWithPrefixAndDispose(
579 "ParamName",
580 clang_ParamCommandComment_getParamName(Comment));
581 if (clang_ParamCommandComment_isParamIndexValid(Comment))
582 printf(" ParamIndex=%u", clang_ParamCommandComment_getParamIndex(Comment))__printf_chk (2 - 1, " ParamIndex=%u", clang_ParamCommandComment_getParamIndex
(Comment))
;
583 else
584 printf(" ParamIndex=Invalid")__printf_chk (2 - 1, " ParamIndex=Invalid");
585 break;
586 case CXComment_TParamCommand:
587 printf("CXComment_TParamCommand")__printf_chk (2 - 1, "CXComment_TParamCommand");
588 PrintCXStringWithPrefixAndDispose(
589 "ParamName",
590 clang_TParamCommandComment_getParamName(Comment));
591 if (clang_TParamCommandComment_isParamPositionValid(Comment)) {
592 printf(" ParamPosition={")__printf_chk (2 - 1, " ParamPosition={");
593 for (i = 0, e = clang_TParamCommandComment_getDepth(Comment);
594 i != e; ++i) {
595 printf("%u", clang_TParamCommandComment_getIndex(Comment, i))__printf_chk (2 - 1, "%u", clang_TParamCommandComment_getIndex
(Comment, i))
;
596 if (i != e - 1)
597 printf(", ")__printf_chk (2 - 1, ", ");
598 }
599 printf("}")__printf_chk (2 - 1, "}");
600 } else
601 printf(" ParamPosition=Invalid")__printf_chk (2 - 1, " ParamPosition=Invalid");
602 break;
603 case CXComment_VerbatimBlockCommand:
604 printf("CXComment_VerbatimBlockCommand")__printf_chk (2 - 1, "CXComment_VerbatimBlockCommand");
605 PrintCXStringWithPrefixAndDispose(
606 "CommandName",
607 clang_BlockCommandComment_getCommandName(Comment));
608 break;
609 case CXComment_VerbatimBlockLine:
610 printf("CXComment_VerbatimBlockLine")__printf_chk (2 - 1, "CXComment_VerbatimBlockLine");
611 PrintCXStringWithPrefixAndDispose(
612 "Text",
613 clang_VerbatimBlockLineComment_getText(Comment));
614 break;
615 case CXComment_VerbatimLine:
616 printf("CXComment_VerbatimLine")__printf_chk (2 - 1, "CXComment_VerbatimLine");
617 PrintCXStringWithPrefixAndDispose(
618 "Text",
619 clang_VerbatimLineComment_getText(Comment));
620 break;
621 case CXComment_FullComment:
622 printf("CXComment_FullComment")__printf_chk (2 - 1, "CXComment_FullComment");
623 break;
624 }
625 if (Kind != CXComment_Null) {
626 const unsigned NumChildren = clang_Comment_getNumChildren(Comment);
627 unsigned i;
628 for (i = 0; i != NumChildren; ++i) {
629 printf("\n// %s: ", FileCheckPrefix)__printf_chk (2 - 1, "\n// %s: ", FileCheckPrefix);
630 DumpCXCommentInternal(Ctx, clang_Comment_getChild(Comment, i));
631 }
632 }
633 printf(")")__printf_chk (2 - 1, ")");
634 Ctx->IndentLevel--;
635}
636
637static void DumpCXComment(CXComment Comment) {
638 struct CommentASTDumpingContext Ctx;
639 Ctx.IndentLevel = 1;
640 printf("\n// %s: CommentAST=[\n// %s:", FileCheckPrefix, FileCheckPrefix)__printf_chk (2 - 1, "\n// %s: CommentAST=[\n// %s:", FileCheckPrefix
, FileCheckPrefix)
;
641 DumpCXCommentInternal(&Ctx, Comment);
642 printf("]")__printf_chk (2 - 1, "]");
643}
644
645static void ValidateCommentXML(const char *Str, const char *CommentSchemaFile) {
646#ifdef CLANG_HAVE_LIBXML1
647 xmlRelaxNGParserCtxtPtr RNGParser;
648 xmlRelaxNGPtr Schema;
649 xmlDocPtr Doc;
650 xmlRelaxNGValidCtxtPtr ValidationCtxt;
651 int status;
652
653 if (!CommentSchemaFile)
654 return;
655
656 RNGParser = xmlRelaxNGNewParserCtxt(CommentSchemaFile);
657 if (!RNGParser) {
658 printf(" libXMLError")__printf_chk (2 - 1, " libXMLError");
659 return;
660 }
661 Schema = xmlRelaxNGParse(RNGParser);
662
663 Doc = xmlParseDoc((const xmlChar *) Str);
664
665 if (!Doc) {
666 xmlErrorPtr Error = xmlGetLastError();
667 printf(" CommentXMLInvalid [not well-formed XML: %s]", Error->message)__printf_chk (2 - 1, " CommentXMLInvalid [not well-formed XML: %s]"
, Error->message)
;
668 return;
669 }
670
671 ValidationCtxt = xmlRelaxNGNewValidCtxt(Schema);
672 status = xmlRelaxNGValidateDoc(ValidationCtxt, Doc);
673 if (!status)
674 printf(" CommentXMLValid")__printf_chk (2 - 1, " CommentXMLValid");
675 else if (status > 0) {
676 xmlErrorPtr Error = xmlGetLastError();
677 printf(" CommentXMLInvalid [not valid XML: %s]", Error->message)__printf_chk (2 - 1, " CommentXMLInvalid [not valid XML: %s]"
, Error->message)
;
678 } else
679 printf(" libXMLError")__printf_chk (2 - 1, " libXMLError");
680
681 xmlRelaxNGFreeValidCtxt(ValidationCtxt);
682 xmlFreeDoc(Doc);
683 xmlRelaxNGFree(Schema);
684 xmlRelaxNGFreeParserCtxt(RNGParser);
685#endif
686}
687
688static void PrintCursorComments(CXCursor Cursor,
689 const char *CommentSchemaFile) {
690 {
691 CXString RawComment;
692 const char *RawCommentCString;
693 CXString BriefComment;
694 const char *BriefCommentCString;
695
696 RawComment = clang_Cursor_getRawCommentText(Cursor);
697 RawCommentCString = clang_getCString(RawComment);
698 if (RawCommentCString != NULL((void*)0) && RawCommentCString[0] != '\0') {
699 PrintCStringWithPrefix("RawComment", RawCommentCString);
700 PrintRange(clang_Cursor_getCommentRange(Cursor), "RawCommentRange");
701
702 BriefComment = clang_Cursor_getBriefCommentText(Cursor);
703 BriefCommentCString = clang_getCString(BriefComment);
704 if (BriefCommentCString != NULL((void*)0) && BriefCommentCString[0] != '\0')
705 PrintCStringWithPrefix("BriefComment", BriefCommentCString);
706 clang_disposeString(BriefComment);
707 }
708 clang_disposeString(RawComment);
709 }
710
711 {
712 CXComment Comment = clang_Cursor_getParsedComment(Cursor);
713 if (clang_Comment_getKind(Comment) != CXComment_Null) {
714 PrintCXStringWithPrefixAndDispose("FullCommentAsHTML",
715 clang_FullComment_getAsHTML(Comment));
716 {
717 CXString XML;
718 XML = clang_FullComment_getAsXML(Comment);
719 PrintCXStringWithPrefix("FullCommentAsXML", XML);
720 ValidateCommentXML(clang_getCString(XML), CommentSchemaFile);
721 clang_disposeString(XML);
722 }
723
724 DumpCXComment(Comment);
725 }
726 }
727}
728
729typedef struct {
730 unsigned line;
731 unsigned col;
732} LineCol;
733
734static int lineCol_cmp(const void *p1, const void *p2) {
735 const LineCol *lhs = p1;
736 const LineCol *rhs = p2;
737 if (lhs->line != rhs->line)
738 return (int)lhs->line - (int)rhs->line;
739 return (int)lhs->col - (int)rhs->col;
740}
741
742static CXString CursorToText(CXCursor Cursor) {
743 CXString text;
744 switch (wanted_display_type) {
745 case DisplayType_Spelling:
746 return clang_getCursorSpelling(Cursor);
747 case DisplayType_DisplayName:
748 return clang_getCursorDisplayName(Cursor);
749 case DisplayType_Pretty: {
750 CXPrintingPolicy Policy = clang_getCursorPrintingPolicy(Cursor);
751 ModifyPrintingPolicyAccordingToEnv(Policy);
752 text = clang_getCursorPrettyPrinted(Cursor, Policy);
753 clang_PrintingPolicy_dispose(Policy);
754 return text;
755 }
756 }
757 assert(0 && "unknown display type")((void) sizeof ((0 && "unknown display type") ? 1 : 0
), __extension__ ({ if (0 && "unknown display type") ;
else __assert_fail ("0 && \"unknown display type\"",
"clang/tools/c-index-test/c-index-test.c", 757, __extension__
__PRETTY_FUNCTION__); }))
; /* no llvm_unreachable in C. */
758 /* Set to NULL to prevent uninitialized variable warnings. */
759 text.data = NULL((void*)0);
760 text.private_flags = 0;
761 return text;
762}
763
764static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) {
765 CXTranslationUnit TU = clang_Cursor_getTranslationUnit(Cursor);
766 if (clang_isInvalid(Cursor.kind)) {
767 CXString ks = clang_getCursorKindSpelling(Cursor.kind);
768 printf("Invalid Cursor => %s", clang_getCString(ks))__printf_chk (2 - 1, "Invalid Cursor => %s", clang_getCString
(ks))
;
769 clang_disposeString(ks);
770 }
771 else {
772 CXString string, ks;
773 CXCursor Referenced;
774 unsigned line, column;
775 CXCursor SpecializationOf;
776 CXCursor *overridden;
777 unsigned num_overridden;
778 unsigned RefNameRangeNr;
779 CXSourceRange CursorExtent;
780 CXSourceRange RefNameRange;
781 int AlwaysUnavailable;
782 int AlwaysDeprecated;
783 CXString UnavailableMessage;
784 CXString DeprecatedMessage;
785 CXPlatformAvailability PlatformAvailability[2];
786 int NumPlatformAvailability;
787 int I;
788
789 ks = clang_getCursorKindSpelling(Cursor.kind);
790 string = CursorToText(Cursor);
791 printf("%s=%s", clang_getCString(ks),__printf_chk (2 - 1, "%s=%s", clang_getCString(ks), clang_getCString
(string))
792 clang_getCString(string))__printf_chk (2 - 1, "%s=%s", clang_getCString(ks), clang_getCString
(string))
;
793 clang_disposeString(ks);
794 clang_disposeString(string);
795
796 Referenced = clang_getCursorReferenced(Cursor);
797 if (!clang_equalCursors(Referenced, clang_getNullCursor())) {
798 if (clang_getCursorKind(Referenced) == CXCursor_OverloadedDeclRef) {
799 unsigned I, N = clang_getNumOverloadedDecls(Referenced);
800 printf("[")__printf_chk (2 - 1, "[");
801 for (I = 0; I != N; ++I) {
802 CXCursor Ovl = clang_getOverloadedDecl(Referenced, I);
803 CXSourceLocation Loc;
804 if (I)
805 printf(", ")__printf_chk (2 - 1, ", ");
806
807 Loc = clang_getCursorLocation(Ovl);
808 clang_getSpellingLocation(Loc, 0, &line, &column, 0);
809 printf("%d:%d", line, column)__printf_chk (2 - 1, "%d:%d", line, column);
810 }
811 printf("]")__printf_chk (2 - 1, "]");
812 } else {
813 CXSourceLocation Loc = clang_getCursorLocation(Referenced);
814 clang_getSpellingLocation(Loc, 0, &line, &column, 0);
815 printf(":%d:%d", line, column)__printf_chk (2 - 1, ":%d:%d", line, column);
816 }
817
818 if (clang_getCursorKind(Referenced) == CXCursor_TypedefDecl) {
819 CXType T = clang_getCursorType(Referenced);
820 if (clang_Type_isTransparentTagTypedef(T)) {
821 CXType Underlying = clang_getTypedefDeclUnderlyingType(Referenced);
822 CXString S = clang_getTypeSpelling(Underlying);
823 printf(" (Transparent: %s)", clang_getCString(S))__printf_chk (2 - 1, " (Transparent: %s)", clang_getCString(S
))
;
824 clang_disposeString(S);
825 }
826 }
827 }
828
829 if (clang_isCursorDefinition(Cursor))
830 printf(" (Definition)")__printf_chk (2 - 1, " (Definition)");
831
832 switch (clang_getCursorAvailability(Cursor)) {
833 case CXAvailability_Available:
834 break;
835
836 case CXAvailability_Deprecated:
837 printf(" (deprecated)")__printf_chk (2 - 1, " (deprecated)");
838 break;
839
840 case CXAvailability_NotAvailable:
841 printf(" (unavailable)")__printf_chk (2 - 1, " (unavailable)");
842 break;
843
844 case CXAvailability_NotAccessible:
845 printf(" (inaccessible)")__printf_chk (2 - 1, " (inaccessible)");
846 break;
847 }
848
849 NumPlatformAvailability
850 = clang_getCursorPlatformAvailability(Cursor,
851 &AlwaysDeprecated,
852 &DeprecatedMessage,
853 &AlwaysUnavailable,
854 &UnavailableMessage,
855 PlatformAvailability, 2);
856 if (AlwaysUnavailable) {
857 printf(" (always unavailable: \"%s\")",__printf_chk (2 - 1, " (always unavailable: \"%s\")", clang_getCString
(UnavailableMessage))
858 clang_getCString(UnavailableMessage))__printf_chk (2 - 1, " (always unavailable: \"%s\")", clang_getCString
(UnavailableMessage))
;
859 } else if (AlwaysDeprecated) {
860 printf(" (always deprecated: \"%s\")",__printf_chk (2 - 1, " (always deprecated: \"%s\")", clang_getCString
(DeprecatedMessage))
861 clang_getCString(DeprecatedMessage))__printf_chk (2 - 1, " (always deprecated: \"%s\")", clang_getCString
(DeprecatedMessage))
;
862 } else {
863 for (I = 0; I != NumPlatformAvailability; ++I) {
864 if (I >= 2)
865 break;
866
867 printf(" (%s", clang_getCString(PlatformAvailability[I].Platform))__printf_chk (2 - 1, " (%s", clang_getCString(PlatformAvailability
[I].Platform))
;
868 if (PlatformAvailability[I].Unavailable)
869 printf(", unavailable")__printf_chk (2 - 1, ", unavailable");
870 else {
871 printVersion(", introduced=", PlatformAvailability[I].Introduced);
872 printVersion(", deprecated=", PlatformAvailability[I].Deprecated);
873 printVersion(", obsoleted=", PlatformAvailability[I].Obsoleted);
874 }
875 if (clang_getCString(PlatformAvailability[I].Message)[0])
876 printf(", message=\"%s\"",__printf_chk (2 - 1, ", message=\"%s\"", clang_getCString(PlatformAvailability
[I].Message))
877 clang_getCString(PlatformAvailability[I].Message))__printf_chk (2 - 1, ", message=\"%s\"", clang_getCString(PlatformAvailability
[I].Message))
;
878 printf(")")__printf_chk (2 - 1, ")");
879 }
880 }
881 for (I = 0; I != NumPlatformAvailability; ++I) {
882 if (I >= 2)
883 break;
884 clang_disposeCXPlatformAvailability(PlatformAvailability + I);
885 }
886
887 clang_disposeString(DeprecatedMessage);
888 clang_disposeString(UnavailableMessage);
889
890 if (clang_CXXConstructor_isDefaultConstructor(Cursor))
891 printf(" (default constructor)")__printf_chk (2 - 1, " (default constructor)");
892
893 if (clang_CXXConstructor_isMoveConstructor(Cursor))
894 printf(" (move constructor)")__printf_chk (2 - 1, " (move constructor)");
895 if (clang_CXXConstructor_isCopyConstructor(Cursor))
896 printf(" (copy constructor)")__printf_chk (2 - 1, " (copy constructor)");
897 if (clang_CXXConstructor_isConvertingConstructor(Cursor))
898 printf(" (converting constructor)")__printf_chk (2 - 1, " (converting constructor)");
899 if (clang_CXXField_isMutable(Cursor))
900 printf(" (mutable)")__printf_chk (2 - 1, " (mutable)");
901 if (clang_CXXMethod_isDefaulted(Cursor))
902 printf(" (defaulted)")__printf_chk (2 - 1, " (defaulted)");
903 if (clang_CXXMethod_isDeleted(Cursor))
904 printf(" (deleted)")__printf_chk (2 - 1, " (deleted)");
905 if (clang_CXXMethod_isStatic(Cursor))
906 printf(" (static)")__printf_chk (2 - 1, " (static)");
907 if (clang_CXXMethod_isVirtual(Cursor))
908 printf(" (virtual)")__printf_chk (2 - 1, " (virtual)");
909 if (clang_CXXMethod_isConst(Cursor))
910 printf(" (const)")__printf_chk (2 - 1, " (const)");
911 if (clang_CXXMethod_isPureVirtual(Cursor))
912 printf(" (pure)")__printf_chk (2 - 1, " (pure)");
913 if (clang_CXXRecord_isAbstract(Cursor))
914 printf(" (abstract)")__printf_chk (2 - 1, " (abstract)");
915 if (clang_EnumDecl_isScoped(Cursor))
916 printf(" (scoped)")__printf_chk (2 - 1, " (scoped)");
917 if (clang_Cursor_isVariadic(Cursor))
918 printf(" (variadic)")__printf_chk (2 - 1, " (variadic)");
919 if (clang_Cursor_isObjCOptional(Cursor))
920 printf(" (@optional)")__printf_chk (2 - 1, " (@optional)");
921 if (clang_isInvalidDeclaration(Cursor))
922 printf(" (invalid)")__printf_chk (2 - 1, " (invalid)");
923
924 switch (clang_getCursorExceptionSpecificationType(Cursor))
925 {
926 case CXCursor_ExceptionSpecificationKind_None:
927 break;
928
929 case CXCursor_ExceptionSpecificationKind_DynamicNone:
930 printf(" (noexcept dynamic none)")__printf_chk (2 - 1, " (noexcept dynamic none)");
931 break;
932
933 case CXCursor_ExceptionSpecificationKind_Dynamic:
934 printf(" (noexcept dynamic)")__printf_chk (2 - 1, " (noexcept dynamic)");
935 break;
936
937 case CXCursor_ExceptionSpecificationKind_MSAny:
938 printf(" (noexcept dynamic any)")__printf_chk (2 - 1, " (noexcept dynamic any)");
939 break;
940
941 case CXCursor_ExceptionSpecificationKind_BasicNoexcept:
942 printf(" (noexcept)")__printf_chk (2 - 1, " (noexcept)");
943 break;
944
945 case CXCursor_ExceptionSpecificationKind_ComputedNoexcept:
946 printf(" (computed-noexcept)")__printf_chk (2 - 1, " (computed-noexcept)");
947 break;
948
949 case CXCursor_ExceptionSpecificationKind_Unevaluated:
950 case CXCursor_ExceptionSpecificationKind_Uninstantiated:
951 case CXCursor_ExceptionSpecificationKind_Unparsed:
952 break;
953 }
954
955 {
956 CXString language;
957 CXString definedIn;
958 unsigned generated;
959 if (clang_Cursor_isExternalSymbol(Cursor, &language, &definedIn,
960 &generated)) {
961 printf(" (external lang: %s, defined: %s, gen: %d)",__printf_chk (2 - 1, " (external lang: %s, defined: %s, gen: %d)"
, clang_getCString(language), clang_getCString(definedIn), generated
)
962 clang_getCString(language), clang_getCString(definedIn), generated)__printf_chk (2 - 1, " (external lang: %s, defined: %s, gen: %d)"
, clang_getCString(language), clang_getCString(definedIn), generated
)
;
963 clang_disposeString(language);
964 clang_disposeString(definedIn);
965 }
966 }
967
968 if (Cursor.kind == CXCursor_IBOutletCollectionAttr) {
969 CXType T =
970 clang_getCanonicalType(clang_getIBOutletCollectionType(Cursor));
971 CXString S = clang_getTypeKindSpelling(T.kind);
972 printf(" [IBOutletCollection=%s]", clang_getCString(S))__printf_chk (2 - 1, " [IBOutletCollection=%s]", clang_getCString
(S))
;
973 clang_disposeString(S);
974 }
975
976 if (Cursor.kind == CXCursor_CXXBaseSpecifier) {
977 enum CX_CXXAccessSpecifier access = clang_getCXXAccessSpecifier(Cursor);
978 unsigned isVirtual = clang_isVirtualBase(Cursor);
979 const char *accessStr = 0;
980
981 switch (access) {
982 case CX_CXXInvalidAccessSpecifier:
983 accessStr = "invalid"; break;
984 case CX_CXXPublic:
985 accessStr = "public"; break;
986 case CX_CXXProtected:
987 accessStr = "protected"; break;
988 case CX_CXXPrivate:
989 accessStr = "private"; break;
990 }
991
992 printf(" [access=%s isVirtual=%s]", accessStr,__printf_chk (2 - 1, " [access=%s isVirtual=%s]", accessStr, isVirtual
? "true" : "false")
993 isVirtual ? "true" : "false")__printf_chk (2 - 1, " [access=%s isVirtual=%s]", accessStr, isVirtual
? "true" : "false")
;
994 }
995
996 SpecializationOf = clang_getSpecializedCursorTemplate(Cursor);
997 if (!clang_equalCursors(SpecializationOf, clang_getNullCursor())) {
998 CXSourceLocation Loc = clang_getCursorLocation(SpecializationOf);
999 CXString Name = clang_getCursorSpelling(SpecializationOf);
1000 clang_getSpellingLocation(Loc, 0, &line, &column, 0);
1001 printf(" [Specialization of %s:%d:%d]",__printf_chk (2 - 1, " [Specialization of %s:%d:%d]", clang_getCString
(Name), line, column)
1002 clang_getCString(Name), line, column)__printf_chk (2 - 1, " [Specialization of %s:%d:%d]", clang_getCString
(Name), line, column)
;
1003 clang_disposeString(Name);
1004
1005 if (Cursor.kind == CXCursor_FunctionDecl
1006 || Cursor.kind == CXCursor_StructDecl
1007 || Cursor.kind == CXCursor_ClassDecl
1008 || Cursor.kind == CXCursor_ClassTemplatePartialSpecialization) {
1009 /* Collect the template parameter kinds from the base template. */
1010 int NumTemplateArgs = clang_Cursor_getNumTemplateArguments(Cursor);
1011 int I;
1012 if (NumTemplateArgs < 0) {
1013 printf(" [no template arg info]")__printf_chk (2 - 1, " [no template arg info]");
1014 }
1015 for (I = 0; I < NumTemplateArgs; I++) {
1016 enum CXTemplateArgumentKind TAK =
1017 clang_Cursor_getTemplateArgumentKind(Cursor, I);
1018 switch(TAK) {
1019 case CXTemplateArgumentKind_Type:
1020 {
1021 CXType T = clang_Cursor_getTemplateArgumentType(Cursor, I);
1022 CXString S = clang_getTypeSpelling(T);
1023 printf(" [Template arg %d: kind: %d, type: %s]",__printf_chk (2 - 1, " [Template arg %d: kind: %d, type: %s]"
, I, TAK, clang_getCString(S))
1024 I, TAK, clang_getCString(S))__printf_chk (2 - 1, " [Template arg %d: kind: %d, type: %s]"
, I, TAK, clang_getCString(S))
;
1025 clang_disposeString(S);
1026 }
1027 break;
1028 case CXTemplateArgumentKind_Integral:
1029 printf(" [Template arg %d: kind: %d, intval: %lld]",__printf_chk (2 - 1, " [Template arg %d: kind: %d, intval: %lld]"
, I, TAK, clang_Cursor_getTemplateArgumentValue(Cursor, I))
1030 I, TAK, clang_Cursor_getTemplateArgumentValue(Cursor, I))__printf_chk (2 - 1, " [Template arg %d: kind: %d, intval: %lld]"
, I, TAK, clang_Cursor_getTemplateArgumentValue(Cursor, I))
;
1031 break;
1032 default:
1033 printf(" [Template arg %d: kind: %d]\n", I, TAK)__printf_chk (2 - 1, " [Template arg %d: kind: %d]\n", I, TAK
)
;
1034 }
1035 }
1036 }
1037 }
1038
1039 clang_getOverriddenCursors(Cursor, &overridden, &num_overridden);
1040 if (num_overridden) {
1041 unsigned I;
1042 LineCol lineCols[50];
1043 assert(num_overridden <= 50)((void) sizeof ((num_overridden <= 50) ? 1 : 0), __extension__
({ if (num_overridden <= 50) ; else __assert_fail ("num_overridden <= 50"
, "clang/tools/c-index-test/c-index-test.c", 1043, __extension__
__PRETTY_FUNCTION__); }))
;
1044 printf(" [Overrides ")__printf_chk (2 - 1, " [Overrides ");
1045 for (I = 0; I != num_overridden; ++I) {
1046 CXSourceLocation Loc = clang_getCursorLocation(overridden[I]);
1047 clang_getSpellingLocation(Loc, 0, &line, &column, 0);
1048 lineCols[I].line = line;
1049 lineCols[I].col = column;
1050 }
1051 /* Make the order of the override list deterministic. */
1052 qsort(lineCols, num_overridden, sizeof(LineCol), lineCol_cmp);
1053 for (I = 0; I != num_overridden; ++I) {
1054 if (I)
1055 printf(", ")__printf_chk (2 - 1, ", ");
1056 printf("@%d:%d", lineCols[I].line, lineCols[I].col)__printf_chk (2 - 1, "@%d:%d", lineCols[I].line, lineCols[I].
col)
;
1057 }
1058 printf("]")__printf_chk (2 - 1, "]");
1059 clang_disposeOverriddenCursors(overridden);
1060 }
1061
1062 if (Cursor.kind == CXCursor_InclusionDirective) {
1063 CXFile File = clang_getIncludedFile(Cursor);
1064 CXString Included = clang_getFileName(File);
1065 const char *IncludedString = clang_getCString(Included);
1066 printf(" (%s)", IncludedString ? IncludedString : "(null)")__printf_chk (2 - 1, " (%s)", IncludedString ? IncludedString
: "(null)")
;
1067 clang_disposeString(Included);
1068
1069 if (clang_isFileMultipleIncludeGuarded(TU, File))
1070 printf(" [multi-include guarded]")__printf_chk (2 - 1, " [multi-include guarded]");
1071 }
1072
1073 CursorExtent = clang_getCursorExtent(Cursor);
1074 RefNameRange = clang_getCursorReferenceNameRange(Cursor,
1075 CXNameRange_WantQualifier
1076 | CXNameRange_WantSinglePiece
1077 | CXNameRange_WantTemplateArgs,
1078 0);
1079 if (!clang_equalRanges(CursorExtent, RefNameRange))
1080 PrintRange(RefNameRange, "SingleRefName");
1081
1082 for (RefNameRangeNr = 0; 1; RefNameRangeNr++) {
1083 RefNameRange = clang_getCursorReferenceNameRange(Cursor,
1084 CXNameRange_WantQualifier
1085 | CXNameRange_WantTemplateArgs,
1086 RefNameRangeNr);
1087 if (clang_equalRanges(clang_getNullRange(), RefNameRange))
1088 break;
1089 if (!clang_equalRanges(CursorExtent, RefNameRange))
1090 PrintRange(RefNameRange, "RefName");
1091 }
1092
1093 PrintCursorComments(Cursor, CommentSchemaFile);
1094
1095 {
1096 unsigned PropAttrs = clang_Cursor_getObjCPropertyAttributes(Cursor, 0);
1097 if (PropAttrs != CXObjCPropertyAttr_noattr) {
1098 printf(" [")__printf_chk (2 - 1, " [");
1099 #define PRINT_PROP_ATTR(A)if (PropAttrs & CXObjCPropertyAttr_A) __printf_chk (2 - 1
, "A" ",")
\
1100 if (PropAttrs & CXObjCPropertyAttr_##A) printf(#A ",")__printf_chk (2 - 1, #A ",")
1101 PRINT_PROP_ATTR(readonly)if (PropAttrs & CXObjCPropertyAttr_readonly) __printf_chk
(2 - 1, "readonly" ",")
;
1102 PRINT_PROP_ATTR(getter)if (PropAttrs & CXObjCPropertyAttr_getter) __printf_chk (
2 - 1, "getter" ",")
;
1103 PRINT_PROP_ATTR(assign)if (PropAttrs & CXObjCPropertyAttr_assign) __printf_chk (
2 - 1, "assign" ",")
;
1104 PRINT_PROP_ATTR(readwrite)if (PropAttrs & CXObjCPropertyAttr_readwrite) __printf_chk
(2 - 1, "readwrite" ",")
;
1105 PRINT_PROP_ATTR(retain)if (PropAttrs & CXObjCPropertyAttr_retain) __printf_chk (
2 - 1, "retain" ",")
;
1106 PRINT_PROP_ATTR(copy)if (PropAttrs & CXObjCPropertyAttr_copy) __printf_chk (2 -
1, "copy" ",")
;
1107 PRINT_PROP_ATTR(nonatomic)if (PropAttrs & CXObjCPropertyAttr_nonatomic) __printf_chk
(2 - 1, "nonatomic" ",")
;
1108 PRINT_PROP_ATTR(setter)if (PropAttrs & CXObjCPropertyAttr_setter) __printf_chk (
2 - 1, "setter" ",")
;
1109 PRINT_PROP_ATTR(atomic)if (PropAttrs & CXObjCPropertyAttr_atomic) __printf_chk (
2 - 1, "atomic" ",")
;
1110 PRINT_PROP_ATTR(weak)if (PropAttrs & CXObjCPropertyAttr_weak) __printf_chk (2 -
1, "weak" ",")
;
1111 PRINT_PROP_ATTR(strong)if (PropAttrs & CXObjCPropertyAttr_strong) __printf_chk (
2 - 1, "strong" ",")
;
1112 PRINT_PROP_ATTR(unsafe_unretained)if (PropAttrs & CXObjCPropertyAttr_unsafe_unretained) __printf_chk
(2 - 1, "unsafe_unretained" ",")
;
1113 PRINT_PROP_ATTR(class)if (PropAttrs & CXObjCPropertyAttr_class) __printf_chk (2
- 1, "class" ",")
;
1114 printf("]")__printf_chk (2 - 1, "]");
1115 }
1116 }
1117
1118 if (Cursor.kind == CXCursor_ObjCPropertyDecl) {
1119 CXString Name = clang_Cursor_getObjCPropertyGetterName(Cursor);
1120 CXString Spelling = clang_getCursorSpelling(Cursor);
1121 const char *CName = clang_getCString(Name);
1122 const char *CSpelling = clang_getCString(Spelling);
1123 if (CName && strcmp(CName, CSpelling)) {
1124 printf(" (getter=%s)", CName)__printf_chk (2 - 1, " (getter=%s)", CName);
1125 }
1126 clang_disposeString(Spelling);
1127 clang_disposeString(Name);
1128 }
1129
1130 if (Cursor.kind == CXCursor_ObjCPropertyDecl) {
1131 CXString Name = clang_Cursor_getObjCPropertySetterName(Cursor);
1132 CXString Spelling = clang_getCursorSpelling(Cursor);
1133 const char *CName = clang_getCString(Name);
1134 const char *CSpelling = clang_getCString(Spelling);
1135 char *DefaultSetter = malloc(strlen(CSpelling) + 5);
1136 sprintf(DefaultSetter, "set%s:", CSpelling)__builtin___sprintf_chk (DefaultSetter, 2 - 1, __builtin_object_size
(DefaultSetter, 2 > 1), "set%s:", CSpelling)
;
1137 DefaultSetter[3] &= ~(1 << 5); /* Make uppercase */
1138 if (CName && strcmp(CName, DefaultSetter)) {
1139 printf(" (setter=%s)", CName)__printf_chk (2 - 1, " (setter=%s)", CName);
1140 }
1141 free(DefaultSetter);
1142 clang_disposeString(Spelling);
1143 clang_disposeString(Name);
1144 }
1145
1146 {
1147 unsigned QT = clang_Cursor_getObjCDeclQualifiers(Cursor);
1148 if (QT != CXObjCDeclQualifier_None) {
1149 printf(" [")__printf_chk (2 - 1, " [");
1150 #define PRINT_OBJC_QUAL(A)if (QT & CXObjCDeclQualifier_A) __printf_chk (2 - 1, "A" ","
)
\
1151 if (QT & CXObjCDeclQualifier_##A) printf(#A ",")__printf_chk (2 - 1, #A ",")
1152 PRINT_OBJC_QUAL(In)if (QT & CXObjCDeclQualifier_In) __printf_chk (2 - 1, "In"
",")
;
1153 PRINT_OBJC_QUAL(Inout)if (QT & CXObjCDeclQualifier_Inout) __printf_chk (2 - 1, "Inout"
",")
;
1154 PRINT_OBJC_QUAL(Out)if (QT & CXObjCDeclQualifier_Out) __printf_chk (2 - 1, "Out"
",")
;
1155 PRINT_OBJC_QUAL(Bycopy)if (QT & CXObjCDeclQualifier_Bycopy) __printf_chk (2 - 1,
"Bycopy" ",")
;
1156 PRINT_OBJC_QUAL(Byref)if (QT & CXObjCDeclQualifier_Byref) __printf_chk (2 - 1, "Byref"
",")
;
1157 PRINT_OBJC_QUAL(Oneway)if (QT & CXObjCDeclQualifier_Oneway) __printf_chk (2 - 1,
"Oneway" ",")
;
1158 printf("]")__printf_chk (2 - 1, "]");
1159 }
1160 }
1161 }
1162}
1163
1164static const char* GetCursorSource(CXCursor Cursor) {
1165 CXSourceLocation Loc = clang_getCursorLocation(Cursor);
1166 CXString source;
1167 CXFile file;
1168 clang_getExpansionLocation(Loc, &file, 0, 0, 0);
1169 source = clang_getFileName(file);
1170 if (!clang_getCString(source)) {
1171 clang_disposeString(source);
1172 return "<invalid loc>";
1173 }
1174 else {
1175 const char *b = basename(clang_getCString(source));
1176 clang_disposeString(source);
1177 return b;
1178 }
1179}
1180
1181static CXString createCXString(const char *CS) {
1182 CXString Str;
1183 Str.data = (const void *) CS;
1184 Str.private_flags = 0;
1185 return Str;
1186}
1187
1188/******************************************************************************/
1189/* Callbacks. */
1190/******************************************************************************/
1191
1192typedef void (*PostVisitTU)(CXTranslationUnit);
1193
1194void PrintDiagnostic(CXDiagnostic Diagnostic) {
1195 FILE *out = stderrstderr;
1196 CXFile file;
1197 CXString Msg;
1198 unsigned display_opts = CXDiagnostic_DisplaySourceLocation
1199 | CXDiagnostic_DisplayColumn | CXDiagnostic_DisplaySourceRanges
1200 | CXDiagnostic_DisplayOption;
1201 unsigned i, num_fixits;
1202
1203 if (clang_getDiagnosticSeverity(Diagnostic) == CXDiagnostic_Ignored)
1204 return;
1205
1206 Msg = clang_formatDiagnostic(Diagnostic, display_opts);
1207 fprintf(stderr, "%s\n", clang_getCString(Msg))__fprintf_chk (stderr, 2 - 1, "%s\n", clang_getCString(Msg));
1208 clang_disposeString(Msg);
1209
1210 clang_getSpellingLocation(clang_getDiagnosticLocation(Diagnostic),
1211 &file, 0, 0, 0);
1212 if (!file)
1213 return;
1214
1215 num_fixits = clang_getDiagnosticNumFixIts(Diagnostic);
1216 fprintf(stderr, "Number FIX-ITs = %d\n", num_fixits)__fprintf_chk (stderr, 2 - 1, "Number FIX-ITs = %d\n", num_fixits
)
;
1217 for (i = 0; i != num_fixits; ++i) {
1218 CXSourceRange range;
1219 CXString insertion_text = clang_getDiagnosticFixIt(Diagnostic, i, &range);
1220 CXSourceLocation start = clang_getRangeStart(range);
1221 CXSourceLocation end = clang_getRangeEnd(range);
1222 unsigned start_line, start_column, end_line, end_column;
1223 CXFile start_file, end_file;
1224 clang_getSpellingLocation(start, &start_file, &start_line,
1225 &start_column, 0);
1226 clang_getSpellingLocation(end, &end_file, &end_line, &end_column, 0);
1227 if (clang_equalLocations(start, end)) {
1228 /* Insertion. */
1229 if (start_file == file)
1230 fprintf(out, "FIX-IT: Insert \"%s\" at %d:%d\n",__fprintf_chk (out, 2 - 1, "FIX-IT: Insert \"%s\" at %d:%d\n"
, clang_getCString(insertion_text), start_line, start_column)
1231 clang_getCString(insertion_text), start_line, start_column)__fprintf_chk (out, 2 - 1, "FIX-IT: Insert \"%s\" at %d:%d\n"
, clang_getCString(insertion_text), start_line, start_column)
;
1232 } else if (strcmp(clang_getCString(insertion_text), "") == 0) {
1233 /* Removal. */
1234 if (start_file == file && end_file == file) {
1235 fprintf(out, "FIX-IT: Remove ")__fprintf_chk (out, 2 - 1, "FIX-IT: Remove ");
1236 PrintExtent(out, start_line, start_column, end_line, end_column);
1237 fprintf(out, "\n")__fprintf_chk (out, 2 - 1, "\n");
1238 }
1239 } else {
1240 /* Replacement. */
1241 if (start_file == end_file) {
1242 fprintf(out, "FIX-IT: Replace ")__fprintf_chk (out, 2 - 1, "FIX-IT: Replace ");
1243 PrintExtent(out, start_line, start_column, end_line, end_column);
1244 fprintf(out, " with \"%s\"\n", clang_getCString(insertion_text))__fprintf_chk (out, 2 - 1, " with \"%s\"\n", clang_getCString
(insertion_text))
;
1245 }
1246 }
1247 clang_disposeString(insertion_text);
1248 }
1249}
1250
1251void PrintDiagnosticSet(CXDiagnosticSet Set) {
1252 int i = 0, n = clang_getNumDiagnosticsInSet(Set);
1253 for ( ; i != n ; ++i) {
1254 CXDiagnostic Diag = clang_getDiagnosticInSet(Set, i);
1255 CXDiagnosticSet ChildDiags = clang_getChildDiagnostics(Diag);
1256 PrintDiagnostic(Diag);
1257 if (ChildDiags)
1258 PrintDiagnosticSet(ChildDiags);
1259 }
1260}
1261
1262void PrintDiagnostics(CXTranslationUnit TU) {
1263 CXDiagnosticSet TUSet = clang_getDiagnosticSetFromTU(TU);
1264 PrintDiagnosticSet(TUSet);
1265 clang_disposeDiagnosticSet(TUSet);
1266}
1267
1268void PrintMemoryUsage(CXTranslationUnit TU) {
1269 unsigned long total = 0;
1270 unsigned i = 0;
1271 CXTUResourceUsage usage = clang_getCXTUResourceUsage(TU);
1272 fprintf(stderr, "Memory usage:\n")__fprintf_chk (stderr, 2 - 1, "Memory usage:\n");
1273 for (i = 0 ; i != usage.numEntries; ++i) {
1274 const char *name = clang_getTUResourceUsageName(usage.entries[i].kind);
1275 unsigned long amount = usage.entries[i].amount;
1276 total += amount;
1277 fprintf(stderr, " %s : %ld bytes (%f MBytes)\n", name, amount,__fprintf_chk (stderr, 2 - 1, " %s : %ld bytes (%f MBytes)\n"
, name, amount, ((double) amount)/(1024*1024))
1278 ((double) amount)/(1024*1024))__fprintf_chk (stderr, 2 - 1, " %s : %ld bytes (%f MBytes)\n"
, name, amount, ((double) amount)/(1024*1024))
;
1279 }
1280 fprintf(stderr, " TOTAL = %ld bytes (%f MBytes)\n", total,__fprintf_chk (stderr, 2 - 1, " TOTAL = %ld bytes (%f MBytes)\n"
, total, ((double) total)/(1024*1024))
1281 ((double) total)/(1024*1024))__fprintf_chk (stderr, 2 - 1, " TOTAL = %ld bytes (%f MBytes)\n"
, total, ((double) total)/(1024*1024))
;
1282 clang_disposeCXTUResourceUsage(usage);
1283}
1284
1285/******************************************************************************/
1286/* Logic for testing traversal. */
1287/******************************************************************************/
1288
1289static void PrintCursorExtent(CXCursor C) {
1290 CXSourceRange extent = clang_getCursorExtent(C);
1291 PrintRange(extent, "Extent");
1292}
1293
1294/* Data used by the visitors. */
1295typedef struct {
1296 CXTranslationUnit TU;
1297 enum CXCursorKind *Filter;
1298 const char *CommentSchemaFile;
1299} VisitorData;
1300
1301
1302enum CXChildVisitResult FilteredPrintingVisitor(CXCursor Cursor,
1303 CXCursor Parent,
1304 CXClientData ClientData) {
1305 VisitorData *Data = (VisitorData *)ClientData;
1306 if (!Data->Filter || (Cursor.kind == *(enum CXCursorKind *)Data->Filter)) {
1307 CXSourceLocation Loc = clang_getCursorLocation(Cursor);
1308 unsigned line, column;
1309 clang_getSpellingLocation(Loc, 0, &line, &column, 0);
1310 printf("// %s: %s:%d:%d: ", FileCheckPrefix,__printf_chk (2 - 1, "// %s: %s:%d:%d: ", FileCheckPrefix, GetCursorSource
(Cursor), line, column)
1311 GetCursorSource(Cursor), line, column)__printf_chk (2 - 1, "// %s: %s:%d:%d: ", FileCheckPrefix, GetCursorSource
(Cursor), line, column)
;
1312 PrintCursor(Cursor, Data->CommentSchemaFile);
1313 PrintCursorExtent(Cursor);
1314 if (clang_isDeclaration(Cursor.kind)) {
1315 enum CX_CXXAccessSpecifier access = clang_getCXXAccessSpecifier(Cursor);
1316 const char *accessStr = 0;
1317
1318 switch (access) {
1319 case CX_CXXInvalidAccessSpecifier: break;
1320 case CX_CXXPublic:
1321 accessStr = "public"; break;
1322 case CX_CXXProtected:
1323 accessStr = "protected"; break;
1324 case CX_CXXPrivate:
1325 accessStr = "private"; break;
1326 }
1327
1328 if (accessStr)
1329 printf(" [access=%s]", accessStr)__printf_chk (2 - 1, " [access=%s]", accessStr);
1330 }
1331 printf("\n")__printf_chk (2 - 1, "\n");
1332 return CXChildVisit_Recurse;
1333 }
1334
1335 return CXChildVisit_Continue;
1336}
1337
1338static enum CXChildVisitResult FunctionScanVisitor(CXCursor Cursor,
1339 CXCursor Parent,
1340 CXClientData ClientData) {
1341 const char *startBuf, *endBuf;
1342 unsigned startLine, startColumn, endLine, endColumn, curLine, curColumn;
1343 CXCursor Ref;
1344 VisitorData *Data = (VisitorData *)ClientData;
1345
1346 if (Cursor.kind != CXCursor_FunctionDecl ||
1347 !clang_isCursorDefinition(Cursor))
1348 return CXChildVisit_Continue;
1349
1350 clang_getDefinitionSpellingAndExtent(Cursor, &startBuf, &endBuf,
1351 &startLine, &startColumn,
1352 &endLine, &endColumn);
1353 /* Probe the entire body, looking for both decls and refs. */
1354 curLine = startLine;
1355 curColumn = startColumn;
1356
1357 while (startBuf < endBuf) {
1358 CXSourceLocation Loc;
1359 CXFile file;
1360 CXString source;
1361
1362 if (*startBuf == '\n') {
1363 startBuf++;
1364 curLine++;
1365 curColumn = 1;
1366 } else if (*startBuf != '\t')
1367 curColumn++;
1368
1369 Loc = clang_getCursorLocation(Cursor);
1370 clang_getSpellingLocation(Loc, &file, 0, 0, 0);
1371
1372 source = clang_getFileName(file);
1373 if (clang_getCString(source)) {
1374 CXSourceLocation RefLoc
1375 = clang_getLocation(Data->TU, file, curLine, curColumn);
1376 Ref = clang_getCursor(Data->TU, RefLoc);
1377 if (Ref.kind == CXCursor_NoDeclFound) {
1378 /* Nothing found here; that's fine. */
1379 } else if (Ref.kind != CXCursor_FunctionDecl) {
1380 printf("// %s: %s:%d:%d: ", FileCheckPrefix, GetCursorSource(Ref),__printf_chk (2 - 1, "// %s: %s:%d:%d: ", FileCheckPrefix, GetCursorSource
(Ref), curLine, curColumn)
1381 curLine, curColumn)__printf_chk (2 - 1, "// %s: %s:%d:%d: ", FileCheckPrefix, GetCursorSource
(Ref), curLine, curColumn)
;
1382 PrintCursor(Ref, Data->CommentSchemaFile);
1383 printf("\n")__printf_chk (2 - 1, "\n");
1384 }
1385 }
1386 clang_disposeString(source);
1387 startBuf++;
1388 }
1389
1390 return CXChildVisit_Continue;
1391}
1392
1393/******************************************************************************/
1394/* USR testing. */
1395/******************************************************************************/
1396
1397enum CXChildVisitResult USRVisitor(CXCursor C, CXCursor parent,
1398 CXClientData ClientData) {
1399 VisitorData *Data = (VisitorData *)ClientData;
1400 if (!Data->Filter || (C.kind == *(enum CXCursorKind *)Data->Filter)) {
1401 CXString USR = clang_getCursorUSR(C);
1402 const char *cstr = clang_getCString(USR);
1403 if (!cstr || cstr[0] == '\0') {
1404 clang_disposeString(USR);
1405 return CXChildVisit_Recurse;
1406 }
1407 printf("// %s: %s %s", FileCheckPrefix, GetCursorSource(C), cstr)__printf_chk (2 - 1, "// %s: %s %s", FileCheckPrefix, GetCursorSource
(C), cstr)
;
1408
1409 PrintCursorExtent(C);
1410 printf("\n")__printf_chk (2 - 1, "\n");
1411 clang_disposeString(USR);
1412
1413 return CXChildVisit_Recurse;
1414 }
1415
1416 return CXChildVisit_Continue;
1417}
1418
1419/******************************************************************************/
1420/* Inclusion stack testing. */
1421/******************************************************************************/
1422
1423void InclusionVisitor(CXFile includedFile, CXSourceLocation *includeStack,
1424 unsigned includeStackLen, CXClientData data) {
1425
1426 unsigned i;
1427 CXString fname;
1428
1429 fname = clang_getFileName(includedFile);
1430 printf("file: %s\nincluded by:\n", clang_getCString(fname))__printf_chk (2 - 1, "file: %s\nincluded by:\n", clang_getCString
(fname))
;
1431 clang_disposeString(fname);
1432
1433 for (i = 0; i < includeStackLen; ++i) {
1434 CXFile includingFile;
1435 unsigned line, column;
1436 clang_getSpellingLocation(includeStack[i], &includingFile, &line,
1437 &column, 0);
1438 fname = clang_getFileName(includingFile);
1439 printf(" %s:%d:%d\n", clang_getCString(fname), line, column)__printf_chk (2 - 1, " %s:%d:%d\n", clang_getCString(fname),
line, column)
;
1440 clang_disposeString(fname);
1441 }
1442 printf("\n")__printf_chk (2 - 1, "\n");
1443}
1444
1445void PrintInclusionStack(CXTranslationUnit TU) {
1446 clang_getInclusions(TU, InclusionVisitor, NULL((void*)0));
1447}
1448
1449/******************************************************************************/
1450/* Linkage testing. */
1451/******************************************************************************/
1452
1453static enum CXChildVisitResult PrintLinkage(CXCursor cursor, CXCursor p,
1454 CXClientData d) {
1455 const char *linkage = 0;
1456
1457 if (clang_isInvalid(clang_getCursorKind(cursor)))
1458 return CXChildVisit_Recurse;
1459
1460 switch (clang_getCursorLinkage(cursor)) {
1461 case CXLinkage_Invalid: break;
1462 case CXLinkage_NoLinkage: linkage = "NoLinkage"; break;
1463 case CXLinkage_Internal: linkage = "Internal"; break;
1464 case CXLinkage_UniqueExternal: linkage = "UniqueExternal"; break;
1465 case CXLinkage_External: linkage = "External"; break;
1466 }
1467
1468 if (linkage) {
1469 PrintCursor(cursor, NULL((void*)0));
1470 printf("linkage=%s\n", linkage)__printf_chk (2 - 1, "linkage=%s\n", linkage);
1471 }
1472
1473 return CXChildVisit_Recurse;
1474}
1475
1476/******************************************************************************/
1477/* Visibility testing. */
1478/******************************************************************************/
1479
1480static enum CXChildVisitResult PrintVisibility(CXCursor cursor, CXCursor p,
1481 CXClientData d) {
1482 const char *visibility = 0;
1483
1484 if (clang_isInvalid(clang_getCursorKind(cursor)))
1485 return CXChildVisit_Recurse;
1486
1487 switch (clang_getCursorVisibility(cursor)) {
1488 case CXVisibility_Invalid: break;
1489 case CXVisibility_Hidden: visibility = "Hidden"; break;
1490 case CXVisibility_Protected: visibility = "Protected"; break;
1491 case CXVisibility_Default: visibility = "Default"; break;
1492 }
1493
1494 if (visibility) {
1495 PrintCursor(cursor, NULL((void*)0));
1496 printf("visibility=%s\n", visibility)__printf_chk (2 - 1, "visibility=%s\n", visibility);
1497 }
1498
1499 return CXChildVisit_Recurse;
1500}
1501
1502/******************************************************************************/
1503/* Typekind testing. */
1504/******************************************************************************/
1505
1506static void PrintTypeAndTypeKind(CXType T, const char *Format) {
1507 CXString TypeSpelling, TypeKindSpelling;
1508
1509 TypeSpelling = clang_getTypeSpelling(T);
1510 TypeKindSpelling = clang_getTypeKindSpelling(T.kind);
1511 printf(Format,__printf_chk (2 - 1, Format, clang_getCString(TypeSpelling), clang_getCString
(TypeKindSpelling))
1512 clang_getCString(TypeSpelling),__printf_chk (2 - 1, Format, clang_getCString(TypeSpelling), clang_getCString
(TypeKindSpelling))
1513 clang_getCString(TypeKindSpelling))__printf_chk (2 - 1, Format, clang_getCString(TypeSpelling), clang_getCString
(TypeKindSpelling))
;
1514 clang_disposeString(TypeSpelling);
1515 clang_disposeString(TypeKindSpelling);
1516}
1517
1518static enum CXVisitorResult FieldVisitor(CXCursor C,
1519 CXClientData client_data) {
1520 (*(int *) client_data)+=1;
1521 return CXVisit_Continue;
1522}
1523
1524static void PrintTypeTemplateArgs(CXType T, const char *Format) {
1525 int NumTArgs = clang_Type_getNumTemplateArguments(T);
1526 if (NumTArgs != -1 && NumTArgs != 0) {
1527 int i;
1528 CXType TArg;
1529 printf(Format, NumTArgs)__printf_chk (2 - 1, Format, NumTArgs);
1530 for (i = 0; i < NumTArgs; ++i) {
1531 TArg = clang_Type_getTemplateArgumentAsType(T, i);
1532 if (TArg.kind != CXType_Invalid) {
1533 PrintTypeAndTypeKind(TArg, " [type=%s] [typekind=%s]");
1534 }
1535 }
1536 /* Ensure that the returned type is invalid when indexing off-by-one. */
1537 TArg = clang_Type_getTemplateArgumentAsType(T, i);
1538 assert(TArg.kind == CXType_Invalid)((void) sizeof ((TArg.kind == CXType_Invalid) ? 1 : 0), __extension__
({ if (TArg.kind == CXType_Invalid) ; else __assert_fail ("TArg.kind == CXType_Invalid"
, "clang/tools/c-index-test/c-index-test.c", 1538, __extension__
__PRETTY_FUNCTION__); }))
;
1539 printf("]")__printf_chk (2 - 1, "]");
1540 }
1541}
1542
1543static void PrintNullabilityKind(CXType T, const char *Format) {
1544 enum CXTypeNullabilityKind N = clang_Type_getNullability(T);
1545
1546 const char *nullability = 0;
1547 switch (N) {
1548 case CXTypeNullability_NonNull:
1549 nullability = "nonnull";
1550 break;
1551 case CXTypeNullability_Nullable:
1552 nullability = "nullable";
1553 break;
1554 case CXTypeNullability_NullableResult:
1555 nullability = "nullable_result";
1556 break;
1557 case CXTypeNullability_Unspecified:
1558 nullability = "unspecified";
1559 break;
1560 case CXTypeNullability_Invalid:
1561 break;
1562 }
1563
1564 if (nullability) {
1565 printf(Format, nullability)__printf_chk (2 - 1, Format, nullability);
1566 }
1567}
1568
1569static enum CXChildVisitResult PrintType(CXCursor cursor, CXCursor p,
1570 CXClientData d) {
1571 if (!clang_isInvalid(clang_getCursorKind(cursor))) {
1572 CXType T = clang_getCursorType(cursor);
1573 CXType PT = clang_getPointeeType(T);
1574 enum CXRefQualifierKind RQ = clang_Type_getCXXRefQualifier(T);
1575 PrintCursor(cursor, NULL((void*)0));
1576 PrintTypeAndTypeKind(T, " [type=%s] [typekind=%s]");
1577 PrintNullabilityKind(T, " [nullability=%s]");
1578 if (clang_isConstQualifiedType(T))
1579 printf(" const")__printf_chk (2 - 1, " const");
1580 if (clang_isVolatileQualifiedType(T))
1581 printf(" volatile")__printf_chk (2 - 1, " volatile");
1582 if (clang_isRestrictQualifiedType(T))
1583 printf(" restrict")__printf_chk (2 - 1, " restrict");
1584 if (RQ == CXRefQualifier_LValue)
1585 printf(" lvalue-ref-qualifier")__printf_chk (2 - 1, " lvalue-ref-qualifier");
1586 if (RQ == CXRefQualifier_RValue)
1587 printf(" rvalue-ref-qualifier")__printf_chk (2 - 1, " rvalue-ref-qualifier");
1588 /* Print the template argument types if they exist. */
1589 PrintTypeTemplateArgs(T, " [templateargs/%d=");
1590 /* Print the canonical type if it is different. */
1591 {
1592 CXType CT = clang_getCanonicalType(T);
1593 if (!clang_equalTypes(T, CT)) {
1594 PrintTypeAndTypeKind(CT, " [canonicaltype=%s] [canonicaltypekind=%s]");
1595 PrintTypeTemplateArgs(CT, " [canonicaltemplateargs/%d=");
1596 }
1597 }
1598 /* Print the value type if it exists. */
1599 {
1600 CXType VT = clang_Type_getValueType(T);
1601 if (VT.kind != CXType_Invalid)
1602 PrintTypeAndTypeKind(VT, " [valuetype=%s] [valuetypekind=%s]");
1603 }
1604 /* Print the modified type if it exists. */
1605 {
1606 CXType MT = clang_Type_getModifiedType(T);
1607 if (MT.kind != CXType_Invalid) {
1608 PrintTypeAndTypeKind(MT, " [modifiedtype=%s] [modifiedtypekind=%s]");
1609 }
1610 }
1611 /* Print the return type if it exists. */
1612 {
1613 CXType RT = clang_getCursorResultType(cursor);
1614 if (RT.kind != CXType_Invalid) {
1615 PrintTypeAndTypeKind(RT, " [resulttype=%s] [resulttypekind=%s]");
1616 }
1617 PrintNullabilityKind(RT, " [resultnullability=%s]");
1618 }
1619 /* Print the argument types if they exist. */
1620 {
1621 int NumArgs = clang_Cursor_getNumArguments(cursor);
1622 if (NumArgs != -1 && NumArgs != 0) {
1623 int i;
1624 printf(" [args=")__printf_chk (2 - 1, " [args=");
1625 for (i = 0; i < NumArgs; ++i) {
1626 CXType T = clang_getCursorType(clang_Cursor_getArgument(cursor, i));
1627 if (T.kind != CXType_Invalid) {
1628 PrintTypeAndTypeKind(T, " [%s] [%s]");
1629 PrintNullabilityKind(T, " [%s]");
1630 }
1631 }
1632 printf("]")__printf_chk (2 - 1, "]");
1633 }
1634 }
1635 /* Print ObjC base types, type arguments, and protocol list if available. */
1636 {
1637 CXType BT = clang_Type_getObjCObjectBaseType(PT);
1638 if (BT.kind != CXType_Invalid) {
1639 PrintTypeAndTypeKind(BT, " [basetype=%s] [basekind=%s]");
1640 }
1641 }
1642 {
1643 unsigned NumTypeArgs = clang_Type_getNumObjCTypeArgs(PT);
1644 if (NumTypeArgs > 0) {
1645 unsigned i;
1646 printf(" [typeargs=")__printf_chk (2 - 1, " [typeargs=");
1647 for (i = 0; i < NumTypeArgs; ++i) {
1648 CXType TA = clang_Type_getObjCTypeArg(PT, i);
1649 if (TA.kind != CXType_Invalid) {
1650 PrintTypeAndTypeKind(TA, " [%s] [%s]");
1651 }
1652 }
1653 printf("]")__printf_chk (2 - 1, "]");
1654 }
1655 }
1656 {
1657 unsigned NumProtocols = clang_Type_getNumObjCProtocolRefs(PT);
1658 if (NumProtocols > 0) {
1659 unsigned i;
1660 printf(" [protocols=")__printf_chk (2 - 1, " [protocols=");
1661 for (i = 0; i < NumProtocols; ++i) {
1662 CXCursor P = clang_Type_getObjCProtocolDecl(PT, i);
1663 if (!clang_isInvalid(clang_getCursorKind(P))) {
1664 PrintCursor(P, NULL((void*)0));
1665 }
1666 }
1667 printf("]")__printf_chk (2 - 1, "]");
1668 }
1669 }
1670 /* Print if this is a non-POD type. */
1671 printf(" [isPOD=%d]", clang_isPODType(T))__printf_chk (2 - 1, " [isPOD=%d]", clang_isPODType(T));
1672 /* Print the pointee type. */
1673 {
1674 if (PT.kind != CXType_Invalid) {
1675 PrintTypeAndTypeKind(PT, " [pointeetype=%s] [pointeekind=%s]");
1676 }
1677 }
1678 /* Print the number of fields if they exist. */
1679 {
1680 int numFields = 0;
1681 if (clang_Type_visitFields(T, FieldVisitor, &numFields)){
1682 if (numFields != 0) {
1683 printf(" [nbFields=%d]", numFields)__printf_chk (2 - 1, " [nbFields=%d]", numFields);
1684 }
1685 }
1686 }
1687
1688 /* Print if it is an anonymous record or namespace. */
1689 {
1690 unsigned isAnon = clang_Cursor_isAnonymous(cursor);
1691 if (isAnon != 0) {
1692 printf(" [isAnon=%d]", isAnon)__printf_chk (2 - 1, " [isAnon=%d]", isAnon);
1693 }
1694 }
1695
1696 /* Print if it is an anonymous record decl */
1697 {
1698 unsigned isAnonRecDecl = clang_Cursor_isAnonymousRecordDecl(cursor);
1699 printf(" [isAnonRecDecl=%d]", isAnonRecDecl)__printf_chk (2 - 1, " [isAnonRecDecl=%d]", isAnonRecDecl);
1700 }
1701
1702 /* Print if it is an inline namespace decl */
1703 {
1704 unsigned isInlineNamespace = clang_Cursor_isInlineNamespace(cursor);
1705 if (isInlineNamespace != 0)
1706 printf(" [isInlineNamespace=%d]", isInlineNamespace)__printf_chk (2 - 1, " [isInlineNamespace=%d]", isInlineNamespace
)
;
1707 }
1708
1709 printf("\n")__printf_chk (2 - 1, "\n");
1710 }
1711 return CXChildVisit_Recurse;
1712}
1713
1714static void PrintSingleTypeSize(CXType T, const char *TypeKindFormat,
1715 const char *SizeFormat,
1716 const char *AlignFormat) {
1717 PrintTypeAndTypeKind(T, TypeKindFormat);
1718 /* Print the type sizeof if applicable. */
1719 {
1720 long long Size = clang_Type_getSizeOf(T);
1721 if (Size >= 0 || Size < -1 ) {
1722 printf(SizeFormat, Size)__printf_chk (2 - 1, SizeFormat, Size);
1723 }
1724 }
1725 /* Print the type alignof if applicable. */
1726 {
1727 long long Align = clang_Type_getAlignOf(T);
1728 if (Align >= 0 || Align < -1) {
1729 printf(AlignFormat, Align)__printf_chk (2 - 1, AlignFormat, Align);
1730 }
1731 }
1732
1733 /* Print the return type if it exists. */
1734 {
1735 CXType RT = clang_getResultType(T);
1736 if (RT.kind != CXType_Invalid)
1737 PrintSingleTypeSize(RT, " [resulttype=%s] [resulttypekind=%s]",
1738 " [resultsizeof=%lld]", " [resultalignof=%lld]");
1739 }
1740}
1741
1742static enum CXChildVisitResult PrintTypeSize(CXCursor cursor, CXCursor p,
1743 CXClientData d) {
1744 CXType T;
1745 enum CXCursorKind K = clang_getCursorKind(cursor);
1746 if (clang_isInvalid(K))
1747 return CXChildVisit_Recurse;
1748 T = clang_getCursorType(cursor);
1749 PrintCursor(cursor, NULL((void*)0));
1750 PrintSingleTypeSize(T, " [type=%s] [typekind=%s]", " [sizeof=%lld]",
1751 " [alignof=%lld]");
1752 /* Print the record field offset if applicable. */
1753 {
1754 CXString FieldSpelling = clang_getCursorSpelling(cursor);
1755 const char *FieldName = clang_getCString(FieldSpelling);
1756 /* recurse to get the first parent record that is not anonymous. */
1757 unsigned RecordIsAnonymous = 0;
1758 if (clang_getCursorKind(cursor) == CXCursor_FieldDecl) {
1759 CXCursor Record;
1760 CXCursor Parent = p;
1761 do {
1762 Record = Parent;
1763 Parent = clang_getCursorSemanticParent(Record);
1764 RecordIsAnonymous = clang_Cursor_isAnonymous(Record);
1765 /* Recurse as long as the parent is a CXType_Record and the Record
1766 is anonymous */
1767 } while ( clang_getCursorType(Parent).kind == CXType_Record &&
1768 RecordIsAnonymous > 0);
1769 {
1770 long long Offset = clang_Type_getOffsetOf(clang_getCursorType(Record),
1771 FieldName);
1772 long long Offset2 = clang_Cursor_getOffsetOfField(cursor);
1773 if (Offset == Offset2){
1774 printf(" [offsetof=%lld]", Offset)__printf_chk (2 - 1, " [offsetof=%lld]", Offset);
1775 } else {
1776 /* Offsets will be different in anonymous records. */
1777 printf(" [offsetof=%lld/%lld]", Offset, Offset2)__printf_chk (2 - 1, " [offsetof=%lld/%lld]", Offset, Offset2
)
;
1778 }
1779 }
1780 }
1781 clang_disposeString(FieldSpelling);
1782 }
1783 /* Print if its a bitfield */
1784 {
1785 int IsBitfield = clang_Cursor_isBitField(cursor);
1786 if (IsBitfield)
1787 printf(" [BitFieldSize=%d]", clang_getFieldDeclBitWidth(cursor))__printf_chk (2 - 1, " [BitFieldSize=%d]", clang_getFieldDeclBitWidth
(cursor))
;
1788 }
1789
1790 printf("\n")__printf_chk (2 - 1, "\n");
1791
1792 return CXChildVisit_Recurse;
1793}
1794
1795/******************************************************************************/
1796/* Mangling testing. */
1797/******************************************************************************/
1798
1799static enum CXChildVisitResult PrintMangledName(CXCursor cursor, CXCursor p,
1800 CXClientData d) {
1801 CXString MangledName;
1802 if (clang_isUnexposed(clang_getCursorKind(cursor)))
1803 return CXChildVisit_Recurse;
1804 PrintCursor(cursor, NULL((void*)0));
1805 MangledName = clang_Cursor_getMangling(cursor);
1806 printf(" [mangled=%s]\n", clang_getCString(MangledName))__printf_chk (2 - 1, " [mangled=%s]\n", clang_getCString(MangledName
))
;
1807 clang_disposeString(MangledName);
1808 return CXChildVisit_Continue;
1809}
1810
1811static enum CXChildVisitResult PrintManglings(CXCursor cursor, CXCursor p,
1812 CXClientData d) {
1813 unsigned I, E;
1814 CXStringSet *Manglings = NULL((void*)0);
1815 if (clang_isUnexposed(clang_getCursorKind(cursor)))
1816 return CXChildVisit_Recurse;
1817 if (!clang_isDeclaration(clang_getCursorKind(cursor)))
1818 return CXChildVisit_Recurse;
1819 if (clang_getCursorKind(cursor) == CXCursor_ParmDecl)
1820 return CXChildVisit_Continue;
1821 PrintCursor(cursor, NULL((void*)0));
1822 Manglings = clang_Cursor_getCXXManglings(cursor);
1823 if (Manglings) {
1824 for (I = 0, E = Manglings->Count; I < E; ++I)
1825 printf(" [mangled=%s]", clang_getCString(Manglings->Strings[I]))__printf_chk (2 - 1, " [mangled=%s]", clang_getCString(Manglings
->Strings[I]))
;
1826 clang_disposeStringSet(Manglings);
1827 printf("\n")__printf_chk (2 - 1, "\n");
1828 }
1829 Manglings = clang_Cursor_getObjCManglings(cursor);
1830 if (Manglings) {
1831 for (I = 0, E = Manglings->Count; I < E; ++I)
1832 printf(" [mangled=%s]", clang_getCString(Manglings->Strings[I]))__printf_chk (2 - 1, " [mangled=%s]", clang_getCString(Manglings
->Strings[I]))
;
1833 clang_disposeStringSet(Manglings);
1834 printf("\n")__printf_chk (2 - 1, "\n");
1835 }
1836 return CXChildVisit_Recurse;
1837}
1838
1839/******************************************************************************/
1840/* Bitwidth testing. */
1841/******************************************************************************/
1842
1843static enum CXChildVisitResult PrintBitWidth(CXCursor cursor, CXCursor p,
1844 CXClientData d) {
1845 int Bitwidth;
1846 if (clang_getCursorKind(cursor) != CXCursor_FieldDecl)
1847 return CXChildVisit_Recurse;
1848
1849 Bitwidth = clang_getFieldDeclBitWidth(cursor);
1850 if (Bitwidth >= 0) {
1851 PrintCursor(cursor, NULL((void*)0));
1852 printf(" bitwidth=%d\n", Bitwidth)__printf_chk (2 - 1, " bitwidth=%d\n", Bitwidth);
1853 }
1854
1855 return CXChildVisit_Recurse;
1856}
1857
1858/******************************************************************************/
1859/* Type declaration testing */
1860/******************************************************************************/
1861
1862static enum CXChildVisitResult PrintTypeDeclaration(CXCursor cursor, CXCursor p,
1863 CXClientData d) {
1864 CXCursor typeDeclaration = clang_getTypeDeclaration(clang_getCursorType(cursor));
1865
1866 if (clang_isDeclaration(typeDeclaration.kind)) {
1867 PrintCursor(cursor, NULL((void*)0));
1868 PrintTypeAndTypeKind(clang_getCursorType(typeDeclaration), " [typedeclaration=%s] [typekind=%s]\n");
1869 }
1870
1871 return CXChildVisit_Recurse;
1872}
1873
1874/******************************************************************************/
1875/* Declaration attributes testing */
1876/******************************************************************************/
1877
1878static enum CXChildVisitResult PrintDeclAttributes(CXCursor cursor, CXCursor p,
1879 CXClientData d) {
1880 if (clang_isDeclaration(cursor.kind)) {
1881 printf("\n")__printf_chk (2 - 1, "\n");
1882 PrintCursor(cursor, NULL((void*)0));
1883 return CXChildVisit_Recurse;
1884 } else if (clang_isAttribute(cursor.kind)) {
1885 printf(" ")__printf_chk (2 - 1, " ");
1886 PrintCursor(cursor, NULL((void*)0));
1887 }
1888 return CXChildVisit_Continue;
1889}
1890
1891/******************************************************************************/
1892/* Target information testing. */
1893/******************************************************************************/
1894
1895static int print_target_info(int argc, const char **argv) {
1896 CXIndex Idx;
1897 CXTranslationUnit TU;
1898 CXTargetInfo TargetInfo;
1899 CXString Triple;
1900 const char *FileName;
1901 enum CXErrorCode Err;
1902 int PointerWidth;
1903
1904 if (argc == 0) {
1905 fprintf(stderr, "No filename specified\n")__fprintf_chk (stderr, 2 - 1, "No filename specified\n");
1906 return 1;
1907 }
1908
1909 FileName = argv[1];
1910
1911 Idx = clang_createIndex(0, 1);
1912 Err = clang_parseTranslationUnit2(Idx, FileName, argv, argc, NULL((void*)0), 0,
1913 getDefaultParsingOptions(), &TU);
1914 if (Err != CXError_Success) {
1915 fprintf(stderr, "Couldn't parse translation unit!\n")__fprintf_chk (stderr, 2 - 1, "Couldn't parse translation unit!\n"
)
;
1916 describeLibclangFailure(Err);
1917 clang_disposeIndex(Idx);
1918 return 1;
1919 }
1920
1921 TargetInfo = clang_getTranslationUnitTargetInfo(TU);
1922
1923 Triple = clang_TargetInfo_getTriple(TargetInfo);
1924 printf("TargetTriple: %s\n", clang_getCString(Triple))__printf_chk (2 - 1, "TargetTriple: %s\n", clang_getCString(Triple
))
;
1925 clang_disposeString(Triple);
1926
1927 PointerWidth = clang_TargetInfo_getPointerWidth(TargetInfo);
1928 printf("PointerWidth: %d\n", PointerWidth)__printf_chk (2 - 1, "PointerWidth: %d\n", PointerWidth);
1929
1930 clang_TargetInfo_dispose(TargetInfo);
1931 clang_disposeTranslationUnit(TU);
1932 clang_disposeIndex(Idx);
1933 return 0;
1934}
1935
1936/******************************************************************************/
1937/* Loading ASTs/source. */
1938/******************************************************************************/
1939
1940static int perform_test_load(CXIndex Idx, CXTranslationUnit TU,
1941 const char *filter, const char *prefix,
1942 CXCursorVisitor Visitor,
1943 PostVisitTU PV,
1944 const char *CommentSchemaFile) {
1945
1946 if (prefix)
1947 FileCheckPrefix = prefix;
1948
1949 if (Visitor) {
1950 enum CXCursorKind K = CXCursor_NotImplemented;
1951 enum CXCursorKind *ck = &K;
1952 VisitorData Data;
1953
1954 /* Perform some simple filtering. */
1955 if (!strcmp(filter, "all") || !strcmp(filter, "local")) ck = NULL((void*)0);
1956 else if (!strcmp(filter, "all-display") ||
1957 !strcmp(filter, "local-display")) {
1958 ck = NULL((void*)0);
1959 wanted_display_type = DisplayType_DisplayName;
1960 }
1961 else if (!strcmp(filter, "all-pretty") ||
1962 !strcmp(filter, "local-pretty")) {
1963 ck = NULL((void*)0);
1964 wanted_display_type = DisplayType_Pretty;
1965 }
1966 else if (!strcmp(filter, "none")) K = (enum CXCursorKind) ~0;
1967 else if (!strcmp(filter, "category")) K = CXCursor_ObjCCategoryDecl;
1968 else if (!strcmp(filter, "interface")) K = CXCursor_ObjCInterfaceDecl;
1969 else if (!strcmp(filter, "protocol")) K = CXCursor_ObjCProtocolDecl;
1970 else if (!strcmp(filter, "function")) K = CXCursor_FunctionDecl;
1971 else if (!strcmp(filter, "typedef")) K = CXCursor_TypedefDecl;
1972 else if (!strcmp(filter, "scan-function")) Visitor = FunctionScanVisitor;
1973 else {
1974 fprintf(stderr, "Unknown filter for -test-load-tu: %s\n", filter)__fprintf_chk (stderr, 2 - 1, "Unknown filter for -test-load-tu: %s\n"
, filter)
;
1975 return 1;
1976 }
1977
1978 Data.TU = TU;
1979 Data.Filter = ck;
1980 Data.CommentSchemaFile = CommentSchemaFile;
1981 clang_visitChildren(clang_getTranslationUnitCursor(TU), Visitor, &Data);
1982 }
1983
1984 if (PV)
1985 PV(TU);
1986
1987 PrintDiagnostics(TU);
1988 if (checkForErrors(TU) != 0) {
1989 clang_disposeTranslationUnit(TU);
1990 return -1;
1991 }
1992
1993 clang_disposeTranslationUnit(TU);
1994 return 0;
1995}
1996
1997int perform_test_load_tu(const char *file, const char *filter,
1998 const char *prefix, CXCursorVisitor Visitor,
1999 PostVisitTU PV) {
2000 CXIndex Idx;
2001 CXTranslationUnit TU;
2002 int result;
2003 Idx = clang_createIndex(/* excludeDeclsFromPCH */
2004 !strcmp(filter, "local") ? 1 : 0,
2005 /* displayDiagnostics=*/1);
2006
2007 if (!CreateTranslationUnit(Idx, file, &TU)) {
2008 clang_disposeIndex(Idx);
2009 return 1;
2010 }
2011
2012 result = perform_test_load(Idx, TU, filter, prefix, Visitor, PV, NULL((void*)0));
2013 clang_disposeIndex(Idx);
2014 return result;
2015}
2016
2017int perform_test_load_source(int argc, const char **argv,
2018 const char *filter, CXCursorVisitor Visitor,
2019 PostVisitTU PV) {
2020 CXIndex Idx;
2021 CXTranslationUnit TU;
2022 const char *CommentSchemaFile;
2023 struct CXUnsavedFile *unsaved_files = 0;
2024 int num_unsaved_files = 0;
2025 enum CXErrorCode Err;
2026 int result;
2027 unsigned Repeats = 0;
2028 unsigned I;
2029 const char *InvocationPath;
2030
2031 Idx = clang_createIndex(/* excludeDeclsFromPCH */
2032 (!strcmp(filter, "local") ||
2033 !strcmp(filter, "local-display") ||
2034 !strcmp(filter, "local-pretty"))
2035 ? 1
2036 : 0,
2037 /* displayDiagnostics=*/1);
2038 InvocationPath = getenv("CINDEXTEST_INVOCATION_EMISSION_PATH");
2039 if (InvocationPath)
2040 clang_CXIndex_setInvocationEmissionPathOption(Idx, InvocationPath);
2041
2042 if ((CommentSchemaFile = parse_comments_schema(argc, argv))) {
2043 argc--;
2044 argv++;
2045 }
2046
2047 if (parse_remapped_files(argc, argv, 0, &unsaved_files, &num_unsaved_files)) {
2048 clang_disposeIndex(Idx);
2049 return -1;
2050 }
2051
2052 if (getenv("CINDEXTEST_EDITING"))
2053 Repeats = 5;
2054
2055 Err = clang_parseTranslationUnit2(Idx, 0,
2056 argv + num_unsaved_files,
2057 argc - num_unsaved_files,
2058 unsaved_files, num_unsaved_files,
2059 getDefaultParsingOptions(), &TU);
2060 if (Err != CXError_Success) {
2061 fprintf(stderr, "Unable to load translation unit!\n")__fprintf_chk (stderr, 2 - 1, "Unable to load translation unit!\n"
)
;
2062 describeLibclangFailure(Err);
2063 free_remapped_files(unsaved_files, num_unsaved_files);
2064 clang_disposeIndex(Idx);
2065 return 1;
2066 }
2067
2068 for (I = 0; I != Repeats; ++I) {
2069 if (checkForErrors(TU) != 0)
2070 return -1;
2071
2072 if (Repeats > 1) {
2073 clang_suspendTranslationUnit(TU);
2074
2075 Err = clang_reparseTranslationUnit(TU, num_unsaved_files, unsaved_files,
2076 clang_defaultReparseOptions(TU));
2077 if (Err != CXError_Success) {
2078 describeLibclangFailure(Err);
2079 free_remapped_files(unsaved_files, num_unsaved_files);
2080 clang_disposeIndex(Idx);
2081 return 1;
2082 }
2083 }
2084 }
2085
2086 result = perform_test_load(Idx, TU, filter, NULL((void*)0), Visitor, PV,
2087 CommentSchemaFile);
2088 free_remapped_files(unsaved_files, num_unsaved_files);
2089 clang_disposeIndex(Idx);
2090 return result;
2091}
2092
2093int perform_test_reparse_source(int argc, const char **argv, int trials,
2094 const char *filter, CXCursorVisitor Visitor,
2095 PostVisitTU PV) {
2096 CXIndex Idx;
2097 CXTranslationUnit TU;
2098 struct CXUnsavedFile *unsaved_files = 0;
2099 int num_unsaved_files = 0;
2100 int compiler_arg_idx = 0;
2101 enum CXErrorCode Err;
2102 int result, i;
2103 int trial;
2104 int execute_after_trial = 0;
2105 const char *execute_command = NULL((void*)0);
2106 int remap_after_trial = 0;
2107 char *endptr = 0;
2108
2109 Idx = clang_createIndex(/* excludeDeclsFromPCH */
2110 !strcmp(filter, "local") ? 1 : 0,
21
'?' condition is true
2111 /* displayDiagnostics=*/1);
2112
2113 if (parse_remapped_files(argc, argv, 0, &unsaved_files, &num_unsaved_files)) {
22
Taking false branch
2114 clang_disposeIndex(Idx);
2115 return -1;
2116 }
2117
2118 for (i = 0; i < argc; ++i) {
23
Loop condition is true. Entering loop body
2119 if (strcmp(argv[i], "--") == 0)
24
Taking true branch
2120 break;
2121 }
2122 if (i
25.1
'i' is < 'argc'
< argc)
25
Execution continues on line 2122
26
Taking true branch
2123 compiler_arg_idx = i+1;
2124 if (num_unsaved_files
26.1
'num_unsaved_files' is <= 'compiler_arg_idx'
> compiler_arg_idx)
27
Taking false branch
2125 compiler_arg_idx = num_unsaved_files;
2126
2127 /* Load the initial translation unit -- we do this without honoring remapped
2128 * files, so that we have a way to test results after changing the source. */
2129 Err = clang_parseTranslationUnit2(Idx, 0,
2130 argv + compiler_arg_idx,
2131 argc - compiler_arg_idx,
2132 0, 0, getDefaultParsingOptions(), &TU);
2133 if (Err != CXError_Success) {
28
Assuming 'Err' is equal to CXError_Success
29
Taking false branch
2134 fprintf(stderr, "Unable to load translation unit!\n")__fprintf_chk (stderr, 2 - 1, "Unable to load translation unit!\n"
)
;
2135 describeLibclangFailure(Err);
2136 free_remapped_files(unsaved_files, num_unsaved_files);
2137 clang_disposeIndex(Idx);
2138 return 1;
2139 }
2140
2141 if (checkForErrors(TU) != 0)
30
Taking false branch
2142 return -1;
2143
2144 if (getenv("CINDEXTEST_EXECUTE_COMMAND")) {
31
Assuming the environment variable does not exist
32
Taking false branch
2145 execute_command = getenv("CINDEXTEST_EXECUTE_COMMAND");
2146 }
2147 if (getenv("CINDEXTEST_EXECUTE_AFTER_TRIAL")) {
33
Assuming the environment variable does not exist
34
Taking false branch
2148 execute_after_trial =
2149 strtol(getenv("CINDEXTEST_EXECUTE_AFTER_TRIAL"), &endptr, 10);
2150 }
2151
2152 if (getenv("CINDEXTEST_REMAP_AFTER_TRIAL")) {
35
Assuming the environment variable exists
36
Taking true branch
2153 remap_after_trial =
2154 strtol(getenv("CINDEXTEST_REMAP_AFTER_TRIAL"), &endptr, 10);
37
Assuming the environment variable does not exist
38
Null pointer passed to 1st parameter expecting 'nonnull'
2155 }
2156
2157 for (trial = 0; trial < trials; ++trial) {
2158 if (execute_command && trial == execute_after_trial) {
2159 result = indextest_perform_shell_execution(execute_command);
2160 if (result != 0)
2161 return result;
2162 }
2163
2164 free_remapped_files(unsaved_files, num_unsaved_files);
2165 if (parse_remapped_files_with_try(trial, argc, argv, 0,
2166 &unsaved_files, &num_unsaved_files)) {
2167 clang_disposeTranslationUnit(TU);
2168 clang_disposeIndex(Idx);
2169 return -1;
2170 }
2171
2172 Err = clang_reparseTranslationUnit(
2173 TU,
2174 trial >= remap_after_trial ? num_unsaved_files : 0,
2175 trial >= remap_after_trial ? unsaved_files : 0,
2176 clang_defaultReparseOptions(TU));
2177 if (Err != CXError_Success) {
2178 fprintf(stderr, "Unable to reparse translation unit!\n")__fprintf_chk (stderr, 2 - 1, "Unable to reparse translation unit!\n"
)
;
2179 describeLibclangFailure(Err);
2180 clang_disposeTranslationUnit(TU);
2181 free_remapped_files(unsaved_files, num_unsaved_files);
2182 clang_disposeIndex(Idx);
2183 return -1;
2184 }
2185
2186 if (checkForErrors(TU) != 0)
2187 return -1;
2188 }
2189
2190 result = perform_test_load(Idx, TU, filter, NULL((void*)0), Visitor, PV, NULL((void*)0));
2191
2192 free_remapped_files(unsaved_files, num_unsaved_files);
2193 clang_disposeIndex(Idx);
2194 return result;
2195}
2196
2197static int perform_single_file_parse(const char *filename) {
2198 CXIndex Idx;
2199 CXTranslationUnit TU;
2200 enum CXErrorCode Err;
2201 int result;
2202
2203 Idx = clang_createIndex(/* excludeDeclsFromPCH */1,
2204 /* displayDiagnostics=*/1);
2205
2206 Err = clang_parseTranslationUnit2(Idx, filename,
2207 /*command_line_args=*/NULL((void*)0),
2208 /*num_command_line_args=*/0,
2209 /*unsaved_files=*/NULL((void*)0),
2210 /*num_unsaved_files=*/0,
2211 CXTranslationUnit_SingleFileParse, &TU);
2212 if (Err != CXError_Success) {
2213 fprintf(stderr, "Unable to load translation unit!\n")__fprintf_chk (stderr, 2 - 1, "Unable to load translation unit!\n"
)
;
2214 describeLibclangFailure(Err);
2215 clang_disposeIndex(Idx);
2216 return 1;
2217 }
2218
2219 result = perform_test_load(Idx, TU, /*filter=*/"all", /*prefix=*/NULL((void*)0), FilteredPrintingVisitor, /*PostVisit=*/NULL((void*)0),
2220 /*CommentSchemaFile=*/NULL((void*)0));
2221 clang_disposeIndex(Idx);
2222 return result;
2223}
2224
2225static int perform_file_retain_excluded_cb(const char *filename) {
2226 CXIndex Idx;
2227 CXTranslationUnit TU;
2228 enum CXErrorCode Err;
2229 int result;
2230
2231 Idx = clang_createIndex(/* excludeDeclsFromPCH */1,
2232 /* displayDiagnostics=*/1);
2233
2234 Err = clang_parseTranslationUnit2(Idx, filename,
2235 /*command_line_args=*/NULL((void*)0),
2236 /*num_command_line_args=*/0,
2237 /*unsaved_files=*/NULL((void*)0),
2238 /*num_unsaved_files=*/0,
2239 CXTranslationUnit_RetainExcludedConditionalBlocks, &TU);
2240 if (Err != CXError_Success) {
2241 fprintf(stderr, "Unable to load translation unit!\n")__fprintf_chk (stderr, 2 - 1, "Unable to load translation unit!\n"
)
;
2242 describeLibclangFailure(Err);
2243 clang_disposeIndex(Idx);
2244 return 1;
2245 }
2246
2247 result = perform_test_load(Idx, TU, /*filter=*/"all", /*prefix=*/NULL((void*)0), FilteredPrintingVisitor, /*PostVisit=*/NULL((void*)0),
2248 /*CommentSchemaFile=*/NULL((void*)0));
2249 clang_disposeIndex(Idx);
2250 return result;
2251}
2252
2253/******************************************************************************/
2254/* Logic for testing clang_getCursor(). */
2255/******************************************************************************/
2256
2257static void print_cursor_file_scan(CXTranslationUnit TU, CXCursor cursor,
2258 unsigned start_line, unsigned start_col,
2259 unsigned end_line, unsigned end_col,
2260 const char *prefix) {
2261 printf("// %s: ", FileCheckPrefix)__printf_chk (2 - 1, "// %s: ", FileCheckPrefix);
2262 if (prefix)
2263 printf("-%s", prefix)__printf_chk (2 - 1, "-%s", prefix);
2264 PrintExtent(stdoutstdout, start_line, start_col, end_line, end_col);
2265 printf(" ")__printf_chk (2 - 1, " ");
2266 PrintCursor(cursor, NULL((void*)0));
2267 printf("\n")__printf_chk (2 - 1, "\n");
2268}
2269
2270static int perform_file_scan(const char *ast_file, const char *source_file,
2271 const char *prefix) {
2272 CXIndex Idx;
2273 CXTranslationUnit TU;
2274 FILE *fp;
2275 CXCursor prevCursor = clang_getNullCursor();
2276 CXFile file;
2277 unsigned line = 1, col = 1;
2278 unsigned start_line = 1, start_col = 1;
2279
2280 if (!(Idx = clang_createIndex(/* excludeDeclsFromPCH */ 1,
2281 /* displayDiagnostics=*/1))) {
2282 fprintf(stderr, "Could not create Index\n")__fprintf_chk (stderr, 2 - 1, "Could not create Index\n");
2283 return 1;
2284 }
2285
2286 if (!CreateTranslationUnit(Idx, ast_file, &TU))
2287 return 1;
2288
2289 if ((fp = fopen(source_file, "r")) == NULL((void*)0)) {
2290 fprintf(stderr, "Could not open '%s'\n", source_file)__fprintf_chk (stderr, 2 - 1, "Could not open '%s'\n", source_file
)
;
2291 clang_disposeTranslationUnit(TU);
2292 return 1;
2293 }
2294
2295 file = clang_getFile(TU, source_file);
2296 for (;;) {
2297 CXCursor cursor;
2298 int c = fgetc(fp);
2299
2300 if (c == '\n') {
2301 ++line;
2302 col = 1;
2303 } else
2304 ++col;
2305
2306 /* Check the cursor at this position, and dump the previous one if we have
2307 * found something new.
2308 */
2309 cursor = clang_getCursor(TU, clang_getLocation(TU, file, line, col));
2310 if ((c == EOF(-1) || !clang_equalCursors(cursor, prevCursor)) &&
2311 prevCursor.kind != CXCursor_InvalidFile) {
2312 print_cursor_file_scan(TU, prevCursor, start_line, start_col,
2313 line, col, prefix);
2314 start_line = line;
2315 start_col = col;
2316 }
2317 if (c == EOF(-1))
2318 break;
2319
2320 prevCursor = cursor;
2321 }
2322
2323 fclose(fp);
2324 clang_disposeTranslationUnit(TU);
2325 clang_disposeIndex(Idx);
2326 return 0;
2327}
2328
2329/******************************************************************************/
2330/* Logic for testing clang code completion. */
2331/******************************************************************************/
2332
2333/* Parse file:line:column from the input string. Returns 0 on success, non-zero
2334 on failure. If successful, the pointer *filename will contain newly-allocated
2335 memory (that will be owned by the caller) to store the file name. */
2336int parse_file_line_column(const char *input, char **filename, unsigned *line,
2337 unsigned *column, unsigned *second_line,
2338 unsigned *second_column) {
2339 /* Find the second colon. */
2340 const char *last_colon = strrchr(input, ':');
2341 unsigned values[4], i;
2342 unsigned num_values = (second_line && second_column)? 4 : 2;
2343
2344 char *endptr = 0;
2345 if (!last_colon || last_colon == input) {
2346 if (num_values == 4)
2347 fprintf(stderr, "could not parse filename:line:column:line:column in "__fprintf_chk (stderr, 2 - 1, "could not parse filename:line:column:line:column in "
"'%s'\n", input)
2348 "'%s'\n", input)__fprintf_chk (stderr, 2 - 1, "could not parse filename:line:column:line:column in "
"'%s'\n", input)
;
2349 else
2350 fprintf(stderr, "could not parse filename:line:column in '%s'\n", input)__fprintf_chk (stderr, 2 - 1, "could not parse filename:line:column in '%s'\n"
, input)
;
2351 return 1;
2352 }
2353
2354 for (i = 0; i != num_values; ++i) {
2355 const char *prev_colon;
2356
2357 /* Parse the next line or column. */
2358 values[num_values - i - 1] = strtol(last_colon + 1, &endptr, 10);
2359 if (*endptr != 0 && *endptr != ':') {
2360 fprintf(stderr, "could not parse %s in '%s'\n",__fprintf_chk (stderr, 2 - 1, "could not parse %s in '%s'\n",
(i % 2 ? "column" : "line"), input)
2361 (i % 2 ? "column" : "line"), input)__fprintf_chk (stderr, 2 - 1, "could not parse %s in '%s'\n",
(i % 2 ? "column" : "line"), input)
;
2362 return 1;
2363 }
2364
2365 if (i + 1 == num_values)
2366 break;
2367
2368 /* Find the previous colon. */
2369 prev_colon = last_colon - 1;
2370 while (prev_colon != input && *prev_colon != ':')
2371 --prev_colon;
2372 if (prev_colon == input) {
2373 fprintf(stderr, "could not parse %s in '%s'\n",__fprintf_chk (stderr, 2 - 1, "could not parse %s in '%s'\n",
(i % 2 == 0? "column" : "line"), input)
2374 (i % 2 == 0? "column" : "line"), input)__fprintf_chk (stderr, 2 - 1, "could not parse %s in '%s'\n",
(i % 2 == 0? "column" : "line"), input)
;
2375 return 1;
2376 }
2377
2378 last_colon = prev_colon;
2379 }
2380
2381 *line = values[0];
2382 *column = values[1];
2383
2384 if (second_line && second_column) {
2385 *second_line = values[2];
2386 *second_column = values[3];
2387 }
2388
2389 /* Copy the file name. */
2390 *filename = (char*)malloc(last_colon - input + 1);
2391 assert(*filename)((void) sizeof ((*filename) ? 1 : 0), __extension__ ({ if (*filename
) ; else __assert_fail ("*filename", "clang/tools/c-index-test/c-index-test.c"
, 2391, __extension__ __PRETTY_FUNCTION__); }))
;
2392 memcpy(*filename, input, last_colon - input);
2393 (*filename)[last_colon - input] = 0;
2394 return 0;
2395}
2396
2397const char *
2398clang_getCompletionChunkKindSpelling(enum CXCompletionChunkKind Kind) {
2399 switch (Kind) {
2400 case CXCompletionChunk_Optional: return "Optional";
2401 case CXCompletionChunk_TypedText: return "TypedText";
2402 case CXCompletionChunk_Text: return "Text";
2403 case CXCompletionChunk_Placeholder: return "Placeholder";
2404 case CXCompletionChunk_Informative: return "Informative";
2405 case CXCompletionChunk_CurrentParameter: return "CurrentParameter";
2406 case CXCompletionChunk_LeftParen: return "LeftParen";
2407 case CXCompletionChunk_RightParen: return "RightParen";
2408 case CXCompletionChunk_LeftBracket: return "LeftBracket";
2409 case CXCompletionChunk_RightBracket: return "RightBracket";
2410 case CXCompletionChunk_LeftBrace: return "LeftBrace";
2411 case CXCompletionChunk_RightBrace: return "RightBrace";
2412 case CXCompletionChunk_LeftAngle: return "LeftAngle";
2413 case CXCompletionChunk_RightAngle: return "RightAngle";
2414 case CXCompletionChunk_Comma: return "Comma";
2415 case CXCompletionChunk_ResultType: return "ResultType";
2416 case CXCompletionChunk_Colon: return "Colon";
2417 case CXCompletionChunk_SemiColon: return "SemiColon";
2418 case CXCompletionChunk_Equal: return "Equal";
2419 case CXCompletionChunk_HorizontalSpace: return "HorizontalSpace";
2420 case CXCompletionChunk_VerticalSpace: return "VerticalSpace";
2421 }
2422
2423 return "Unknown";
2424}
2425
2426static int checkForErrors(CXTranslationUnit TU) {
2427 unsigned Num, i;
2428 CXDiagnostic Diag;
2429 CXString DiagStr;
2430
2431 if (!getenv("CINDEXTEST_FAILONERROR"))
2432 return 0;
2433
2434 Num = clang_getNumDiagnostics(TU);
2435 for (i = 0; i != Num; ++i) {
2436 Diag = clang_getDiagnostic(TU, i);
2437 if (clang_getDiagnosticSeverity(Diag) >= CXDiagnostic_Error) {
2438 DiagStr = clang_formatDiagnostic(Diag,
2439 clang_defaultDiagnosticDisplayOptions());
2440 fprintf(stderr, "%s\n", clang_getCString(DiagStr))__fprintf_chk (stderr, 2 - 1, "%s\n", clang_getCString(DiagStr
))
;
2441 clang_disposeString(DiagStr);
2442 clang_disposeDiagnostic(Diag);
2443 return -1;
2444 }
2445 clang_disposeDiagnostic(Diag);
2446 }
2447
2448 return 0;
2449}
2450
2451static void print_completion_string(CXCompletionString completion_string,
2452 FILE *file) {
2453 int I, N;
2454
2455 N = clang_getNumCompletionChunks(completion_string);
2456 for (I = 0; I != N; ++I) {
2457 CXString text;
2458 const char *cstr;
2459 enum CXCompletionChunkKind Kind
2460 = clang_getCompletionChunkKind(completion_string, I);
2461
2462 if (Kind == CXCompletionChunk_Optional) {
2463 fprintf(file, "{Optional ")__fprintf_chk (file, 2 - 1, "{Optional ");
2464 print_completion_string(
2465 clang_getCompletionChunkCompletionString(completion_string, I),
2466 file);
2467 fprintf(file, "}")__fprintf_chk (file, 2 - 1, "}");
2468 continue;
2469 }
2470
2471 if (Kind == CXCompletionChunk_VerticalSpace) {
2472 fprintf(file, "{VerticalSpace }")__fprintf_chk (file, 2 - 1, "{VerticalSpace }");
2473 continue;
2474 }
2475
2476 text = clang_getCompletionChunkText(completion_string, I);
2477 cstr = clang_getCString(text);
2478 fprintf(file, "{%s %s}",__fprintf_chk (file, 2 - 1, "{%s %s}", clang_getCompletionChunkKindSpelling
(Kind), cstr ? cstr : "")
2479 clang_getCompletionChunkKindSpelling(Kind),__fprintf_chk (file, 2 - 1, "{%s %s}", clang_getCompletionChunkKindSpelling
(Kind), cstr ? cstr : "")
2480 cstr ? cstr : "")__fprintf_chk (file, 2 - 1, "{%s %s}", clang_getCompletionChunkKindSpelling
(Kind), cstr ? cstr : "")
;
2481 clang_disposeString(text);
2482 }
2483
2484}
2485
2486static void print_line_column(CXSourceLocation location, FILE *file) {
2487 unsigned line, column;
2488 clang_getExpansionLocation(location, NULL((void*)0), &line, &column, NULL((void*)0));
2489 fprintf(file, "%d:%d", line, column)__fprintf_chk (file, 2 - 1, "%d:%d", line, column);
2490}
2491
2492static void print_token_range(CXTranslationUnit translation_unit,
2493 CXSourceLocation start, FILE *file) {
2494 CXToken *token = clang_getToken(translation_unit, start);
2495
2496 fprintf(file, "{")__fprintf_chk (file, 2 - 1, "{");
2497 if (token != NULL((void*)0)) {
2498 CXSourceRange token_range = clang_getTokenExtent(translation_unit, *token);
2499 print_line_column(clang_getRangeStart(token_range), file);
2500 fprintf(file, "-")__fprintf_chk (file, 2 - 1, "-");
2501 print_line_column(clang_getRangeEnd(token_range), file);
2502 clang_disposeTokens(translation_unit, token, 1);
2503 }
2504
2505 fprintf(file, "}")__fprintf_chk (file, 2 - 1, "}");
2506}
2507
2508static void print_completion_result(CXTranslationUnit translation_unit,
2509 CXCodeCompleteResults *completion_results,
2510 unsigned index,
2511 FILE *file) {
2512 CXCompletionResult *completion_result = completion_results->Results + index;
2513 CXString ks = clang_getCursorKindSpelling(completion_result->CursorKind);
2514 unsigned annotationCount;
2515 enum CXCursorKind ParentKind;
2516 CXString ParentName;
2517 CXString BriefComment;
2518 CXString Annotation;
2519 const char *BriefCommentCString;
2520 unsigned i;
2521
2522 fprintf(file, "%s:", clang_getCString(ks))__fprintf_chk (file, 2 - 1, "%s:", clang_getCString(ks));
2523 clang_disposeString(ks);
2524
2525 print_completion_string(completion_result->CompletionString, file);
2526 fprintf(file, " (%u)",__fprintf_chk (file, 2 - 1, " (%u)", clang_getCompletionPriority
(completion_result->CompletionString))
2527 clang_getCompletionPriority(completion_result->CompletionString))__fprintf_chk (file, 2 - 1, " (%u)", clang_getCompletionPriority
(completion_result->CompletionString))
;
2528 switch (clang_getCompletionAvailability(completion_result->CompletionString)){
2529 case CXAvailability_Available:
2530 break;
2531
2532 case CXAvailability_Deprecated:
2533 fprintf(file, " (deprecated)")__fprintf_chk (file, 2 - 1, " (deprecated)");
2534 break;
2535
2536 case CXAvailability_NotAvailable:
2537 fprintf(file, " (unavailable)")__fprintf_chk (file, 2 - 1, " (unavailable)");
2538 break;
2539
2540 case CXAvailability_NotAccessible:
2541 fprintf(file, " (inaccessible)")__fprintf_chk (file, 2 - 1, " (inaccessible)");
2542 break;
2543 }
2544
2545 annotationCount = clang_getCompletionNumAnnotations(
2546 completion_result->CompletionString);
2547 if (annotationCount) {
2548 unsigned i;
2549 fprintf(file, " (")__fprintf_chk (file, 2 - 1, " (");
2550 for (i = 0; i < annotationCount; ++i) {
2551 if (i != 0)
2552 fprintf(file, ", ")__fprintf_chk (file, 2 - 1, ", ");
2553 Annotation =
2554 clang_getCompletionAnnotation(completion_result->CompletionString, i);
2555 fprintf(file, "\"%s\"", clang_getCString(Annotation))__fprintf_chk (file, 2 - 1, "\"%s\"", clang_getCString(Annotation
))
;
2556 clang_disposeString(Annotation);
2557 }
2558 fprintf(file, ")")__fprintf_chk (file, 2 - 1, ")");
2559 }
2560
2561 if (!getenv("CINDEXTEST_NO_COMPLETION_PARENTS")) {
2562 ParentName = clang_getCompletionParent(completion_result->CompletionString,
2563 &ParentKind);
2564 if (ParentKind != CXCursor_NotImplemented) {
2565 CXString KindSpelling = clang_getCursorKindSpelling(ParentKind);
2566 fprintf(file, " (parent: %s '%s')",__fprintf_chk (file, 2 - 1, " (parent: %s '%s')", clang_getCString
(KindSpelling), clang_getCString(ParentName))
2567 clang_getCString(KindSpelling),__fprintf_chk (file, 2 - 1, " (parent: %s '%s')", clang_getCString
(KindSpelling), clang_getCString(ParentName))
2568 clang_getCString(ParentName))__fprintf_chk (file, 2 - 1, " (parent: %s '%s')", clang_getCString
(KindSpelling), clang_getCString(ParentName))
;
2569 clang_disposeString(KindSpelling);
2570 }
2571 clang_disposeString(ParentName);
2572 }
2573
2574 BriefComment = clang_getCompletionBriefComment(
2575 completion_result->CompletionString);
2576 BriefCommentCString = clang_getCString(BriefComment);
2577 if (BriefCommentCString && *BriefCommentCString != '\0') {
2578 fprintf(file, "(brief comment: %s)", BriefCommentCString)__fprintf_chk (file, 2 - 1, "(brief comment: %s)", BriefCommentCString
)
;
2579 }
2580 clang_disposeString(BriefComment);
2581
2582 for (i = 0; i < clang_getCompletionNumFixIts(completion_results, index);
2583 ++i) {
2584 CXSourceRange correction_range;
2585 CXString FixIt = clang_getCompletionFixIt(completion_results, index, i,
2586 &correction_range);
2587 fprintf(file, " (requires fix-it: ")__fprintf_chk (file, 2 - 1, " (requires fix-it: ");
2588 print_token_range(translation_unit, clang_getRangeStart(correction_range),
2589 file);
2590 fprintf(file, " to \"%s\")", clang_getCString(FixIt))__fprintf_chk (file, 2 - 1, " to \"%s\")", clang_getCString(FixIt
))
;
2591 clang_disposeString(FixIt);
2592 }
2593
2594 fprintf(file, "\n")__fprintf_chk (file, 2 - 1, "\n");
2595}
2596
2597void print_completion_contexts(unsigned long long contexts, FILE *file) {
2598 fprintf(file, "Completion contexts:\n")__fprintf_chk (file, 2 - 1, "Completion contexts:\n");
2599 if (contexts == CXCompletionContext_Unknown) {
2600 fprintf(file, "Unknown\n")__fprintf_chk (file, 2 - 1, "Unknown\n");
2601 }
2602 if (contexts & CXCompletionContext_AnyType) {
2603 fprintf(file, "Any type\n")__fprintf_chk (file, 2 - 1, "Any type\n");
2604 }
2605 if (contexts & CXCompletionContext_AnyValue) {
2606 fprintf(file, "Any value\n")__fprintf_chk (file, 2 - 1, "Any value\n");
2607 }
2608 if (contexts & CXCompletionContext_ObjCObjectValue) {
2609 fprintf(file, "Objective-C object value\n")__fprintf_chk (file, 2 - 1, "Objective-C object value\n");
2610 }
2611 if (contexts & CXCompletionContext_ObjCSelectorValue) {
2612 fprintf(file, "Objective-C selector value\n")__fprintf_chk (file, 2 - 1, "Objective-C selector value\n");
2613 }
2614 if (contexts & CXCompletionContext_CXXClassTypeValue) {
2615 fprintf(file, "C++ class type value\n")__fprintf_chk (file, 2 - 1, "C++ class type value\n");
2616 }
2617 if (contexts & CXCompletionContext_DotMemberAccess) {
2618 fprintf(file, "Dot member access\n")__fprintf_chk (file, 2 - 1, "Dot member access\n");
2619 }
2620 if (contexts & CXCompletionContext_ArrowMemberAccess) {
2621 fprintf(file, "Arrow member access\n")__fprintf_chk (file, 2 - 1, "Arrow member access\n");
2622 }
2623 if (contexts & CXCompletionContext_ObjCPropertyAccess) {
2624 fprintf(file, "Objective-C property access\n")__fprintf_chk (file, 2 - 1, "Objective-C property access\n");
2625 }
2626 if (contexts & CXCompletionContext_EnumTag) {
2627 fprintf(file, "Enum tag\n")__fprintf_chk (file, 2 - 1, "Enum tag\n");
2628 }
2629 if (contexts & CXCompletionContext_UnionTag) {
2630 fprintf(file, "Union tag\n")__fprintf_chk (file, 2 - 1, "Union tag\n");
2631 }
2632 if (contexts & CXCompletionContext_StructTag) {
2633 fprintf(file, "Struct tag\n")__fprintf_chk (file, 2 - 1, "Struct tag\n");
2634 }
2635 if (contexts & CXCompletionContext_ClassTag) {
2636 fprintf(file, "Class name\n")__fprintf_chk (file, 2 - 1, "Class name\n");
2637 }
2638 if (contexts & CXCompletionContext_Namespace) {
2639 fprintf(file, "Namespace or namespace alias\n")__fprintf_chk (file, 2 - 1, "Namespace or namespace alias\n");
2640 }
2641 if (contexts & CXCompletionContext_NestedNameSpecifier) {
2642 fprintf(file, "Nested name specifier\n")__fprintf_chk (file, 2 - 1, "Nested name specifier\n");
2643 }
2644 if (contexts & CXCompletionContext_ObjCInterface) {
2645 fprintf(file, "Objective-C interface\n")__fprintf_chk (file, 2 - 1, "Objective-C interface\n");
2646 }
2647 if (contexts & CXCompletionContext_ObjCProtocol) {
2648 fprintf(file, "Objective-C protocol\n")__fprintf_chk (file, 2 - 1, "Objective-C protocol\n");
2649 }
2650 if (contexts & CXCompletionContext_ObjCCategory) {
2651 fprintf(file, "Objective-C category\n")__fprintf_chk (file, 2 - 1, "Objective-C category\n");
2652 }
2653 if (contexts & CXCompletionContext_ObjCInstanceMessage) {
2654 fprintf(file, "Objective-C instance method\n")__fprintf_chk (file, 2 - 1, "Objective-C instance method\n");
2655 }
2656 if (contexts & CXCompletionContext_ObjCClassMessage) {
2657 fprintf(file, "Objective-C class method\n")__fprintf_chk (file, 2 - 1, "Objective-C class method\n");
2658 }
2659 if (contexts & CXCompletionContext_ObjCSelectorName) {
2660 fprintf(file, "Objective-C selector name\n")__fprintf_chk (file, 2 - 1, "Objective-C selector name\n");
2661 }
2662 if (contexts & CXCompletionContext_MacroName) {
2663 fprintf(file, "Macro name\n")__fprintf_chk (file, 2 - 1, "Macro name\n");
2664 }
2665 if (contexts & CXCompletionContext_NaturalLanguage) {
2666 fprintf(file, "Natural language\n")__fprintf_chk (file, 2 - 1, "Natural language\n");
2667 }
2668}
2669
2670int perform_code_completion(int argc, const char **argv, int timing_only) {
2671 const char *input = argv[1];
2672 char *filename = 0;
2673 unsigned line;
2674 unsigned column;
2675 CXIndex CIdx;
2676 int errorCode;
2677 struct CXUnsavedFile *unsaved_files = 0;
2678 int num_unsaved_files = 0;
2679 CXCodeCompleteResults *results = 0;
2680 enum CXErrorCode Err;
2681 CXTranslationUnit TU;
2682 unsigned I, Repeats = 1;
2683 unsigned completionOptions = clang_defaultCodeCompleteOptions();
2684 const char *InvocationPath;
2685
2686 if (getenv("CINDEXTEST_CODE_COMPLETE_PATTERNS"))
2687 completionOptions |= CXCodeComplete_IncludeCodePatterns;
2688 if (getenv("CINDEXTEST_COMPLETION_BRIEF_COMMENTS"))
2689 completionOptions |= CXCodeComplete_IncludeBriefComments;
2690 if (getenv("CINDEXTEST_COMPLETION_SKIP_PREAMBLE"))
2691 completionOptions |= CXCodeComplete_SkipPreamble;
2692 if (getenv("CINDEXTEST_COMPLETION_INCLUDE_FIXITS"))
2693 completionOptions |= CXCodeComplete_IncludeCompletionsWithFixIts;
2694
2695 if (timing_only)
2696 input += strlen("-code-completion-timing=");
2697 else
2698 input += strlen("-code-completion-at=");
2699
2700 if ((errorCode = parse_file_line_column(input, &filename, &line, &column,
2701 0, 0)))
2702 return errorCode;
2703
2704 if (parse_remapped_files(argc, argv, 2, &unsaved_files, &num_unsaved_files))
2705 return -1;
2706
2707 CIdx = clang_createIndex(0, 0);
2708 InvocationPath = getenv("CINDEXTEST_INVOCATION_EMISSION_PATH");
2709 if (InvocationPath)
2710 clang_CXIndex_setInvocationEmissionPathOption(CIdx, InvocationPath);
2711
2712 if (getenv("CINDEXTEST_EDITING"))
2713 Repeats = 5;
2714
2715 Err = clang_parseTranslationUnit2(CIdx, 0,
2716 argv + num_unsaved_files + 2,
2717 argc - num_unsaved_files - 2,
2718 0, 0, getDefaultParsingOptions(), &TU);
2719 if (Err != CXError_Success) {
2720 fprintf(stderr, "Unable to load translation unit!\n")__fprintf_chk (stderr, 2 - 1, "Unable to load translation unit!\n"
)
;
2721 describeLibclangFailure(Err);
2722 return 1;
2723 }
2724
2725 Err = clang_reparseTranslationUnit(TU, 0, 0,
2726 clang_defaultReparseOptions(TU));
2727
2728 if (Err != CXError_Success) {
2729 fprintf(stderr, "Unable to reparse translation unit!\n")__fprintf_chk (stderr, 2 - 1, "Unable to reparse translation unit!\n"
)
;
2730 describeLibclangFailure(Err);
2731 clang_disposeTranslationUnit(TU);
2732 return 1;
2733 }
2734
2735 for (I = 0; I != Repeats; ++I) {
2736 results = clang_codeCompleteAt(TU, filename, line, column,
2737 unsaved_files, num_unsaved_files,
2738 completionOptions);
2739 if (!results) {
2740 fprintf(stderr, "Unable to perform code completion!\n")__fprintf_chk (stderr, 2 - 1, "Unable to perform code completion!\n"
)
;
2741 return 1;
2742 }
2743 if (I != Repeats-1)
2744 clang_disposeCodeCompleteResults(results);
2745 }
2746
2747 if (results) {
2748 unsigned i, n = results->NumResults, containerIsIncomplete = 0;
2749 unsigned long long contexts;
2750 enum CXCursorKind containerKind;
2751 CXString objCSelector;
2752 const char *selectorString;
2753 if (!timing_only) {
2754 /* Sort the code-completion results based on the typed text. */
2755 clang_sortCodeCompletionResults(results->Results, results->NumResults);
2756
2757 for (i = 0; i != n; ++i)
2758 print_completion_result(TU, results, i, stdoutstdout);
2759 }
2760 n = clang_codeCompleteGetNumDiagnostics(results);
2761 for (i = 0; i != n; ++i) {
2762 CXDiagnostic diag = clang_codeCompleteGetDiagnostic(results, i);
2763 PrintDiagnostic(diag);
2764 clang_disposeDiagnostic(diag);
2765 }
2766
2767 contexts = clang_codeCompleteGetContexts(results);
2768 print_completion_contexts(contexts, stdoutstdout);
2769
2770 containerKind = clang_codeCompleteGetContainerKind(results,
2771 &containerIsIncomplete);
2772
2773 if (containerKind != CXCursor_InvalidCode) {
2774 /* We have found a container */
2775 CXString containerUSR, containerKindSpelling;
2776 containerKindSpelling = clang_getCursorKindSpelling(containerKind);
2777 printf("Container Kind: %s\n", clang_getCString(containerKindSpelling))__printf_chk (2 - 1, "Container Kind: %s\n", clang_getCString
(containerKindSpelling))
;
2778 clang_disposeString(containerKindSpelling);
2779
2780 if (containerIsIncomplete) {
2781 printf("Container is incomplete\n")__printf_chk (2 - 1, "Container is incomplete\n");
2782 }
2783 else {
2784 printf("Container is complete\n")__printf_chk (2 - 1, "Container is complete\n");
2785 }
2786
2787 containerUSR = clang_codeCompleteGetContainerUSR(results);
2788 printf("Container USR: %s\n", clang_getCString(containerUSR))__printf_chk (2 - 1, "Container USR: %s\n", clang_getCString(
containerUSR))
;
2789 clang_disposeString(containerUSR);
2790 }
2791
2792 objCSelector = clang_codeCompleteGetObjCSelector(results);
2793 selectorString = clang_getCString(objCSelector);
2794 if (selectorString && strlen(selectorString) > 0) {
2795 printf("Objective-C selector: %s\n", selectorString)__printf_chk (2 - 1, "Objective-C selector: %s\n", selectorString
)
;
2796 }
2797 clang_disposeString(objCSelector);
2798
2799 clang_disposeCodeCompleteResults(results);
2800 }
2801 clang_disposeTranslationUnit(TU);
2802 clang_disposeIndex(CIdx);
2803 free(filename);
2804
2805 free_remapped_files(unsaved_files, num_unsaved_files);
2806
2807 return 0;
2808}
2809
2810typedef struct {
2811 char *filename;
2812 unsigned line;
2813 unsigned column;
2814} CursorSourceLocation;
2815
2816typedef void (*cursor_handler_t)(CXCursor cursor);
2817
2818static int inspect_cursor_at(int argc, const char **argv,
2819 const char *locations_flag,
2820 cursor_handler_t handler) {
2821 CXIndex CIdx;
2822 int errorCode;
2823 struct CXUnsavedFile *unsaved_files = 0;
2824 int num_unsaved_files = 0;
2825 enum CXErrorCode Err;
2826 CXTranslationUnit TU;
2827 CXCursor Cursor;
2828 CursorSourceLocation *Locations = 0;
2829 unsigned NumLocations = 0, Loc;
2830 unsigned Repeats = 1;
2831 unsigned I;
2832
2833 /* Count the number of locations. */
2834 while (strstr(argv[NumLocations+1], locations_flag) == argv[NumLocations+1])
2835 ++NumLocations;
2836
2837 /* Parse the locations. */
2838 assert(NumLocations > 0 && "Unable to count locations?")((void) sizeof ((NumLocations > 0 && "Unable to count locations?"
) ? 1 : 0), __extension__ ({ if (NumLocations > 0 &&
"Unable to count locations?") ; else __assert_fail ("NumLocations > 0 && \"Unable to count locations?\""
, "clang/tools/c-index-test/c-index-test.c", 2838, __extension__
__PRETTY_FUNCTION__); }))
;
2839 Locations = (CursorSourceLocation *)malloc(
2840 NumLocations * sizeof(CursorSourceLocation));
2841 assert(Locations)((void) sizeof ((Locations) ? 1 : 0), __extension__ ({ if (Locations
) ; else __assert_fail ("Locations", "clang/tools/c-index-test/c-index-test.c"
, 2841, __extension__ __PRETTY_FUNCTION__); }))
;
2842 for (Loc = 0; Loc < NumLocations; ++Loc) {
2843 const char *input = argv[Loc + 1] + strlen(locations_flag);
2844 if ((errorCode = parse_file_line_column(input, &Locations[Loc].filename,
2845 &Locations[Loc].line,
2846 &Locations[Loc].column, 0, 0)))
2847 return errorCode;
2848 }
2849
2850 if (parse_remapped_files(argc, argv, NumLocations + 1, &unsaved_files,
2851 &num_unsaved_files))
2852 return -1;
2853
2854 if (getenv("CINDEXTEST_EDITING"))
2855 Repeats = 5;
2856
2857 /* Parse the translation unit. When we're testing clang_getCursor() after
2858 reparsing, don't remap unsaved files until the second parse. */
2859 CIdx = clang_createIndex(1, 1);
2860 Err = clang_parseTranslationUnit2(CIdx, argv[argc - 1],
2861 argv + num_unsaved_files + 1 + NumLocations,
2862 argc - num_unsaved_files - 2 - NumLocations,
2863 unsaved_files,
2864 Repeats > 1? 0 : num_unsaved_files,
2865 getDefaultParsingOptions(), &TU);
2866 if (Err != CXError_Success) {
2867 fprintf(stderr, "unable to parse input\n")__fprintf_chk (stderr, 2 - 1, "unable to parse input\n");
2868 describeLibclangFailure(Err);
2869 return -1;
2870 }
2871
2872 if (checkForErrors(TU) != 0)
2873 return -1;
2874
2875 for (I = 0; I != Repeats; ++I) {
2876 if (Repeats > 1) {
2877 Err = clang_reparseTranslationUnit(TU, num_unsaved_files, unsaved_files,
2878 clang_defaultReparseOptions(TU));
2879 if (Err != CXError_Success) {
2880 describeLibclangFailure(Err);
2881 clang_disposeTranslationUnit(TU);
2882 return 1;
2883 }
2884 }
2885
2886 if (checkForErrors(TU) != 0)
2887 return -1;
2888
2889 for (Loc = 0; Loc < NumLocations; ++Loc) {
2890 CXFile file = clang_getFile(TU, Locations[Loc].filename);
2891 if (!file)
2892 continue;
2893
2894 Cursor = clang_getCursor(TU,
2895 clang_getLocation(TU, file, Locations[Loc].line,
2896 Locations[Loc].column));
2897
2898 if (checkForErrors(TU) != 0)
2899 return -1;
2900
2901 if (I + 1 == Repeats) {
2902 handler(Cursor);
2903 free(Locations[Loc].filename);
2904 }
2905 }
2906 }
2907
2908 PrintDiagnostics(TU);
2909 clang_disposeTranslationUnit(TU);
2910 clang_disposeIndex(CIdx);
2911 free(Locations);
2912 free_remapped_files(unsaved_files, num_unsaved_files);
2913 return 0;
2914}
2915
2916static void inspect_print_cursor(CXCursor Cursor) {
2917 CXTranslationUnit TU = clang_Cursor_getTranslationUnit(Cursor);
2918 CXCompletionString completionString = clang_getCursorCompletionString(
2919 Cursor);
2920 CXSourceLocation CursorLoc = clang_getCursorLocation(Cursor);
2921 CXString Spelling;
2922 const char *cspell;
2923 unsigned line, column;
2924 clang_getSpellingLocation(CursorLoc, 0, &line, &column, 0);
2925 printf("%d:%d ", line, column)__printf_chk (2 - 1, "%d:%d ", line, column);
2926 PrintCursor(Cursor, NULL((void*)0));
2927 PrintCursorExtent(Cursor);
2928 Spelling = clang_getCursorSpelling(Cursor);
2929 cspell = clang_getCString(Spelling);
2930 if (cspell && strlen(cspell) != 0) {
2931 unsigned pieceIndex;
2932 printf(" Spelling=%s (", cspell)__printf_chk (2 - 1, " Spelling=%s (", cspell);
2933 for (pieceIndex = 0; ; ++pieceIndex) {
2934 CXSourceRange range =
2935 clang_Cursor_getSpellingNameRange(Cursor, pieceIndex, 0);
2936 if (clang_Range_isNull(range))
2937 break;
2938 PrintRange(range, 0);
2939 }
2940 printf(")")__printf_chk (2 - 1, ")");
2941 }
2942 clang_disposeString(Spelling);
2943 if (clang_Cursor_getObjCSelectorIndex(Cursor) != -1)
2944 printf(" Selector index=%d",__printf_chk (2 - 1, " Selector index=%d", clang_Cursor_getObjCSelectorIndex
(Cursor))
2945 clang_Cursor_getObjCSelectorIndex(Cursor))__printf_chk (2 - 1, " Selector index=%d", clang_Cursor_getObjCSelectorIndex
(Cursor))
;
2946 if (clang_Cursor_isDynamicCall(Cursor))
2947 printf(" Dynamic-call")__printf_chk (2 - 1, " Dynamic-call");
2948 if (Cursor.kind == CXCursor_ObjCMessageExpr ||
2949 Cursor.kind == CXCursor_MemberRefExpr) {
2950 CXType T = clang_Cursor_getReceiverType(Cursor);
2951 if (T.kind != CXType_Invalid) {
2952 CXString S = clang_getTypeKindSpelling(T.kind);
2953 printf(" Receiver-type=%s", clang_getCString(S))__printf_chk (2 - 1, " Receiver-type=%s", clang_getCString(S)
)
;
2954 clang_disposeString(S);
2955 }
2956 }
2957
2958 {
2959 CXModule mod = clang_Cursor_getModule(Cursor);
2960 CXFile astFile;
2961 CXString name, astFilename;
2962 unsigned i, numHeaders;
2963 if (mod) {
2964 astFile = clang_Module_getASTFile(mod);
2965 astFilename = clang_getFileName(astFile);
2966 name = clang_Module_getFullName(mod);
2967 numHeaders = clang_Module_getNumTopLevelHeaders(TU, mod);
2968 printf(" ModuleName=%s (%s) system=%d Headers(%d):",__printf_chk (2 - 1, " ModuleName=%s (%s) system=%d Headers(%d):"
, clang_getCString(name), clang_getCString(astFilename), clang_Module_isSystem
(mod), numHeaders)
2969 clang_getCString(name), clang_getCString(astFilename),__printf_chk (2 - 1, " ModuleName=%s (%s) system=%d Headers(%d):"
, clang_getCString(name), clang_getCString(astFilename), clang_Module_isSystem
(mod), numHeaders)
2970 clang_Module_isSystem(mod), numHeaders)__printf_chk (2 - 1, " ModuleName=%s (%s) system=%d Headers(%d):"
, clang_getCString(name), clang_getCString(astFilename), clang_Module_isSystem
(mod), numHeaders)
;
2971 clang_disposeString(name);
2972 clang_disposeString(astFilename);
2973 for (i = 0; i < numHeaders; ++i) {
2974 CXFile file = clang_Module_getTopLevelHeader(TU, mod, i);
2975 CXString filename = clang_getFileName(file);
2976 printf("\n%s", clang_getCString(filename))__printf_chk (2 - 1, "\n%s", clang_getCString(filename));
2977 clang_disposeString(filename);
2978 }
2979 }
2980 }
2981
2982 if (completionString != NULL((void*)0)) {
2983 printf("\nCompletion string: ")__printf_chk (2 - 1, "\nCompletion string: ");
2984 print_completion_string(completionString, stdoutstdout);
2985 }
2986 printf("\n")__printf_chk (2 - 1, "\n");
2987}
2988
2989static void display_evaluate_results(CXEvalResult result) {
2990 switch (clang_EvalResult_getKind(result)) {
2991 case CXEval_Int:
2992 {
2993 printf("Kind: Int, ")__printf_chk (2 - 1, "Kind: Int, ");
2994 if (clang_EvalResult_isUnsignedInt(result)) {
2995 unsigned long long val = clang_EvalResult_getAsUnsigned(result);
2996 printf("unsigned, Value: %llu", val)__printf_chk (2 - 1, "unsigned, Value: %llu", val);
2997 } else {
2998 long long val = clang_EvalResult_getAsLongLong(result);
2999 printf("Value: %lld", val)__printf_chk (2 - 1, "Value: %lld", val);
3000 }
3001 break;
3002 }
3003 case CXEval_Float:
3004 {
3005 double val = clang_EvalResult_getAsDouble(result);
3006 printf("Kind: Float , Value: %f", val)__printf_chk (2 - 1, "Kind: Float , Value: %f", val);
3007 break;
3008 }
3009 case CXEval_ObjCStrLiteral:
3010 {
3011 const char* str = clang_EvalResult_getAsStr(result);
3012 printf("Kind: ObjCString , Value: %s", str)__printf_chk (2 - 1, "Kind: ObjCString , Value: %s", str);
3013 break;
3014 }
3015 case CXEval_StrLiteral:
3016 {
3017 const char* str = clang_EvalResult_getAsStr(result);
3018 printf("Kind: CString , Value: %s", str)__printf_chk (2 - 1, "Kind: CString , Value: %s", str);
3019 break;
3020 }
3021 case CXEval_CFStr:
3022 {
3023 const char* str = clang_EvalResult_getAsStr(result);
3024 printf("Kind: CFString , Value: %s", str)__printf_chk (2 - 1, "Kind: CFString , Value: %s", str);
3025 break;
3026 }
3027 default:
3028 printf("Unexposed")__printf_chk (2 - 1, "Unexposed");
3029 break;
3030 }
3031}
3032
3033static void inspect_evaluate_cursor(CXCursor Cursor) {
3034 CXSourceLocation CursorLoc = clang_getCursorLocation(Cursor);
3035 CXString Spelling;
3036 const char *cspell;
3037 unsigned line, column;
3038 CXEvalResult ER;
3039
3040 clang_getSpellingLocation(CursorLoc, 0, &line, &column, 0);
3041 printf("%d:%d ", line, column)__printf_chk (2 - 1, "%d:%d ", line, column);
3042 PrintCursor(Cursor, NULL((void*)0));
3043 PrintCursorExtent(Cursor);
3044 Spelling = clang_getCursorSpelling(Cursor);
3045 cspell = clang_getCString(Spelling);
3046 if (cspell && strlen(cspell) != 0) {
3047 unsigned pieceIndex;
3048 printf(" Spelling=%s (", cspell)__printf_chk (2 - 1, " Spelling=%s (", cspell);
3049 for (pieceIndex = 0; ; ++pieceIndex) {
3050 CXSourceRange range =
3051 clang_Cursor_getSpellingNameRange(Cursor, pieceIndex, 0);
3052 if (clang_Range_isNull(range))
3053 break;
3054 PrintRange(range, 0);
3055 }
3056 printf(")")__printf_chk (2 - 1, ")");
3057 }
3058 clang_disposeString(Spelling);
3059
3060 ER = clang_Cursor_Evaluate(Cursor);
3061 if (!ER) {
3062 printf("Not Evaluatable")__printf_chk (2 - 1, "Not Evaluatable");
3063 } else {
3064 display_evaluate_results(ER);
3065 clang_EvalResult_dispose(ER);
3066 }
3067 printf("\n")__printf_chk (2 - 1, "\n");
3068}
3069
3070static void inspect_macroinfo_cursor(CXCursor Cursor) {
3071 CXSourceLocation CursorLoc = clang_getCursorLocation(Cursor);
3072 CXString Spelling;
3073 const char *cspell;
3074 unsigned line, column;
3075 clang_getSpellingLocation(CursorLoc, 0, &line, &column, 0);
3076 printf("%d:%d ", line, column)__printf_chk (2 - 1, "%d:%d ", line, column);
3077 PrintCursor(Cursor, NULL((void*)0));
3078 PrintCursorExtent(Cursor);
3079 Spelling = clang_getCursorSpelling(Cursor);
3080 cspell = clang_getCString(Spelling);
3081 if (cspell && strlen(cspell) != 0) {
3082 unsigned pieceIndex;
3083 printf(" Spelling=%s (", cspell)__printf_chk (2 - 1, " Spelling=%s (", cspell);
3084 for (pieceIndex = 0; ; ++pieceIndex) {
3085 CXSourceRange range =
3086 clang_Cursor_getSpellingNameRange(Cursor, pieceIndex, 0);
3087 if (clang_Range_isNull(range))
3088 break;
3089 PrintRange(range, 0);
3090 }
3091 printf(")")__printf_chk (2 - 1, ")");
3092 }
3093 clang_disposeString(Spelling);
3094
3095 if (clang_Cursor_isMacroBuiltin(Cursor)) {
3096 printf("[builtin macro]")__printf_chk (2 - 1, "[builtin macro]");
3097 } else if (clang_Cursor_isMacroFunctionLike(Cursor)) {
3098 printf("[function macro]")__printf_chk (2 - 1, "[function macro]");
3099 }
3100 printf("\n")__printf_chk (2 - 1, "\n");
3101}
3102
3103static enum CXVisitorResult findFileRefsVisit(void *context,
3104 CXCursor cursor, CXSourceRange range) {
3105 if (clang_Range_isNull(range))
3106 return CXVisit_Continue;
3107
3108 PrintCursor(cursor, NULL((void*)0));
3109 PrintRange(range, "");
3110 printf("\n")__printf_chk (2 - 1, "\n");
3111 return CXVisit_Continue;
3112}
3113
3114static int find_file_refs_at(int argc, const char **argv) {
3115 CXIndex CIdx;
3116 int errorCode;
3117 struct CXUnsavedFile *unsaved_files = 0;
3118 int num_unsaved_files = 0;
3119 enum CXErrorCode Err;
3120 CXTranslationUnit TU;
3121 CXCursor Cursor;
3122 CursorSourceLocation *Locations = 0;
3123 unsigned NumLocations = 0, Loc;
3124 unsigned Repeats = 1;
3125 unsigned I;
3126
3127 /* Count the number of locations. */
3128 while (strstr(argv[NumLocations+1], "-file-refs-at=") == argv[NumLocations+1])
3129 ++NumLocations;
3130
3131 /* Parse the locations. */
3132 assert(NumLocations > 0 && "Unable to count locations?")((void) sizeof ((NumLocations > 0 && "Unable to count locations?"
) ? 1 : 0), __extension__ ({ if (NumLocations > 0 &&
"Unable to count locations?") ; else __assert_fail ("NumLocations > 0 && \"Unable to count locations?\""
, "clang/tools/c-index-test/c-index-test.c", 3132, __extension__
__PRETTY_FUNCTION__); }))
;
3133 Locations = (CursorSourceLocation *)malloc(
3134 NumLocations * sizeof(CursorSourceLocation));
3135 assert(Locations)((void) sizeof ((Locations) ? 1 : 0), __extension__ ({ if (Locations
) ; else __assert_fail ("Locations", "clang/tools/c-index-test/c-index-test.c"
, 3135, __extension__ __PRETTY_FUNCTION__); }))
;
3136 for (Loc = 0; Loc < NumLocations; ++Loc) {
3137 const char *input = argv[Loc + 1] + strlen("-file-refs-at=");
3138 if ((errorCode = parse_file_line_column(input, &Locations[Loc].filename,
3139 &Locations[Loc].line,
3140 &Locations[Loc].column, 0, 0)))
3141 return errorCode;
3142 }
3143
3144 if (parse_remapped_files(argc, argv, NumLocations + 1, &unsaved_files,
3145 &num_unsaved_files))
3146 return -1;
3147
3148 if (getenv("CINDEXTEST_EDITING"))
3149 Repeats = 5;
3150
3151 /* Parse the translation unit. When we're testing clang_getCursor() after
3152 reparsing, don't remap unsaved files until the second parse. */
3153 CIdx = clang_createIndex(1, 1);
3154 Err = clang_parseTranslationUnit2(CIdx, argv[argc - 1],
3155 argv + num_unsaved_files + 1 + NumLocations,
3156 argc - num_unsaved_files - 2 - NumLocations,
3157 unsaved_files,
3158 Repeats > 1? 0 : num_unsaved_files,
3159 getDefaultParsingOptions(), &TU);
3160 if (Err != CXError_Success) {
3161 fprintf(stderr, "unable to parse input\n")__fprintf_chk (stderr, 2 - 1, "unable to parse input\n");
3162 describeLibclangFailure(Err);
3163 clang_disposeTranslationUnit(TU);
3164 return -1;
3165 }
3166
3167 if (checkForErrors(TU) != 0)
3168 return -1;
3169
3170 for (I = 0; I != Repeats; ++I) {
3171 if (Repeats > 1) {
3172 Err = clang_reparseTranslationUnit(TU, num_unsaved_files, unsaved_files,
3173 clang_defaultReparseOptions(TU));
3174 if (Err != CXError_Success) {
3175 describeLibclangFailure(Err);
3176 clang_disposeTranslationUnit(TU);
3177 return 1;
3178 }
3179 }
3180
3181 if (checkForErrors(TU) != 0)
3182 return -1;
3183
3184 for (Loc = 0; Loc < NumLocations; ++Loc) {
3185 CXFile file = clang_getFile(TU, Locations[Loc].filename);
3186 if (!file)
3187 continue;
3188
3189 Cursor = clang_getCursor(TU,
3190 clang_getLocation(TU, file, Locations[Loc].line,
3191 Locations[Loc].column));
3192
3193 if (checkForErrors(TU) != 0)
3194 return -1;
3195
3196 if (I + 1 == Repeats) {
3197 CXCursorAndRangeVisitor visitor = { 0, findFileRefsVisit };
3198 PrintCursor(Cursor, NULL((void*)0));
3199 printf("\n")__printf_chk (2 - 1, "\n");
3200 clang_findReferencesInFile(Cursor, file, visitor);
3201 free(Locations[Loc].filename);
3202
3203 if (checkForErrors(TU) != 0)
3204 return -1;
3205 }
3206 }
3207 }
3208
3209 PrintDiagnostics(TU);
3210 clang_disposeTranslationUnit(TU);
3211 clang_disposeIndex(CIdx);
3212 free(Locations);
3213 free_remapped_files(unsaved_files, num_unsaved_files);
3214 return 0;
3215}
3216
3217static enum CXVisitorResult findFileIncludesVisit(void *context,
3218 CXCursor cursor, CXSourceRange range) {
3219 PrintCursor(cursor, NULL((void*)0));
3220 PrintRange(range, "");
3221 printf("\n")__printf_chk (2 - 1, "\n");
3222 return CXVisit_Continue;
3223}
3224
3225static int find_file_includes_in(int argc, const char **argv) {
3226 CXIndex CIdx;
3227 struct CXUnsavedFile *unsaved_files = 0;
3228 int num_unsaved_files = 0;
3229 enum CXErrorCode Err;
3230 CXTranslationUnit TU;
3231 const char **Filenames = 0;
3232 unsigned NumFilenames = 0;
3233 unsigned Repeats = 1;
3234 unsigned I, FI;
3235
3236 /* Count the number of locations. */
3237 while (strstr(argv[NumFilenames+1], "-file-includes-in=") == argv[NumFilenames+1])
3238 ++NumFilenames;
3239
3240 /* Parse the locations. */
3241 assert(NumFilenames > 0 && "Unable to count filenames?")((void) sizeof ((NumFilenames > 0 && "Unable to count filenames?"
) ? 1 : 0), __extension__ ({ if (NumFilenames > 0 &&
"Unable to count filenames?") ; else __assert_fail ("NumFilenames > 0 && \"Unable to count filenames?\""
, "clang/tools/c-index-test/c-index-test.c", 3241, __extension__
__PRETTY_FUNCTION__); }))
;
3242 Filenames = (const char **)malloc(NumFilenames * sizeof(const char *));
3243 assert(Filenames)((void) sizeof ((Filenames) ? 1 : 0), __extension__ ({ if (Filenames
) ; else __assert_fail ("Filenames", "clang/tools/c-index-test/c-index-test.c"
, 3243, __extension__ __PRETTY_FUNCTION__); }))
;
3244 for (I = 0; I < NumFilenames; ++I) {
3245 const char *input = argv[I + 1] + strlen("-file-includes-in=");
3246 /* Copy the file name. */
3247 Filenames[I] = input;
3248 }
3249
3250 if (parse_remapped_files(argc, argv, NumFilenames + 1, &unsaved_files,
3251 &num_unsaved_files))
3252 return -1;
3253
3254 if (getenv("CINDEXTEST_EDITING"))
3255 Repeats = 2;
3256
3257 /* Parse the translation unit. When we're testing clang_getCursor() after
3258 reparsing, don't remap unsaved files until the second parse. */
3259 CIdx = clang_createIndex(1, 1);
3260 Err = clang_parseTranslationUnit2(
3261 CIdx, argv[argc - 1],
3262 argv + num_unsaved_files + 1 + NumFilenames,
3263 argc - num_unsaved_files - 2 - NumFilenames,
3264 unsaved_files,
3265 Repeats > 1 ? 0 : num_unsaved_files, getDefaultParsingOptions(), &TU);
3266
3267 if (Err != CXError_Success) {
3268 fprintf(stderr, "unable to parse input\n")__fprintf_chk (stderr, 2 - 1, "unable to parse input\n");
3269 describeLibclangFailure(Err);
3270 clang_disposeTranslationUnit(TU);
3271 return -1;
3272 }
3273
3274 if (checkForErrors(TU) != 0)
3275 return -1;
3276
3277 for (I = 0; I != Repeats; ++I) {
3278 if (Repeats > 1) {
3279 Err = clang_reparseTranslationUnit(TU, num_unsaved_files, unsaved_files,
3280 clang_defaultReparseOptions(TU));
3281 if (Err != CXError_Success) {
3282 describeLibclangFailure(Err);
3283 clang_disposeTranslationUnit(TU);
3284 return 1;
3285 }
3286 }
3287
3288 if (checkForErrors(TU) != 0)
3289 return -1;
3290
3291 for (FI = 0; FI < NumFilenames; ++FI) {
3292 CXFile file = clang_getFile(TU, Filenames[FI]);
3293 if (!file)
3294 continue;
3295
3296 if (checkForErrors(TU) != 0)
3297 return -1;
3298
3299 if (I + 1 == Repeats) {
3300 CXCursorAndRangeVisitor visitor = { 0, findFileIncludesVisit };
3301 clang_findIncludesInFile(TU, file, visitor);
3302
3303 if (checkForErrors(TU) != 0)
3304 return -1;
3305 }
3306 }
3307 }
3308
3309 PrintDiagnostics(TU);
3310 clang_disposeTranslationUnit(TU);
3311 clang_disposeIndex(CIdx);
3312 free((void *)Filenames);
3313 free_remapped_files(unsaved_files, num_unsaved_files);
3314 return 0;
3315}
3316
3317#define MAX_IMPORTED_ASTFILES200 200
3318
3319typedef struct {
3320 char **filenames;
3321 unsigned num_files;
3322} ImportedASTFilesData;
3323
3324static ImportedASTFilesData *importedASTs_create(void) {
3325 ImportedASTFilesData *p;
3326 p = malloc(sizeof(ImportedASTFilesData));
3327 assert(p)((void) sizeof ((p) ? 1 : 0), __extension__ ({ if (p) ; else __assert_fail
("p", "clang/tools/c-index-test/c-index-test.c", 3327, __extension__
__PRETTY_FUNCTION__); }))
;
3328 p->filenames = malloc(MAX_IMPORTED_ASTFILES200 * sizeof(const char *));
3329 assert(p->filenames)((void) sizeof ((p->filenames) ? 1 : 0), __extension__ ({ if
(p->filenames) ; else __assert_fail ("p->filenames", "clang/tools/c-index-test/c-index-test.c"
, 3329, __extension__ __PRETTY_FUNCTION__); }))
;
3330 p->num_files = 0;
3331 return p;
3332}
3333
3334static void importedASTs_dispose(ImportedASTFilesData *p) {
3335 unsigned i;
3336 if (!p)
3337 return;
3338
3339 for (i = 0; i < p->num_files; ++i)
3340 free(p->filenames[i]);
3341 free(p->filenames);
3342 free(p);
3343}
3344
3345static void importedASTS_insert(ImportedASTFilesData *p, const char *file) {
3346 unsigned i;
3347 assert(p && file)((void) sizeof ((p && file) ? 1 : 0), __extension__ (
{ if (p && file) ; else __assert_fail ("p && file"
, "clang/tools/c-index-test/c-index-test.c", 3347, __extension__
__PRETTY_FUNCTION__); }))
;
3348 for (i = 0; i < p->num_files; ++i)
3349 if (strcmp(file, p->filenames[i]) == 0)
3350 return;
3351 assert(p->num_files + 1 < MAX_IMPORTED_ASTFILES)((void) sizeof ((p->num_files + 1 < 200) ? 1 : 0), __extension__
({ if (p->num_files + 1 < 200) ; else __assert_fail ("p->num_files + 1 < MAX_IMPORTED_ASTFILES"
, "clang/tools/c-index-test/c-index-test.c", 3351, __extension__
__PRETTY_FUNCTION__); }))
;
3352 p->filenames[p->num_files++] = strdup(file);
3353}
3354
3355typedef struct IndexDataStringList_ {
3356 struct IndexDataStringList_ *next;
3357 char data[1]; /* Dynamically sized. */
3358} IndexDataStringList;
3359
3360typedef struct {
3361 const char *check_prefix;
3362 int first_check_printed;
3363 int fail_for_error;
3364 int abort;
3365 CXString main_filename;
3366 ImportedASTFilesData *importedASTs;
3367 IndexDataStringList *strings;
3368 CXTranslationUnit TU;
3369} IndexData;
3370
3371static void free_client_data(IndexData *index_data) {
3372 IndexDataStringList *node = index_data->strings;
3373 while (node) {
3374 IndexDataStringList *next = node->next;
3375 free(node);
3376 node = next;
3377 }
3378 index_data->strings = NULL((void*)0);
3379}
3380
3381static void printCheck(IndexData *data) {
3382 if (data->check_prefix) {
3383 if (data->first_check_printed) {
3384 printf("// %s-NEXT: ", data->check_prefix)__printf_chk (2 - 1, "// %s-NEXT: ", data->check_prefix);
3385 } else {
3386 printf("// %s : ", data->check_prefix)__printf_chk (2 - 1, "// %s : ", data->check_prefix);
3387 data->first_check_printed = 1;
3388 }
3389 }
3390}
3391
3392static void printCXIndexFile(CXIdxClientFile file) {
3393 CXString filename = clang_getFileName((CXFile)file);
3394 printf("%s", clang_getCString(filename))__printf_chk (2 - 1, "%s", clang_getCString(filename));
3395 clang_disposeString(filename);
3396}
3397
3398static void printCXIndexLoc(CXIdxLoc loc, CXClientData client_data) {
3399 IndexData *index_data;
3400 CXString filename;
3401 const char *cname;
3402 CXIdxClientFile file;
3403 unsigned line, column;
3404 const char *main_filename;
3405 int isMainFile;
3406
3407 index_data = (IndexData *)client_data;
3408 clang_indexLoc_getFileLocation(loc, &file, 0, &line, &column, 0);
3409 if (line == 0) {
3410 printf("<invalid>")__printf_chk (2 - 1, "<invalid>");
3411 return;
3412 }
3413 if (!file) {
3414 printf("<no idxfile>")__printf_chk (2 - 1, "<no idxfile>");
3415 return;
3416 }
3417 filename = clang_getFileName((CXFile)file);
3418 cname = clang_getCString(filename);
3419 main_filename = clang_getCString(index_data->main_filename);
3420 if (strcmp(cname, main_filename) == 0)
3421 isMainFile = 1;
3422 else
3423 isMainFile = 0;
3424 clang_disposeString(filename);
3425
3426 if (!isMainFile) {
3427 printCXIndexFile(file);
3428 printf(":")__printf_chk (2 - 1, ":");
3429 }
3430 printf("%d:%d", line, column)__printf_chk (2 - 1, "%d:%d", line, column);
3431}
3432
3433static unsigned digitCount(unsigned val) {
3434 unsigned c = 1;
3435 while (1) {
3436 if (val < 10)
3437 return c;
3438 ++c;
3439 val /= 10;
3440 }
3441}
3442
3443static CXIdxClientContainer makeClientContainer(CXClientData *client_data,
3444 const CXIdxEntityInfo *info,
3445 CXIdxLoc loc) {
3446 IndexData *index_data;
3447 IndexDataStringList *node;
3448 const char *name;
3449 char *newStr;
3450 CXIdxClientFile file;
3451 unsigned line, column;
3452
3453 name = info->name;
3454 if (!name)
3455 name = "<anon-tag>";
3456
3457 clang_indexLoc_getFileLocation(loc, &file, 0, &line, &column, 0);
3458
3459 node =
3460 (IndexDataStringList *)malloc(sizeof(IndexDataStringList) + strlen(name) +
3461 digitCount(line) + digitCount(column) + 2);
3462 assert(node)((void) sizeof ((node) ? 1 : 0), __extension__ ({ if (node) ;
else __assert_fail ("node", "clang/tools/c-index-test/c-index-test.c"
, 3462, __extension__ __PRETTY_FUNCTION__); }))
;
3463 newStr = node->data;
3464 sprintf(newStr, "%s:%d:%d", name, line, column)__builtin___sprintf_chk (newStr, 2 - 1, __builtin_object_size
(newStr, 2 > 1), "%s:%d:%d", name, line, column)
;
3465
3466 /* Remember string so it can be freed later. */
3467 index_data = (IndexData *)client_data;
3468 node->next = index_data->strings;
3469 index_data->strings = node;
3470
3471 return (CXIdxClientContainer)newStr;
3472}
3473
3474static void printCXIndexContainer(const CXIdxContainerInfo *info) {
3475 CXIdxClientContainer container;
3476 container = clang_index_getClientContainer(info);
3477 if (!container)
3478 printf("[<<NULL>>]")__printf_chk (2 - 1, "[<<NULL>>]");
3479 else
3480 printf("[%s]", (const char *)container)__printf_chk (2 - 1, "[%s]", (const char *)container);
3481}
3482
3483static const char *getEntityKindString(CXIdxEntityKind kind) {
3484 switch (kind) {
3485 case CXIdxEntity_Unexposed: return "<<UNEXPOSED>>";
3486 case CXIdxEntity_Typedef: return "typedef";
3487 case CXIdxEntity_Function: return "function";
3488 case CXIdxEntity_Variable: return "variable";
3489 case CXIdxEntity_Field: return "field";
3490 case CXIdxEntity_EnumConstant: return "enumerator";
3491 case CXIdxEntity_ObjCClass: return "objc-class";
3492 case CXIdxEntity_ObjCProtocol: return "objc-protocol";
3493 case CXIdxEntity_ObjCCategory: return "objc-category";
3494 case CXIdxEntity_ObjCInstanceMethod: return "objc-instance-method";
3495 case CXIdxEntity_ObjCClassMethod: return "objc-class-method";
3496 case CXIdxEntity_ObjCProperty: return "objc-property";
3497 case CXIdxEntity_ObjCIvar: return "objc-ivar";
3498 case CXIdxEntity_Enum: return "enum";
3499 case CXIdxEntity_Struct: return "struct";
3500 case CXIdxEntity_Union: return "union";
3501 case CXIdxEntity_CXXClass: return "c++-class";
3502 case CXIdxEntity_CXXNamespace: return "namespace";
3503 case CXIdxEntity_CXXNamespaceAlias: return "namespace-alias";
3504 case CXIdxEntity_CXXStaticVariable: return "c++-static-var";
3505 case CXIdxEntity_CXXStaticMethod: return "c++-static-method";
3506 case CXIdxEntity_CXXInstanceMethod: return "c++-instance-method";
3507 case CXIdxEntity_CXXConstructor: return "constructor";
3508 case CXIdxEntity_CXXDestructor: return "destructor";
3509 case CXIdxEntity_CXXConversionFunction: return "conversion-func";
3510 case CXIdxEntity_CXXTypeAlias: return "type-alias";
3511 case CXIdxEntity_CXXInterface: return "c++-__interface";
3512 case CXIdxEntity_CXXConcept:
3513 return "concept";
3514 }
3515 assert(0 && "Garbage entity kind")((void) sizeof ((0 && "Garbage entity kind") ? 1 : 0)
, __extension__ ({ if (0 && "Garbage entity kind") ; else
__assert_fail ("0 && \"Garbage entity kind\"", "clang/tools/c-index-test/c-index-test.c"
, 3515, __extension__ __PRETTY_FUNCTION__); }))
;
3516 return 0;
3517}
3518
3519static const char *getEntityTemplateKindString(CXIdxEntityCXXTemplateKind kind) {
3520 switch (kind) {
3521 case CXIdxEntity_NonTemplate: return "";
3522 case CXIdxEntity_Template: return "-template";
3523 case CXIdxEntity_TemplatePartialSpecialization:
3524 return "-template-partial-spec";
3525 case CXIdxEntity_TemplateSpecialization: return "-template-spec";
3526 }
3527 assert(0 && "Garbage entity kind")((void) sizeof ((0 && "Garbage entity kind") ? 1 : 0)
, __extension__ ({ if (0 && "Garbage entity kind") ; else
__assert_fail ("0 && \"Garbage entity kind\"", "clang/tools/c-index-test/c-index-test.c"
, 3527, __extension__ __PRETTY_FUNCTION__); }))
;
3528 return 0;
3529}
3530
3531static const char *getEntityLanguageString(CXIdxEntityLanguage kind) {
3532 switch (kind) {
3533 case CXIdxEntityLang_None: return "<none>";
3534 case CXIdxEntityLang_C: return "C";
3535 case CXIdxEntityLang_ObjC: return "ObjC";
3536 case CXIdxEntityLang_CXX: return "C++";
3537 case CXIdxEntityLang_Swift: return "Swift";
3538 }
3539 assert(0 && "Garbage language kind")((void) sizeof ((0 && "Garbage language kind") ? 1 : 0
), __extension__ ({ if (0 && "Garbage language kind")
; else __assert_fail ("0 && \"Garbage language kind\""
, "clang/tools/c-index-test/c-index-test.c", 3539, __extension__
__PRETTY_FUNCTION__); }))
;
3540 return 0;
3541}
3542
3543static void printEntityInfo(const char *cb,
3544 CXClientData client_data,
3545 const CXIdxEntityInfo *info) {
3546 const char *name;
3547 IndexData *index_data;
3548 unsigned i;
3549 index_data = (IndexData *)client_data;
3550 printCheck(index_data);
3551
3552 if (!info) {
3553 printf("%s: <<NULL>>", cb)__printf_chk (2 - 1, "%s: <<NULL>>", cb);
3554 return;
3555 }
3556
3557 name = info->name;
3558 if (!name)
3559 name = "<anon-tag>";
3560
3561 printf("%s: kind: %s%s", cb, getEntityKindString(info->kind),__printf_chk (2 - 1, "%s: kind: %s%s", cb, getEntityKindString
(info->kind), getEntityTemplateKindString(info->templateKind
))
3562 getEntityTemplateKindString(info->templateKind))__printf_chk (2 - 1, "%s: kind: %s%s", cb, getEntityKindString
(info->kind), getEntityTemplateKindString(info->templateKind
))
;
3563 printf(" | name: %s", name)__printf_chk (2 - 1, " | name: %s", name);
3564 printf(" | USR: %s", info->USR)__printf_chk (2 - 1, " | USR: %s", info->USR);
3565 printf(" | lang: %s", getEntityLanguageString(info->lang))__printf_chk (2 - 1, " | lang: %s", getEntityLanguageString(info
->lang))
;
3566
3567 for (i = 0; i != info->numAttributes; ++i) {
3568 const CXIdxAttrInfo *Attr = info->attributes[i];
3569 printf(" <attribute>: ")__printf_chk (2 - 1, " <attribute>: ");
3570 PrintCursor(Attr->cursor, NULL((void*)0));
3571 }
3572}
3573
3574static void printBaseClassInfo(CXClientData client_data,
3575 const CXIdxBaseClassInfo *info) {
3576 printEntityInfo(" <base>", client_data, info->base);
3577 printf(" | cursor: ")__printf_chk (2 - 1, " | cursor: ");
3578 PrintCursor(info->cursor, NULL((void*)0));
3579 printf(" | loc: ")__printf_chk (2 - 1, " | loc: ");
3580 printCXIndexLoc(info->loc, client_data);
3581}
3582
3583static void printProtocolList(const CXIdxObjCProtocolRefListInfo *ProtoInfo,
3584 CXClientData client_data) {
3585 unsigned i;
3586 for (i = 0; i < ProtoInfo->numProtocols; ++i) {
3587 printEntityInfo(" <protocol>", client_data,
3588 ProtoInfo->protocols[i]->protocol);
3589 printf(" | cursor: ")__printf_chk (2 - 1, " | cursor: ");
3590 PrintCursor(ProtoInfo->protocols[i]->cursor, NULL((void*)0));
3591 printf(" | loc: ")__printf_chk (2 - 1, " | loc: ");
3592 printCXIndexLoc(ProtoInfo->protocols[i]->loc, client_data);
3593 printf("\n")__printf_chk (2 - 1, "\n");
3594 }
3595}
3596
3597static void printSymbolRole(CXSymbolRole role) {
3598 if (role & CXSymbolRole_Declaration)
3599 printf(" decl")__printf_chk (2 - 1, " decl");
3600 if (role & CXSymbolRole_Definition)
3601 printf(" def")__printf_chk (2 - 1, " def");
3602 if (role & CXSymbolRole_Reference)
3603 printf(" ref")__printf_chk (2 - 1, " ref");
3604 if (role & CXSymbolRole_Read)
3605 printf(" read")__printf_chk (2 - 1, " read");
3606 if (role & CXSymbolRole_Write)
3607 printf(" write")__printf_chk (2 - 1, " write");
3608 if (role & CXSymbolRole_Call)
3609 printf(" call")__printf_chk (2 - 1, " call");
3610 if (role & CXSymbolRole_Dynamic)
3611 printf(" dyn")__printf_chk (2 - 1, " dyn");
3612 if (role & CXSymbolRole_AddressOf)
3613 printf(" addr")__printf_chk (2 - 1, " addr");
3614 if (role & CXSymbolRole_Implicit)
3615 printf(" implicit")__printf_chk (2 - 1, " implicit");
3616}
3617
3618static void index_diagnostic(CXClientData client_data,
3619 CXDiagnosticSet diagSet, void *reserved) {
3620 CXString str;
3621 const char *cstr;
3622 unsigned numDiags, i;
3623 CXDiagnostic diag;
3624 IndexData *index_data;
3625 index_data = (IndexData *)client_data;
3626 printCheck(index_data);
3627
3628 numDiags = clang_getNumDiagnosticsInSet(diagSet);
3629 for (i = 0; i != numDiags; ++i) {
3630 diag = clang_getDiagnosticInSet(diagSet, i);
3631 str = clang_formatDiagnostic(diag, clang_defaultDiagnosticDisplayOptions());
3632 cstr = clang_getCString(str);
3633 printf("[diagnostic]: %s\n", cstr)__printf_chk (2 - 1, "[diagnostic]: %s\n", cstr);
3634 clang_disposeString(str);
3635
3636 if (getenv("CINDEXTEST_FAILONERROR") &&
3637 clang_getDiagnosticSeverity(diag) >= CXDiagnostic_Error) {
3638 index_data->fail_for_error = 1;
3639 }
3640 }
3641}
3642
3643static CXIdxClientFile index_enteredMainFile(CXClientData client_data,
3644 CXFile file, void *reserved) {
3645 IndexData *index_data;
3646
3647 index_data = (IndexData *)client_data;
3648 printCheck(index_data);
3649
3650 index_data->main_filename = clang_getFileName(file);
3651
3652 printf("[enteredMainFile]: ")__printf_chk (2 - 1, "[enteredMainFile]: ");
3653 printCXIndexFile((CXIdxClientFile)file);
3654 printf("\n")__printf_chk (2 - 1, "\n");
3655
3656 return (CXIdxClientFile)file;
3657}
3658
3659static CXIdxClientFile index_ppIncludedFile(CXClientData client_data,
3660 const CXIdxIncludedFileInfo *info) {
3661 IndexData *index_data;
3662 CXModule Mod;
3663 index_data = (IndexData *)client_data;
3664 printCheck(index_data);
3665
3666 printf("[ppIncludedFile]: ")__printf_chk (2 - 1, "[ppIncludedFile]: ");
3667 printCXIndexFile((CXIdxClientFile)info->file);
3668 printf(" | name: \"%s\"", info->filename)__printf_chk (2 - 1, " | name: \"%s\"", info->filename);
3669 printf(" | hash loc: ")__printf_chk (2 - 1, " | hash loc: ");
3670 printCXIndexLoc(info->hashLoc, client_data);
3671 printf(" | isImport: %d | isAngled: %d | isModule: %d",__printf_chk (2 - 1, " | isImport: %d | isAngled: %d | isModule: %d"
, info->isImport, info->isAngled, info->isModuleImport
)
3672 info->isImport, info->isAngled, info->isModuleImport)__printf_chk (2 - 1, " | isImport: %d | isAngled: %d | isModule: %d"
, info->isImport, info->isAngled, info->isModuleImport
)
;
3673
3674 Mod = clang_getModuleForFile(index_data->TU, (CXFile)info->file);
3675 if (Mod) {
3676 CXString str = clang_Module_getFullName(Mod);
3677 const char *cstr = clang_getCString(str);
3678 printf(" | module: %s", cstr)__printf_chk (2 - 1, " | module: %s", cstr);
3679 clang_disposeString(str);
3680 }
3681
3682 printf("\n")__printf_chk (2 - 1, "\n");
3683
3684 return (CXIdxClientFile)info->file;
3685}
3686
3687static CXIdxClientFile index_importedASTFile(CXClientData client_data,
3688 const CXIdxImportedASTFileInfo *info) {
3689 IndexData *index_data;
3690 index_data = (IndexData *)client_data;
3691 printCheck(index_data);
3692
3693 if (index_data->importedASTs) {
3694 CXString filename = clang_getFileName(info->file);
3695 importedASTS_insert(index_data->importedASTs, clang_getCString(filename));
3696 clang_disposeString(filename);
3697 }
3698
3699 printf("[importedASTFile]: ")__printf_chk (2 - 1, "[importedASTFile]: ");
3700 printCXIndexFile((CXIdxClientFile)info->file);
3701 if (info->module) {
3702 CXString name = clang_Module_getFullName(info->module);
3703 printf(" | loc: ")__printf_chk (2 - 1, " | loc: ");
3704 printCXIndexLoc(info->loc, client_data);
3705 printf(" | name: \"%s\"", clang_getCString(name))__printf_chk (2 - 1, " | name: \"%s\"", clang_getCString(name
))
;
3706 printf(" | isImplicit: %d\n", info->isImplicit)__printf_chk (2 - 1, " | isImplicit: %d\n", info->isImplicit
)
;
3707 clang_disposeString(name);
3708 } else {
3709 /* PCH file, the rest are not relevant. */
3710 printf("\n")__printf_chk (2 - 1, "\n");
3711 }
3712
3713 return (CXIdxClientFile)info->file;
3714}
3715
3716static CXIdxClientContainer
3717index_startedTranslationUnit(CXClientData client_data, void *reserved) {
3718 IndexData *index_data;
3719 index_data = (IndexData *)client_data;
3720 printCheck(index_data);
3721
3722 printf("[startedTranslationUnit]\n")__printf_chk (2 - 1, "[startedTranslationUnit]\n");
3723 return (CXIdxClientContainer)"TU";
3724}
3725
3726static void index_indexDeclaration(CXClientData client_data,
3727 const CXIdxDeclInfo *info) {
3728 IndexData *index_data;
3729 const CXIdxObjCCategoryDeclInfo *CatInfo;
3730 const CXIdxObjCInterfaceDeclInfo *InterInfo;
3731 const CXIdxObjCProtocolRefListInfo *ProtoInfo;
3732 const CXIdxObjCPropertyDeclInfo *PropInfo;
3733 const CXIdxCXXClassDeclInfo *CXXClassInfo;
3734 unsigned i;
3735 index_data = (IndexData *)client_data;
3736
3737 printEntityInfo("[indexDeclaration]", client_data, info->entityInfo);
3738 printf(" | cursor: ")__printf_chk (2 - 1, " | cursor: ");
3739 PrintCursor(info->cursor, NULL((void*)0));
3740 printf(" | loc: ")__printf_chk (2 - 1, " | loc: ");
3741 printCXIndexLoc(info->loc, client_data);
3742 printf(" | semantic-container: ")__printf_chk (2 - 1, " | semantic-container: ");
3743 printCXIndexContainer(info->semanticContainer);
3744 printf(" | lexical-container: ")__printf_chk (2 - 1, " | lexical-container: ");
3745 printCXIndexContainer(info->lexicalContainer);
3746 printf(" | isRedecl: %d", info->isRedeclaration)__printf_chk (2 - 1, " | isRedecl: %d", info->isRedeclaration
)
;
3747 printf(" | isDef: %d", info->isDefinition)__printf_chk (2 - 1, " | isDef: %d", info->isDefinition);
3748 if (info->flags & CXIdxDeclFlag_Skipped) {
3749 assert(!info->isContainer)((void) sizeof ((!info->isContainer) ? 1 : 0), __extension__
({ if (!info->isContainer) ; else __assert_fail ("!info->isContainer"
, "clang/tools/c-index-test/c-index-test.c", 3749, __extension__
__PRETTY_FUNCTION__); }))
;
3750 printf(" | isContainer: skipped")__printf_chk (2 - 1, " | isContainer: skipped");
3751 } else {
3752 printf(" | isContainer: %d", info->isContainer)__printf_chk (2 - 1, " | isContainer: %d", info->isContainer
)
;
3753 }
3754 printf(" | isImplicit: %d\n", info->isImplicit)__printf_chk (2 - 1, " | isImplicit: %d\n", info->isImplicit
)
;
3755
3756 for (i = 0; i != info->numAttributes; ++i) {
3757 const CXIdxAttrInfo *Attr = info->attributes[i];
3758 printf(" <attribute>: ")__printf_chk (2 - 1, " <attribute>: ");
3759 PrintCursor(Attr->cursor, NULL((void*)0));
3760 printf("\n")__printf_chk (2 - 1, "\n");
3761 }
3762
3763 if (clang_index_isEntityObjCContainerKind(info->entityInfo->kind)) {
3764 const char *kindName = 0;
3765 CXIdxObjCContainerKind K = clang_index_getObjCContainerDeclInfo(info)->kind;
3766 switch (K) {
3767 case CXIdxObjCContainer_ForwardRef:
3768 kindName = "forward-ref"; break;
3769 case CXIdxObjCContainer_Interface:
3770 kindName = "interface"; break;
3771 case CXIdxObjCContainer_Implementation:
3772 kindName = "implementation"; break;
3773 }
3774 printCheck(index_data);
3775 printf(" <ObjCContainerInfo>: kind: %s\n", kindName)__printf_chk (2 - 1, " <ObjCContainerInfo>: kind: %s\n"
, kindName)
;
3776 }
3777
3778 if ((CatInfo = clang_index_getObjCCategoryDeclInfo(info))) {
3779 printEntityInfo(" <ObjCCategoryInfo>: class", client_data,
3780 CatInfo->objcClass);
3781 printf(" | cursor: ")__printf_chk (2 - 1, " | cursor: ");
3782 PrintCursor(CatInfo->classCursor, NULL((void*)0));
3783 printf(" | loc: ")__printf_chk (2 - 1, " | loc: ");
3784 printCXIndexLoc(CatInfo->classLoc, client_data);
3785 printf("\n")__printf_chk (2 - 1, "\n");
3786 }
3787
3788 if ((InterInfo = clang_index_getObjCInterfaceDeclInfo(info))) {
3789 if (InterInfo->superInfo) {
3790 printBaseClassInfo(client_data, InterInfo->superInfo);
3791 printf("\n")__printf_chk (2 - 1, "\n");
3792 }
3793 }
3794
3795 if ((ProtoInfo = clang_index_getObjCProtocolRefListInfo(info))) {
3796 printProtocolList(ProtoInfo, client_data);
3797 }
3798
3799 if ((PropInfo = clang_index_getObjCPropertyDeclInfo(info))) {
3800 if (PropInfo->getter) {
3801 printEntityInfo(" <getter>", client_data, PropInfo->getter);
3802 printf("\n")__printf_chk (2 - 1, "\n");
3803 }
3804 if (PropInfo->setter) {
3805 printEntityInfo(" <setter>", client_data, PropInfo->setter);
3806 printf("\n")__printf_chk (2 - 1, "\n");
3807 }
3808 }
3809
3810 if ((CXXClassInfo = clang_index_getCXXClassDeclInfo(info))) {
3811 for (i = 0; i != CXXClassInfo->numBases; ++i) {
3812 printBaseClassInfo(client_data, CXXClassInfo->bases[i]);
3813 printf("\n")__printf_chk (2 - 1, "\n");
3814 }
3815 }
3816
3817 if (info->declAsContainer)
3818 clang_index_setClientContainer(
3819 info->declAsContainer,
3820 makeClientContainer(client_data, info->entityInfo, info->loc));
3821}
3822
3823static void index_indexEntityReference(CXClientData client_data,
3824 const CXIdxEntityRefInfo *info) {
3825 printEntityInfo("[indexEntityReference]", client_data,
3826 info->referencedEntity);
3827 printf(" | cursor: ")__printf_chk (2 - 1, " | cursor: ");
3828 PrintCursor(info->cursor, NULL((void*)0));
3829 printf(" | loc: ")__printf_chk (2 - 1, " | loc: ");
3830 printCXIndexLoc(info->loc, client_data);
3831 printEntityInfo(" | <parent>:", client_data, info->parentEntity);
3832 printf(" | container: ")__printf_chk (2 - 1, " | container: ");
3833 printCXIndexContainer(info->container);
3834 printf(" | refkind: ")__printf_chk (2 - 1, " | refkind: ");
3835 switch (info->kind) {
3836 case CXIdxEntityRef_Direct: printf("direct")__printf_chk (2 - 1, "direct"); break;
3837 case CXIdxEntityRef_Implicit: printf("implicit")__printf_chk (2 - 1, "implicit"); break;
3838 }
3839 printf(" | role:")__printf_chk (2 - 1, " | role:");
3840 printSymbolRole(info->role);
3841 printf("\n")__printf_chk (2 - 1, "\n");
3842}
3843
3844static int index_abortQuery(CXClientData client_data, void *reserved) {
3845 IndexData *index_data;
3846 index_data = (IndexData *)client_data;
3847 return index_data->abort;
3848}
3849
3850static IndexerCallbacks IndexCB = {
3851 index_abortQuery,
3852 index_diagnostic,
3853 index_enteredMainFile,
3854 index_ppIncludedFile,
3855 index_importedASTFile,
3856 index_startedTranslationUnit,
3857 index_indexDeclaration,
3858 index_indexEntityReference
3859};
3860
3861static unsigned getIndexOptions(void) {
3862 unsigned index_opts;
3863 index_opts = 0;
3864 if (getenv("CINDEXTEST_SUPPRESSREFS"))
3865 index_opts |= CXIndexOpt_SuppressRedundantRefs;
3866 if (getenv("CINDEXTEST_INDEXLOCALSYMBOLS"))
3867 index_opts |= CXIndexOpt_IndexFunctionLocalSymbols;
3868 if (!getenv("CINDEXTEST_DISABLE_SKIPPARSEDBODIES"))
3869 index_opts |= CXIndexOpt_SkipParsedBodiesInSession;
3870 if (getenv("CINDEXTEST_INDEXIMPLICITTEMPLATEINSTANTIATIONS"))
3871 index_opts |= CXIndexOpt_IndexImplicitTemplateInstantiations;
3872
3873 return index_opts;
3874}
3875
3876static int index_compile_args(int num_args, const char **args,
3877 CXIndexAction idxAction,
3878 ImportedASTFilesData *importedASTs,
3879 const char *check_prefix) {
3880 IndexData index_data;
3881 unsigned index_opts;
3882 int result;
3883
3884 if (num_args == 0) {
3885 fprintf(stderr, "no compiler arguments\n")__fprintf_chk (stderr, 2 - 1, "no compiler arguments\n");
3886 return -1;
3887 }
3888
3889 index_data.check_prefix = check_prefix;
3890 index_data.first_check_printed = 0;
3891 index_data.fail_for_error = 0;
3892 index_data.abort = 0;
3893 index_data.main_filename = createCXString("");
3894 index_data.importedASTs = importedASTs;
3895 index_data.strings = NULL((void*)0);
3896 index_data.TU = NULL((void*)0);
3897
3898 index_opts = getIndexOptions();
3899 result = clang_indexSourceFile(idxAction, &index_data,
3900 &IndexCB,sizeof(IndexCB), index_opts,
3901 0, args, num_args, 0, 0, 0,
3902 getDefaultParsingOptions());
3903 if (result != CXError_Success)
3904 describeLibclangFailure(result);
3905
3906 if (index_data.fail_for_error)
3907 result = -1;
3908
3909 clang_disposeString(index_data.main_filename);
3910 free_client_data(&index_data);
3911 return result;
3912}
3913
3914static int index_ast_file(const char *ast_file,
3915 CXIndex Idx,
3916 CXIndexAction idxAction,
3917 ImportedASTFilesData *importedASTs,
3918 const char *check_prefix) {
3919 CXTranslationUnit TU;
3920 IndexData index_data;
3921 unsigned index_opts;
3922 int result;
3923
3924 if (!CreateTranslationUnit(Idx, ast_file, &TU))
3925 return -1;
3926
3927 index_data.check_prefix = check_prefix;
3928 index_data.first_check_printed = 0;
3929 index_data.fail_for_error = 0;
3930 index_data.abort = 0;
3931 index_data.main_filename = createCXString("");
3932 index_data.importedASTs = importedASTs;
3933 index_data.strings = NULL((void*)0);
3934 index_data.TU = TU;
3935
3936 index_opts = getIndexOptions();
3937 result = clang_indexTranslationUnit(idxAction, &index_data,
3938 &IndexCB,sizeof(IndexCB),
3939 index_opts, TU);
3940 if (index_data.fail_for_error)
3941 result = -1;
3942
3943 clang_disposeTranslationUnit(TU);
3944 clang_disposeString(index_data.main_filename);
3945 free_client_data(&index_data);
3946 return result;
3947}
3948
3949static int index_file(int argc, const char **argv, int full) {
3950 const char *check_prefix;
3951 CXIndex Idx;
3952 CXIndexAction idxAction;
3953 ImportedASTFilesData *importedASTs;
3954 int result;
3955
3956 check_prefix = 0;
3957 if (argc > 0) {
3958 if (strstr(argv[0], "-check-prefix=") == argv[0]) {
3959 check_prefix = argv[0] + strlen("-check-prefix=");
3960 ++argv;
3961 --argc;
3962 }
3963 }
3964
3965 if (!(Idx = clang_createIndex(/* excludeDeclsFromPCH */ 1,
3966 /* displayDiagnostics=*/1))) {
3967 fprintf(stderr, "Could not create Index\n")__fprintf_chk (stderr, 2 - 1, "Could not create Index\n");
3968 return 1;
3969 }
3970 idxAction = clang_IndexAction_create(Idx);
3971 importedASTs = 0;
3972 if (full)
3973 importedASTs = importedASTs_create();
3974
3975 result = index_compile_args(argc, argv, idxAction, importedASTs, check_prefix);
3976 if (result != 0)
3977 goto finished;
3978
3979 if (full) {
3980 unsigned i;
3981 for (i = 0; i < importedASTs->num_files && result == 0; ++i) {
3982 result = index_ast_file(importedASTs->filenames[i], Idx, idxAction,
3983 importedASTs, check_prefix);
3984 }
3985 }
3986
3987finished:
3988 importedASTs_dispose(importedASTs);
3989 clang_IndexAction_dispose(idxAction);
3990 clang_disposeIndex(Idx);
3991 return result;
3992}
3993
3994static int index_tu(int argc, const char **argv) {
3995 const char *check_prefix;
3996 CXIndex Idx;
3997 CXIndexAction idxAction;
3998 int result;
3999
4000 check_prefix = 0;
4001 if (argc > 0) {
4002 if (strstr(argv[0], "-check-prefix=") == argv[0]) {
4003 check_prefix = argv[0] + strlen("-check-prefix=");
4004 ++argv;
4005 --argc;
4006 }
4007 }
4008
4009 if (!(Idx = clang_createIndex(/* excludeDeclsFromPCH */ 1,
4010 /* displayDiagnostics=*/1))) {
4011 fprintf(stderr, "Could not create Index\n")__fprintf_chk (stderr, 2 - 1, "Could not create Index\n");
4012 return 1;
4013 }
4014 idxAction = clang_IndexAction_create(Idx);
4015
4016 result = index_ast_file(argv[0], Idx, idxAction,
4017 /*importedASTs=*/0, check_prefix);
4018
4019 clang_IndexAction_dispose(idxAction);
4020 clang_disposeIndex(Idx);
4021 return result;
4022}
4023
4024static int index_compile_db(int argc, const char **argv) {
4025 const char *check_prefix;
4026 CXIndex Idx;
4027 CXIndexAction idxAction;
4028 int errorCode = 0;
4029
4030 check_prefix = 0;
4031 if (argc > 0) {
4032 if (strstr(argv[0], "-check-prefix=") == argv[0]) {
4033 check_prefix = argv[0] + strlen("-check-prefix=");
4034 ++argv;
4035 --argc;
4036 }
4037 }
4038
4039 if (argc == 0) {
4040 fprintf(stderr, "no compilation database\n")__fprintf_chk (stderr, 2 - 1, "no compilation database\n");
4041 return -1;
4042 }
4043
4044 if (!(Idx = clang_createIndex(/* excludeDeclsFromPCH */ 1,
4045 /* displayDiagnostics=*/1))) {
4046 fprintf(stderr, "Could not create Index\n")__fprintf_chk (stderr, 2 - 1, "Could not create Index\n");
4047 return 1;
4048 }
4049 idxAction = clang_IndexAction_create(Idx);
4050
4051 {
4052 const char *database = argv[0];
4053 CXCompilationDatabase db = 0;
4054 CXCompileCommands CCmds = 0;
4055 CXCompileCommand CCmd;
4056 CXCompilationDatabase_Error ec;
4057 CXString wd;
4058#define MAX_COMPILE_ARGS512 512
4059 CXString cxargs[MAX_COMPILE_ARGS512];
4060 const char *args[MAX_COMPILE_ARGS512];
4061 char *tmp;
4062 unsigned len;
4063 char *buildDir;
4064 int i, a, numCmds, numArgs;
4065
4066 len = strlen(database);
4067 tmp = (char *) malloc(len+1);
4068 assert(tmp)((void) sizeof ((tmp) ? 1 : 0), __extension__ ({ if (tmp) ; else
__assert_fail ("tmp", "clang/tools/c-index-test/c-index-test.c"
, 4068, __extension__ __PRETTY_FUNCTION__); }))
;
4069 memcpy(tmp, database, len+1);
4070 buildDir = dirname(tmp);
4071
4072 db = clang_CompilationDatabase_fromDirectory(buildDir, &ec);
4073
4074 if (db) {
4075
4076 if (ec!=CXCompilationDatabase_NoError) {
4077 printf("unexpected error %d code while loading compilation database\n", ec)__printf_chk (2 - 1, "unexpected error %d code while loading compilation database\n"
, ec)
;
4078 errorCode = -1;
4079 goto cdb_end;
4080 }
4081
4082 if (chdir(buildDir) != 0) {
4083 printf("Could not chdir to %s\n", buildDir)__printf_chk (2 - 1, "Could not chdir to %s\n", buildDir);
4084 errorCode = -1;
4085 goto cdb_end;
4086 }
4087
4088 CCmds = clang_CompilationDatabase_getAllCompileCommands(db);
4089 if (!CCmds) {
4090 printf("compilation db is empty\n")__printf_chk (2 - 1, "compilation db is empty\n");
4091 errorCode = -1;
4092 goto cdb_end;
4093 }
4094
4095 numCmds = clang_CompileCommands_getSize(CCmds);
4096
4097 if (numCmds==0) {
4098 fprintf(stderr, "should not get an empty compileCommand set\n")__fprintf_chk (stderr, 2 - 1, "should not get an empty compileCommand set\n"
)
;
4099 errorCode = -1;
4100 goto cdb_end;
4101 }
4102
4103 for (i=0; i<numCmds && errorCode == 0; ++i) {
4104 CCmd = clang_CompileCommands_getCommand(CCmds, i);
4105
4106 wd = clang_CompileCommand_getDirectory(CCmd);
4107 if (chdir(clang_getCString(wd)) != 0) {
4108 printf("Could not chdir to %s\n", clang_getCString(wd))__printf_chk (2 - 1, "Could not chdir to %s\n", clang_getCString
(wd))
;
4109 errorCode = -1;
4110 goto cdb_end;
4111 }
4112 clang_disposeString(wd);
4113
4114 numArgs = clang_CompileCommand_getNumArgs(CCmd);
4115 if (numArgs > MAX_COMPILE_ARGS512){
4116 fprintf(stderr, "got more compile arguments than maximum\n")__fprintf_chk (stderr, 2 - 1, "got more compile arguments than maximum\n"
)
;
4117 errorCode = -1;
4118 goto cdb_end;
4119 }
4120 for (a=0; a<numArgs; ++a) {
4121 cxargs[a] = clang_CompileCommand_getArg(CCmd, a);
4122 args[a] = clang_getCString(cxargs[a]);
4123 }
4124
4125 errorCode = index_compile_args(numArgs, args, idxAction,
4126 /*importedASTs=*/0, check_prefix);
4127
4128 for (a=0; a<numArgs; ++a)
4129 clang_disposeString(cxargs[a]);
4130 }
4131 } else {
4132 printf("database loading failed with error code %d.\n", ec)__printf_chk (2 - 1, "database loading failed with error code %d.\n"
, ec)
;
4133 errorCode = -1;
4134 }
4135
4136 cdb_end:
4137 clang_CompileCommands_dispose(CCmds);
4138 clang_CompilationDatabase_dispose(db);
4139 free(tmp);
4140
4141 }
4142
4143 clang_IndexAction_dispose(idxAction);
4144 clang_disposeIndex(Idx);
4145 return errorCode;
4146}
4147
4148int perform_token_annotation(int argc, const char **argv) {
4149 const char *input = argv[1];
4150 char *filename = 0;
4151 unsigned line, second_line;
4152 unsigned column, second_column;
4153 CXIndex CIdx;
4154 CXTranslationUnit TU = 0;
4155 int errorCode;
4156 struct CXUnsavedFile *unsaved_files = 0;
4157 int num_unsaved_files = 0;
4158 CXToken *tokens;
4159 unsigned num_tokens;
4160 CXSourceRange range;
4161 CXSourceLocation startLoc, endLoc;
4162 CXFile file = 0;
4163 CXCursor *cursors = 0;
4164 CXSourceRangeList *skipped_ranges = 0;
4165 enum CXErrorCode Err;
4166 unsigned i;
4167
4168 input += strlen("-test-annotate-tokens=");
4169 if ((errorCode = parse_file_line_column(input, &filename, &line, &column,
4170 &second_line, &second_column)))
4171 return errorCode;
4172
4173 if (parse_remapped_files(argc, argv, 2, &unsaved_files, &num_unsaved_files)) {
4174 free(filename);
4175 return -1;
4176 }
4177
4178 CIdx = clang_createIndex(0, 1);
4179 Err = clang_parseTranslationUnit2(CIdx, argv[argc - 1],
4180 argv + num_unsaved_files + 2,
4181 argc - num_unsaved_files - 3,
4182 unsaved_files,
4183 num_unsaved_files,
4184 getDefaultParsingOptions(), &TU);
4185 if (Err != CXError_Success) {
4186 fprintf(stderr, "unable to parse input\n")__fprintf_chk (stderr, 2 - 1, "unable to parse input\n");
4187 describeLibclangFailure(Err);
4188 clang_disposeIndex(CIdx);
4189 free(filename);
4190 free_remapped_files(unsaved_files, num_unsaved_files);
4191 return -1;
4192 }
4193 errorCode = 0;
4194
4195 if (checkForErrors(TU) != 0) {
4196 errorCode = -1;
4197 goto teardown;
4198 }
4199
4200 if (getenv("CINDEXTEST_EDITING")) {
4201 for (i = 0; i < 5; ++i) {
4202 Err = clang_reparseTranslationUnit(TU, num_unsaved_files, unsaved_files,
4203 clang_defaultReparseOptions(TU));
4204 if (Err != CXError_Success) {
4205 fprintf(stderr, "Unable to reparse translation unit!\n")__fprintf_chk (stderr, 2 - 1, "Unable to reparse translation unit!\n"
)
;
4206 describeLibclangFailure(Err);
4207 errorCode = -1;
4208 goto teardown;
4209 }
4210 }
4211 }
4212
4213 if (checkForErrors(TU) != 0) {
4214 errorCode = -1;
4215 goto teardown;
4216 }
4217
4218 file = clang_getFile(TU, filename);
4219 if (!file) {
4220 fprintf(stderr, "file %s is not in this translation unit\n", filename)__fprintf_chk (stderr, 2 - 1, "file %s is not in this translation unit\n"
, filename)
;
4221 errorCode = -1;
4222 goto teardown;
4223 }
4224
4225 startLoc = clang_getLocation(TU, file, line, column);
4226 if (clang_equalLocations(clang_getNullLocation(), startLoc)) {
4227 fprintf(stderr, "invalid source location %s:%d:%d\n", filename, line,__fprintf_chk (stderr, 2 - 1, "invalid source location %s:%d:%d\n"
, filename, line, column)
4228 column)__fprintf_chk (stderr, 2 - 1, "invalid source location %s:%d:%d\n"
, filename, line, column)
;
4229 errorCode = -1;
4230 goto teardown;
4231 }
4232
4233 endLoc = clang_getLocation(TU, file, second_line, second_column);
4234 if (clang_equalLocations(clang_getNullLocation(), endLoc)) {
4235 fprintf(stderr, "invalid source location %s:%d:%d\n", filename,__fprintf_chk (stderr, 2 - 1, "invalid source location %s:%d:%d\n"
, filename, second_line, second_column)
4236 second_line, second_column)__fprintf_chk (stderr, 2 - 1, "invalid source location %s:%d:%d\n"
, filename, second_line, second_column)
;
4237 errorCode = -1;
4238 goto teardown;
4239 }
4240
4241 range = clang_getRange(startLoc, endLoc);
4242 clang_tokenize(TU, range, &tokens, &num_tokens);
4243
4244 if (checkForErrors(TU) != 0) {
4245 errorCode = -1;
4246 goto teardown;
4247 }
4248
4249 cursors = (CXCursor *)malloc(num_tokens * sizeof(CXCursor));
4250 assert(cursors)((void) sizeof ((cursors) ? 1 : 0), __extension__ ({ if (cursors
) ; else __assert_fail ("cursors", "clang/tools/c-index-test/c-index-test.c"
, 4250, __extension__ __PRETTY_FUNCTION__); }))
;
4251 clang_annotateTokens(TU, tokens, num_tokens, cursors);
4252
4253 if (checkForErrors(TU) != 0) {
4254 errorCode = -1;
4255 goto teardown;
4256 }
4257
4258 skipped_ranges = clang_getSkippedRanges(TU, file);
4259 for (i = 0; i != skipped_ranges->count; ++i) {
4260 unsigned start_line, start_column, end_line, end_column;
4261 clang_getSpellingLocation(clang_getRangeStart(skipped_ranges->ranges[i]),
4262 0, &start_line, &start_column, 0);
4263 clang_getSpellingLocation(clang_getRangeEnd(skipped_ranges->ranges[i]),
4264 0, &end_line, &end_column, 0);
4265 printf("Skipping: ")__printf_chk (2 - 1, "Skipping: ");
4266 PrintExtent(stdoutstdout, start_line, start_column, end_line, end_column);
4267 printf("\n")__printf_chk (2 - 1, "\n");
4268 }
4269 clang_disposeSourceRangeList(skipped_ranges);
4270
4271 for (i = 0; i != num_tokens; ++i) {
4272 const char *kind = "<unknown>";
4273 CXString spelling = clang_getTokenSpelling(TU, tokens[i]);
4274 CXSourceRange extent = clang_getTokenExtent(TU, tokens[i]);
4275 unsigned start_line, start_column, end_line, end_column;
4276
4277 switch (clang_getTokenKind(tokens[i])) {
4278 case CXToken_Punctuation: kind = "Punctuation"; break;
4279 case CXToken_Keyword: kind = "Keyword"; break;
4280 case CXToken_Identifier: kind = "Identifier"; break;
4281 case CXToken_Literal: kind = "Literal"; break;
4282 case CXToken_Comment: kind = "Comment"; break;
4283 }
4284 clang_getSpellingLocation(clang_getRangeStart(extent),
4285 0, &start_line, &start_column, 0);
4286 clang_getSpellingLocation(clang_getRangeEnd(extent),
4287 0, &end_line, &end_column, 0);
4288 printf("%s: \"%s\" ", kind, clang_getCString(spelling))__printf_chk (2 - 1, "%s: \"%s\" ", kind, clang_getCString(spelling
))
;
4289 clang_disposeString(spelling);
4290 PrintExtent(stdoutstdout, start_line, start_column, end_line, end_column);
4291 if (!clang_isInvalid(cursors[i].kind)) {
4292 printf(" ")__printf_chk (2 - 1, " ");
4293 PrintCursor(cursors[i], NULL((void*)0));
4294 }
4295 printf("\n")__printf_chk (2 - 1, "\n");
4296 }
4297 free(cursors);
4298 clang_disposeTokens(TU, tokens, num_tokens);
4299
4300 teardown:
4301 PrintDiagnostics(TU);
4302 clang_disposeTranslationUnit(TU);
4303 clang_disposeIndex(CIdx);
4304 free(filename);
4305 free_remapped_files(unsaved_files, num_unsaved_files);
4306 return errorCode;
4307}
4308
4309static int
4310perform_test_compilation_db(const char *database, int argc, const char **argv) {
4311 CXCompilationDatabase db;
4312 CXCompileCommands CCmds;
4313 CXCompileCommand CCmd;
4314 CXCompilationDatabase_Error ec;
4315 CXString wd;
4316 CXString arg;
4317 int errorCode = 0;
4318 char *tmp;
4319 unsigned len;
4320 char *buildDir;
4321 int i, j, a, numCmds, numArgs;
4322
4323 len = strlen(database);
4324 tmp = (char *) malloc(len+1);
4325 assert(tmp)((void) sizeof ((tmp) ? 1 : 0), __extension__ ({ if (tmp) ; else
__assert_fail ("tmp", "clang/tools/c-index-test/c-index-test.c"
, 4325, __extension__ __PRETTY_FUNCTION__); }))
;
4326 memcpy(tmp, database, len+1);
4327 buildDir = dirname(tmp);
4328
4329 db = clang_CompilationDatabase_fromDirectory(buildDir, &ec);
4330
4331 if (db) {
4332
4333 if (ec!=CXCompilationDatabase_NoError) {
4334 printf("unexpected error %d code while loading compilation database\n", ec)__printf_chk (2 - 1, "unexpected error %d code while loading compilation database\n"
, ec)
;
4335 errorCode = -1;
4336 goto cdb_end;
4337 }
4338
4339 for (i=0; i<argc && errorCode==0; ) {
4340 if (strcmp(argv[i],"lookup")==0){
4341 CCmds = clang_CompilationDatabase_getCompileCommands(db, argv[i+1]);
4342
4343 if (!CCmds) {
4344 printf("file %s not found in compilation db\n", argv[i+1])__printf_chk (2 - 1, "file %s not found in compilation db\n",
argv[i+1])
;
4345 errorCode = -1;
4346 break;
4347 }
4348
4349 numCmds = clang_CompileCommands_getSize(CCmds);
4350
4351 if (numCmds==0) {
4352 fprintf(stderr, "should not get an empty compileCommand set for file"__fprintf_chk (stderr, 2 - 1, "should not get an empty compileCommand set for file"
" '%s'\n", argv[i+1])
4353 " '%s'\n", argv[i+1])__fprintf_chk (stderr, 2 - 1, "should not get an empty compileCommand set for file"
" '%s'\n", argv[i+1])
;
4354 errorCode = -1;
4355 break;
4356 }
4357
4358 for (j=0; j<numCmds; ++j) {
4359 CCmd = clang_CompileCommands_getCommand(CCmds, j);
4360
4361 wd = clang_CompileCommand_getDirectory(CCmd);
4362 printf("workdir:'%s'", clang_getCString(wd))__printf_chk (2 - 1, "workdir:'%s'", clang_getCString(wd));
4363 clang_disposeString(wd);
4364
4365 printf(" cmdline:'")__printf_chk (2 - 1, " cmdline:'");
4366 numArgs = clang_CompileCommand_getNumArgs(CCmd);
4367 for (a=0; a<numArgs; ++a) {
4368 if (a) printf(" ")__printf_chk (2 - 1, " ");
4369 arg = clang_CompileCommand_getArg(CCmd, a);
4370 printf("%s", clang_getCString(arg))__printf_chk (2 - 1, "%s", clang_getCString(arg));
4371 clang_disposeString(arg);
4372 }
4373 printf("'\n")__printf_chk (2 - 1, "'\n");
4374 }
4375
4376 clang_CompileCommands_dispose(CCmds);
4377
4378 i += 2;
4379 }
4380 }
4381 clang_CompilationDatabase_dispose(db);
4382 } else {
4383 printf("database loading failed with error code %d.\n", ec)__printf_chk (2 - 1, "database loading failed with error code %d.\n"
, ec)
;
4384 errorCode = -1;
4385 }
4386
4387cdb_end:
4388 free(tmp);
4389
4390 return errorCode;
4391}
4392
4393/******************************************************************************/
4394/* USR printing. */
4395/******************************************************************************/
4396
4397static int insufficient_usr(const char *kind, const char *usage) {
4398 fprintf(stderr, "USR for '%s' requires: %s\n", kind, usage)__fprintf_chk (stderr, 2 - 1, "USR for '%s' requires: %s\n", kind
, usage)
;
4399 return 1;
4400}
4401
4402static unsigned isUSR(const char *s) {
4403 return s[0] == 'c' && s[1] == ':';
4404}
4405
4406static int not_usr(const char *s, const char *arg) {
4407 fprintf(stderr, "'%s' argument ('%s') is not a USR\n", s, arg)__fprintf_chk (stderr, 2 - 1, "'%s' argument ('%s') is not a USR\n"
, s, arg)
;
4408 return 1;
4409}
4410
4411static void print_usr(CXString usr) {
4412 const char *s = clang_getCString(usr);
4413 printf("%s\n", s)__printf_chk (2 - 1, "%s\n", s);
4414 clang_disposeString(usr);
4415}
4416
4417static void display_usrs(void) {
4418 fprintf(stderr, "-print-usrs options:\n"__fprintf_chk (stderr, 2 - 1, "-print-usrs options:\n" " ObjCCategory <class name> <category name>\n"
" ObjCClass <class name>\n" " ObjCIvar <ivar name> <class USR>\n"
" ObjCMethod <selector> [0=class method|1=instance method] "
"<class USR>\n" " ObjCProperty <property name> <class USR>\n"
" ObjCProtocol <protocol name>\n")
4419 " ObjCCategory <class name> <category name>\n"__fprintf_chk (stderr, 2 - 1, "-print-usrs options:\n" " ObjCCategory <class name> <category name>\n"
" ObjCClass <class name>\n" " ObjCIvar <ivar name> <class USR>\n"
" ObjCMethod <selector> [0=class method|1=instance method] "
"<class USR>\n" " ObjCProperty <property name> <class USR>\n"
" ObjCProtocol <protocol name>\n")
4420 " ObjCClass <class name>\n"__fprintf_chk (stderr, 2 - 1, "-print-usrs options:\n" " ObjCCategory <class name> <category name>\n"
" ObjCClass <class name>\n" " ObjCIvar <ivar name> <class USR>\n"
" ObjCMethod <selector> [0=class method|1=instance method] "
"<class USR>\n" " ObjCProperty <property name> <class USR>\n"
" ObjCProtocol <protocol name>\n")
4421 " ObjCIvar <ivar name> <class USR>\n"__fprintf_chk (stderr, 2 - 1, "-print-usrs options:\n" " ObjCCategory <class name> <category name>\n"
" ObjCClass <class name>\n" " ObjCIvar <ivar name> <class USR>\n"
" ObjCMethod <selector> [0=class method|1=instance method] "
"<class USR>\n" " ObjCProperty <property name> <class USR>\n"
" ObjCProtocol <protocol name>\n")
4422 " ObjCMethod <selector> [0=class method|1=instance method] "__fprintf_chk (stderr, 2 - 1, "-print-usrs options:\n" " ObjCCategory <class name> <category name>\n"
" ObjCClass <class name>\n" " ObjCIvar <ivar name> <class USR>\n"
" ObjCMethod <selector> [0=class method|1=instance method] "
"<class USR>\n" " ObjCProperty <property name> <class USR>\n"
" ObjCProtocol <protocol name>\n")
4423 "<class USR>\n"__fprintf_chk (stderr, 2 - 1, "-print-usrs options:\n" " ObjCCategory <class name> <category name>\n"
" ObjCClass <class name>\n" " ObjCIvar <ivar name> <class USR>\n"
" ObjCMethod <selector> [0=class method|1=instance method] "
"<class USR>\n" " ObjCProperty <property name> <class USR>\n"
" ObjCProtocol <protocol name>\n")
4424 " ObjCProperty <property name> <class USR>\n"__fprintf_chk (stderr, 2 - 1, "-print-usrs options:\n" " ObjCCategory <class name> <category name>\n"
" ObjCClass <class name>\n" " ObjCIvar <ivar name> <class USR>\n"
" ObjCMethod <selector> [0=class method|1=instance method] "
"<class USR>\n" " ObjCProperty <property name> <class USR>\n"
" ObjCProtocol <protocol name>\n")
4425 " ObjCProtocol <protocol name>\n")__fprintf_chk (stderr, 2 - 1, "-print-usrs options:\n" " ObjCCategory <class name> <category name>\n"
" ObjCClass <class name>\n" " ObjCIvar <ivar name> <class USR>\n"
" ObjCMethod <selector> [0=class method|1=instance method] "
"<class USR>\n" " ObjCProperty <property name> <class USR>\n"
" ObjCProtocol <protocol name>\n")
;
4426}
4427
4428int print_usrs(const char **I, const char **E) {
4429 while (I != E) {
4430 const char *kind = *I;
4431 unsigned len = strlen(kind);
4432 switch (len) {
4433 case 8:
4434 if (memcmp(kind, "ObjCIvar", 8) == 0) {
4435 if (I + 2 >= E)
4436 return insufficient_usr(kind, "<ivar name> <class USR>");
4437 if (!isUSR(I[2]))
4438 return not_usr("<class USR>", I[2]);
4439 else {
4440 CXString x = createCXString(I[2]);
4441 print_usr(clang_constructUSR_ObjCIvar(I[1], x));
4442 }
4443
4444 I += 3;
4445 continue;
4446 }
4447 break;
4448 case 9:
4449 if (memcmp(kind, "ObjCClass", 9) == 0) {
4450 if (I + 1 >= E)
4451 return insufficient_usr(kind, "<class name>");
4452 print_usr(clang_constructUSR_ObjCClass(I[1]));
4453 I += 2;
4454 continue;
4455 }
4456 break;
4457 case 10:
4458 if (memcmp(kind, "ObjCMethod", 10) == 0) {
4459 if (I + 3 >= E)
4460 return insufficient_usr(kind, "<method selector> "
4461 "[0=class method|1=instance method] <class USR>");
4462 if (!isUSR(I[3]))
4463 return not_usr("<class USR>", I[3]);
4464 else {
4465 CXString x = createCXString(I[3]);
4466 print_usr(clang_constructUSR_ObjCMethod(I[1], atoi(I[2]), x));
4467 }
4468 I += 4;
4469 continue;
4470 }
4471 break;
4472 case 12:
4473 if (memcmp(kind, "ObjCCategory", 12) == 0) {
4474 if (I + 2 >= E)
4475 return insufficient_usr(kind, "<class name> <category name>");
4476 print_usr(clang_constructUSR_ObjCCategory(I[1], I[2]));
4477 I += 3;
4478 continue;
4479 }
4480 if (memcmp(kind, "ObjCProtocol", 12) == 0) {
4481 if (I + 1 >= E)
4482 return insufficient_usr(kind, "<protocol name>");
4483 print_usr(clang_constructUSR_ObjCProtocol(I[1]));
4484 I += 2;
4485 continue;
4486 }
4487 if (memcmp(kind, "ObjCProperty", 12) == 0) {
4488 if (I + 2 >= E)
4489 return insufficient_usr(kind, "<property name> <class USR>");
4490 if (!isUSR(I[2]))
4491 return not_usr("<class USR>", I[2]);
4492 else {
4493 CXString x = createCXString(I[2]);
4494 print_usr(clang_constructUSR_ObjCProperty(I[1], x));
4495 }
4496 I += 3;
4497 continue;
4498 }
4499 break;
4500 default:
4501 break;
4502 }
4503 break;
4504 }
4505
4506 if (I != E) {
4507 fprintf(stderr, "Invalid USR kind: %s\n", *I)__fprintf_chk (stderr, 2 - 1, "Invalid USR kind: %s\n", *I);
4508 display_usrs();
4509 return 1;
4510 }
4511 return 0;
4512}
4513
4514int print_usrs_file(const char *file_name) {
4515 char line[2048];
4516 const char *args[128];
4517 unsigned numChars = 0;
4518
4519 FILE *fp = fopen(file_name, "r");
4520 if (!fp) {
4521 fprintf(stderr, "error: cannot open '%s'\n", file_name)__fprintf_chk (stderr, 2 - 1, "error: cannot open '%s'\n", file_name
)
;
4522 return 1;
4523 }
4524
4525 /* This code is not really all that safe, but it works fine for testing. */
4526 while (!feof(fp)) {
4527 char c = fgetc(fp);
4528 if (c == '\n') {
4529 unsigned i = 0;
4530 const char *s = 0;
4531
4532 if (numChars == 0)
4533 continue;
4534
4535 line[numChars] = '\0';
4536 numChars = 0;
4537
4538 if (line[0] == '/' && line[1] == '/')
4539 continue;
4540
4541 s = strtok(line, " ");
4542 while (s) {
4543 args[i] = s;
4544 ++i;
4545 s = strtok(0, " ");
4546 }
4547 if (print_usrs(&args[0], &args[i]))
4548 return 1;
4549 }
4550 else
4551 line[numChars++] = c;
4552 }
4553
4554 fclose(fp);
4555 return 0;
4556}
4557
4558/******************************************************************************/
4559/* Command line processing. */
4560/******************************************************************************/
4561int write_pch_file(const char *filename, int argc, const char *argv[]) {
4562 CXIndex Idx;
4563 CXTranslationUnit TU;
4564 struct CXUnsavedFile *unsaved_files = 0;
4565 int num_unsaved_files = 0;
4566 enum CXErrorCode Err;
4567 int result = 0;
4568
4569 Idx = clang_createIndex(/* excludeDeclsFromPCH */1, /* displayDiagnostics=*/1);
4570
4571 if (parse_remapped_files(argc, argv, 0, &unsaved_files, &num_unsaved_files)) {
4572 clang_disposeIndex(Idx);
4573 return -1;
4574 }
4575
4576 Err = clang_parseTranslationUnit2(
4577 Idx, 0, argv + num_unsaved_files, argc - num_unsaved_files,
4578 unsaved_files, num_unsaved_files,
4579 CXTranslationUnit_Incomplete |
4580 CXTranslationUnit_DetailedPreprocessingRecord |
4581 CXTranslationUnit_ForSerialization,
4582 &TU);
4583 if (Err != CXError_Success) {
4584 fprintf(stderr, "Unable to load translation unit!\n")__fprintf_chk (stderr, 2 - 1, "Unable to load translation unit!\n"
)
;
4585 describeLibclangFailure(Err);
4586 free_remapped_files(unsaved_files, num_unsaved_files);
4587 clang_disposeTranslationUnit(TU);
4588 clang_disposeIndex(Idx);
4589 return 1;
4590 }
4591
4592 switch (clang_saveTranslationUnit(TU, filename,
4593 clang_defaultSaveOptions(TU))) {
4594 case CXSaveError_None:
4595 break;
4596
4597 case CXSaveError_TranslationErrors:
4598 fprintf(stderr, "Unable to write PCH file %s: translation errors\n",__fprintf_chk (stderr, 2 - 1, "Unable to write PCH file %s: translation errors\n"
, filename)
4599 filename)__fprintf_chk (stderr, 2 - 1, "Unable to write PCH file %s: translation errors\n"
, filename)
;
4600 result = 2;
4601 break;
4602
4603 case CXSaveError_InvalidTU:
4604 fprintf(stderr, "Unable to write PCH file %s: invalid translation unit\n",__fprintf_chk (stderr, 2 - 1, "Unable to write PCH file %s: invalid translation unit\n"
, filename)
4605 filename)__fprintf_chk (stderr, 2 - 1, "Unable to write PCH file %s: invalid translation unit\n"
, filename)
;
4606 result = 3;
4607 break;
4608
4609 case CXSaveError_Unknown:
4610 default:
4611 fprintf(stderr, "Unable to write PCH file %s: unknown error \n", filename)__fprintf_chk (stderr, 2 - 1, "Unable to write PCH file %s: unknown error \n"
, filename)
;
4612 result = 1;
4613 break;
4614 }
4615
4616 clang_disposeTranslationUnit(TU);
4617 free_remapped_files(unsaved_files, num_unsaved_files);
4618 clang_disposeIndex(Idx);
4619 return result;
4620}
4621
4622/******************************************************************************/
4623/* Serialized diagnostics. */
4624/******************************************************************************/
4625
4626static const char *getDiagnosticCodeStr(enum CXLoadDiag_Error error) {
4627 switch (error) {
4628 case CXLoadDiag_CannotLoad: return "Cannot Load File";
4629 case CXLoadDiag_None: break;
4630 case CXLoadDiag_Unknown: return "Unknown";
4631 case CXLoadDiag_InvalidFile: return "Invalid File";
4632 }
4633 return "None";
4634}
4635
4636static const char *getSeverityString(enum CXDiagnosticSeverity severity) {
4637 switch (severity) {
4638 case CXDiagnostic_Note: return "note";
4639 case CXDiagnostic_Error: return "error";
4640 case CXDiagnostic_Fatal: return "fatal";
4641 case CXDiagnostic_Ignored: return "ignored";
4642 case CXDiagnostic_Warning: return "warning";
4643 }
4644 return "unknown";
4645}
4646
4647static void printIndent(unsigned indent) {
4648 if (indent == 0)
4649 return;
4650 fprintf(stderr, "+")__fprintf_chk (stderr, 2 - 1, "+");
4651 --indent;
4652 while (indent > 0) {
4653 fprintf(stderr, "-")__fprintf_chk (stderr, 2 - 1, "-");
4654 --indent;
4655 }
4656}
4657
4658static void printLocation(CXSourceLocation L) {
4659 CXFile File;
4660 CXString FileName;
4661 unsigned line, column, offset;
4662
4663 clang_getExpansionLocation(L, &File, &line, &column, &offset);
4664 FileName = clang_getFileName(File);
4665
4666 fprintf(stderr, "%s:%d:%d", clang_getCString(FileName), line, column)__fprintf_chk (stderr, 2 - 1, "%s:%d:%d", clang_getCString(FileName
), line, column)
;
4667 clang_disposeString(FileName);
4668}
4669
4670static void printRanges(CXDiagnostic D, unsigned indent) {
4671 unsigned i, n = clang_getDiagnosticNumRanges(D);
4672
4673 for (i = 0; i < n; ++i) {
4674 CXSourceLocation Start, End;
4675 CXSourceRange SR = clang_getDiagnosticRange(D, i);
4676 Start = clang_getRangeStart(SR);
4677 End = clang_getRangeEnd(SR);
4678
4679 printIndent(indent);
4680 fprintf(stderr, "Range: ")__fprintf_chk (stderr, 2 - 1, "Range: ");
4681 printLocation(Start);
4682 fprintf(stderr, " ")__fprintf_chk (stderr, 2 - 1, " ");
4683 printLocation(End);
4684 fprintf(stderr, "\n")__fprintf_chk (stderr, 2 - 1, "\n");
4685 }
4686}
4687
4688static void printFixIts(CXDiagnostic D, unsigned indent) {
4689 unsigned i, n = clang_getDiagnosticNumFixIts(D);
4690 fprintf(stderr, "Number FIXITs = %d\n", n)__fprintf_chk (stderr, 2 - 1, "Number FIXITs = %d\n", n);
4691 for (i = 0 ; i < n; ++i) {
4692 CXSourceRange ReplacementRange;
4693 CXString text;
4694 text = clang_getDiagnosticFixIt(D, i, &ReplacementRange);
4695
4696 printIndent(indent);
4697 fprintf(stderr, "FIXIT: (")__fprintf_chk (stderr, 2 - 1, "FIXIT: (");
4698 printLocation(clang_getRangeStart(ReplacementRange));
4699 fprintf(stderr, " - ")__fprintf_chk (stderr, 2 - 1, " - ");
4700 printLocation(clang_getRangeEnd(ReplacementRange));
4701 fprintf(stderr, "): \"%s\"\n", clang_getCString(text))__fprintf_chk (stderr, 2 - 1, "): \"%s\"\n", clang_getCString
(text))
;
4702 clang_disposeString(text);
4703 }
4704}
4705
4706static void printDiagnosticSet(CXDiagnosticSet Diags, unsigned indent) {
4707 unsigned i, n;
4708
4709 if (!Diags)
4710 return;
4711
4712 n = clang_getNumDiagnosticsInSet(Diags);
4713 for (i = 0; i < n; ++i) {
4714 CXSourceLocation DiagLoc;
4715 CXDiagnostic D;
4716 CXFile File;
4717 CXString FileName, DiagSpelling, DiagOption, DiagCat;
4718 unsigned line, column, offset;
4719 const char *FileNameStr = 0, *DiagOptionStr = 0, *DiagCatStr = 0;
4720
4721 D = clang_getDiagnosticInSet(Diags, i);
4722 DiagLoc = clang_getDiagnosticLocation(D);
4723 clang_getExpansionLocation(DiagLoc, &File, &line, &column, &offset);
4724 FileName = clang_getFileName(File);
4725 FileNameStr = clang_getCString(FileName);
4726 DiagSpelling = clang_getDiagnosticSpelling(D);
4727
4728 printIndent(indent);
4729
4730 fprintf(stderr, "%s:%d:%d: %s: %s",__fprintf_chk (stderr, 2 - 1, "%s:%d:%d: %s: %s", FileNameStr
? FileNameStr : "(null)", line, column, getSeverityString(clang_getDiagnosticSeverity
(D)), clang_getCString(DiagSpelling))
4731 FileNameStr ? FileNameStr : "(null)",__fprintf_chk (stderr, 2 - 1, "%s:%d:%d: %s: %s", FileNameStr
? FileNameStr : "(null)", line, column, getSeverityString(clang_getDiagnosticSeverity
(D)), clang_getCString(DiagSpelling))
4732 line,__fprintf_chk (stderr, 2 - 1, "%s:%d:%d: %s: %s", FileNameStr
? FileNameStr : "(null)", line, column, getSeverityString(clang_getDiagnosticSeverity
(D)), clang_getCString(DiagSpelling))
4733 column,__fprintf_chk (stderr, 2 - 1, "%s:%d:%d: %s: %s", FileNameStr
? FileNameStr : "(null)", line, column, getSeverityString(clang_getDiagnosticSeverity
(D)), clang_getCString(DiagSpelling))
4734 getSeverityString(clang_getDiagnosticSeverity(D)),__fprintf_chk (stderr, 2 - 1, "%s:%d:%d: %s: %s", FileNameStr
? FileNameStr : "(null)", line, column, getSeverityString(clang_getDiagnosticSeverity
(D)), clang_getCString(DiagSpelling))
4735 clang_getCString(DiagSpelling))__fprintf_chk (stderr, 2 - 1, "%s:%d:%d: %s: %s", FileNameStr
? FileNameStr : "(null)", line, column, getSeverityString(clang_getDiagnosticSeverity
(D)), clang_getCString(DiagSpelling))
;
4736
4737 DiagOption = clang_getDiagnosticOption(D, 0);
4738 DiagOptionStr = clang_getCString(DiagOption);
4739 if (DiagOptionStr) {
4740 fprintf(stderr, " [%s]", DiagOptionStr)__fprintf_chk (stderr, 2 - 1, " [%s]", DiagOptionStr);
4741 }
4742
4743 DiagCat = clang_getDiagnosticCategoryText(D);
4744 DiagCatStr = clang_getCString(DiagCat);
4745 if (DiagCatStr) {
4746 fprintf(stderr, " [%s]", DiagCatStr)__fprintf_chk (stderr, 2 - 1, " [%s]", DiagCatStr);
4747 }
4748
4749 fprintf(stderr, "\n")__fprintf_chk (stderr, 2 - 1, "\n");
4750
4751 printRanges(D, indent);
4752 printFixIts(D, indent);
4753
4754 /* Print subdiagnostics. */
4755 printDiagnosticSet(clang_getChildDiagnostics(D), indent+2);
4756
4757 clang_disposeString(FileName);
4758 clang_disposeString(DiagSpelling);
4759 clang_disposeString(DiagOption);
4760 clang_disposeString(DiagCat);
4761 }
4762}
4763
4764static int read_diagnostics(const char *filename) {
4765 enum CXLoadDiag_Error error;
4766 CXString errorString;
4767 CXDiagnosticSet Diags = 0;
4768
4769 Diags = clang_loadDiagnostics(filename, &error, &errorString);
4770 if (!Diags) {
4771 fprintf(stderr, "Trouble deserializing file (%s): %s\n",__fprintf_chk (stderr, 2 - 1, "Trouble deserializing file (%s): %s\n"
, getDiagnosticCodeStr(error), clang_getCString(errorString))
4772 getDiagnosticCodeStr(error),__fprintf_chk (stderr, 2 - 1, "Trouble deserializing file (%s): %s\n"
, getDiagnosticCodeStr(error), clang_getCString(errorString))
4773 clang_getCString(errorString))__fprintf_chk (stderr, 2 - 1, "Trouble deserializing file (%s): %s\n"
, getDiagnosticCodeStr(error), clang_getCString(errorString))
;
4774 clang_disposeString(errorString);
4775 return 1;
4776 }
4777
4778 printDiagnosticSet(Diags, 0);
4779 fprintf(stderr, "Number of diagnostics: %d\n",__fprintf_chk (stderr, 2 - 1, "Number of diagnostics: %d\n", clang_getNumDiagnosticsInSet
(Diags))
4780 clang_getNumDiagnosticsInSet(Diags))__fprintf_chk (stderr, 2 - 1, "Number of diagnostics: %d\n", clang_getNumDiagnosticsInSet
(Diags))
;
4781 clang_disposeDiagnosticSet(Diags);
4782 return 0;
4783}
4784
4785static int perform_print_build_session_timestamp(void) {
4786 printf("%lld\n", clang_getBuildSessionTimestamp())__printf_chk (2 - 1, "%lld\n", clang_getBuildSessionTimestamp
())
;
4787 return 0;
4788}
4789
4790/******************************************************************************/
4791/* Command line processing. */
4792/******************************************************************************/
4793
4794static CXCursorVisitor GetVisitor(const char *s) {
4795 if (s[0] == '\0')
4796 return FilteredPrintingVisitor;
4797 if (strcmp(s, "-usrs") == 0)
4798 return USRVisitor;
4799 if (strncmp(s, "-memory-usage", 13) == 0)
4800 return GetVisitor(s + 13);
4801 return NULL((void*)0);
4802}
4803
4804static void print_usage(void) {
4805 fprintf(stderr,__fprintf_chk (stderr, 2 - 1, "usage: c-index-test -code-completion-at=<site> <compiler arguments>\n"
" c-index-test -code-completion-timing=<site> <compiler arguments>\n"
" c-index-test -cursor-at=<site> <compiler arguments>\n"
" c-index-test -evaluate-cursor-at=<site> <compiler arguments>\n"
" c-index-test -get-macro-info-cursor-at=<site> <compiler arguments>\n"
" c-index-test -file-refs-at=<site> <compiler arguments>\n"
" c-index-test -file-includes-in=<filename> <compiler arguments>\n"
)
4806 "usage: c-index-test -code-completion-at=<site> <compiler arguments>\n"__fprintf_chk (stderr, 2 - 1, "usage: c-index-test -code-completion-at=<site> <compiler arguments>\n"
" c-index-test -code-completion-timing=<site> <compiler arguments>\n"
" c-index-test -cursor-at=<site> <compiler arguments>\n"
" c-index-test -evaluate-cursor-at=<site> <compiler arguments>\n"
" c-index-test -get-macro-info-cursor-at=<site> <compiler arguments>\n"
" c-index-test -file-refs-at=<site> <compiler arguments>\n"
" c-index-test -file-includes-in=<filename> <compiler arguments>\n"
)
4807 " c-index-test -code-completion-timing=<site> <compiler arguments>\n"__fprintf_chk (stderr, 2 - 1, "usage: c-index-test -code-completion-at=<site> <compiler arguments>\n"
" c-index-test -code-completion-timing=<site> <compiler arguments>\n"
" c-index-test -cursor-at=<site> <compiler arguments>\n"
" c-index-test -evaluate-cursor-at=<site> <compiler arguments>\n"
" c-index-test -get-macro-info-cursor-at=<site> <compiler arguments>\n"
" c-index-test -file-refs-at=<site> <compiler arguments>\n"
" c-index-test -file-includes-in=<filename> <compiler arguments>\n"
)
4808 " c-index-test -cursor-at=<site> <compiler arguments>\n"__fprintf_chk (stderr, 2 - 1, "usage: c-index-test -code-completion-at=<site> <compiler arguments>\n"
" c-index-test -code-completion-timing=<site> <compiler arguments>\n"
" c-index-test -cursor-at=<site> <compiler arguments>\n"
" c-index-test -evaluate-cursor-at=<site> <compiler arguments>\n"
" c-index-test -get-macro-info-cursor-at=<site> <compiler arguments>\n"
" c-index-test -file-refs-at=<site> <compiler arguments>\n"
" c-index-test -file-includes-in=<filename> <compiler arguments>\n"
)
4809 " c-index-test -evaluate-cursor-at=<site> <compiler arguments>\n"__fprintf_chk (stderr, 2 - 1, "usage: c-index-test -code-completion-at=<site> <compiler arguments>\n"
" c-index-test -code-completion-timing=<site> <compiler arguments>\n"
" c-index-test -cursor-at=<site> <compiler arguments>\n"
" c-index-test -evaluate-cursor-at=<site> <compiler arguments>\n"
" c-index-test -get-macro-info-cursor-at=<site> <compiler arguments>\n"
" c-index-test -file-refs-at=<site> <compiler arguments>\n"
" c-index-test -file-includes-in=<filename> <compiler arguments>\n"
)
4810 " c-index-test -get-macro-info-cursor-at=<site> <compiler arguments>\n"__fprintf_chk (stderr, 2 - 1, "usage: c-index-test -code-completion-at=<site> <compiler arguments>\n"
" c-index-test -code-completion-timing=<site> <compiler arguments>\n"
" c-index-test -cursor-at=<site> <compiler arguments>\n"
" c-index-test -evaluate-cursor-at=<site> <compiler arguments>\n"
" c-index-test -get-macro-info-cursor-at=<site> <compiler arguments>\n"
" c-index-test -file-refs-at=<site> <compiler arguments>\n"
" c-index-test -file-includes-in=<filename> <compiler arguments>\n"
)
4811 " c-index-test -file-refs-at=<site> <compiler arguments>\n"__fprintf_chk (stderr, 2 - 1, "usage: c-index-test -code-completion-at=<site> <compiler arguments>\n"
" c-index-test -code-completion-timing=<site> <compiler arguments>\n"
" c-index-test -cursor-at=<site> <compiler arguments>\n"
" c-index-test -evaluate-cursor-at=<site> <compiler arguments>\n"
" c-index-test -get-macro-info-cursor-at=<site> <compiler arguments>\n"
" c-index-test -file-refs-at=<site> <compiler arguments>\n"
" c-index-test -file-includes-in=<filename> <compiler arguments>\n"
)
4812 " c-index-test -file-includes-in=<filename> <compiler arguments>\n")__fprintf_chk (stderr, 2 - 1, "usage: c-index-test -code-completion-at=<site> <compiler arguments>\n"
" c-index-test -code-completion-timing=<site> <compiler arguments>\n"
" c-index-test -cursor-at=<site> <compiler arguments>\n"
" c-index-test -evaluate-cursor-at=<site> <compiler arguments>\n"
" c-index-test -get-macro-info-cursor-at=<site> <compiler arguments>\n"
" c-index-test -file-refs-at=<site> <compiler arguments>\n"
" c-index-test -file-includes-in=<filename> <compiler arguments>\n"
)
;
4813 fprintf(stderr,__fprintf_chk (stderr, 2 - 1, " c-index-test -index-file [-check-prefix=<FileCheck prefix>] <compiler arguments>\n"
" c-index-test -index-file-full [-check-prefix=<FileCheck prefix>] <compiler arguments>\n"
" c-index-test -index-tu [-check-prefix=<FileCheck prefix>] <AST file>\n"
" c-index-test -index-compile-db [-check-prefix=<FileCheck prefix>] <compilation database>\n"
" c-index-test -test-file-scan <AST file> <source file> "
"[FileCheck prefix]\n")
4814 " c-index-test -index-file [-check-prefix=<FileCheck prefix>] <compiler arguments>\n"__fprintf_chk (stderr, 2 - 1, " c-index-test -index-file [-check-prefix=<FileCheck prefix>] <compiler arguments>\n"
" c-index-test -index-file-full [-check-prefix=<FileCheck prefix>] <compiler arguments>\n"
" c-index-test -index-tu [-check-prefix=<FileCheck prefix>] <AST file>\n"
" c-index-test -index-compile-db [-check-prefix=<FileCheck prefix>] <compilation database>\n"
" c-index-test -test-file-scan <AST file> <source file> "
"[FileCheck prefix]\n")
4815 " c-index-test -index-file-full [-check-prefix=<FileCheck prefix>] <compiler arguments>\n"__fprintf_chk (stderr, 2 - 1, " c-index-test -index-file [-check-prefix=<FileCheck prefix>] <compiler arguments>\n"
" c-index-test -index-file-full [-check-prefix=<FileCheck prefix>] <compiler arguments>\n"
" c-index-test -index-tu [-check-prefix=<FileCheck prefix>] <AST file>\n"
" c-index-test -index-compile-db [-check-prefix=<FileCheck prefix>] <compilation database>\n"
" c-index-test -test-file-scan <AST file> <source file> "
"[FileCheck prefix]\n")
4816 " c-index-test -index-tu [-check-prefix=<FileCheck prefix>] <AST file>\n"__fprintf_chk (stderr, 2 - 1, " c-index-test -index-file [-check-prefix=<FileCheck prefix>] <compiler arguments>\n"
" c-index-test -index-file-full [-check-prefix=<FileCheck prefix>] <compiler arguments>\n"
" c-index-test -index-tu [-check-prefix=<FileCheck prefix>] <AST file>\n"
" c-index-test -index-compile-db [-check-prefix=<FileCheck prefix>] <compilation database>\n"
" c-index-test -test-file-scan <AST file> <source file> "
"[FileCheck prefix]\n")
4817 " c-index-test -index-compile-db [-check-prefix=<FileCheck prefix>] <compilation database>\n"__fprintf_chk (stderr, 2 - 1, " c-index-test -index-file [-check-prefix=<FileCheck prefix>] <compiler arguments>\n"
" c-index-test -index-file-full [-check-prefix=<FileCheck prefix>] <compiler arguments>\n"
" c-index-test -index-tu [-check-prefix=<FileCheck prefix>] <AST file>\n"
" c-index-test -index-compile-db [-check-prefix=<FileCheck prefix>] <compilation database>\n"
" c-index-test -test-file-scan <AST file> <source file> "
"[FileCheck prefix]\n")
4818 " c-index-test -test-file-scan <AST file> <source file> "__fprintf_chk (stderr, 2 - 1, " c-index-test -index-file [-check-prefix=<FileCheck prefix>] <compiler arguments>\n"
" c-index-test -index-file-full [-check-prefix=<FileCheck prefix>] <compiler arguments>\n"
" c-index-test -index-tu [-check-prefix=<FileCheck prefix>] <AST file>\n"
" c-index-test -index-compile-db [-check-prefix=<FileCheck prefix>] <compilation database>\n"
" c-index-test -test-file-scan <AST file> <source file> "
"[FileCheck prefix]\n")
4819 "[FileCheck prefix]\n")__fprintf_chk (stderr, 2 - 1, " c-index-test -index-file [-check-prefix=<FileCheck prefix>] <compiler arguments>\n"
" c-index-test -index-file-full [-check-prefix=<FileCheck prefix>] <compiler arguments>\n"
" c-index-test -index-tu [-check-prefix=<FileCheck prefix>] <AST file>\n"
" c-index-test -index-compile-db [-check-prefix=<FileCheck prefix>] <compilation database>\n"
" c-index-test -test-file-scan <AST file> <source file> "
"[FileCheck prefix]\n")
;
4820 fprintf(stderr,__fprintf_chk (stderr, 2 - 1, " c-index-test -test-load-tu <AST file> <symbol filter> "
"[FileCheck prefix]\n" " c-index-test -test-load-tu-usrs <AST file> <symbol filter> "
"[FileCheck prefix]\n" " c-index-test -test-load-source <symbol filter> {<args>}*\n"
)
4821 " c-index-test -test-load-tu <AST file> <symbol filter> "__fprintf_chk (stderr, 2 - 1, " c-index-test -test-load-tu <AST file> <symbol filter> "
"[FileCheck prefix]\n" " c-index-test -test-load-tu-usrs <AST file> <symbol filter> "
"[FileCheck prefix]\n" " c-index-test -test-load-source <symbol filter> {<args>}*\n"
)
4822 "[FileCheck prefix]\n"__fprintf_chk (stderr, 2 - 1, " c-index-test -test-load-tu <AST file> <symbol filter> "
"[FileCheck prefix]\n" " c-index-test -test-load-tu-usrs <AST file> <symbol filter> "
"[FileCheck prefix]\n" " c-index-test -test-load-source <symbol filter> {<args>}*\n"
)
4823 " c-index-test -test-load-tu-usrs <AST file> <symbol filter> "__fprintf_chk (stderr, 2 - 1, " c-index-test -test-load-tu <AST file> <symbol filter> "
"[FileCheck prefix]\n" " c-index-test -test-load-tu-usrs <AST file> <symbol filter> "
"[FileCheck prefix]\n" " c-index-test -test-load-source <symbol filter> {<args>}*\n"
)
4824 "[FileCheck prefix]\n"__fprintf_chk (stderr, 2 - 1, " c-index-test -test-load-tu <AST file> <symbol filter> "
"[FileCheck prefix]\n" " c-index-test -test-load-tu-usrs <AST file> <symbol filter> "
"[FileCheck prefix]\n" " c-index-test -test-load-source <symbol filter> {<args>}*\n"
)
4825 " c-index-test -test-load-source <symbol filter> {<args>}*\n")__fprintf_chk (stderr, 2 - 1, " c-index-test -test-load-tu <AST file> <symbol filter> "
"[FileCheck prefix]\n" " c-index-test -test-load-tu-usrs <AST file> <symbol filter> "
"[FileCheck prefix]\n" " c-index-test -test-load-source <symbol filter> {<args>}*\n"
)
;
4826 fprintf(stderr,__fprintf_chk (stderr, 2 - 1, " c-index-test -test-load-source-memory-usage "
"<symbol filter> {<args>}*\n" " c-index-test -test-load-source-reparse <trials> <symbol filter> "
" {<args>}*\n" " c-index-test -test-load-source-usrs <symbol filter> {<args>}*\n"
" c-index-test -test-load-source-usrs-memory-usage " "<symbol filter> {<args>}*\n"
" c-index-test -test-annotate-tokens=<range> {<args>}*\n"
" c-index-test -test-inclusion-stack-source {<args>}*\n"
" c-index-test -test-inclusion-stack-tu <AST file>\n"
)
4827 " c-index-test -test-load-source-memory-usage "__fprintf_chk (stderr, 2 - 1, " c-index-test -test-load-source-memory-usage "
"<symbol filter> {<args>}*\n" " c-index-test -test-load-source-reparse <trials> <symbol filter> "
" {<args>}*\n" " c-index-test -test-load-source-usrs <symbol filter> {<args>}*\n"
" c-index-test -test-load-source-usrs-memory-usage " "<symbol filter> {<args>}*\n"
" c-index-test -test-annotate-tokens=<range> {<args>}*\n"
" c-index-test -test-inclusion-stack-source {<args>}*\n"
" c-index-test -test-inclusion-stack-tu <AST file>\n"
)
4828 "<symbol filter> {<args>}*\n"__fprintf_chk (stderr, 2 - 1, " c-index-test -test-load-source-memory-usage "
"<symbol filter> {<args>}*\n" " c-index-test -test-load-source-reparse <trials> <symbol filter> "
" {<args>}*\n" " c-index-test -test-load-source-usrs <symbol filter> {<args>}*\n"
" c-index-test -test-load-source-usrs-memory-usage " "<symbol filter> {<args>}*\n"
" c-index-test -test-annotate-tokens=<range> {<args>}*\n"
" c-index-test -test-inclusion-stack-source {<args>}*\n"
" c-index-test -test-inclusion-stack-tu <AST file>\n"
)
4829 " c-index-test -test-load-source-reparse <trials> <symbol filter> "__fprintf_chk (stderr, 2 - 1, " c-index-test -test-load-source-memory-usage "
"<symbol filter> {<args>}*\n" " c-index-test -test-load-source-reparse <trials> <symbol filter> "
" {<args>}*\n" " c-index-test -test-load-source-usrs <symbol filter> {<args>}*\n"
" c-index-test -test-load-source-usrs-memory-usage " "<symbol filter> {<args>}*\n"
" c-index-test -test-annotate-tokens=<range> {<args>}*\n"
" c-index-test -test-inclusion-stack-source {<args>}*\n"
" c-index-test -test-inclusion-stack-tu <AST file>\n"
)
4830 " {<args>}*\n"__fprintf_chk (stderr, 2 - 1, " c-index-test -test-load-source-memory-usage "
"<symbol filter> {<args>}*\n" " c-index-test -test-load-source-reparse <trials> <symbol filter> "
" {<args>}*\n" " c-index-test -test-load-source-usrs <symbol filter> {<args>}*\n"
" c-index-test -test-load-source-usrs-memory-usage " "<symbol filter> {<args>}*\n"
" c-index-test -test-annotate-tokens=<range> {<args>}*\n"
" c-index-test -test-inclusion-stack-source {<args>}*\n"
" c-index-test -test-inclusion-stack-tu <AST file>\n"
)
4831 " c-index-test -test-load-source-usrs <symbol filter> {<args>}*\n"__fprintf_chk (stderr, 2 - 1, " c-index-test -test-load-source-memory-usage "
"<symbol filter> {<args>}*\n" " c-index-test -test-load-source-reparse <trials> <symbol filter> "
" {<args>}*\n" " c-index-test -test-load-source-usrs <symbol filter> {<args>}*\n"
" c-index-test -test-load-source-usrs-memory-usage " "<symbol filter> {<args>}*\n"
" c-index-test -test-annotate-tokens=<range> {<args>}*\n"
" c-index-test -test-inclusion-stack-source {<args>}*\n"
" c-index-test -test-inclusion-stack-tu <AST file>\n"
)
4832 " c-index-test -test-load-source-usrs-memory-usage "__fprintf_chk (stderr, 2 - 1, " c-index-test -test-load-source-memory-usage "
"<symbol filter> {<args>}*\n" " c-index-test -test-load-source-reparse <trials> <symbol filter> "
" {<args>}*\n" " c-index-test -test-load-source-usrs <symbol filter> {<args>}*\n"
" c-index-test -test-load-source-usrs-memory-usage " "<symbol filter> {<args>}*\n"
" c-index-test -test-annotate-tokens=<range> {<args>}*\n"
" c-index-test -test-inclusion-stack-source {<args>}*\n"
" c-index-test -test-inclusion-stack-tu <AST file>\n"
)
4833 "<symbol filter> {<args>}*\n"__fprintf_chk (stderr, 2 - 1, " c-index-test -test-load-source-memory-usage "
"<symbol filter> {<args>}*\n" " c-index-test -test-load-source-reparse <trials> <symbol filter> "
" {<args>}*\n" " c-index-test -test-load-source-usrs <symbol filter> {<args>}*\n"
" c-index-test -test-load-source-usrs-memory-usage " "<symbol filter> {<args>}*\n"
" c-index-test -test-annotate-tokens=<range> {<args>}*\n"
" c-index-test -test-inclusion-stack-source {<args>}*\n"
" c-index-test -test-inclusion-stack-tu <AST file>\n"
)
4834 " c-index-test -test-annotate-tokens=<range> {<args>}*\n"__fprintf_chk (stderr, 2 - 1, " c-index-test -test-load-source-memory-usage "
"<symbol filter> {<args>}*\n" " c-index-test -test-load-source-reparse <trials> <symbol filter> "
" {<args>}*\n" " c-index-test -test-load-source-usrs <symbol filter> {<args>}*\n"
" c-index-test -test-load-source-usrs-memory-usage " "<symbol filter> {<args>}*\n"
" c-index-test -test-annotate-tokens=<range> {<args>}*\n"
" c-index-test -test-inclusion-stack-source {<args>}*\n"
" c-index-test -test-inclusion-stack-tu <AST file>\n"
)
4835 " c-index-test -test-inclusion-stack-source {<args>}*\n"__fprintf_chk (stderr, 2 - 1, " c-index-test -test-load-source-memory-usage "
"<symbol filter> {<args>}*\n" " c-index-test -test-load-source-reparse <trials> <symbol filter> "
" {<args>}*\n" " c-index-test -test-load-source-usrs <symbol filter> {<args>}*\n"
" c-index-test -test-load-source-usrs-memory-usage " "<symbol filter> {<args>}*\n"
" c-index-test -test-annotate-tokens=<range> {<args>}*\n"
" c-index-test -test-inclusion-stack-source {<args>}*\n"
" c-index-test -test-inclusion-stack-tu <AST file>\n"
)
4836 " c-index-test -test-inclusion-stack-tu <AST file>\n")__fprintf_chk (stderr, 2 - 1, " c-index-test -test-load-source-memory-usage "
"<symbol filter> {<args>}*\n" " c-index-test -test-load-source-reparse <trials> <symbol filter> "
" {<args>}*\n" " c-index-test -test-load-source-usrs <symbol filter> {<args>}*\n"
" c-index-test -test-load-source-usrs-memory-usage " "<symbol filter> {<args>}*\n"
" c-index-test -test-annotate-tokens=<range> {<args>}*\n"
" c-index-test -test-inclusion-stack-source {<args>}*\n"
" c-index-test -test-inclusion-stack-tu <AST file>\n"
)
;
4837 fprintf(stderr,__fprintf_chk (stderr, 2 - 1, " c-index-test -test-print-linkage-source {<args>}*\n"
" c-index-test -test-print-visibility {<args>}*\n"
" c-index-test -test-print-type {<args>}*\n" " c-index-test -test-print-type-size {<args>}*\n"
" c-index-test -test-print-bitwidth {<args>}*\n"
" c-index-test -test-print-target-info {<args>}*\n"
" c-index-test -test-print-type-declaration {<args>}*\n"
" c-index-test -print-usr [<CursorKind> {<args>}]*\n"
" c-index-test -print-usr-file <file>\n")
4838 " c-index-test -test-print-linkage-source {<args>}*\n"__fprintf_chk (stderr, 2 - 1, " c-index-test -test-print-linkage-source {<args>}*\n"
" c-index-test -test-print-visibility {<args>}*\n"
" c-index-test -test-print-type {<args>}*\n" " c-index-test -test-print-type-size {<args>}*\n"
" c-index-test -test-print-bitwidth {<args>}*\n"
" c-index-test -test-print-target-info {<args>}*\n"
" c-index-test -test-print-type-declaration {<args>}*\n"
" c-index-test -print-usr [<CursorKind> {<args>}]*\n"
" c-index-test -print-usr-file <file>\n")
4839 " c-index-test -test-print-visibility {<args>}*\n"__fprintf_chk (stderr, 2 - 1, " c-index-test -test-print-linkage-source {<args>}*\n"
" c-index-test -test-print-visibility {<args>}*\n"
" c-index-test -test-print-type {<args>}*\n" " c-index-test -test-print-type-size {<args>}*\n"
" c-index-test -test-print-bitwidth {<args>}*\n"
" c-index-test -test-print-target-info {<args>}*\n"
" c-index-test -test-print-type-declaration {<args>}*\n"
" c-index-test -print-usr [<CursorKind> {<args>}]*\n"
" c-index-test -print-usr-file <file>\n")
4840 " c-index-test -test-print-type {<args>}*\n"__fprintf_chk (stderr, 2 - 1, " c-index-test -test-print-linkage-source {<args>}*\n"
" c-index-test -test-print-visibility {<args>}*\n"
" c-index-test -test-print-type {<args>}*\n" " c-index-test -test-print-type-size {<args>}*\n"
" c-index-test -test-print-bitwidth {<args>}*\n"
" c-index-test -test-print-target-info {<args>}*\n"
" c-index-test -test-print-type-declaration {<args>}*\n"
" c-index-test -print-usr [<CursorKind> {<args>}]*\n"
" c-index-test -print-usr-file <file>\n")
4841 " c-index-test -test-print-type-size {<args>}*\n"__fprintf_chk (stderr, 2 - 1, " c-index-test -test-print-linkage-source {<args>}*\n"
" c-index-test -test-print-visibility {<args>}*\n"
" c-index-test -test-print-type {<args>}*\n" " c-index-test -test-print-type-size {<args>}*\n"
" c-index-test -test-print-bitwidth {<args>}*\n"
" c-index-test -test-print-target-info {<args>}*\n"
" c-index-test -test-print-type-declaration {<args>}*\n"
" c-index-test -print-usr [<CursorKind> {<args>}]*\n"
" c-index-test -print-usr-file <file>\n")
4842 " c-index-test -test-print-bitwidth {<args>}*\n"__fprintf_chk (stderr, 2 - 1, " c-index-test -test-print-linkage-source {<args>}*\n"
" c-index-test -test-print-visibility {<args>}*\n"
" c-index-test -test-print-type {<args>}*\n" " c-index-test -test-print-type-size {<args>}*\n"
" c-index-test -test-print-bitwidth {<args>}*\n"
" c-index-test -test-print-target-info {<args>}*\n"
" c-index-test -test-print-type-declaration {<args>}*\n"
" c-index-test -print-usr [<CursorKind> {<args>}]*\n"
" c-index-test -print-usr-file <file>\n")
4843 " c-index-test -test-print-target-info {<args>}*\n"__fprintf_chk (stderr, 2 - 1, " c-index-test -test-print-linkage-source {<args>}*\n"
" c-index-test -test-print-visibility {<args>}*\n"
" c-index-test -test-print-type {<args>}*\n" " c-index-test -test-print-type-size {<args>}*\n"
" c-index-test -test-print-bitwidth {<args>}*\n"
" c-index-test -test-print-target-info {<args>}*\n"
" c-index-test -test-print-type-declaration {<args>}*\n"
" c-index-test -print-usr [<CursorKind> {<args>}]*\n"
" c-index-test -print-usr-file <file>\n")
4844 " c-index-test -test-print-type-declaration {<args>}*\n"__fprintf_chk (stderr, 2 - 1, " c-index-test -test-print-linkage-source {<args>}*\n"
" c-index-test -test-print-visibility {<args>}*\n"
" c-index-test -test-print-type {<args>}*\n" " c-index-test -test-print-type-size {<args>}*\n"
" c-index-test -test-print-bitwidth {<args>}*\n"
" c-index-test -test-print-target-info {<args>}*\n"
" c-index-test -test-print-type-declaration {<args>}*\n"
" c-index-test -print-usr [<CursorKind> {<args>}]*\n"
" c-index-test -print-usr-file <file>\n")
4845 " c-index-test -print-usr [<CursorKind> {<args>}]*\n"__fprintf_chk (stderr, 2 - 1, " c-index-test -test-print-linkage-source {<args>}*\n"
" c-index-test -test-print-visibility {<args>}*\n"
" c-index-test -test-print-type {<args>}*\n" " c-index-test -test-print-type-size {<args>}*\n"
" c-index-test -test-print-bitwidth {<args>}*\n"
" c-index-test -test-print-target-info {<args>}*\n"
" c-index-test -test-print-type-declaration {<args>}*\n"
" c-index-test -print-usr [<CursorKind> {<args>}]*\n"
" c-index-test -print-usr-file <file>\n")
4846 " c-index-test -print-usr-file <file>\n")__fprintf_chk (stderr, 2 - 1, " c-index-test -test-print-linkage-source {<args>}*\n"
" c-index-test -test-print-visibility {<args>}*\n"
" c-index-test -test-print-type {<args>}*\n" " c-index-test -test-print-type-size {<args>}*\n"
" c-index-test -test-print-bitwidth {<args>}*\n"
" c-index-test -test-print-target-info {<args>}*\n"
" c-index-test -test-print-type-declaration {<args>}*\n"
" c-index-test -print-usr [<CursorKind> {<args>}]*\n"
" c-index-test -print-usr-file <file>\n")
;
4847 fprintf(stderr,__fprintf_chk (stderr, 2 - 1, " c-index-test -write-pch <file> <compiler arguments>\n"
" c-index-test -compilation-db [lookup <filename>] database\n"
)
4848 " c-index-test -write-pch <file> <compiler arguments>\n"__fprintf_chk (stderr, 2 - 1, " c-index-test -write-pch <file> <compiler arguments>\n"
" c-index-test -compilation-db [lookup <filename>] database\n"
)
4849 " c-index-test -compilation-db [lookup <filename>] database\n")__fprintf_chk (stderr, 2 - 1, " c-index-test -write-pch <file> <compiler arguments>\n"
" c-index-test -compilation-db [lookup <filename>] database\n"
)
;
4850 fprintf(stderr,__fprintf_chk (stderr, 2 - 1, " c-index-test -print-build-session-timestamp\n"
)
4851 " c-index-test -print-build-session-timestamp\n")__fprintf_chk (stderr, 2 - 1, " c-index-test -print-build-session-timestamp\n"
)
;
4852 fprintf(stderr,__fprintf_chk (stderr, 2 - 1, " c-index-test -read-diagnostics <file>\n\n"
)
4853 " c-index-test -read-diagnostics <file>\n\n")__fprintf_chk (stderr, 2 - 1, " c-index-test -read-diagnostics <file>\n\n"
)
;
4854 fprintf(stderr,__fprintf_chk (stderr, 2 - 1, " <symbol filter> values:\n%s"
, " all - load all symbols, including those from PCH\n" " local - load all symbols except those in PCH\n"
" category - only load ObjC categories (non-PCH)\n" " interface - only load ObjC interfaces (non-PCH)\n"
" protocol - only load ObjC protocols (non-PCH)\n" " function - only load functions (non-PCH)\n"
" typedef - only load typdefs (non-PCH)\n" " scan-function - scan function bodies (non-PCH)\n\n"
)
4855 " <symbol filter> values:\n%s",__fprintf_chk (stderr, 2 - 1, " <symbol filter> values:\n%s"
, " all - load all symbols, including those from PCH\n" " local - load all symbols except those in PCH\n"
" category - only load ObjC categories (non-PCH)\n" " interface - only load ObjC interfaces (non-PCH)\n"
" protocol - only load ObjC protocols (non-PCH)\n" " function - only load functions (non-PCH)\n"
" typedef - only load typdefs (non-PCH)\n" " scan-function - scan function bodies (non-PCH)\n\n"
)
4856 " all - load all symbols, including those from PCH\n"__fprintf_chk (stderr, 2 - 1, " <symbol filter> values:\n%s"
, " all - load all symbols, including those from PCH\n" " local - load all symbols except those in PCH\n"
" category - only load ObjC categories (non-PCH)\n" " interface - only load ObjC interfaces (non-PCH)\n"
" protocol - only load ObjC protocols (non-PCH)\n" " function - only load functions (non-PCH)\n"
" typedef - only load typdefs (non-PCH)\n" " scan-function - scan function bodies (non-PCH)\n\n"
)
4857 " local - load all symbols except those in PCH\n"__fprintf_chk (stderr, 2 - 1, " <symbol filter> values:\n%s"
, " all - load all symbols, including those from PCH\n" " local - load all symbols except those in PCH\n"
" category - only load ObjC categories (non-PCH)\n" " interface - only load ObjC interfaces (non-PCH)\n"
" protocol - only load ObjC protocols (non-PCH)\n" " function - only load functions (non-PCH)\n"
" typedef - only load typdefs (non-PCH)\n" " scan-function - scan function bodies (non-PCH)\n\n"
)
4858 " category - only load ObjC categories (non-PCH)\n"__fprintf_chk (stderr, 2 - 1, " <symbol filter> values:\n%s"
, " all - load all symbols, including those from PCH\n" " local - load all symbols except those in PCH\n"
" category - only load ObjC categories (non-PCH)\n" " interface - only load ObjC interfaces (non-PCH)\n"
" protocol - only load ObjC protocols (non-PCH)\n" " function - only load functions (non-PCH)\n"
" typedef - only load typdefs (non-PCH)\n" " scan-function - scan function bodies (non-PCH)\n\n"
)
4859 " interface - only load ObjC interfaces (non-PCH)\n"__fprintf_chk (stderr, 2 - 1, " <symbol filter> values:\n%s"
, " all - load all symbols, including those from PCH\n" " local - load all symbols except those in PCH\n"
" category - only load ObjC categories (non-PCH)\n" " interface - only load ObjC interfaces (non-PCH)\n"
" protocol - only load ObjC protocols (non-PCH)\n" " function - only load functions (non-PCH)\n"
" typedef - only load typdefs (non-PCH)\n" " scan-function - scan function bodies (non-PCH)\n\n"
)
4860 " protocol - only load ObjC protocols (non-PCH)\n"__fprintf_chk (stderr, 2 - 1, " <symbol filter> values:\n%s"
, " all - load all symbols, including those from PCH\n" " local - load all symbols except those in PCH\n"
" category - only load ObjC categories (non-PCH)\n" " interface - only load ObjC interfaces (non-PCH)\n"
" protocol - only load ObjC protocols (non-PCH)\n" " function - only load functions (non-PCH)\n"
" typedef - only load typdefs (non-PCH)\n" " scan-function - scan function bodies (non-PCH)\n\n"
)
4861 " function - only load functions (non-PCH)\n"__fprintf_chk (stderr, 2 - 1, " <symbol filter> values:\n%s"
, " all - load all symbols, including those from PCH\n" " local - load all symbols except those in PCH\n"
" category - only load ObjC categories (non-PCH)\n" " interface - only load ObjC interfaces (non-PCH)\n"
" protocol - only load ObjC protocols (non-PCH)\n" " function - only load functions (non-PCH)\n"
" typedef - only load typdefs (non-PCH)\n" " scan-function - scan function bodies (non-PCH)\n\n"
)
4862 " typedef - only load typdefs (non-PCH)\n"__fprintf_chk (stderr, 2 - 1, " <symbol filter> values:\n%s"
, " all - load all symbols, including those from PCH\n" " local - load all symbols except those in PCH\n"
" category - only load ObjC categories (non-PCH)\n" " interface - only load ObjC interfaces (non-PCH)\n"
" protocol - only load ObjC protocols (non-PCH)\n" " function - only load functions (non-PCH)\n"
" typedef - only load typdefs (non-PCH)\n" " scan-function - scan function bodies (non-PCH)\n\n"
)
4863 " scan-function - scan function bodies (non-PCH)\n\n")__fprintf_chk (stderr, 2 - 1, " <symbol filter> values:\n%s"
, " all - load all symbols, including those from PCH\n" " local - load all symbols except those in PCH\n"
" category - only load ObjC categories (non-PCH)\n" " interface - only load ObjC interfaces (non-PCH)\n"
" protocol - only load ObjC protocols (non-PCH)\n" " function - only load functions (non-PCH)\n"
" typedef - only load typdefs (non-PCH)\n" " scan-function - scan function bodies (non-PCH)\n\n"
)
;
4864}
4865
4866/***/
4867
4868int cindextest_main(int argc, const char **argv) {
4869 clang_enableStackTraces();
4870 if (argc > 2 && strcmp(argv[1], "-read-diagnostics") == 0)
1
Assuming 'argc' is > 2
2
Assuming the condition is false
4871 return read_diagnostics(argv[2]);
4872 if (argc
2.1
'argc' is > 2
> 2 && strstr(argv[1], "-code-completion-at=") == argv[1])
3
Assuming the condition is false
4873 return perform_code_completion(argc, argv, 0);
4874 if (argc
3.1
'argc' is > 2
> 2 && strstr(argv[1], "-code-completion-timing=") == argv[1])
4
Assuming the condition is false
4875 return perform_code_completion(argc, argv, 1);
4876 if (argc
4.1
'argc' is > 2
> 2 && strstr(argv[1], "-cursor-at=") == argv[1])
5
Assuming the condition is false
4877 return inspect_cursor_at(argc, argv, "-cursor-at=", inspect_print_cursor);
4878 if (argc
5.1
'argc' is > 2
> 2 && strstr(argv[1], "-evaluate-cursor-at=") == argv[1])
6
Assuming the condition is false
4879 return inspect_cursor_at(argc, argv, "-evaluate-cursor-at=",
4880 inspect_evaluate_cursor);
4881 if (argc
6.1
'argc' is > 2
> 2 && strstr(argv[1], "-get-macro-info-cursor-at=") == argv[1])
7
Assuming the condition is false
4882 return inspect_cursor_at(argc, argv, "-get-macro-info-cursor-at=",
4883 inspect_macroinfo_cursor);
4884 if (argc
7.1
'argc' is > 2
> 2 && strstr(argv[1], "-file-refs-at=") == argv[1])
8
Assuming the condition is false
4885 return find_file_refs_at(argc, argv);
4886 if (argc
8.1
'argc' is > 2
> 2 && strstr(argv[1], "-file-includes-in=") == argv[1])
9
Assuming the condition is false
4887 return find_file_includes_in(argc, argv);
4888 if (argc
9.1
'argc' is > 2
> 2 && strcmp(argv[1], "-index-file") == 0)
10
Assuming the condition is false
4889 return index_file(argc - 2, argv + 2, /*full=*/0);
4890 if (argc
10.1
'argc' is > 2
> 2 && strcmp(argv[1], "-index-file-full") == 0)
11
Assuming the condition is false
4891 return index_file(argc - 2, argv + 2, /*full=*/1);
4892 if (argc
11.1
'argc' is > 2
> 2 && strcmp(argv[1], "-index-tu") == 0)
12
Assuming the condition is false
4893 return index_tu(argc - 2, argv + 2);
4894 if (argc
12.1
'argc' is > 2
> 2 && strcmp(argv[1], "-index-compile-db") == 0)
13
Assuming the condition is false
4895 return index_compile_db(argc - 2, argv + 2);
4896 else if (argc >= 4 && strncmp(argv[1], "-test-load-tu", 13) == 0) {
14
Assuming 'argc' is >= 4
15
Assuming the condition is false
4897 CXCursorVisitor I = GetVisitor(argv[1] + 13);
4898 if (I)
4899 return perform_test_load_tu(argv[2], argv[3], argc >= 5 ? argv[4] : 0, I,
4900 NULL((void*)0));
4901 }
4902 else if (argc >= 5 && strncmp(argv[1], "-test-load-source-reparse", 25) == 0){
16
Assuming 'argc' is >= 5
17
Taking true branch
4903 CXCursorVisitor I = GetVisitor(argv[1] + 25);
4904 if (I) {
18
Assuming 'I' is non-null
19
Taking true branch
4905 int trials = atoi(argv[2]);
4906 return perform_test_reparse_source(argc - 4, argv + 4, trials, argv[3], I,
20
Calling 'perform_test_reparse_source'
4907 NULL((void*)0));
4908 }
4909 }
4910 else if (argc >= 4 && strncmp(argv[1], "-test-load-source", 17) == 0) {
4911 CXCursorVisitor I = GetVisitor(argv[1] + 17);
4912
4913 PostVisitTU postVisit = 0;
4914 if (strstr(argv[1], "-memory-usage"))
4915 postVisit = PrintMemoryUsage;
4916
4917 if (I)
4918 return perform_test_load_source(argc - 3, argv + 3, argv[2], I,
4919 postVisit);
4920 }
4921 else if (argc >= 3 && strcmp(argv[1], "-single-file-parse") == 0)
4922 return perform_single_file_parse(argv[2]);
4923 else if (argc >= 3 && strcmp(argv[1], "-retain-excluded-conditional-blocks") == 0)
4924 return perform_file_retain_excluded_cb(argv[2]);
4925 else if (argc >= 4 && strcmp(argv[1], "-test-file-scan") == 0)
4926 return perform_file_scan(argv[2], argv[3],
4927 argc >= 5 ? argv[4] : 0);
4928 else if (argc > 2 && strstr(argv[1], "-test-annotate-tokens=") == argv[1])
4929 return perform_token_annotation(argc, argv);
4930 else if (argc > 2 && strcmp(argv[1], "-test-inclusion-stack-source") == 0)
4931 return perform_test_load_source(argc - 2, argv + 2, "all", NULL((void*)0),
4932 PrintInclusionStack);
4933 else if (argc > 2 && strcmp(argv[1], "-test-inclusion-stack-tu") == 0)
4934 return perform_test_load_tu(argv[2], "all", NULL((void*)0), NULL((void*)0),
4935 PrintInclusionStack);
4936 else if (argc > 2 && strcmp(argv[1], "-test-print-linkage-source") == 0)
4937 return perform_test_load_source(argc - 2, argv + 2, "all", PrintLinkage,
4938 NULL((void*)0));
4939 else if (argc > 2 && strcmp(argv[1], "-test-print-visibility") == 0)
4940 return perform_test_load_source(argc - 2, argv + 2, "all", PrintVisibility,
4941 NULL((void*)0));
4942 else if (argc > 2 && strcmp(argv[1], "-test-print-type") == 0)
4943 return perform_test_load_source(argc - 2, argv + 2, "all",
4944 PrintType, 0);
4945 else if (argc > 2 && strcmp(argv[1], "-test-print-type-size") == 0)
4946 return perform_test_load_source(argc - 2, argv + 2, "all",
4947 PrintTypeSize, 0);
4948 else if (argc > 2 && strcmp(argv[1], "-test-print-type-declaration") == 0)
4949 return perform_test_load_source(argc - 2, argv + 2, "all",
4950 PrintTypeDeclaration, 0);
4951 else if (argc > 2 && strcmp(argv[1], "-test-print-decl-attributes") == 0)
4952 return perform_test_load_source(argc - 2, argv + 2, "all",
4953 PrintDeclAttributes, 0);
4954 else if (argc > 2 && strcmp(argv[1], "-test-print-bitwidth") == 0)
4955 return perform_test_load_source(argc - 2, argv + 2, "all",
4956 PrintBitWidth, 0);
4957 else if (argc > 2 && strcmp(argv[1], "-test-print-mangle") == 0)
4958 return perform_test_load_tu(argv[2], "all", NULL((void*)0), PrintMangledName, NULL((void*)0));
4959 else if (argc > 2 && strcmp(argv[1], "-test-print-manglings") == 0)
4960 return perform_test_load_tu(argv[2], "all", NULL((void*)0), PrintManglings, NULL((void*)0));
4961 else if (argc > 2 && strcmp(argv[1], "-test-print-target-info") == 0)
4962 return print_target_info(argc - 2, argv + 2);
4963 else if (argc > 1 && strcmp(argv[1], "-print-usr") == 0) {
4964 if (argc > 2)
4965 return print_usrs(argv + 2, argv + argc);
4966 else {
4967 display_usrs();
4968 return 1;
4969 }
4970 }
4971 else if (argc > 2 && strcmp(argv[1], "-print-usr-file") == 0)
4972 return print_usrs_file(argv[2]);
4973 else if (argc > 2 && strcmp(argv[1], "-write-pch") == 0)
4974 return write_pch_file(argv[2], argc - 3, argv + 3);
4975 else if (argc > 2 && strcmp(argv[1], "-compilation-db") == 0)
4976 return perform_test_compilation_db(argv[argc-1], argc - 3, argv + 2);
4977 else if (argc == 2 && strcmp(argv[1], "-print-build-session-timestamp") == 0)
4978 return perform_print_build_session_timestamp();
4979
4980 print_usage();
4981 return 1;
4982}
4983
4984/***/
4985
4986/* We intentionally run in a separate thread to ensure we at least minimal
4987 * testing of a multithreaded environment (for example, having a reduced stack
4988 * size). */
4989
4990typedef struct thread_info {
4991 int (*main_func)(int argc, const char **argv);
4992 int argc;
4993 const char **argv;
4994 int result;
4995} thread_info;
4996void thread_runner(void *client_data_v) {
4997 thread_info *client_data = client_data_v;
4998 client_data->result = client_data->main_func(client_data->argc,
4999 client_data->argv);
5000}
5001
5002static void flush_atexit(void) {
5003 /* stdout, and surprisingly even stderr, are not always flushed on process
5004 * and thread exit, particularly when the system is under heavy load. */
5005 fflush(stdoutstdout);
5006 fflush(stderrstderr);
5007}
5008
5009int main(int argc, const char **argv) {
5010 thread_info client_data;
5011
5012 atexit(flush_atexit);
5013
5014#ifdef CLANG_HAVE_LIBXML1
5015 LIBXML_TEST_VERSIONxmlCheckVersion(20910);
5016#endif
5017
5018 if (argc > 1 && strcmp(argv[1], "core") == 0)
5019 return indextest_core_main(argc, argv);
5020
5021 client_data.main_func = cindextest_main;
5022 client_data.argc = argc;
5023 client_data.argv = argv;
5024
5025 if (getenv("CINDEXTEST_NOTHREADS"))
5026 return client_data.main_func(client_data.argc, client_data.argv);
5027
5028 clang_executeOnThread(thread_runner, &client_data, 0);
5029 return client_data.result;
5030}