Bug Summary

File:build/source/clang/tools/c-index-test/c-index-test.c
Warning:line 2153, column 9
Null pointer passed to 1st parameter expecting 'nonnull'

Annotated Source Code

Press '?' to see keyboard shortcuts

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