Bug Summary

File:build/source/clang/tools/c-index-test/c-index-test.c
Warning:line 2849, column 14
Potential leak of memory pointed to by 'Locations'

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