Bug Summary

File:tools/clang/tools/c-index-test/c-index-test.c
Warning:line 1843, column 15
Potential leak of memory pointed to by 'unsaved_files'

Annotated Source Code

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