Bug Summary

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

Annotated Source Code

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