Bug Summary

File:tools/clang/tools/c-index-test/c-index-test.c
Warning:line 1841, 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~svn303373/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~svn303373/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~svn303373/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 Err = clang_reparseTranslationUnit(TU, num_unsaved_files, unsaved_files,
1746 clang_defaultReparseOptions(TU));
1747 if (Err != CXError_Success) {
1748 describeLibclangFailure(Err);
1749 free_remapped_files(unsaved_files, num_unsaved_files);
1750 clang_disposeIndex(Idx);
1751 return 1;
1752 }
1753 }
1754 }
1755
1756 result = perform_test_load(Idx, TU, filter, NULL((void*)0), Visitor, PV,
1757 CommentSchemaFile);
1758 free_remapped_files(unsaved_files, num_unsaved_files);
1759 clang_disposeIndex(Idx);
1760 return result;
1761}
1762
1763int perform_test_reparse_source(int argc, const char **argv, int trials,
1764 const char *filter, CXCursorVisitor Visitor,
1765 PostVisitTU PV) {
1766 CXIndex Idx;
1767 CXTranslationUnit TU;
1768 struct CXUnsavedFile *unsaved_files = 0;
1769 int num_unsaved_files = 0;
1770 int compiler_arg_idx = 0;
1771 enum CXErrorCode Err;
1772 int result, i;
1773 int trial;
1774 int remap_after_trial = 0;
1775 char *endptr = 0;
1776
1777 Idx = clang_createIndex(/* excludeDeclsFromPCH */
1778 !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
1779 /* displayDiagnostics=*/1);
1780
1781 if (parse_remapped_files(argc, argv, 0, &unsaved_files, &num_unsaved_files)) {
3
Assuming the condition is false
4
Taking false branch
1782 clang_disposeIndex(Idx);
1783 return -1;
1784 }
1785
1786 for (i = 0; i < argc; ++i) {
5
Assuming 'i' is >= 'argc'
6
Loop condition is false. Execution continues on line 1790
1787 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)
1788 break;
1789 }
1790 if (i < argc)
7
Taking false branch
1791 compiler_arg_idx = i+1;
1792 if (num_unsaved_files > compiler_arg_idx)
8
Assuming 'num_unsaved_files' is <= 'compiler_arg_idx'
9
Taking false branch
1793 compiler_arg_idx = num_unsaved_files;
1794
1795 /* Load the initial translation unit -- we do this without honoring remapped
1796 * files, so that we have a way to test results after changing the source. */
1797 Err = clang_parseTranslationUnit2(Idx, 0,
1798 argv + compiler_arg_idx,
1799 argc - compiler_arg_idx,
1800 0, 0, getDefaultParsingOptions(), &TU);
1801 if (Err != CXError_Success) {
10
Assuming 'Err' is equal to CXError_Success
11
Taking false branch
1802 fprintf(stderrstderr, "Unable to load translation unit!\n");
1803 describeLibclangFailure(Err);
1804 free_remapped_files(unsaved_files, num_unsaved_files);
1805 clang_disposeIndex(Idx);
1806 return 1;
1807 }
1808
1809 if (checkForErrors(TU) != 0)
12
Assuming the condition is false
13
Taking false branch
1810 return -1;
1811
1812 if (getenv("CINDEXTEST_REMAP_AFTER_TRIAL")) {
14
Assuming the condition is true
15
Taking true branch
1813 remap_after_trial =
1814 strtol(getenv("CINDEXTEST_REMAP_AFTER_TRIAL"), &endptr, 10);
1815 }
1816
1817 for (trial = 0; trial < trials; ++trial) {
16
Assuming 'trial' is < 'trials'
17
Loop condition is true. Entering loop body
1818 free_remapped_files(unsaved_files, num_unsaved_files);
1819 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
1820 &unsaved_files, &num_unsaved_files)) {
1821 clang_disposeTranslationUnit(TU);
1822 clang_disposeIndex(Idx);
1823 return -1;
1824 }
1825
1826 Err = clang_reparseTranslationUnit(
1827 TU,
1828 trial >= remap_after_trial ? num_unsaved_files : 0,
30
Assuming 'trial' is < 'remap_after_trial'
31
'?' condition is false
1829 trial >= remap_after_trial ? unsaved_files : 0,
32
'?' condition is false
1830 clang_defaultReparseOptions(TU));
1831 if (Err != CXError_Success) {
33
Assuming 'Err' is equal to CXError_Success
34
Taking false branch
1832 fprintf(stderrstderr, "Unable to reparse translation unit!\n");
1833 describeLibclangFailure(Err);
1834 clang_disposeTranslationUnit(TU);
1835 free_remapped_files(unsaved_files, num_unsaved_files);
1836 clang_disposeIndex(Idx);
1837 return -1;
1838 }
1839
1840 if (checkForErrors(TU) != 0)
35
Assuming the condition is true
36
Taking true branch
1841 return -1;
37
Potential leak of memory pointed to by 'unsaved_files'
1842 }
1843
1844 result = perform_test_load(Idx, TU, filter, NULL((void*)0), Visitor, PV, NULL((void*)0));
1845
1846 free_remapped_files(unsaved_files, num_unsaved_files);
1847 clang_disposeIndex(Idx);
1848 return result;
1849}
1850
1851/******************************************************************************/
1852/* Logic for testing clang_getCursor(). */
1853/******************************************************************************/
1854
1855static void print_cursor_file_scan(CXTranslationUnit TU, CXCursor cursor,
1856 unsigned start_line, unsigned start_col,
1857 unsigned end_line, unsigned end_col,
1858 const char *prefix) {
1859 printf("// %s: ", FileCheckPrefix);
1860 if (prefix)
1861 printf("-%s", prefix);
1862 PrintExtent(stdoutstdout, start_line, start_col, end_line, end_col);
1863 printf(" ");
1864 PrintCursor(cursor, NULL((void*)0));
1865 printf("\n");
1866}
1867
1868static int perform_file_scan(const char *ast_file, const char *source_file,
1869 const char *prefix) {
1870 CXIndex Idx;
1871 CXTranslationUnit TU;
1872 FILE *fp;
1873 CXCursor prevCursor = clang_getNullCursor();
1874 CXFile file;
1875 unsigned line = 1, col = 1;
1876 unsigned start_line = 1, start_col = 1;
1877
1878 if (!(Idx = clang_createIndex(/* excludeDeclsFromPCH */ 1,
1879 /* displayDiagnostics=*/1))) {
1880 fprintf(stderrstderr, "Could not create Index\n");
1881 return 1;
1882 }
1883
1884 if (!CreateTranslationUnit(Idx, ast_file, &TU))
1885 return 1;
1886
1887 if ((fp = fopen(source_file, "r")) == NULL((void*)0)) {
1888 fprintf(stderrstderr, "Could not open '%s'\n", source_file);
1889 clang_disposeTranslationUnit(TU);
1890 return 1;
1891 }
1892
1893 file = clang_getFile(TU, source_file);
1894 for (;;) {
1895 CXCursor cursor;
1896 int c = fgetc(fp);
1897
1898 if (c == '\n') {
1899 ++line;
1900 col = 1;
1901 } else
1902 ++col;
1903
1904 /* Check the cursor at this position, and dump the previous one if we have
1905 * found something new.
1906 */
1907 cursor = clang_getCursor(TU, clang_getLocation(TU, file, line, col));
1908 if ((c == EOF(-1) || !clang_equalCursors(cursor, prevCursor)) &&
1909 prevCursor.kind != CXCursor_InvalidFile) {
1910 print_cursor_file_scan(TU, prevCursor, start_line, start_col,
1911 line, col, prefix);
1912 start_line = line;
1913 start_col = col;
1914 }
1915 if (c == EOF(-1))
1916 break;
1917
1918 prevCursor = cursor;
1919 }
1920
1921 fclose(fp);
1922 clang_disposeTranslationUnit(TU);
1923 clang_disposeIndex(Idx);
1924 return 0;
1925}
1926
1927/******************************************************************************/
1928/* Logic for testing clang code completion. */
1929/******************************************************************************/
1930
1931/* Parse file:line:column from the input string. Returns 0 on success, non-zero
1932 on failure. If successful, the pointer *filename will contain newly-allocated
1933 memory (that will be owned by the caller) to store the file name. */
1934int parse_file_line_column(const char *input, char **filename, unsigned *line,
1935 unsigned *column, unsigned *second_line,
1936 unsigned *second_column) {
1937 /* Find the second colon. */
1938 const char *last_colon = strrchr(input, ':');
1939 unsigned values[4], i;
1940 unsigned num_values = (second_line && second_column)? 4 : 2;
1941
1942 char *endptr = 0;
1943 if (!last_colon || last_colon == input) {
1944 if (num_values == 4)
1945 fprintf(stderrstderr, "could not parse filename:line:column:line:column in "
1946 "'%s'\n", input);
1947 else
1948 fprintf(stderrstderr, "could not parse filename:line:column in '%s'\n", input);
1949 return 1;
1950 }
1951
1952 for (i = 0; i != num_values; ++i) {
1953 const char *prev_colon;
1954
1955 /* Parse the next line or column. */
1956 values[num_values - i - 1] = strtol(last_colon + 1, &endptr, 10);
1957 if (*endptr != 0 && *endptr != ':') {
1958 fprintf(stderrstderr, "could not parse %s in '%s'\n",
1959 (i % 2 ? "column" : "line"), input);
1960 return 1;
1961 }
1962
1963 if (i + 1 == num_values)
1964 break;
1965
1966 /* Find the previous colon. */
1967 prev_colon = last_colon - 1;
1968 while (prev_colon != input && *prev_colon != ':')
1969 --prev_colon;
1970 if (prev_colon == input) {
1971 fprintf(stderrstderr, "could not parse %s in '%s'\n",
1972 (i % 2 == 0? "column" : "line"), input);
1973 return 1;
1974 }
1975
1976 last_colon = prev_colon;
1977 }
1978
1979 *line = values[0];
1980 *column = values[1];
1981
1982 if (second_line && second_column) {
1983 *second_line = values[2];
1984 *second_column = values[3];
1985 }
1986
1987 /* Copy the file name. */
1988 *filename = (char*)malloc(last_colon - input + 1);
1989 memcpy(*filename, input, last_colon - input);
1990 (*filename)[last_colon - input] = 0;
1991 return 0;
1992}
1993
1994const char *
1995clang_getCompletionChunkKindSpelling(enum CXCompletionChunkKind Kind) {
1996 switch (Kind) {
1997 case CXCompletionChunk_Optional: return "Optional";
1998 case CXCompletionChunk_TypedText: return "TypedText";
1999 case CXCompletionChunk_Text: return "Text";
2000 case CXCompletionChunk_Placeholder: return "Placeholder";
2001 case CXCompletionChunk_Informative: return "Informative";
2002 case CXCompletionChunk_CurrentParameter: return "CurrentParameter";
2003 case CXCompletionChunk_LeftParen: return "LeftParen";
2004 case CXCompletionChunk_RightParen: return "RightParen";
2005 case CXCompletionChunk_LeftBracket: return "LeftBracket";
2006 case CXCompletionChunk_RightBracket: return "RightBracket";
2007 case CXCompletionChunk_LeftBrace: return "LeftBrace";
2008 case CXCompletionChunk_RightBrace: return "RightBrace";
2009 case CXCompletionChunk_LeftAngle: return "LeftAngle";
2010 case CXCompletionChunk_RightAngle: return "RightAngle";
2011 case CXCompletionChunk_Comma: return "Comma";
2012 case CXCompletionChunk_ResultType: return "ResultType";
2013 case CXCompletionChunk_Colon: return "Colon";
2014 case CXCompletionChunk_SemiColon: return "SemiColon";
2015 case CXCompletionChunk_Equal: return "Equal";
2016 case CXCompletionChunk_HorizontalSpace: return "HorizontalSpace";
2017 case CXCompletionChunk_VerticalSpace: return "VerticalSpace";
2018 }
2019
2020 return "Unknown";
2021}
2022
2023static int checkForErrors(CXTranslationUnit TU) {
2024 unsigned Num, i;
2025 CXDiagnostic Diag;
2026 CXString DiagStr;
2027
2028 if (!getenv("CINDEXTEST_FAILONERROR"))
2029 return 0;
2030
2031 Num = clang_getNumDiagnostics(TU);
2032 for (i = 0; i != Num; ++i) {
2033 Diag = clang_getDiagnostic(TU, i);
2034 if (clang_getDiagnosticSeverity(Diag) >= CXDiagnostic_Error) {
2035 DiagStr = clang_formatDiagnostic(Diag,
2036 clang_defaultDiagnosticDisplayOptions());
2037 fprintf(stderrstderr, "%s\n", clang_getCString(DiagStr));
2038 clang_disposeString(DiagStr);
2039 clang_disposeDiagnostic(Diag);
2040 return -1;
2041 }
2042 clang_disposeDiagnostic(Diag);
2043 }
2044
2045 return 0;
2046}
2047
2048static void print_completion_string(CXCompletionString completion_string,
2049 FILE *file) {
2050 int I, N;
2051
2052 N = clang_getNumCompletionChunks(completion_string);
2053 for (I = 0; I != N; ++I) {
2054 CXString text;
2055 const char *cstr;
2056 enum CXCompletionChunkKind Kind
2057 = clang_getCompletionChunkKind(completion_string, I);
2058
2059 if (Kind == CXCompletionChunk_Optional) {
2060 fprintf(file, "{Optional ");
2061 print_completion_string(
2062 clang_getCompletionChunkCompletionString(completion_string, I),
2063 file);
2064 fprintf(file, "}");
2065 continue;
2066 }
2067
2068 if (Kind == CXCompletionChunk_VerticalSpace) {
2069 fprintf(file, "{VerticalSpace }");
2070 continue;
2071 }
2072
2073 text = clang_getCompletionChunkText(completion_string, I);
2074 cstr = clang_getCString(text);
2075 fprintf(file, "{%s %s}",
2076 clang_getCompletionChunkKindSpelling(Kind),
2077 cstr ? cstr : "");
2078 clang_disposeString(text);
2079 }
2080
2081}
2082
2083static void print_completion_result(CXCompletionResult *completion_result,
2084 FILE *file) {
2085 CXString ks = clang_getCursorKindSpelling(completion_result->CursorKind);
2086 unsigned annotationCount;
2087 enum CXCursorKind ParentKind;
2088 CXString ParentName;
2089 CXString BriefComment;
2090 CXString Annotation;
2091 const char *BriefCommentCString;
2092
2093 fprintf(file, "%s:", clang_getCString(ks));
2094 clang_disposeString(ks);
2095
2096 print_completion_string(completion_result->CompletionString, file);
2097 fprintf(file, " (%u)",
2098 clang_getCompletionPriority(completion_result->CompletionString));
2099 switch (clang_getCompletionAvailability(completion_result->CompletionString)){
2100 case CXAvailability_Available:
2101 break;
2102
2103 case CXAvailability_Deprecated:
2104 fprintf(file, " (deprecated)");
2105 break;
2106
2107 case CXAvailability_NotAvailable:
2108 fprintf(file, " (unavailable)");
2109 break;
2110
2111 case CXAvailability_NotAccessible:
2112 fprintf(file, " (inaccessible)");
2113 break;
2114 }
2115
2116 annotationCount = clang_getCompletionNumAnnotations(
2117 completion_result->CompletionString);
2118 if (annotationCount) {
2119 unsigned i;
2120 fprintf(file, " (");
2121 for (i = 0; i < annotationCount; ++i) {
2122 if (i != 0)
2123 fprintf(file, ", ");
2124 Annotation =
2125 clang_getCompletionAnnotation(completion_result->CompletionString, i);
2126 fprintf(file, "\"%s\"", clang_getCString(Annotation));
2127 clang_disposeString(Annotation);
2128 }
2129 fprintf(file, ")");
2130 }
2131
2132 if (!getenv("CINDEXTEST_NO_COMPLETION_PARENTS")) {
2133 ParentName = clang_getCompletionParent(completion_result->CompletionString,
2134 &ParentKind);
2135 if (ParentKind != CXCursor_NotImplemented) {
2136 CXString KindSpelling = clang_getCursorKindSpelling(ParentKind);
2137 fprintf(file, " (parent: %s '%s')",
2138 clang_getCString(KindSpelling),
2139 clang_getCString(ParentName));
2140 clang_disposeString(KindSpelling);
2141 }
2142 clang_disposeString(ParentName);
2143 }
2144
2145 BriefComment = clang_getCompletionBriefComment(
2146 completion_result->CompletionString);
2147 BriefCommentCString = clang_getCString(BriefComment);
2148 if (BriefCommentCString && *BriefCommentCString != '\0') {
2149 fprintf(file, "(brief comment: %s)", BriefCommentCString);
2150 }
2151 clang_disposeString(BriefComment);
2152
2153 fprintf(file, "\n");
2154}
2155
2156void print_completion_contexts(unsigned long long contexts, FILE *file) {
2157 fprintf(file, "Completion contexts:\n");
2158 if (contexts == CXCompletionContext_Unknown) {
2159 fprintf(file, "Unknown\n");
2160 }
2161 if (contexts & CXCompletionContext_AnyType) {
2162 fprintf(file, "Any type\n");
2163 }
2164 if (contexts & CXCompletionContext_AnyValue) {
2165 fprintf(file, "Any value\n");
2166 }
2167 if (contexts & CXCompletionContext_ObjCObjectValue) {
2168 fprintf(file, "Objective-C object value\n");
2169 }
2170 if (contexts & CXCompletionContext_ObjCSelectorValue) {
2171 fprintf(file, "Objective-C selector value\n");
2172 }
2173 if (contexts & CXCompletionContext_CXXClassTypeValue) {
2174 fprintf(file, "C++ class type value\n");
2175 }
2176 if (contexts & CXCompletionContext_DotMemberAccess) {
2177 fprintf(file, "Dot member access\n");
2178 }
2179 if (contexts & CXCompletionContext_ArrowMemberAccess) {
2180 fprintf(file, "Arrow member access\n");
2181 }
2182 if (contexts & CXCompletionContext_ObjCPropertyAccess) {
2183 fprintf(file, "Objective-C property access\n");
2184 }
2185 if (contexts & CXCompletionContext_EnumTag) {
2186 fprintf(file, "Enum tag\n");
2187 }
2188 if (contexts & CXCompletionContext_UnionTag) {
2189 fprintf(file, "Union tag\n");
2190 }
2191 if (contexts & CXCompletionContext_StructTag) {
2192 fprintf(file, "Struct tag\n");
2193 }
2194 if (contexts & CXCompletionContext_ClassTag) {
2195 fprintf(file, "Class name\n");
2196 }
2197 if (contexts & CXCompletionContext_Namespace) {
2198 fprintf(file, "Namespace or namespace alias\n");
2199 }
2200 if (contexts & CXCompletionContext_NestedNameSpecifier) {
2201 fprintf(file, "Nested name specifier\n");
2202 }
2203 if (contexts & CXCompletionContext_ObjCInterface) {
2204 fprintf(file, "Objective-C interface\n");
2205 }
2206 if (contexts & CXCompletionContext_ObjCProtocol) {
2207 fprintf(file, "Objective-C protocol\n");
2208 }
2209 if (contexts & CXCompletionContext_ObjCCategory) {
2210 fprintf(file, "Objective-C category\n");
2211 }
2212 if (contexts & CXCompletionContext_ObjCInstanceMessage) {
2213 fprintf(file, "Objective-C instance method\n");
2214 }
2215 if (contexts & CXCompletionContext_ObjCClassMessage) {
2216 fprintf(file, "Objective-C class method\n");
2217 }
2218 if (contexts & CXCompletionContext_ObjCSelectorName) {
2219 fprintf(file, "Objective-C selector name\n");
2220 }
2221 if (contexts & CXCompletionContext_MacroName) {
2222 fprintf(file, "Macro name\n");
2223 }
2224 if (contexts & CXCompletionContext_NaturalLanguage) {
2225 fprintf(file, "Natural language\n");
2226 }
2227}
2228
2229int perform_code_completion(int argc, const char **argv, int timing_only) {
2230 const char *input = argv[1];
2231 char *filename = 0;
2232 unsigned line;
2233 unsigned column;
2234 CXIndex CIdx;
2235 int errorCode;
2236 struct CXUnsavedFile *unsaved_files = 0;
2237 int num_unsaved_files = 0;
2238 CXCodeCompleteResults *results = 0;
2239 enum CXErrorCode Err;
2240 CXTranslationUnit TU;
2241 unsigned I, Repeats = 1;
2242 unsigned completionOptions = clang_defaultCodeCompleteOptions();
2243
2244 if (getenv("CINDEXTEST_CODE_COMPLETE_PATTERNS"))
2245 completionOptions |= CXCodeComplete_IncludeCodePatterns;
2246 if (getenv("CINDEXTEST_COMPLETION_BRIEF_COMMENTS"))
2247 completionOptions |= CXCodeComplete_IncludeBriefComments;
2248
2249 if (timing_only)
2250 input += strlen("-code-completion-timing=");
2251 else
2252 input += strlen("-code-completion-at=");
2253
2254 if ((errorCode = parse_file_line_column(input, &filename, &line, &column,
2255 0, 0)))
2256 return errorCode;
2257
2258 if (parse_remapped_files(argc, argv, 2, &unsaved_files, &num_unsaved_files))
2259 return -1;
2260
2261 CIdx = clang_createIndex(0, 0);
2262
2263 if (getenv("CINDEXTEST_EDITING"))
2264 Repeats = 5;
2265
2266 Err = clang_parseTranslationUnit2(CIdx, 0,
2267 argv + num_unsaved_files + 2,
2268 argc - num_unsaved_files - 2,
2269 0, 0, getDefaultParsingOptions(), &TU);
2270 if (Err != CXError_Success) {
2271 fprintf(stderrstderr, "Unable to load translation unit!\n");
2272 describeLibclangFailure(Err);
2273 return 1;
2274 }
2275
2276 Err = clang_reparseTranslationUnit(TU, 0, 0,
2277 clang_defaultReparseOptions(TU));
2278
2279 if (Err != CXError_Success) {
2280 fprintf(stderrstderr, "Unable to reparse translation unit!\n");
2281 describeLibclangFailure(Err);
2282 clang_disposeTranslationUnit(TU);
2283 return 1;
2284 }
2285
2286 for (I = 0; I != Repeats; ++I) {
2287 results = clang_codeCompleteAt(TU, filename, line, column,
2288 unsaved_files, num_unsaved_files,
2289 completionOptions);
2290 if (!results) {
2291 fprintf(stderrstderr, "Unable to perform code completion!\n");
2292 return 1;
2293 }
2294 if (I != Repeats-1)
2295 clang_disposeCodeCompleteResults(results);
2296 }
2297
2298 if (results) {
2299 unsigned i, n = results->NumResults, containerIsIncomplete = 0;
2300 unsigned long long contexts;
2301 enum CXCursorKind containerKind;
2302 CXString objCSelector;
2303 const char *selectorString;
2304 if (!timing_only) {
2305 /* Sort the code-completion results based on the typed text. */
2306 clang_sortCodeCompletionResults(results->Results, results->NumResults);
2307
2308 for (i = 0; i != n; ++i)
2309 print_completion_result(results->Results + i, stdoutstdout);
2310 }
2311 n = clang_codeCompleteGetNumDiagnostics(results);
2312 for (i = 0; i != n; ++i) {
2313 CXDiagnostic diag = clang_codeCompleteGetDiagnostic(results, i);
2314 PrintDiagnostic(diag);
2315 clang_disposeDiagnostic(diag);
2316 }
2317
2318 contexts = clang_codeCompleteGetContexts(results);
2319 print_completion_contexts(contexts, stdoutstdout);
2320
2321 containerKind = clang_codeCompleteGetContainerKind(results,
2322 &containerIsIncomplete);
2323
2324 if (containerKind != CXCursor_InvalidCode) {
2325 /* We have found a container */
2326 CXString containerUSR, containerKindSpelling;
2327 containerKindSpelling = clang_getCursorKindSpelling(containerKind);
2328 printf("Container Kind: %s\n", clang_getCString(containerKindSpelling));
2329 clang_disposeString(containerKindSpelling);
2330
2331 if (containerIsIncomplete) {
2332 printf("Container is incomplete\n");
2333 }
2334 else {
2335 printf("Container is complete\n");
2336 }
2337
2338 containerUSR = clang_codeCompleteGetContainerUSR(results);
2339 printf("Container USR: %s\n", clang_getCString(containerUSR));
2340 clang_disposeString(containerUSR);
2341 }
2342
2343 objCSelector = clang_codeCompleteGetObjCSelector(results);
2344 selectorString = clang_getCString(objCSelector);
2345 if (selectorString && strlen(selectorString) > 0) {
2346 printf("Objective-C selector: %s\n", selectorString);
2347 }
2348 clang_disposeString(objCSelector);
2349
2350 clang_disposeCodeCompleteResults(results);
2351 }
2352 clang_disposeTranslationUnit(TU);
2353 clang_disposeIndex(CIdx);
2354 free(filename);
2355
2356 free_remapped_files(unsaved_files, num_unsaved_files);
2357
2358 return 0;
2359}
2360
2361typedef struct {
2362 char *filename;
2363 unsigned line;
2364 unsigned column;
2365} CursorSourceLocation;
2366
2367typedef void (*cursor_handler_t)(CXCursor cursor);
2368
2369static int inspect_cursor_at(int argc, const char **argv,
2370 const char *locations_flag,
2371 cursor_handler_t handler) {
2372 CXIndex CIdx;
2373 int errorCode;
2374 struct CXUnsavedFile *unsaved_files = 0;
2375 int num_unsaved_files = 0;
2376 enum CXErrorCode Err;
2377 CXTranslationUnit TU;
2378 CXCursor Cursor;
2379 CursorSourceLocation *Locations = 0;
2380 unsigned NumLocations = 0, Loc;
2381 unsigned Repeats = 1;
2382 unsigned I;
2383
2384 /* Count the number of locations. */
2385 while (strstr(argv[NumLocations+1], locations_flag) == argv[NumLocations+1])
2386 ++NumLocations;
2387
2388 /* Parse the locations. */
2389 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~svn303373/tools/clang/tools/c-index-test/c-index-test.c"
, 2389, __PRETTY_FUNCTION__))
;
2390 Locations = (CursorSourceLocation *)malloc(
2391 NumLocations * sizeof(CursorSourceLocation));
2392 for (Loc = 0; Loc < NumLocations; ++Loc) {
2393 const char *input = argv[Loc + 1] + strlen(locations_flag);
2394 if ((errorCode = parse_file_line_column(input, &Locations[Loc].filename,
2395 &Locations[Loc].line,
2396 &Locations[Loc].column, 0, 0)))
2397 return errorCode;
2398 }
2399
2400 if (parse_remapped_files(argc, argv, NumLocations + 1, &unsaved_files,
2401 &num_unsaved_files))
2402 return -1;
2403
2404 if (getenv("CINDEXTEST_EDITING"))
2405 Repeats = 5;
2406
2407 /* Parse the translation unit. When we're testing clang_getCursor() after
2408 reparsing, don't remap unsaved files until the second parse. */
2409 CIdx = clang_createIndex(1, 1);
2410 Err = clang_parseTranslationUnit2(CIdx, argv[argc - 1],
2411 argv + num_unsaved_files + 1 + NumLocations,
2412 argc - num_unsaved_files - 2 - NumLocations,
2413 unsaved_files,
2414 Repeats > 1? 0 : num_unsaved_files,
2415 getDefaultParsingOptions(), &TU);
2416 if (Err != CXError_Success) {
2417 fprintf(stderrstderr, "unable to parse input\n");
2418 describeLibclangFailure(Err);
2419 return -1;
2420 }
2421
2422 if (checkForErrors(TU) != 0)
2423 return -1;
2424
2425 for (I = 0; I != Repeats; ++I) {
2426 if (Repeats > 1) {
2427 Err = clang_reparseTranslationUnit(TU, num_unsaved_files, unsaved_files,
2428 clang_defaultReparseOptions(TU));
2429 if (Err != CXError_Success) {
2430 describeLibclangFailure(Err);
2431 clang_disposeTranslationUnit(TU);
2432 return 1;
2433 }
2434 }
2435
2436 if (checkForErrors(TU) != 0)
2437 return -1;
2438
2439 for (Loc = 0; Loc < NumLocations; ++Loc) {
2440 CXFile file = clang_getFile(TU, Locations[Loc].filename);
2441 if (!file)
2442 continue;
2443
2444 Cursor = clang_getCursor(TU,
2445 clang_getLocation(TU, file, Locations[Loc].line,
2446 Locations[Loc].column));
2447
2448 if (checkForErrors(TU) != 0)
2449 return -1;
2450
2451 if (I + 1 == Repeats) {
2452 handler(Cursor);
2453 free(Locations[Loc].filename);
2454 }
2455 }
2456 }
2457
2458 PrintDiagnostics(TU);
2459 clang_disposeTranslationUnit(TU);
2460 clang_disposeIndex(CIdx);
2461 free(Locations);
2462 free_remapped_files(unsaved_files, num_unsaved_files);
2463 return 0;
2464}
2465
2466static void inspect_print_cursor(CXCursor Cursor) {
2467 CXTranslationUnit TU = clang_Cursor_getTranslationUnit(Cursor);
2468 CXCompletionString completionString = clang_getCursorCompletionString(
2469 Cursor);
2470 CXSourceLocation CursorLoc = clang_getCursorLocation(Cursor);
2471 CXString Spelling;
2472 const char *cspell;
2473 unsigned line, column;
2474 clang_getSpellingLocation(CursorLoc, 0, &line, &column, 0);
2475 printf("%d:%d ", line, column);
2476 PrintCursor(Cursor, NULL((void*)0));
2477 PrintCursorExtent(Cursor);
2478 Spelling = clang_getCursorSpelling(Cursor);
2479 cspell = clang_getCString(Spelling);
2480 if (cspell && strlen(cspell) != 0) {
2481 unsigned pieceIndex;
2482 printf(" Spelling=%s (", cspell);
2483 for (pieceIndex = 0; ; ++pieceIndex) {
2484 CXSourceRange range =
2485 clang_Cursor_getSpellingNameRange(Cursor, pieceIndex, 0);
2486 if (clang_Range_isNull(range))
2487 break;
2488 PrintRange(range, 0);
2489 }
2490 printf(")");
2491 }
2492 clang_disposeString(Spelling);
2493 if (clang_Cursor_getObjCSelectorIndex(Cursor) != -1)
2494 printf(" Selector index=%d",
2495 clang_Cursor_getObjCSelectorIndex(Cursor));
2496 if (clang_Cursor_isDynamicCall(Cursor))
2497 printf(" Dynamic-call");
2498 if (Cursor.kind == CXCursor_ObjCMessageExpr ||
2499 Cursor.kind == CXCursor_MemberRefExpr) {
2500 CXType T = clang_Cursor_getReceiverType(Cursor);
2501 if (T.kind != CXType_Invalid) {
2502 CXString S = clang_getTypeKindSpelling(T.kind);
2503 printf(" Receiver-type=%s", clang_getCString(S));
2504 clang_disposeString(S);
2505 }
2506 }
2507
2508 {
2509 CXModule mod = clang_Cursor_getModule(Cursor);
2510 CXFile astFile;
2511 CXString name, astFilename;
2512 unsigned i, numHeaders;
2513 if (mod) {
2514 astFile = clang_Module_getASTFile(mod);
2515 astFilename = clang_getFileName(astFile);
2516 name = clang_Module_getFullName(mod);
2517 numHeaders = clang_Module_getNumTopLevelHeaders(TU, mod);
2518 printf(" ModuleName=%s (%s) system=%d Headers(%d):",
2519 clang_getCString(name), clang_getCString(astFilename),
2520 clang_Module_isSystem(mod), numHeaders);
2521 clang_disposeString(name);
2522 clang_disposeString(astFilename);
2523 for (i = 0; i < numHeaders; ++i) {
2524 CXFile file = clang_Module_getTopLevelHeader(TU, mod, i);
2525 CXString filename = clang_getFileName(file);
2526 printf("\n%s", clang_getCString(filename));
2527 clang_disposeString(filename);
2528 }
2529 }
2530 }
2531
2532 if (completionString != NULL((void*)0)) {
2533 printf("\nCompletion string: ");
2534 print_completion_string(completionString, stdoutstdout);
2535 }
2536 printf("\n");
2537}
2538
2539static void display_evaluate_results(CXEvalResult result) {
2540 switch (clang_EvalResult_getKind(result)) {
2541 case CXEval_Int:
2542 {
2543 printf("Kind: Int, ");
2544 if (clang_EvalResult_isUnsignedInt(result)) {
2545 unsigned long long val = clang_EvalResult_getAsUnsigned(result);
2546 printf("unsigned, Value: %llu", val);
2547 } else {
2548 long long val = clang_EvalResult_getAsLongLong(result);
2549 printf("Value: %lld", val);
2550 }
2551 break;
2552 }
2553 case CXEval_Float:
2554 {
2555 double val = clang_EvalResult_getAsDouble(result);
2556 printf("Kind: Float , Value: %f", val);
2557 break;
2558 }
2559 case CXEval_ObjCStrLiteral:
2560 {
2561 const char* str = clang_EvalResult_getAsStr(result);
2562 printf("Kind: ObjCString , Value: %s", str);
2563 break;
2564 }
2565 case CXEval_StrLiteral:
2566 {
2567 const char* str = clang_EvalResult_getAsStr(result);
2568 printf("Kind: CString , Value: %s", str);
2569 break;
2570 }
2571 case CXEval_CFStr:
2572 {
2573 const char* str = clang_EvalResult_getAsStr(result);
2574 printf("Kind: CFString , Value: %s", str);
2575 break;
2576 }
2577 default:
2578 printf("Unexposed");
2579 break;
2580 }
2581}
2582
2583static void inspect_evaluate_cursor(CXCursor Cursor) {
2584 CXSourceLocation CursorLoc = clang_getCursorLocation(Cursor);
2585 CXString Spelling;
2586 const char *cspell;
2587 unsigned line, column;
2588 CXEvalResult ER;
2589
2590 clang_getSpellingLocation(CursorLoc, 0, &line, &column, 0);
2591 printf("%d:%d ", line, column);
2592 PrintCursor(Cursor, NULL((void*)0));
2593 PrintCursorExtent(Cursor);
2594 Spelling = clang_getCursorSpelling(Cursor);
2595 cspell = clang_getCString(Spelling);
2596 if (cspell && strlen(cspell) != 0) {
2597 unsigned pieceIndex;
2598 printf(" Spelling=%s (", cspell);
2599 for (pieceIndex = 0; ; ++pieceIndex) {
2600 CXSourceRange range =
2601 clang_Cursor_getSpellingNameRange(Cursor, pieceIndex, 0);
2602 if (clang_Range_isNull(range))
2603 break;
2604 PrintRange(range, 0);
2605 }
2606 printf(")");
2607 }
2608 clang_disposeString(Spelling);
2609
2610 ER = clang_Cursor_Evaluate(Cursor);
2611 if (!ER) {
2612 printf("Not Evaluatable");
2613 } else {
2614 display_evaluate_results(ER);
2615 clang_EvalResult_dispose(ER);
2616 }
2617 printf("\n");
2618}
2619
2620static void inspect_macroinfo_cursor(CXCursor Cursor) {
2621 CXSourceLocation CursorLoc = clang_getCursorLocation(Cursor);
2622 CXString Spelling;
2623 const char *cspell;
2624 unsigned line, column;
2625 clang_getSpellingLocation(CursorLoc, 0, &line, &column, 0);
2626 printf("%d:%d ", line, column);
2627 PrintCursor(Cursor, NULL((void*)0));
2628 PrintCursorExtent(Cursor);
2629 Spelling = clang_getCursorSpelling(Cursor);
2630 cspell = clang_getCString(Spelling);
2631 if (cspell && strlen(cspell) != 0) {
2632 unsigned pieceIndex;
2633 printf(" Spelling=%s (", cspell);
2634 for (pieceIndex = 0; ; ++pieceIndex) {
2635 CXSourceRange range =
2636 clang_Cursor_getSpellingNameRange(Cursor, pieceIndex, 0);
2637 if (clang_Range_isNull(range))
2638 break;
2639 PrintRange(range, 0);
2640 }
2641 printf(")");
2642 }
2643 clang_disposeString(Spelling);
2644
2645 if (clang_Cursor_isMacroBuiltin(Cursor)) {
2646 printf("[builtin macro]");
2647 } else if (clang_Cursor_isMacroFunctionLike(Cursor)) {
2648 printf("[function macro]");
2649 }
2650 printf("\n");
2651}
2652
2653static enum CXVisitorResult findFileRefsVisit(void *context,
2654 CXCursor cursor, CXSourceRange range) {
2655 if (clang_Range_isNull(range))
2656 return CXVisit_Continue;
2657
2658 PrintCursor(cursor, NULL((void*)0));
2659 PrintRange(range, "");
2660 printf("\n");
2661 return CXVisit_Continue;
2662}
2663
2664static int find_file_refs_at(int argc, const char **argv) {
2665 CXIndex CIdx;
2666 int errorCode;
2667 struct CXUnsavedFile *unsaved_files = 0;
2668 int num_unsaved_files = 0;
2669 enum CXErrorCode Err;
2670 CXTranslationUnit TU;
2671 CXCursor Cursor;
2672 CursorSourceLocation *Locations = 0;
2673 unsigned NumLocations = 0, Loc;
2674 unsigned Repeats = 1;
2675 unsigned I;
2676
2677 /* Count the number of locations. */
2678 while (strstr(argv[NumLocations+1], "-file-refs-at=") == argv[NumLocations+1])
2679 ++NumLocations;
2680
2681 /* Parse the locations. */
2682 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~svn303373/tools/clang/tools/c-index-test/c-index-test.c"
, 2682, __PRETTY_FUNCTION__))
;
2683 Locations = (CursorSourceLocation *)malloc(
2684 NumLocations * sizeof(CursorSourceLocation));
2685 for (Loc = 0; Loc < NumLocations; ++Loc) {
2686 const char *input = argv[Loc + 1] + strlen("-file-refs-at=");
2687 if ((errorCode = parse_file_line_column(input, &Locations[Loc].filename,
2688 &Locations[Loc].line,
2689 &Locations[Loc].column, 0, 0)))
2690 return errorCode;
2691 }
2692
2693 if (parse_remapped_files(argc, argv, NumLocations + 1, &unsaved_files,
2694 &num_unsaved_files))
2695 return -1;
2696
2697 if (getenv("CINDEXTEST_EDITING"))
2698 Repeats = 5;
2699
2700 /* Parse the translation unit. When we're testing clang_getCursor() after
2701 reparsing, don't remap unsaved files until the second parse. */
2702 CIdx = clang_createIndex(1, 1);
2703 Err = clang_parseTranslationUnit2(CIdx, argv[argc - 1],
2704 argv + num_unsaved_files + 1 + NumLocations,
2705 argc - num_unsaved_files - 2 - NumLocations,
2706 unsaved_files,
2707 Repeats > 1? 0 : num_unsaved_files,
2708 getDefaultParsingOptions(), &TU);
2709 if (Err != CXError_Success) {
2710 fprintf(stderrstderr, "unable to parse input\n");
2711 describeLibclangFailure(Err);
2712 clang_disposeTranslationUnit(TU);
2713 return -1;
2714 }
2715
2716 if (checkForErrors(TU) != 0)
2717 return -1;
2718
2719 for (I = 0; I != Repeats; ++I) {
2720 if (Repeats > 1) {
2721 Err = clang_reparseTranslationUnit(TU, num_unsaved_files, unsaved_files,
2722 clang_defaultReparseOptions(TU));
2723 if (Err != CXError_Success) {
2724 describeLibclangFailure(Err);
2725 clang_disposeTranslationUnit(TU);
2726 return 1;
2727 }
2728 }
2729
2730 if (checkForErrors(TU) != 0)
2731 return -1;
2732
2733 for (Loc = 0; Loc < NumLocations; ++Loc) {
2734 CXFile file = clang_getFile(TU, Locations[Loc].filename);
2735 if (!file)
2736 continue;
2737
2738 Cursor = clang_getCursor(TU,
2739 clang_getLocation(TU, file, Locations[Loc].line,
2740 Locations[Loc].column));
2741
2742 if (checkForErrors(TU) != 0)
2743 return -1;
2744
2745 if (I + 1 == Repeats) {
2746 CXCursorAndRangeVisitor visitor = { 0, findFileRefsVisit };
2747 PrintCursor(Cursor, NULL((void*)0));
2748 printf("\n");
2749 clang_findReferencesInFile(Cursor, file, visitor);
2750 free(Locations[Loc].filename);
2751
2752 if (checkForErrors(TU) != 0)
2753 return -1;
2754 }
2755 }
2756 }
2757
2758 PrintDiagnostics(TU);
2759 clang_disposeTranslationUnit(TU);
2760 clang_disposeIndex(CIdx);
2761 free(Locations);
2762 free_remapped_files(unsaved_files, num_unsaved_files);
2763 return 0;
2764}
2765
2766static enum CXVisitorResult findFileIncludesVisit(void *context,
2767 CXCursor cursor, CXSourceRange range) {
2768 PrintCursor(cursor, NULL((void*)0));
2769 PrintRange(range, "");
2770 printf("\n");
2771 return CXVisit_Continue;
2772}
2773
2774static int find_file_includes_in(int argc, const char **argv) {
2775 CXIndex CIdx;
2776 struct CXUnsavedFile *unsaved_files = 0;
2777 int num_unsaved_files = 0;
2778 enum CXErrorCode Err;
2779 CXTranslationUnit TU;
2780 const char **Filenames = 0;
2781 unsigned NumFilenames = 0;
2782 unsigned Repeats = 1;
2783 unsigned I, FI;
2784
2785 /* Count the number of locations. */
2786 while (strstr(argv[NumFilenames+1], "-file-includes-in=") == argv[NumFilenames+1])
2787 ++NumFilenames;
2788
2789 /* Parse the locations. */
2790 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~svn303373/tools/clang/tools/c-index-test/c-index-test.c"
, 2790, __PRETTY_FUNCTION__))
;
2791 Filenames = (const char **)malloc(NumFilenames * sizeof(const char *));
2792 for (I = 0; I < NumFilenames; ++I) {
2793 const char *input = argv[I + 1] + strlen("-file-includes-in=");
2794 /* Copy the file name. */
2795 Filenames[I] = input;
2796 }
2797
2798 if (parse_remapped_files(argc, argv, NumFilenames + 1, &unsaved_files,
2799 &num_unsaved_files))
2800 return -1;
2801
2802 if (getenv("CINDEXTEST_EDITING"))
2803 Repeats = 2;
2804
2805 /* Parse the translation unit. When we're testing clang_getCursor() after
2806 reparsing, don't remap unsaved files until the second parse. */
2807 CIdx = clang_createIndex(1, 1);
2808 Err = clang_parseTranslationUnit2(
2809 CIdx, argv[argc - 1],
2810 argv + num_unsaved_files + 1 + NumFilenames,
2811 argc - num_unsaved_files - 2 - NumFilenames,
2812 unsaved_files,
2813 Repeats > 1 ? 0 : num_unsaved_files, getDefaultParsingOptions(), &TU);
2814
2815 if (Err != CXError_Success) {
2816 fprintf(stderrstderr, "unable to parse input\n");
2817 describeLibclangFailure(Err);
2818 clang_disposeTranslationUnit(TU);
2819 return -1;
2820 }
2821
2822 if (checkForErrors(TU) != 0)
2823 return -1;
2824
2825 for (I = 0; I != Repeats; ++I) {
2826 if (Repeats > 1) {
2827 Err = clang_reparseTranslationUnit(TU, num_unsaved_files, unsaved_files,
2828 clang_defaultReparseOptions(TU));
2829 if (Err != CXError_Success) {
2830 describeLibclangFailure(Err);
2831 clang_disposeTranslationUnit(TU);
2832 return 1;
2833 }
2834 }
2835
2836 if (checkForErrors(TU) != 0)
2837 return -1;
2838
2839 for (FI = 0; FI < NumFilenames; ++FI) {
2840 CXFile file = clang_getFile(TU, Filenames[FI]);
2841 if (!file)
2842 continue;
2843
2844 if (checkForErrors(TU) != 0)
2845 return -1;
2846
2847 if (I + 1 == Repeats) {
2848 CXCursorAndRangeVisitor visitor = { 0, findFileIncludesVisit };
2849 clang_findIncludesInFile(TU, file, visitor);
2850
2851 if (checkForErrors(TU) != 0)
2852 return -1;
2853 }
2854 }
2855 }
2856
2857 PrintDiagnostics(TU);
2858 clang_disposeTranslationUnit(TU);
2859 clang_disposeIndex(CIdx);
2860 free((void *)Filenames);
2861 free_remapped_files(unsaved_files, num_unsaved_files);
2862 return 0;
2863}
2864
2865#define MAX_IMPORTED_ASTFILES200 200
2866
2867typedef struct {
2868 char **filenames;
2869 unsigned num_files;
2870} ImportedASTFilesData;
2871
2872static ImportedASTFilesData *importedASTs_create() {
2873 ImportedASTFilesData *p;
2874 p = malloc(sizeof(ImportedASTFilesData));
2875 p->filenames = malloc(MAX_IMPORTED_ASTFILES200 * sizeof(const char *));
2876 p->num_files = 0;
2877 return p;
2878}
2879
2880static void importedASTs_dispose(ImportedASTFilesData *p) {
2881 unsigned i;
2882 if (!p)
2883 return;
2884
2885 for (i = 0; i < p->num_files; ++i)
2886 free(p->filenames[i]);
2887 free(p->filenames);
2888 free(p);
2889}
2890
2891static void importedASTS_insert(ImportedASTFilesData *p, const char *file) {
2892 unsigned i;
2893 assert(p && file)((p && file) ? (void) (0) : __assert_fail ("p && file"
, "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn303373/tools/clang/tools/c-index-test/c-index-test.c"
, 2893, __PRETTY_FUNCTION__))
;
2894 for (i = 0; i < p->num_files; ++i)
2895 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)
2896 return;
2897 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~svn303373/tools/clang/tools/c-index-test/c-index-test.c"
, 2897, __PRETTY_FUNCTION__))
;
2898 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)))
;
2899}
2900
2901typedef struct IndexDataStringList_ {
2902 struct IndexDataStringList_ *next;
2903 char data[1]; /* Dynamically sized. */
2904} IndexDataStringList;
2905
2906typedef struct {
2907 const char *check_prefix;
2908 int first_check_printed;
2909 int fail_for_error;
2910 int abort;
2911 const char *main_filename;
2912 ImportedASTFilesData *importedASTs;
2913 IndexDataStringList *strings;
2914 CXTranslationUnit TU;
2915} IndexData;
2916
2917static void free_client_data(IndexData *index_data) {
2918 IndexDataStringList *node = index_data->strings;
2919 while (node) {
2920 IndexDataStringList *next = node->next;
2921 free(node);
2922 node = next;
2923 }
2924 index_data->strings = NULL((void*)0);
2925}
2926
2927static void printCheck(IndexData *data) {
2928 if (data->check_prefix) {
2929 if (data->first_check_printed) {
2930 printf("// %s-NEXT: ", data->check_prefix);
2931 } else {
2932 printf("// %s : ", data->check_prefix);
2933 data->first_check_printed = 1;
2934 }
2935 }
2936}
2937
2938static void printCXIndexFile(CXIdxClientFile file) {
2939 CXString filename = clang_getFileName((CXFile)file);
2940 printf("%s", clang_getCString(filename));
2941 clang_disposeString(filename);
2942}
2943
2944static void printCXIndexLoc(CXIdxLoc loc, CXClientData client_data) {
2945 IndexData *index_data;
2946 CXString filename;
2947 const char *cname;
2948 CXIdxClientFile file;
2949 unsigned line, column;
2950 int isMainFile;
2951
2952 index_data = (IndexData *)client_data;
2953 clang_indexLoc_getFileLocation(loc, &file, 0, &line, &column, 0);
2954 if (line == 0) {
2955 printf("<invalid>");
2956 return;
2957 }
2958 if (!file) {
2959 printf("<no idxfile>");
2960 return;
2961 }
2962 filename = clang_getFileName((CXFile)file);
2963 cname = clang_getCString(filename);
2964 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)
2965 isMainFile = 1;
2966 else
2967 isMainFile = 0;
2968 clang_disposeString(filename);
2969
2970 if (!isMainFile) {
2971 printCXIndexFile(file);
2972 printf(":");
2973 }
2974 printf("%d:%d", line, column);
2975}
2976
2977static unsigned digitCount(unsigned val) {
2978 unsigned c = 1;
2979 while (1) {
2980 if (val < 10)
2981 return c;
2982 ++c;
2983 val /= 10;
2984 }
2985}
2986
2987static CXIdxClientContainer makeClientContainer(CXClientData *client_data,
2988 const CXIdxEntityInfo *info,
2989 CXIdxLoc loc) {
2990 IndexData *index_data;
2991 IndexDataStringList *node;
2992 const char *name;
2993 char *newStr;
2994 CXIdxClientFile file;
2995 unsigned line, column;
2996
2997 name = info->name;
2998 if (!name)
2999 name = "<anon-tag>";
3000
3001 clang_indexLoc_getFileLocation(loc, &file, 0, &line, &column, 0);
3002
3003 node =
3004 (IndexDataStringList *)malloc(sizeof(IndexDataStringList) + strlen(name) +
3005 digitCount(line) + digitCount(column) + 2);
3006 newStr = node->data;
3007 sprintf(newStr, "%s:%d:%d", name, line, column);
3008
3009 /* Remember string so it can be freed later. */
3010 index_data = (IndexData *)client_data;
3011 node->next = index_data->strings;
3012 index_data->strings = node;
3013
3014 return (CXIdxClientContainer)newStr;
3015}
3016
3017static void printCXIndexContainer(const CXIdxContainerInfo *info) {
3018 CXIdxClientContainer container;
3019 container = clang_index_getClientContainer(info);
3020 if (!container)
3021 printf("[<<NULL>>]");
3022 else
3023 printf("[%s]", (const char *)container);
3024}
3025
3026static const char *getEntityKindString(CXIdxEntityKind kind) {
3027 switch (kind) {
3028 case CXIdxEntity_Unexposed: return "<<UNEXPOSED>>";
3029 case CXIdxEntity_Typedef: return "typedef";
3030 case CXIdxEntity_Function: return "function";
3031 case CXIdxEntity_Variable: return "variable";
3032 case CXIdxEntity_Field: return "field";
3033 case CXIdxEntity_EnumConstant: return "enumerator";
3034 case CXIdxEntity_ObjCClass: return "objc-class";
3035 case CXIdxEntity_ObjCProtocol: return "objc-protocol";
3036 case CXIdxEntity_ObjCCategory: return "objc-category";
3037 case CXIdxEntity_ObjCInstanceMethod: return "objc-instance-method";
3038 case CXIdxEntity_ObjCClassMethod: return "objc-class-method";
3039 case CXIdxEntity_ObjCProperty: return "objc-property";
3040 case CXIdxEntity_ObjCIvar: return "objc-ivar";
3041 case CXIdxEntity_Enum: return "enum";
3042 case CXIdxEntity_Struct: return "struct";
3043 case CXIdxEntity_Union: return "union";
3044 case CXIdxEntity_CXXClass: return "c++-class";
3045 case CXIdxEntity_CXXNamespace: return "namespace";
3046 case CXIdxEntity_CXXNamespaceAlias: return "namespace-alias";
3047 case CXIdxEntity_CXXStaticVariable: return "c++-static-var";
3048 case CXIdxEntity_CXXStaticMethod: return "c++-static-method";
3049 case CXIdxEntity_CXXInstanceMethod: return "c++-instance-method";
3050 case CXIdxEntity_CXXConstructor: return "constructor";
3051 case CXIdxEntity_CXXDestructor: return "destructor";
3052 case CXIdxEntity_CXXConversionFunction: return "conversion-func";
3053 case CXIdxEntity_CXXTypeAlias: return "type-alias";
3054 case CXIdxEntity_CXXInterface: return "c++-__interface";
3055 }
3056 assert(0 && "Garbage entity kind")((0 && "Garbage entity kind") ? (void) (0) : __assert_fail
("0 && \"Garbage entity kind\"", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn303373/tools/clang/tools/c-index-test/c-index-test.c"
, 3056, __PRETTY_FUNCTION__))
;
3057 return 0;
3058}
3059
3060static const char *getEntityTemplateKindString(CXIdxEntityCXXTemplateKind kind) {
3061 switch (kind) {
3062 case CXIdxEntity_NonTemplate: return "";
3063 case CXIdxEntity_Template: return "-template";
3064 case CXIdxEntity_TemplatePartialSpecialization:
3065 return "-template-partial-spec";
3066 case CXIdxEntity_TemplateSpecialization: return "-template-spec";
3067 }
3068 assert(0 && "Garbage entity kind")((0 && "Garbage entity kind") ? (void) (0) : __assert_fail
("0 && \"Garbage entity kind\"", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn303373/tools/clang/tools/c-index-test/c-index-test.c"
, 3068, __PRETTY_FUNCTION__))
;
3069 return 0;
3070}
3071
3072static const char *getEntityLanguageString(CXIdxEntityLanguage kind) {
3073 switch (kind) {
3074 case CXIdxEntityLang_None: return "<none>";
3075 case CXIdxEntityLang_C: return "C";
3076 case CXIdxEntityLang_ObjC: return "ObjC";
3077 case CXIdxEntityLang_CXX: return "C++";
3078 case CXIdxEntityLang_Swift: return "Swift";
3079 }
3080 assert(0 && "Garbage language kind")((0 && "Garbage language kind") ? (void) (0) : __assert_fail
("0 && \"Garbage language kind\"", "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn303373/tools/clang/tools/c-index-test/c-index-test.c"
, 3080, __PRETTY_FUNCTION__))
;
3081 return 0;
3082}
3083
3084static void printEntityInfo(const char *cb,
3085 CXClientData client_data,
3086 const CXIdxEntityInfo *info) {
3087 const char *name;
3088 IndexData *index_data;
3089 unsigned i;
3090 index_data = (IndexData *)client_data;
3091 printCheck(index_data);
3092
3093 if (!info) {
3094 printf("%s: <<NULL>>", cb);
3095 return;
3096 }
3097
3098 name = info->name;
3099 if (!name)
3100 name = "<anon-tag>";
3101
3102 printf("%s: kind: %s%s", cb, getEntityKindString(info->kind),
3103 getEntityTemplateKindString(info->templateKind));
3104 printf(" | name: %s", name);
3105 printf(" | USR: %s", info->USR);
3106 printf(" | lang: %s", getEntityLanguageString(info->lang));
3107
3108 for (i = 0; i != info->numAttributes; ++i) {
3109 const CXIdxAttrInfo *Attr = info->attributes[i];
3110 printf(" <attribute>: ");
3111 PrintCursor(Attr->cursor, NULL((void*)0));
3112 }
3113}
3114
3115static void printBaseClassInfo(CXClientData client_data,
3116 const CXIdxBaseClassInfo *info) {
3117 printEntityInfo(" <base>", client_data, info->base);
3118 printf(" | cursor: ");
3119 PrintCursor(info->cursor, NULL((void*)0));
3120 printf(" | loc: ");
3121 printCXIndexLoc(info->loc, client_data);
3122}
3123
3124static void printProtocolList(const CXIdxObjCProtocolRefListInfo *ProtoInfo,
3125 CXClientData client_data) {
3126 unsigned i;
3127 for (i = 0; i < ProtoInfo->numProtocols; ++i) {
3128 printEntityInfo(" <protocol>", client_data,
3129 ProtoInfo->protocols[i]->protocol);
3130 printf(" | cursor: ");
3131 PrintCursor(ProtoInfo->protocols[i]->cursor, NULL((void*)0));
3132 printf(" | loc: ");
3133 printCXIndexLoc(ProtoInfo->protocols[i]->loc, client_data);
3134 printf("\n");
3135 }
3136}
3137
3138static void index_diagnostic(CXClientData client_data,
3139 CXDiagnosticSet diagSet, void *reserved) {
3140 CXString str;
3141 const char *cstr;
3142 unsigned numDiags, i;
3143 CXDiagnostic diag;
3144 IndexData *index_data;
3145 index_data = (IndexData *)client_data;
3146 printCheck(index_data);
3147
3148 numDiags = clang_getNumDiagnosticsInSet(diagSet);
3149 for (i = 0; i != numDiags; ++i) {
3150 diag = clang_getDiagnosticInSet(diagSet, i);
3151 str = clang_formatDiagnostic(diag, clang_defaultDiagnosticDisplayOptions());
3152 cstr = clang_getCString(str);
3153 printf("[diagnostic]: %s\n", cstr);
3154 clang_disposeString(str);
3155
3156 if (getenv("CINDEXTEST_FAILONERROR") &&
3157 clang_getDiagnosticSeverity(diag) >= CXDiagnostic_Error) {
3158 index_data->fail_for_error = 1;
3159 }
3160 }
3161}
3162
3163static CXIdxClientFile index_enteredMainFile(CXClientData client_data,
3164 CXFile file, void *reserved) {
3165 IndexData *index_data;
3166 CXString filename;
3167
3168 index_data = (IndexData *)client_data;
3169 printCheck(index_data);
3170
3171 filename = clang_getFileName(file);
3172 index_data->main_filename = clang_getCString(filename);
3173 clang_disposeString(filename);
3174
3175 printf("[enteredMainFile]: ");
3176 printCXIndexFile((CXIdxClientFile)file);
3177 printf("\n");
3178
3179 return (CXIdxClientFile)file;
3180}
3181
3182static CXIdxClientFile index_ppIncludedFile(CXClientData client_data,
3183 const CXIdxIncludedFileInfo *info) {
3184 IndexData *index_data;
3185 CXModule Mod;
3186 index_data = (IndexData *)client_data;
3187 printCheck(index_data);
3188
3189 printf("[ppIncludedFile]: ");
3190 printCXIndexFile((CXIdxClientFile)info->file);
3191 printf(" | name: \"%s\"", info->filename);
3192 printf(" | hash loc: ");
3193 printCXIndexLoc(info->hashLoc, client_data);
3194 printf(" | isImport: %d | isAngled: %d | isModule: %d",
3195 info->isImport, info->isAngled, info->isModuleImport);
3196
3197 Mod = clang_getModuleForFile(index_data->TU, (CXFile)info->file);
3198 if (Mod) {
3199 CXString str = clang_Module_getFullName(Mod);
3200 const char *cstr = clang_getCString(str);
3201 printf(" | module: %s", cstr);
3202 clang_disposeString(str);
3203 }
3204
3205 printf("\n");
3206
3207 return (CXIdxClientFile)info->file;
3208}
3209
3210static CXIdxClientFile index_importedASTFile(CXClientData client_data,
3211 const CXIdxImportedASTFileInfo *info) {
3212 IndexData *index_data;
3213 index_data = (IndexData *)client_data;
3214 printCheck(index_data);
3215
3216 if (index_data->importedASTs) {
3217 CXString filename = clang_getFileName(info->file);
3218 importedASTS_insert(index_data->importedASTs, clang_getCString(filename));
3219 clang_disposeString(filename);
3220 }
3221
3222 printf("[importedASTFile]: ");
3223 printCXIndexFile((CXIdxClientFile)info->file);
3224 if (info->module) {
3225 CXString name = clang_Module_getFullName(info->module);
3226 printf(" | loc: ");
3227 printCXIndexLoc(info->loc, client_data);
3228 printf(" | name: \"%s\"", clang_getCString(name));
3229 printf(" | isImplicit: %d\n", info->isImplicit);
3230 clang_disposeString(name);
3231 } else {
3232 /* PCH file, the rest are not relevant. */
3233 printf("\n");
3234 }
3235
3236 return (CXIdxClientFile)info->file;
3237}
3238
3239static CXIdxClientContainer
3240index_startedTranslationUnit(CXClientData client_data, void *reserved) {
3241 IndexData *index_data;
3242 index_data = (IndexData *)client_data;
3243 printCheck(index_data);
3244
3245 printf("[startedTranslationUnit]\n");
3246 return (CXIdxClientContainer)"TU";
3247}
3248
3249static void index_indexDeclaration(CXClientData client_data,
3250 const CXIdxDeclInfo *info) {
3251 IndexData *index_data;
3252 const CXIdxObjCCategoryDeclInfo *CatInfo;
3253 const CXIdxObjCInterfaceDeclInfo *InterInfo;
3254 const CXIdxObjCProtocolRefListInfo *ProtoInfo;
3255 const CXIdxObjCPropertyDeclInfo *PropInfo;
3256 const CXIdxCXXClassDeclInfo *CXXClassInfo;
3257 unsigned i;
3258 index_data = (IndexData *)client_data;
3259
3260 printEntityInfo("[indexDeclaration]", client_data, info->entityInfo);
3261 printf(" | cursor: ");
3262 PrintCursor(info->cursor, NULL((void*)0));
3263 printf(" | loc: ");
3264 printCXIndexLoc(info->loc, client_data);
3265 printf(" | semantic-container: ");
3266 printCXIndexContainer(info->semanticContainer);
3267 printf(" | lexical-container: ");
3268 printCXIndexContainer(info->lexicalContainer);
3269 printf(" | isRedecl: %d", info->isRedeclaration);
3270 printf(" | isDef: %d", info->isDefinition);
3271 if (info->flags & CXIdxDeclFlag_Skipped) {
3272 assert(!info->isContainer)((!info->isContainer) ? (void) (0) : __assert_fail ("!info->isContainer"
, "/tmp/buildd/llvm-toolchain-snapshot-5.0~svn303373/tools/clang/tools/c-index-test/c-index-test.c"
, 3272, __PRETTY_FUNCTION__))
;
3273 printf(" | isContainer: skipped");
3274 } else {
3275 printf(" | isContainer: %d", info->isContainer);
3276 }
3277 printf(" | isImplicit: %d\n", info->isImplicit);
3278
3279 for (i = 0; i != info->numAttributes; ++i) {
3280 const CXIdxAttrInfo *Attr = info->attributes[i];
3281 printf(" <attribute>: ");
3282 PrintCursor(Attr->cursor, NULL((void*)0));
3283 printf("\n");
3284 }
3285
3286 if (clang_index_isEntityObjCContainerKind(info->entityInfo->kind)) {
3287 const char *kindName = 0;
3288 CXIdxObjCContainerKind K = clang_index_getObjCContainerDeclInfo(info)->kind;
3289 switch (K) {
3290 case CXIdxObjCContainer_ForwardRef:
3291 kindName = "forward-ref"; break;
3292 case CXIdxObjCContainer_Interface:
3293 kindName = "interface"; break;
3294 case CXIdxObjCContainer_Implementation:
3295 kindName = "implementation"; break;
3296 }
3297 printCheck(index_data);
3298 printf(" <ObjCContainerInfo>: kind: %s\n", kindName);
3299 }
3300
3301 if ((CatInfo = clang_index_getObjCCategoryDeclInfo(info))) {
3302 printEntityInfo(" <ObjCCategoryInfo>: class", client_data,
3303 CatInfo->objcClass);
3304 printf(" | cursor: ");
3305 PrintCursor(CatInfo->classCursor, NULL((void*)0));
3306 printf(" | loc: ");
3307 printCXIndexLoc(CatInfo->classLoc, client_data);
3308 printf("\n");
3309 }
3310
3311 if ((InterInfo = clang_index_getObjCInterfaceDeclInfo(info))) {
3312 if (InterInfo->superInfo) {
3313 printBaseClassInfo(client_data, InterInfo->superInfo);
3314 printf("\n");
3315 }
3316 }
3317
3318 if ((ProtoInfo = clang_index_getObjCProtocolRefListInfo(info))) {
3319 printProtocolList(ProtoInfo, client_data);
3320 }
3321
3322 if ((PropInfo = clang_index_getObjCPropertyDeclInfo(info))) {
3323 if (PropInfo->getter) {
3324 printEntityInfo(" <getter>", client_data, PropInfo->getter);
3325 printf("\n");
3326 }
3327 if (PropInfo->setter) {
3328 printEntityInfo(" <setter>", client_data, PropInfo->setter);
3329 printf("\n");
3330 }
3331 }
3332
3333 if ((CXXClassInfo = clang_index_getCXXClassDeclInfo(info))) {
3334 for (i = 0; i != CXXClassInfo->numBases; ++i) {
3335 printBaseClassInfo(client_data, CXXClassInfo->bases[i]);
3336 printf("\n");
3337 }
3338 }
3339
3340 if (info->declAsContainer)
3341 clang_index_setClientContainer(
3342 info->declAsContainer,
3343 makeClientContainer(client_data, info->entityInfo, info->loc));
3344}
3345
3346static void index_indexEntityReference(CXClientData client_data,
3347 const CXIdxEntityRefInfo *info) {
3348 printEntityInfo("[indexEntityReference]", client_data,
3349 info->referencedEntity);
3350 printf(" | cursor: ");
3351 PrintCursor(info->cursor, NULL((void*)0));
3352 printf(" | loc: ");
3353 printCXIndexLoc(info->loc, client_data);
3354 printEntityInfo(" | <parent>:", client_data, info->parentEntity);
3355 printf(" | container: ");
3356 printCXIndexContainer(info->container);
3357 printf(" | refkind: ");
3358 switch (info->kind) {
3359 case CXIdxEntityRef_Direct: printf("direct"); break;
3360 case CXIdxEntityRef_Implicit: printf("implicit"); break;
3361 }
3362 printf("\n");
3363}
3364
3365static int index_abortQuery(CXClientData client_data, void *reserved) {
3366 IndexData *index_data;
3367 index_data = (IndexData *)client_data;
3368 return index_data->abort;
3369}
3370
3371static IndexerCallbacks IndexCB = {
3372 index_abortQuery,
3373 index_diagnostic,
3374 index_enteredMainFile,
3375 index_ppIncludedFile,
3376 index_importedASTFile,
3377 index_startedTranslationUnit,
3378 index_indexDeclaration,
3379 index_indexEntityReference
3380};
3381
3382static unsigned getIndexOptions(void) {
3383 unsigned index_opts;
3384 index_opts = 0;
3385 if (getenv("CINDEXTEST_SUPPRESSREFS"))
3386 index_opts |= CXIndexOpt_SuppressRedundantRefs;
3387 if (getenv("CINDEXTEST_INDEXLOCALSYMBOLS"))
3388 index_opts |= CXIndexOpt_IndexFunctionLocalSymbols;
3389 if (!getenv("CINDEXTEST_DISABLE_SKIPPARSEDBODIES"))
3390 index_opts |= CXIndexOpt_SkipParsedBodiesInSession;
3391
3392 return index_opts;
3393}
3394
3395static int index_compile_args(int num_args, const char **args,
3396 CXIndexAction idxAction,
3397 ImportedASTFilesData *importedASTs,
3398 const char *check_prefix) {
3399 IndexData index_data;
3400 unsigned index_opts;
3401 int result;
3402
3403 if (num_args == 0) {
3404 fprintf(stderrstderr, "no compiler arguments\n");
3405 return -1;
3406 }
3407
3408 index_data.check_prefix = check_prefix;
3409 index_data.first_check_printed = 0;
3410 index_data.fail_for_error = 0;
3411 index_data.abort = 0;
3412 index_data.main_filename = "";
3413 index_data.importedASTs = importedASTs;
3414 index_data.strings = NULL((void*)0);
3415 index_data.TU = NULL((void*)0);
3416
3417 index_opts = getIndexOptions();
3418 result = clang_indexSourceFile(idxAction, &index_data,
3419 &IndexCB,sizeof(IndexCB), index_opts,
3420 0, args, num_args, 0, 0, 0,
3421 getDefaultParsingOptions());
3422 if (result != CXError_Success)
3423 describeLibclangFailure(result);
3424
3425 if (index_data.fail_for_error)
3426 result = -1;
3427
3428 free_client_data(&index_data);
3429 return result;
3430}
3431
3432static int index_ast_file(const char *ast_file,
3433 CXIndex Idx,
3434 CXIndexAction idxAction,
3435 ImportedASTFilesData *importedASTs,
3436 const char *check_prefix) {
3437 CXTranslationUnit TU;
3438 IndexData index_data;
3439 unsigned index_opts;
3440 int result;
3441
3442 if (!CreateTranslationUnit(Idx, ast_file, &TU))
3443 return -1;
3444
3445 index_data.check_prefix = check_prefix;
3446 index_data.first_check_printed = 0;
3447 index_data.fail_for_error = 0;
3448 index_data.abort = 0;
3449 index_data.main_filename = "";
3450 index_data.importedASTs = importedASTs;
3451 index_data.strings = NULL((void*)0);
3452 index_data.TU = TU;
3453
3454 index_opts = getIndexOptions();
3455 result = clang_indexTranslationUnit(idxAction, &index_data,
3456 &IndexCB,sizeof(IndexCB),
3457 index_opts, TU);
3458 if (index_data.fail_for_error)
3459 result = -1;
3460
3461 clang_disposeTranslationUnit(TU);
3462 free_client_data(&index_data);
3463 return result;
3464}
3465
3466static int index_file(int argc, const char **argv, int full) {
3467 const char *check_prefix;
3468 CXIndex Idx;
3469 CXIndexAction idxAction;
3470 ImportedASTFilesData *importedASTs;
3471 int result;
3472
3473 check_prefix = 0;
3474 if (argc > 0) {
3475 if (strstr(argv[0], "-check-prefix=") == argv[0]) {
3476 check_prefix = argv[0] + strlen("-check-prefix=");
3477 ++argv;
3478 --argc;
3479 }
3480 }
3481
3482 if (!(Idx = clang_createIndex(/* excludeDeclsFromPCH */ 1,
3483 /* displayDiagnostics=*/1))) {
3484 fprintf(stderrstderr, "Could not create Index\n");
3485 return 1;
3486 }
3487 idxAction = clang_IndexAction_create(Idx);
3488 importedASTs = 0;
3489 if (full)
3490 importedASTs = importedASTs_create();
3491
3492 result = index_compile_args(argc, argv, idxAction, importedASTs, check_prefix);
3493 if (result != 0)
3494 goto finished;
3495
3496 if (full) {
3497 unsigned i;
3498 for (i = 0; i < importedASTs->num_files && result == 0; ++i) {
3499 result = index_ast_file(importedASTs->filenames[i], Idx, idxAction,
3500 importedASTs, check_prefix);
3501 }
3502 }
3503
3504finished:
3505 importedASTs_dispose(importedASTs);
3506 clang_IndexAction_dispose(idxAction);
3507 clang_disposeIndex(Idx);
3508 return result;
3509}
3510
3511static int index_tu(int argc, const char **argv) {
3512 const char *check_prefix;
3513 CXIndex Idx;
3514 CXIndexAction idxAction;
3515 int result;
3516
3517 check_prefix = 0;
3518 if (argc > 0) {
3519 if (strstr(argv[0], "-check-prefix=") == argv[0]) {
3520 check_prefix = argv[0] + strlen("-check-prefix=");
3521 ++argv;
3522 --argc;
3523 }
3524 }
3525
3526 if (!(Idx = clang_createIndex(/* excludeDeclsFromPCH */ 1,
3527 /* displayDiagnostics=*/1))) {
3528 fprintf(stderrstderr, "Could not create Index\n");
3529 return 1;
3530 }
3531 idxAction = clang_IndexAction_create(Idx);
3532
3533 result = index_ast_file(argv[0], Idx, idxAction,
3534 /*importedASTs=*/0, check_prefix);
3535
3536 clang_IndexAction_dispose(idxAction);
3537 clang_disposeIndex(Idx);
3538 return result;
3539}
3540
3541static int index_compile_db(int argc, const char **argv) {
3542 const char *check_prefix;
3543 CXIndex Idx;
3544 CXIndexAction idxAction;
3545 int errorCode = 0;
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 (argc == 0) {
3557 fprintf(stderrstderr, "no compilation database\n");
3558 return -1;
3559 }
3560
3561 if (!(Idx = clang_createIndex(/* excludeDeclsFromPCH */ 1,
3562 /* displayDiagnostics=*/1))) {
3563 fprintf(stderrstderr, "Could not create Index\n");
3564 return 1;
3565 }
3566 idxAction = clang_IndexAction_create(Idx);
3567
3568 {
3569 const char *database = argv[0];
3570 CXCompilationDatabase db = 0;
3571 CXCompileCommands CCmds = 0;
3572 CXCompileCommand CCmd;
3573 CXCompilationDatabase_Error ec;
3574 CXString wd;
3575#define MAX_COMPILE_ARGS512 512
3576 CXString cxargs[MAX_COMPILE_ARGS512];
3577 const char *args[MAX_COMPILE_ARGS512];
3578 char *tmp;
3579 unsigned len;
3580 char *buildDir;
3581 int i, a, numCmds, numArgs;
3582
3583 len = strlen(database);
3584 tmp = (char *) malloc(len+1);
3585 memcpy(tmp, database, len+1);
3586 buildDir = dirname(tmp);
3587
3588 db = clang_CompilationDatabase_fromDirectory(buildDir, &ec);
3589
3590 if (db) {
3591
3592 if (ec!=CXCompilationDatabase_NoError) {
3593 printf("unexpected error %d code while loading compilation database\n", ec);
3594 errorCode = -1;
3595 goto cdb_end;
3596 }
3597
3598 if (chdir(buildDir) != 0) {
3599 printf("Could not chdir to %s\n", buildDir);
3600 errorCode = -1;
3601 goto cdb_end;
3602 }
3603
3604 CCmds = clang_CompilationDatabase_getAllCompileCommands(db);
3605 if (!CCmds) {
3606 printf("compilation db is empty\n");
3607 errorCode = -1;
3608 goto cdb_end;
3609 }
3610
3611 numCmds = clang_CompileCommands_getSize(CCmds);
3612
3613 if (numCmds==0) {
3614 fprintf(stderrstderr, "should not get an empty compileCommand set\n");
3615 errorCode = -1;
3616 goto cdb_end;
3617 }
3618
3619 for (i=0; i<numCmds && errorCode == 0; ++i) {
3620 CCmd = clang_CompileCommands_getCommand(CCmds, i);
3621
3622 wd = clang_CompileCommand_getDirectory(CCmd);
3623 if (chdir(clang_getCString(wd)) != 0) {
3624 printf("Could not chdir to %s\n", clang_getCString(wd));
3625 errorCode = -1;
3626 goto cdb_end;
3627 }
3628 clang_disposeString(wd);
3629
3630 numArgs = clang_CompileCommand_getNumArgs(CCmd);
3631 if (numArgs > MAX_COMPILE_ARGS512){
3632 fprintf(stderrstderr, "got more compile arguments than maximum\n");
3633 errorCode = -1;
3634 goto cdb_end;
3635 }
3636 for (a=0; a<numArgs; ++a) {
3637 cxargs[a] = clang_CompileCommand_getArg(CCmd, a);
3638 args[a] = clang_getCString(cxargs[a]);
3639 }
3640
3641 errorCode = index_compile_args(numArgs, args, idxAction,
3642 /*importedASTs=*/0, check_prefix);
3643
3644 for (a=0; a<numArgs; ++a)
3645 clang_disposeString(cxargs[a]);
3646 }
3647 } else {
3648 printf("database loading failed with error code %d.\n", ec);
3649 errorCode = -1;
3650 }
3651
3652 cdb_end:
3653 clang_CompileCommands_dispose(CCmds);
3654 clang_CompilationDatabase_dispose(db);
3655 free(tmp);
3656
3657 }
3658
3659 clang_IndexAction_dispose(idxAction);
3660 clang_disposeIndex(Idx);
3661 return errorCode;
3662}
3663
3664int perform_token_annotation(int argc, const char **argv) {
3665 const char *input = argv[1];
3666 char *filename = 0;
3667 unsigned line, second_line;
3668 unsigned column, second_column;
3669 CXIndex CIdx;
3670 CXTranslationUnit TU = 0;
3671 int errorCode;
3672 struct CXUnsavedFile *unsaved_files = 0;
3673 int num_unsaved_files = 0;
3674 CXToken *tokens;
3675 unsigned num_tokens;
3676 CXSourceRange range;
3677 CXSourceLocation startLoc, endLoc;
3678 CXFile file = 0;
3679 CXCursor *cursors = 0;
3680 CXSourceRangeList *skipped_ranges = 0;
3681 enum CXErrorCode Err;
3682 unsigned i;
3683
3684 input += strlen("-test-annotate-tokens=");
3685 if ((errorCode = parse_file_line_column(input, &filename, &line, &column,
3686 &second_line, &second_column)))
3687 return errorCode;
3688
3689 if (parse_remapped_files(argc, argv, 2, &unsaved_files, &num_unsaved_files)) {
3690 free(filename);
3691 return -1;
3692 }
3693
3694 CIdx = clang_createIndex(0, 1);
3695 Err = clang_parseTranslationUnit2(CIdx, argv[argc - 1],
3696 argv + num_unsaved_files + 2,
3697 argc - num_unsaved_files - 3,
3698 unsaved_files,
3699 num_unsaved_files,
3700 getDefaultParsingOptions(), &TU);
3701 if (Err != CXError_Success) {
3702 fprintf(stderrstderr, "unable to parse input\n");
3703 describeLibclangFailure(Err);
3704 clang_disposeIndex(CIdx);
3705 free(filename);
3706 free_remapped_files(unsaved_files, num_unsaved_files);
3707 return -1;
3708 }
3709 errorCode = 0;
3710
3711 if (checkForErrors(TU) != 0) {
3712 errorCode = -1;
3713 goto teardown;
3714 }
3715
3716 if (getenv("CINDEXTEST_EDITING")) {
3717 for (i = 0; i < 5; ++i) {
3718 Err = clang_reparseTranslationUnit(TU, num_unsaved_files, unsaved_files,
3719 clang_defaultReparseOptions(TU));
3720 if (Err != CXError_Success) {
3721 fprintf(stderrstderr, "Unable to reparse translation unit!\n");
3722 describeLibclangFailure(Err);
3723 errorCode = -1;
3724 goto teardown;
3725 }
3726 }
3727 }
3728
3729 if (checkForErrors(TU) != 0) {
3730 errorCode = -1;
3731 goto teardown;
3732 }
3733
3734 file = clang_getFile(TU, filename);
3735 if (!file) {
3736 fprintf(stderrstderr, "file %s is not in this translation unit\n", filename);
3737 errorCode = -1;
3738 goto teardown;
3739 }
3740
3741 startLoc = clang_getLocation(TU, file, line, column);
3742 if (clang_equalLocations(clang_getNullLocation(), startLoc)) {
3743 fprintf(stderrstderr, "invalid source location %s:%d:%d\n", filename, line,
3744 column);
3745 errorCode = -1;
3746 goto teardown;
3747 }
3748
3749 endLoc = clang_getLocation(TU, file, second_line, second_column);
3750 if (clang_equalLocations(clang_getNullLocation(), endLoc)) {
3751 fprintf(stderrstderr, "invalid source location %s:%d:%d\n", filename,
3752 second_line, second_column);
3753 errorCode = -1;
3754 goto teardown;
3755 }
3756
3757 range = clang_getRange(startLoc, endLoc);
3758 clang_tokenize(TU, range, &tokens, &num_tokens);
3759
3760 if (checkForErrors(TU) != 0) {
3761 errorCode = -1;
3762 goto teardown;
3763 }
3764
3765 cursors = (CXCursor *)malloc(num_tokens * sizeof(CXCursor));
3766 clang_annotateTokens(TU, tokens, num_tokens, cursors);
3767
3768 if (checkForErrors(TU) != 0) {
3769 errorCode = -1;
3770 goto teardown;
3771 }
3772
3773 skipped_ranges = clang_getSkippedRanges(TU, file);
3774 for (i = 0; i != skipped_ranges->count; ++i) {
3775 unsigned start_line, start_column, end_line, end_column;
3776 clang_getSpellingLocation(clang_getRangeStart(skipped_ranges->ranges[i]),
3777 0, &start_line, &start_column, 0);
3778 clang_getSpellingLocation(clang_getRangeEnd(skipped_ranges->ranges[i]),
3779 0, &end_line, &end_column, 0);
3780 printf("Skipping: ");
3781 PrintExtent(stdoutstdout, start_line, start_column, end_line, end_column);
3782 printf("\n");
3783 }
3784 clang_disposeSourceRangeList(skipped_ranges);
3785
3786 for (i = 0; i != num_tokens; ++i) {
3787 const char *kind = "<unknown>";
3788 CXString spelling = clang_getTokenSpelling(TU, tokens[i]);
3789 CXSourceRange extent = clang_getTokenExtent(TU, tokens[i]);
3790 unsigned start_line, start_column, end_line, end_column;
3791
3792 switch (clang_getTokenKind(tokens[i])) {
3793 case CXToken_Punctuation: kind = "Punctuation"; break;
3794 case CXToken_Keyword: kind = "Keyword"; break;
3795 case CXToken_Identifier: kind = "Identifier"; break;
3796 case CXToken_Literal: kind = "Literal"; break;
3797 case CXToken_Comment: kind = "Comment"; break;
3798 }
3799 clang_getSpellingLocation(clang_getRangeStart(extent),
3800 0, &start_line, &start_column, 0);
3801 clang_getSpellingLocation(clang_getRangeEnd(extent),
3802 0, &end_line, &end_column, 0);
3803 printf("%s: \"%s\" ", kind, clang_getCString(spelling));
3804 clang_disposeString(spelling);
3805 PrintExtent(stdoutstdout, start_line, start_column, end_line, end_column);
3806 if (!clang_isInvalid(cursors[i].kind)) {
3807 printf(" ");
3808 PrintCursor(cursors[i], NULL((void*)0));
3809 }
3810 printf("\n");
3811 }
3812 free(cursors);
3813 clang_disposeTokens(TU, tokens, num_tokens);
3814
3815 teardown:
3816 PrintDiagnostics(TU);
3817 clang_disposeTranslationUnit(TU);
3818 clang_disposeIndex(CIdx);
3819 free(filename);
3820 free_remapped_files(unsaved_files, num_unsaved_files);
3821 return errorCode;
3822}
3823
3824static int
3825perform_test_compilation_db(const char *database, int argc, const char **argv) {
3826 CXCompilationDatabase db;
3827 CXCompileCommands CCmds;
3828 CXCompileCommand CCmd;
3829 CXCompilationDatabase_Error ec;
3830 CXString wd;
3831 CXString arg;
3832 int errorCode = 0;
3833 char *tmp;
3834 unsigned len;
3835 char *buildDir;
3836 int i, j, a, numCmds, numArgs;
3837
3838 len = strlen(database);
3839 tmp = (char *) malloc(len+1);
3840 memcpy(tmp, database, len+1);
3841 buildDir = dirname(tmp);
3842
3843 db = clang_CompilationDatabase_fromDirectory(buildDir, &ec);
3844
3845 if (db) {
3846
3847 if (ec!=CXCompilationDatabase_NoError) {
3848 printf("unexpected error %d code while loading compilation database\n", ec);
3849 errorCode = -1;
3850 goto cdb_end;
3851 }
3852
3853 for (i=0; i<argc && errorCode==0; ) {
3854 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){
3855 CCmds = clang_CompilationDatabase_getCompileCommands(db, argv[i+1]);
3856
3857 if (!CCmds) {
3858 printf("file %s not found in compilation db\n", argv[i+1]);
3859 errorCode = -1;
3860 break;
3861 }
3862
3863 numCmds = clang_CompileCommands_getSize(CCmds);
3864
3865 if (numCmds==0) {
3866 fprintf(stderrstderr, "should not get an empty compileCommand set for file"
3867 " '%s'\n", argv[i+1]);
3868 errorCode = -1;
3869 break;
3870 }
3871
3872 for (j=0; j<numCmds; ++j) {
3873 CCmd = clang_CompileCommands_getCommand(CCmds, j);
3874
3875 wd = clang_CompileCommand_getDirectory(CCmd);
3876 printf("workdir:'%s'", clang_getCString(wd));
3877 clang_disposeString(wd);
3878
3879 printf(" cmdline:'");
3880 numArgs = clang_CompileCommand_getNumArgs(CCmd);
3881 for (a=0; a<numArgs; ++a) {
3882 if (a) printf(" ");
3883 arg = clang_CompileCommand_getArg(CCmd, a);
3884 printf("%s", clang_getCString(arg));
3885 clang_disposeString(arg);
3886 }
3887 printf("'\n");
3888 }
3889
3890 clang_CompileCommands_dispose(CCmds);
3891
3892 i += 2;
3893 }
3894 }
3895 clang_CompilationDatabase_dispose(db);
3896 } else {
3897 printf("database loading failed with error code %d.\n", ec);
3898 errorCode = -1;
3899 }
3900
3901cdb_end:
3902 free(tmp);
3903
3904 return errorCode;
3905}
3906
3907/******************************************************************************/
3908/* USR printing. */
3909/******************************************************************************/
3910
3911static int insufficient_usr(const char *kind, const char *usage) {
3912 fprintf(stderrstderr, "USR for '%s' requires: %s\n", kind, usage);
3913 return 1;
3914}
3915
3916static unsigned isUSR(const char *s) {
3917 return s[0] == 'c' && s[1] == ':';
3918}
3919
3920static int not_usr(const char *s, const char *arg) {
3921 fprintf(stderrstderr, "'%s' argument ('%s') is not a USR\n", s, arg);
3922 return 1;
3923}
3924
3925static void print_usr(CXString usr) {
3926 const char *s = clang_getCString(usr);
3927 printf("%s\n", s);
3928 clang_disposeString(usr);
3929}
3930
3931static void display_usrs() {
3932 fprintf(stderrstderr, "-print-usrs options:\n"
3933 " ObjCCategory <class name> <category name>\n"
3934 " ObjCClass <class name>\n"
3935 " ObjCIvar <ivar name> <class USR>\n"
3936 " ObjCMethod <selector> [0=class method|1=instance method] "
3937 "<class USR>\n"
3938 " ObjCProperty <property name> <class USR>\n"
3939 " ObjCProtocol <protocol name>\n");
3940}
3941
3942int print_usrs(const char **I, const char **E) {
3943 while (I != E) {
3944 const char *kind = *I;
3945 unsigned len = strlen(kind);
3946 switch (len) {
3947 case 8:
3948 if (memcmp(kind, "ObjCIvar", 8) == 0) {
3949 if (I + 2 >= E)
3950 return insufficient_usr(kind, "<ivar name> <class USR>");
3951 if (!isUSR(I[2]))
3952 return not_usr("<class USR>", I[2]);
3953 else {
3954 CXString x;
3955 x.data = (void*) I[2];
3956 x.private_flags = 0;
3957 print_usr(clang_constructUSR_ObjCIvar(I[1], x));
3958 }
3959
3960 I += 3;
3961 continue;
3962 }
3963 break;
3964 case 9:
3965 if (memcmp(kind, "ObjCClass", 9) == 0) {
3966 if (I + 1 >= E)
3967 return insufficient_usr(kind, "<class name>");
3968 print_usr(clang_constructUSR_ObjCClass(I[1]));
3969 I += 2;
3970 continue;
3971 }
3972 break;
3973 case 10:
3974 if (memcmp(kind, "ObjCMethod", 10) == 0) {
3975 if (I + 3 >= E)
3976 return insufficient_usr(kind, "<method selector> "
3977 "[0=class method|1=instance method] <class USR>");
3978 if (!isUSR(I[3]))
3979 return not_usr("<class USR>", I[3]);
3980 else {
3981 CXString x;
3982 x.data = (void*) I[3];
3983 x.private_flags = 0;
3984 print_usr(clang_constructUSR_ObjCMethod(I[1], atoi(I[2]), x));
3985 }
3986 I += 4;
3987 continue;
3988 }
3989 break;
3990 case 12:
3991 if (memcmp(kind, "ObjCCategory", 12) == 0) {
3992 if (I + 2 >= E)
3993 return insufficient_usr(kind, "<class name> <category name>");
3994 print_usr(clang_constructUSR_ObjCCategory(I[1], I[2]));
3995 I += 3;
3996 continue;
3997 }
3998 if (memcmp(kind, "ObjCProtocol", 12) == 0) {
3999 if (I + 1 >= E)
4000 return insufficient_usr(kind, "<protocol name>");
4001 print_usr(clang_constructUSR_ObjCProtocol(I[1]));
4002 I += 2;
4003 continue;
4004 }
4005 if (memcmp(kind, "ObjCProperty", 12) == 0) {
4006 if (I + 2 >= E)
4007 return insufficient_usr(kind, "<property name> <class USR>");
4008 if (!isUSR(I[2]))
4009 return not_usr("<class USR>", I[2]);
4010 else {
4011 CXString x;
4012 x.data = (void*) I[2];
4013 x.private_flags = 0;
4014 print_usr(clang_constructUSR_ObjCProperty(I[1], x));
4015 }
4016 I += 3;
4017 continue;
4018 }
4019 break;
4020 default:
4021 break;
4022 }
4023 break;
4024 }
4025
4026 if (I != E) {
4027 fprintf(stderrstderr, "Invalid USR kind: %s\n", *I);
4028 display_usrs();
4029 return 1;
4030 }
4031 return 0;
4032}
4033
4034int print_usrs_file(const char *file_name) {
4035 char line[2048];
4036 const char *args[128];
4037 unsigned numChars = 0;
4038
4039 FILE *fp = fopen(file_name, "r");
4040 if (!fp) {
4041 fprintf(stderrstderr, "error: cannot open '%s'\n", file_name);
4042 return 1;
4043 }
4044
4045 /* This code is not really all that safe, but it works fine for testing. */
4046 while (!feof(fp)) {
4047 char c = fgetc(fp);
4048 if (c == '\n') {
4049 unsigned i = 0;
4050 const char *s = 0;
4051
4052 if (numChars == 0)
4053 continue;
4054
4055 line[numChars] = '\0';
4056 numChars = 0;
4057
4058 if (line[0] == '/' && line[1] == '/')
4059 continue;
4060
4061 s = strtok(line, " ");
4062 while (s) {
4063 args[i] = s;
4064 ++i;
4065 s = strtok(0, " ");
4066 }
4067 if (print_usrs(&args[0], &args[i]))
4068 return 1;
4069 }
4070 else
4071 line[numChars++] = c;
4072 }
4073
4074 fclose(fp);
4075 return 0;
4076}
4077
4078/******************************************************************************/
4079/* Command line processing. */
4080/******************************************************************************/
4081int write_pch_file(const char *filename, int argc, const char *argv[]) {
4082 CXIndex Idx;
4083 CXTranslationUnit TU;
4084 struct CXUnsavedFile *unsaved_files = 0;
4085 int num_unsaved_files = 0;
4086 enum CXErrorCode Err;
4087 int result = 0;
4088
4089 Idx = clang_createIndex(/* excludeDeclsFromPCH */1, /* displayDiagnostics=*/1);
4090
4091 if (parse_remapped_files(argc, argv, 0, &unsaved_files, &num_unsaved_files)) {
4092 clang_disposeIndex(Idx);
4093 return -1;
4094 }
4095
4096 Err = clang_parseTranslationUnit2(
4097 Idx, 0, argv + num_unsaved_files, argc - num_unsaved_files,
4098 unsaved_files, num_unsaved_files,
4099 CXTranslationUnit_Incomplete |
4100 CXTranslationUnit_DetailedPreprocessingRecord |
4101 CXTranslationUnit_ForSerialization,
4102 &TU);
4103 if (Err != CXError_Success) {
4104 fprintf(stderrstderr, "Unable to load translation unit!\n");
4105 describeLibclangFailure(Err);
4106 free_remapped_files(unsaved_files, num_unsaved_files);
4107 clang_disposeTranslationUnit(TU);
4108 clang_disposeIndex(Idx);
4109 return 1;
4110 }
4111
4112 switch (clang_saveTranslationUnit(TU, filename,
4113 clang_defaultSaveOptions(TU))) {
4114 case CXSaveError_None:
4115 break;
4116
4117 case CXSaveError_TranslationErrors:
4118 fprintf(stderrstderr, "Unable to write PCH file %s: translation errors\n",
4119 filename);
4120 result = 2;
4121 break;
4122
4123 case CXSaveError_InvalidTU:
4124 fprintf(stderrstderr, "Unable to write PCH file %s: invalid translation unit\n",
4125 filename);
4126 result = 3;
4127 break;
4128
4129 case CXSaveError_Unknown:
4130 default:
4131 fprintf(stderrstderr, "Unable to write PCH file %s: unknown error \n", filename);
4132 result = 1;
4133 break;
4134 }
4135
4136 clang_disposeTranslationUnit(TU);
4137 free_remapped_files(unsaved_files, num_unsaved_files);
4138 clang_disposeIndex(Idx);
4139 return result;
4140}
4141
4142/******************************************************************************/
4143/* Serialized diagnostics. */
4144/******************************************************************************/
4145
4146static const char *getDiagnosticCodeStr(enum CXLoadDiag_Error error) {
4147 switch (error) {
4148 case CXLoadDiag_CannotLoad: return "Cannot Load File";
4149 case CXLoadDiag_None: break;
4150 case CXLoadDiag_Unknown: return "Unknown";
4151 case CXLoadDiag_InvalidFile: return "Invalid File";
4152 }
4153 return "None";
4154}
4155
4156static const char *getSeverityString(enum CXDiagnosticSeverity severity) {
4157 switch (severity) {
4158 case CXDiagnostic_Note: return "note";
4159 case CXDiagnostic_Error: return "error";
4160 case CXDiagnostic_Fatal: return "fatal";
4161 case CXDiagnostic_Ignored: return "ignored";
4162 case CXDiagnostic_Warning: return "warning";
4163 }
4164 return "unknown";
4165}
4166
4167static void printIndent(unsigned indent) {
4168 if (indent == 0)
4169 return;
4170 fprintf(stderrstderr, "+");
4171 --indent;
4172 while (indent > 0) {
4173 fprintf(stderrstderr, "-");
4174 --indent;
4175 }
4176}
4177
4178static void printLocation(CXSourceLocation L) {
4179 CXFile File;
4180 CXString FileName;
4181 unsigned line, column, offset;
4182
4183 clang_getExpansionLocation(L, &File, &line, &column, &offset);
4184 FileName = clang_getFileName(File);
4185
4186 fprintf(stderrstderr, "%s:%d:%d", clang_getCString(FileName), line, column);
4187 clang_disposeString(FileName);
4188}
4189
4190static void printRanges(CXDiagnostic D, unsigned indent) {
4191 unsigned i, n = clang_getDiagnosticNumRanges(D);
4192
4193 for (i = 0; i < n; ++i) {
4194 CXSourceLocation Start, End;
4195 CXSourceRange SR = clang_getDiagnosticRange(D, i);
4196 Start = clang_getRangeStart(SR);
4197 End = clang_getRangeEnd(SR);
4198
4199 printIndent(indent);
4200 fprintf(stderrstderr, "Range: ");
4201 printLocation(Start);
4202 fprintf(stderrstderr, " ");
4203 printLocation(End);
4204 fprintf(stderrstderr, "\n");
4205 }
4206}
4207
4208static void printFixIts(CXDiagnostic D, unsigned indent) {
4209 unsigned i, n = clang_getDiagnosticNumFixIts(D);
4210 fprintf(stderrstderr, "Number FIXITs = %d\n", n);
4211 for (i = 0 ; i < n; ++i) {
4212 CXSourceRange ReplacementRange;
4213 CXString text;
4214 text = clang_getDiagnosticFixIt(D, i, &ReplacementRange);
4215
4216 printIndent(indent);
4217 fprintf(stderrstderr, "FIXIT: (");
4218 printLocation(clang_getRangeStart(ReplacementRange));
4219 fprintf(stderrstderr, " - ");
4220 printLocation(clang_getRangeEnd(ReplacementRange));
4221 fprintf(stderrstderr, "): \"%s\"\n", clang_getCString(text));
4222 clang_disposeString(text);
4223 }
4224}
4225
4226static void printDiagnosticSet(CXDiagnosticSet Diags, unsigned indent) {
4227 unsigned i, n;
4228
4229 if (!Diags)
4230 return;
4231
4232 n = clang_getNumDiagnosticsInSet(Diags);
4233 for (i = 0; i < n; ++i) {
4234 CXSourceLocation DiagLoc;
4235 CXDiagnostic D;
4236 CXFile File;
4237 CXString FileName, DiagSpelling, DiagOption, DiagCat;
4238 unsigned line, column, offset;
4239 const char *DiagOptionStr = 0, *DiagCatStr = 0;
4240
4241 D = clang_getDiagnosticInSet(Diags, i);
4242 DiagLoc = clang_getDiagnosticLocation(D);
4243 clang_getExpansionLocation(DiagLoc, &File, &line, &column, &offset);
4244 FileName = clang_getFileName(File);
4245 DiagSpelling = clang_getDiagnosticSpelling(D);
4246
4247 printIndent(indent);
4248
4249 fprintf(stderrstderr, "%s:%d:%d: %s: %s",
4250 clang_getCString(FileName),
4251 line,
4252 column,
4253 getSeverityString(clang_getDiagnosticSeverity(D)),
4254 clang_getCString(DiagSpelling));
4255
4256 DiagOption = clang_getDiagnosticOption(D, 0);
4257 DiagOptionStr = clang_getCString(DiagOption);
4258 if (DiagOptionStr) {
4259 fprintf(stderrstderr, " [%s]", DiagOptionStr);
4260 }
4261
4262 DiagCat = clang_getDiagnosticCategoryText(D);
4263 DiagCatStr = clang_getCString(DiagCat);
4264 if (DiagCatStr) {
4265 fprintf(stderrstderr, " [%s]", DiagCatStr);
4266 }
4267
4268 fprintf(stderrstderr, "\n");
4269
4270 printRanges(D, indent);
4271 printFixIts(D, indent);
4272
4273 /* Print subdiagnostics. */
4274 printDiagnosticSet(clang_getChildDiagnostics(D), indent+2);
4275
4276 clang_disposeString(FileName);
4277 clang_disposeString(DiagSpelling);
4278 clang_disposeString(DiagOption);
4279 clang_disposeString(DiagCat);
4280 }
4281}
4282
4283static int read_diagnostics(const char *filename) {
4284 enum CXLoadDiag_Error error;
4285 CXString errorString;
4286 CXDiagnosticSet Diags = 0;
4287
4288 Diags = clang_loadDiagnostics(filename, &error, &errorString);
4289 if (!Diags) {
4290 fprintf(stderrstderr, "Trouble deserializing file (%s): %s\n",
4291 getDiagnosticCodeStr(error),
4292 clang_getCString(errorString));
4293 clang_disposeString(errorString);
4294 return 1;
4295 }
4296
4297 printDiagnosticSet(Diags, 0);
4298 fprintf(stderrstderr, "Number of diagnostics: %d\n",
4299 clang_getNumDiagnosticsInSet(Diags));
4300 clang_disposeDiagnosticSet(Diags);
4301 return 0;
4302}
4303
4304static int perform_print_build_session_timestamp(void) {
4305 printf("%lld\n", clang_getBuildSessionTimestamp());
4306 return 0;
4307}
4308
4309/******************************************************************************/
4310/* Command line processing. */
4311/******************************************************************************/
4312
4313static CXCursorVisitor GetVisitor(const char *s) {
4314 if (s[0] == '\0')
4315 return FilteredPrintingVisitor;
4316 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)
4317 return USRVisitor;
4318 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)
4319 return GetVisitor(s + 13);
4320 return NULL((void*)0);
4321}
4322
4323static void print_usage(void) {
4324 fprintf(stderrstderr,
4325 "usage: c-index-test -code-completion-at=<site> <compiler arguments>\n"
4326 " c-index-test -code-completion-timing=<site> <compiler arguments>\n"
4327 " c-index-test -cursor-at=<site> <compiler arguments>\n"
4328 " c-index-test -evaluate-cursor-at=<site> <compiler arguments>\n"
4329 " c-index-test -get-macro-info-cursor-at=<site> <compiler arguments>\n"
4330 " c-index-test -file-refs-at=<site> <compiler arguments>\n"
4331 " c-index-test -file-includes-in=<filename> <compiler arguments>\n");
4332 fprintf(stderrstderr,
4333 " c-index-test -index-file [-check-prefix=<FileCheck prefix>] <compiler arguments>\n"
4334 " c-index-test -index-file-full [-check-prefix=<FileCheck prefix>] <compiler arguments>\n"
4335 " c-index-test -index-tu [-check-prefix=<FileCheck prefix>] <AST file>\n"
4336 " c-index-test -index-compile-db [-check-prefix=<FileCheck prefix>] <compilation database>\n"
4337 " c-index-test -test-file-scan <AST file> <source file> "
4338 "[FileCheck prefix]\n");
4339 fprintf(stderrstderr,
4340 " c-index-test -test-load-tu <AST file> <symbol filter> "
4341 "[FileCheck prefix]\n"
4342 " c-index-test -test-load-tu-usrs <AST file> <symbol filter> "
4343 "[FileCheck prefix]\n"
4344 " c-index-test -test-load-source <symbol filter> {<args>}*\n");
4345 fprintf(stderrstderr,
4346 " c-index-test -test-load-source-memory-usage "
4347 "<symbol filter> {<args>}*\n"
4348 " c-index-test -test-load-source-reparse <trials> <symbol filter> "
4349 " {<args>}*\n"
4350 " c-index-test -test-load-source-usrs <symbol filter> {<args>}*\n"
4351 " c-index-test -test-load-source-usrs-memory-usage "
4352 "<symbol filter> {<args>}*\n"
4353 " c-index-test -test-annotate-tokens=<range> {<args>}*\n"
4354 " c-index-test -test-inclusion-stack-source {<args>}*\n"
4355 " c-index-test -test-inclusion-stack-tu <AST file>\n");
4356 fprintf(stderrstderr,
4357 " c-index-test -test-print-linkage-source {<args>}*\n"
4358 " c-index-test -test-print-visibility {<args>}*\n"
4359 " c-index-test -test-print-type {<args>}*\n"
4360 " c-index-test -test-print-type-size {<args>}*\n"
4361 " c-index-test -test-print-bitwidth {<args>}*\n"
4362 " c-index-test -test-print-target-info {<args>}*\n"
4363 " c-index-test -test-print-type-declaration {<args>}*\n"
4364 " c-index-test -print-usr [<CursorKind> {<args>}]*\n"
4365 " c-index-test -print-usr-file <file>\n");
4366 fprintf(stderrstderr,
4367 " c-index-test -write-pch <file> <compiler arguments>\n"
4368 " c-index-test -compilation-db [lookup <filename>] database\n");
4369 fprintf(stderrstderr,
4370 " c-index-test -print-build-session-timestamp\n");
4371 fprintf(stderrstderr,
4372 " c-index-test -read-diagnostics <file>\n\n");
4373 fprintf(stderrstderr,
4374 " <symbol filter> values:\n%s",
4375 " all - load all symbols, including those from PCH\n"
4376 " local - load all symbols except those in PCH\n"
4377 " category - only load ObjC categories (non-PCH)\n"
4378 " interface - only load ObjC interfaces (non-PCH)\n"
4379 " protocol - only load ObjC protocols (non-PCH)\n"
4380 " function - only load functions (non-PCH)\n"
4381 " typedef - only load typdefs (non-PCH)\n"
4382 " scan-function - scan function bodies (non-PCH)\n\n");
4383}
4384
4385/***/
4386
4387int cindextest_main(int argc, const char **argv) {
4388 clang_enableStackTraces();
4389 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)
4390 return read_diagnostics(argv[2]);
4391 if (argc > 2 && strstr(argv[1], "-code-completion-at=") == argv[1])
4392 return perform_code_completion(argc, argv, 0);
4393 if (argc > 2 && strstr(argv[1], "-code-completion-timing=") == argv[1])
4394 return perform_code_completion(argc, argv, 1);
4395 if (argc > 2 && strstr(argv[1], "-cursor-at=") == argv[1])
4396 return inspect_cursor_at(argc, argv, "-cursor-at=", inspect_print_cursor);
4397 if (argc > 2 && strstr(argv[1], "-evaluate-cursor-at=") == argv[1])
4398 return inspect_cursor_at(argc, argv, "-evaluate-cursor-at=",
4399 inspect_evaluate_cursor);
4400 if (argc > 2 && strstr(argv[1], "-get-macro-info-cursor-at=") == argv[1])
4401 return inspect_cursor_at(argc, argv, "-get-macro-info-cursor-at=",
4402 inspect_macroinfo_cursor);
4403 if (argc > 2 && strstr(argv[1], "-file-refs-at=") == argv[1])
4404 return find_file_refs_at(argc, argv);
4405 if (argc > 2 && strstr(argv[1], "-file-includes-in=") == argv[1])
4406 return find_file_includes_in(argc, argv);
4407 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)
4408 return index_file(argc - 2, argv + 2, /*full=*/0);
4409 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)
4410 return index_file(argc - 2, argv + 2, /*full=*/1);
4411 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)
4412 return index_tu(argc - 2, argv + 2);
4413 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)
4414 return index_compile_db(argc - 2, argv + 2);
4415 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) {
4416 CXCursorVisitor I = GetVisitor(argv[1] + 13);
4417 if (I)
4418 return perform_test_load_tu(argv[2], argv[3], argc >= 5 ? argv[4] : 0, I,
4419 NULL((void*)0));
4420 }
4421 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){
4422 CXCursorVisitor I = GetVisitor(argv[1] + 25);
4423 if (I) {
4424 int trials = atoi(argv[2]);
4425 return perform_test_reparse_source(argc - 4, argv + 4, trials, argv[3], I,
4426 NULL((void*)0));
4427 }
4428 }
4429 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) {
4430 CXCursorVisitor I = GetVisitor(argv[1] + 17);
4431
4432 PostVisitTU postVisit = 0;
4433 if (strstr(argv[1], "-memory-usage"))
4434 postVisit = PrintMemoryUsage;
4435
4436 if (I)
4437 return perform_test_load_source(argc - 3, argv + 3, argv[2], I,
4438 postVisit);
4439 }
4440 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)
4441 return perform_file_scan(argv[2], argv[3],
4442 argc >= 5 ? argv[4] : 0);
4443 else if (argc > 2 && strstr(argv[1], "-test-annotate-tokens=") == argv[1])
4444 return perform_token_annotation(argc, argv);
4445 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)
4446 return perform_test_load_source(argc - 2, argv + 2, "all", NULL((void*)0),
4447 PrintInclusionStack);
4448 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)
4449 return perform_test_load_tu(argv[2], "all", NULL((void*)0), NULL((void*)0),
4450 PrintInclusionStack);
4451 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)
4452 return perform_test_load_source(argc - 2, argv + 2, "all", PrintLinkage,
4453 NULL((void*)0));
4454 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)
4455 return perform_test_load_source(argc - 2, argv + 2, "all", PrintVisibility,
4456 NULL((void*)0));
4457 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)
4458 return perform_test_load_source(argc - 2, argv + 2, "all",
4459 PrintType, 0);
4460 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)
4461 return perform_test_load_source(argc - 2, argv + 2, "all",
4462 PrintTypeSize, 0);
4463 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)
4464 return perform_test_load_source(argc - 2, argv + 2, "all",
4465 PrintTypeDeclaration, 0);
4466 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)
4467 return perform_test_load_source(argc - 2, argv + 2, "all",
4468 PrintBitWidth, 0);
4469 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)
4470 return perform_test_load_tu(argv[2], "all", NULL((void*)0), PrintMangledName, NULL((void*)0));
4471 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)
4472 return perform_test_load_tu(argv[2], "all", NULL((void*)0), PrintManglings, NULL((void*)0));
4473 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)
4474 return print_target_info(argc - 2, argv + 2);
4475 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) {
4476 if (argc > 2)
4477 return print_usrs(argv + 2, argv + argc);
4478 else {
4479 display_usrs();
4480 return 1;
4481 }
4482 }
4483 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)
4484 return print_usrs_file(argv[2]);
4485 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)
4486 return write_pch_file(argv[2], argc - 3, argv + 3);
4487 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)
4488 return perform_test_compilation_db(argv[argc-1], argc - 3, argv + 2);
4489 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)
4490 return perform_print_build_session_timestamp();
4491
4492 print_usage();
4493 return 1;
4494}
4495
4496/***/
4497
4498/* We intentionally run in a separate thread to ensure we at least minimal
4499 * testing of a multithreaded environment (for example, having a reduced stack
4500 * size). */
4501
4502typedef struct thread_info {
4503 int (*main_func)(int argc, const char **argv);
4504 int argc;
4505 const char **argv;
4506 int result;
4507} thread_info;
4508void thread_runner(void *client_data_v) {
4509 thread_info *client_data = client_data_v;
4510 client_data->result = client_data->main_func(client_data->argc,
4511 client_data->argv);
4512}
4513
4514static void flush_atexit(void) {
4515 /* stdout, and surprisingly even stderr, are not always flushed on process
4516 * and thread exit, particularly when the system is under heavy load. */
4517 fflush(stdoutstdout);
4518 fflush(stderrstderr);
4519}
4520
4521int main(int argc, const char **argv) {
4522 thread_info client_data;
4523
4524 atexit(flush_atexit);
4525
4526#ifdef CLANG_HAVE_LIBXML
4527 LIBXML_TEST_VERSION
4528#endif
4529
4530 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)
4531 return indextest_core_main(argc, argv);
4532
4533 client_data.main_func = cindextest_main;
4534 client_data.argc = argc;
4535 client_data.argv = argv;
4536
4537 if (getenv("CINDEXTEST_NOTHREADS"))
4538 return client_data.main_func(client_data.argc, client_data.argv);
4539
4540 clang_executeOnThread(thread_runner, &client_data, 0);
4541 return client_data.result;
4542}