Bug Summary

File:tools/clang/tools/c-index-test/c-index-test.c
Warning:line 2882, column 13
Potential leak of memory pointed to by 'Filenames'

Annotated Source Code

[?] Use j/k keys for keyboard navigation

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