Bug Summary

File:tools/clang/tools/c-index-test/c-index-test.c
Warning:line 2770, 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)))((void) sizeof ((*num_unsaved_files < (int)(sizeof(arg_indices
)/sizeof(int))) ? 1 : 0), __extension__ ({ if (*num_unsaved_files
< (int)(sizeof(arg_indices)/sizeof(int))) ; else __assert_fail
("*num_unsaved_files < (int)(sizeof(arg_indices)/sizeof(int))"
, "/build/llvm-toolchain-snapshot-6.0~svn320613/tools/clang/tools/c-index-test/c-index-test.c"
, 161, __extension__ __PRETTY_FUNCTION__); }))
;
162 arg_indices[*num_unsaved_files] = arg;
163 ++*num_unsaved_files;
164 }
165
166 if (*num_unsaved_files == 0)
167 return 0;
168
169 *unsaved_files
170 = (struct CXUnsavedFile *)malloc(sizeof(struct CXUnsavedFile) *
171 *num_unsaved_files);
172 for (i = 0; i != *num_unsaved_files; ++i) {
173 struct CXUnsavedFile *unsaved = *unsaved_files + i;
174 const char *arg_string = argv[arg_indices[i]] + prefix_len;
175 int filename_len;
176 char *filename;
177 char *contents;
178 FILE *to_file;
179 const char *sep = strchr(arg_string, ',')(__extension__ (__builtin_constant_p (',') && !__builtin_constant_p
(arg_string) && (',') == '\0' ? (char *) __rawmemchr
(arg_string, ',') : __builtin_strchr (arg_string, ',')))
;
180 if (!sep) {
181 fprintf(stderrstderr,
182 "error: %sfrom:to argument is missing comma\n", opt_name);
183 free_remapped_files(*unsaved_files, i);
184 *unsaved_files = 0;
185 *num_unsaved_files = 0;
186 return -1;
187 }
188
189 /* Open the file that we're remapping to. */
190 to_file = fopen(sep + 1, "rb");
191 if (!to_file) {
192 fprintf(stderrstderr, "error: cannot open file %s that we are remapping to\n",
193 sep + 1);
194 free_remapped_files(*unsaved_files, i);
195 *unsaved_files = 0;
196 *num_unsaved_files = 0;
197 return -1;
198 }
199
200 /* Determine the length of the file we're remapping to. */
201 fseek(to_file, 0, SEEK_END2);
202 unsaved->Length = ftell(to_file);
203 fseek(to_file, 0, SEEK_SET0);
204
205 /* Read the contents of the file we're remapping to. */
206 contents = (char *)malloc(unsaved->Length + 1);
207 if (fread(contents, 1, unsaved->Length, to_file) != unsaved->Length) {
208 fprintf(stderrstderr, "error: unexpected %s reading 'to' file %s\n",
209 (feof(to_file) ? "EOF" : "error"), sep + 1);
210 fclose(to_file);
211 free_remapped_files(*unsaved_files, i);
212 free(contents);
213 *unsaved_files = 0;
214 *num_unsaved_files = 0;
215 return -1;
216 }
217 contents[unsaved->Length] = 0;
218 unsaved->Contents = contents;
219
220 /* Close the file. */
221 fclose(to_file);
222
223 /* Copy the file name that we're remapping from. */
224 filename_len = sep - arg_string;
225 filename = (char *)malloc(filename_len + 1);
226 memcpy(filename, arg_string, filename_len);
227 filename[filename_len] = 0;
228 unsaved->Filename = filename;
229 }
230
231 return 0;
232}
233
234static int parse_remapped_files(int argc, const char **argv, int start_arg,
235 struct CXUnsavedFile **unsaved_files,
236 int *num_unsaved_files) {
237 return parse_remapped_files_with_opt("-remap-file=", argc, argv, start_arg,
238 unsaved_files, num_unsaved_files);
239}
240
241static int parse_remapped_files_with_try(int try_idx,
242 int argc, const char **argv,
243 int start_arg,
244 struct CXUnsavedFile **unsaved_files,
245 int *num_unsaved_files) {
246 struct CXUnsavedFile *unsaved_files_no_try_idx;
247 int num_unsaved_files_no_try_idx;
248 struct CXUnsavedFile *unsaved_files_try_idx;
249 int num_unsaved_files_try_idx;
250 int ret;
251 char opt_name[32];
252
253 ret = parse_remapped_files(argc, argv, start_arg,
254 &unsaved_files_no_try_idx, &num_unsaved_files_no_try_idx);
255 if (ret)
256 return ret;
257
258 sprintf(opt_name, "-remap-file-%d=", try_idx);
259 ret = parse_remapped_files_with_opt(opt_name, argc, argv, start_arg,
260 &unsaved_files_try_idx, &num_unsaved_files_try_idx);
261 if (ret)
262 return ret;
263
264 if (num_unsaved_files_no_try_idx == 0) {
265 *unsaved_files = unsaved_files_try_idx;
266 *num_unsaved_files = num_unsaved_files_try_idx;
267 return 0;
268 }
269 if (num_unsaved_files_try_idx == 0) {
270 *unsaved_files = unsaved_files_no_try_idx;
271 *num_unsaved_files = num_unsaved_files_no_try_idx;
272 return 0;
273 }
274
275 *num_unsaved_files = num_unsaved_files_no_try_idx + num_unsaved_files_try_idx;
276 *unsaved_files
277 = (struct CXUnsavedFile *)realloc(unsaved_files_no_try_idx,
278 sizeof(struct CXUnsavedFile) *
279 *num_unsaved_files);
280 memcpy(*unsaved_files + num_unsaved_files_no_try_idx,
281 unsaved_files_try_idx, sizeof(struct CXUnsavedFile) *
282 num_unsaved_files_try_idx);
283 free(unsaved_files_try_idx);
284 return 0;
285}
286
287static const char *parse_comments_schema(int argc, const char **argv) {
288 const char *CommentsSchemaArg = "-comments-xml-schema=";
289 const char *CommentSchemaFile = NULL((void*)0);
290
291 if (argc == 0)
292 return CommentSchemaFile;
293
294 if (!strncmp(argv[0], CommentsSchemaArg, strlen(CommentsSchemaArg))(__extension__ (__builtin_constant_p (strlen(CommentsSchemaArg
)) && ((__builtin_constant_p (argv[0]) && strlen
(argv[0]) < ((size_t) (strlen(CommentsSchemaArg)))) || (__builtin_constant_p
(CommentsSchemaArg) && strlen (CommentsSchemaArg) <
((size_t) (strlen(CommentsSchemaArg))))) ? __extension__ ({ size_t
__s1_len, __s2_len; (__builtin_constant_p (argv[0]) &&
__builtin_constant_p (CommentsSchemaArg) && (__s1_len
= __builtin_strlen (argv[0]), __s2_len = __builtin_strlen (CommentsSchemaArg
), (!((size_t)(const void *)((argv[0]) + 1) - (size_t)(const void
*)(argv[0]) == 1) || __s1_len >= 4) && (!((size_t
)(const void *)((CommentsSchemaArg) + 1) - (size_t)(const void
*)(CommentsSchemaArg) == 1) || __s2_len >= 4)) ? __builtin_strcmp
(argv[0], CommentsSchemaArg) : (__builtin_constant_p (argv[0
]) && ((size_t)(const void *)((argv[0]) + 1) - (size_t
)(const void *)(argv[0]) == 1) && (__s1_len = __builtin_strlen
(argv[0]), __s1_len < 4) ? (__builtin_constant_p (CommentsSchemaArg
) && ((size_t)(const void *)((CommentsSchemaArg) + 1)
- (size_t)(const void *)(CommentsSchemaArg) == 1) ? __builtin_strcmp
(argv[0], CommentsSchemaArg) : (__extension__ ({ const unsigned
char *__s2 = (const unsigned char *) (const char *) (CommentsSchemaArg
); int __result = (((const unsigned char *) (const char *) (argv
[0]))[0] - __s2[0]); if (__s1_len > 0 && __result ==
0) { __result = (((const unsigned char *) (const char *) (argv
[0]))[1] - __s2[1]); if (__s1_len > 1 && __result ==
0) { __result = (((const unsigned char *) (const char *) (argv
[0]))[2] - __s2[2]); if (__s1_len > 2 && __result ==
0) __result = (((const unsigned char *) (const char *) (argv
[0]))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p
(CommentsSchemaArg) && ((size_t)(const void *)((CommentsSchemaArg
) + 1) - (size_t)(const void *)(CommentsSchemaArg) == 1) &&
(__s2_len = __builtin_strlen (CommentsSchemaArg), __s2_len <
4) ? (__builtin_constant_p (argv[0]) && ((size_t)(const
void *)((argv[0]) + 1) - (size_t)(const void *)(argv[0]) == 1
) ? __builtin_strcmp (argv[0], CommentsSchemaArg) : -(__extension__
({ const unsigned char *__s2 = (const unsigned char *) (const
char *) (argv[0]); int __result = (((const unsigned char *) (
const char *) (CommentsSchemaArg))[0] - __s2[0]); if (__s2_len
> 0 && __result == 0) { __result = (((const unsigned
char *) (const char *) (CommentsSchemaArg))[1] - __s2[1]); if
(__s2_len > 1 && __result == 0) { __result = (((const
unsigned char *) (const char *) (CommentsSchemaArg))[2] - __s2
[2]); if (__s2_len > 2 && __result == 0) __result =
(((const unsigned char *) (const char *) (CommentsSchemaArg)
)[3] - __s2[3]); } } __result; }))) : __builtin_strcmp (argv[
0], CommentsSchemaArg)))); }) : strncmp (argv[0], CommentsSchemaArg
, strlen(CommentsSchemaArg))))
)
295 CommentSchemaFile = argv[0] + strlen(CommentsSchemaArg);
296
297 return CommentSchemaFile;
298}
299
300/******************************************************************************/
301/* Pretty-printing. */
302/******************************************************************************/
303
304static const char *FileCheckPrefix = "CHECK";
305
306static void PrintCString(const char *CStr) {
307 if (CStr != NULL((void*)0) && CStr[0] != '\0') {
308 for ( ; *CStr; ++CStr) {
309 const char C = *CStr;
310 switch (C) {
311 case '\n': printf("\\n"); break;
312 case '\r': printf("\\r"); break;
313 case '\t': printf("\\t"); break;
314 case '\v': printf("\\v"); break;
315 case '\f': printf("\\f"); break;
316 default: putchar(C); break;
317 }
318 }
319 }
320}
321
322static void PrintCStringWithPrefix(const char *Prefix, const char *CStr) {
323 printf(" %s=[", Prefix);
324 PrintCString(CStr);
325 printf("]");
326}
327
328static void PrintCXStringAndDispose(CXString Str) {
329 PrintCString(clang_getCString(Str));
330 clang_disposeString(Str);
331}
332
333static void PrintCXStringWithPrefix(const char *Prefix, CXString Str) {
334 PrintCStringWithPrefix(Prefix, clang_getCString(Str));
335}
336
337static void PrintCXStringWithPrefixAndDispose(const char *Prefix,
338 CXString Str) {
339 PrintCStringWithPrefix(Prefix, clang_getCString(Str));
340 clang_disposeString(Str);
341}
342
343static void PrintRange(CXSourceRange R, const char *str) {
344 CXFile begin_file, end_file;
345 unsigned begin_line, begin_column, end_line, end_column;
346
347 clang_getSpellingLocation(clang_getRangeStart(R),
348 &begin_file, &begin_line, &begin_column, 0);
349 clang_getSpellingLocation(clang_getRangeEnd(R),
350 &end_file, &end_line, &end_column, 0);
351 if (!begin_file || !end_file)
352 return;
353
354 if (str)
355 printf(" %s=", str);
356 PrintExtent(stdoutstdout, begin_line, begin_column, end_line, end_column);
357}
358
359int want_display_name = 0;
360
361static void printVersion(const char *Prefix, CXVersion Version) {
362 if (Version.Major < 0)
363 return;
364 printf("%s%d", Prefix, Version.Major);
365
366 if (Version.Minor < 0)
367 return;
368 printf(".%d", Version.Minor);
369
370 if (Version.Subminor < 0)
371 return;
372 printf(".%d", Version.Subminor);
373}
374
375struct CommentASTDumpingContext {
376 int IndentLevel;
377};
378
379static void DumpCXCommentInternal(struct CommentASTDumpingContext *Ctx,
380 CXComment Comment) {
381 unsigned i;
382 unsigned e;
383 enum CXCommentKind Kind = clang_Comment_getKind(Comment);
384
385 Ctx->IndentLevel++;
386 for (i = 0, e = Ctx->IndentLevel; i != e; ++i)
387 printf(" ");
388
389 printf("(");
390 switch (Kind) {
391 case CXComment_Null:
392 printf("CXComment_Null");
393 break;
394 case CXComment_Text:
395 printf("CXComment_Text");
396 PrintCXStringWithPrefixAndDispose("Text",
397 clang_TextComment_getText(Comment));
398 if (clang_Comment_isWhitespace(Comment))
399 printf(" IsWhitespace");
400 if (clang_InlineContentComment_hasTrailingNewline(Comment))
401 printf(" HasTrailingNewline");
402 break;
403 case CXComment_InlineCommand:
404 printf("CXComment_InlineCommand");
405 PrintCXStringWithPrefixAndDispose(
406 "CommandName",
407 clang_InlineCommandComment_getCommandName(Comment));
408 switch (clang_InlineCommandComment_getRenderKind(Comment)) {
409 case CXCommentInlineCommandRenderKind_Normal:
410 printf(" RenderNormal");
411 break;
412 case CXCommentInlineCommandRenderKind_Bold:
413 printf(" RenderBold");
414 break;
415 case CXCommentInlineCommandRenderKind_Monospaced:
416 printf(" RenderMonospaced");
417 break;
418 case CXCommentInlineCommandRenderKind_Emphasized:
419 printf(" RenderEmphasized");
420 break;
421 }
422 for (i = 0, e = clang_InlineCommandComment_getNumArgs(Comment);
423 i != e; ++i) {
424 printf(" Arg[%u]=", i);
425 PrintCXStringAndDispose(
426 clang_InlineCommandComment_getArgText(Comment, i));
427 }
428 if (clang_InlineContentComment_hasTrailingNewline(Comment))
429 printf(" HasTrailingNewline");
430 break;
431 case CXComment_HTMLStartTag: {
432 unsigned NumAttrs;
433 printf("CXComment_HTMLStartTag");
434 PrintCXStringWithPrefixAndDispose(
435 "Name",
436 clang_HTMLTagComment_getTagName(Comment));
437 NumAttrs = clang_HTMLStartTag_getNumAttrs(Comment);
438 if (NumAttrs != 0) {
439 printf(" Attrs:");
440 for (i = 0; i != NumAttrs; ++i) {
441 printf(" ");
442 PrintCXStringAndDispose(clang_HTMLStartTag_getAttrName(Comment, i));
443 printf("=");
444 PrintCXStringAndDispose(clang_HTMLStartTag_getAttrValue(Comment, i));
445 }
446 }
447 if (clang_HTMLStartTagComment_isSelfClosing(Comment))
448 printf(" SelfClosing");
449 if (clang_InlineContentComment_hasTrailingNewline(Comment))
450 printf(" HasTrailingNewline");
451 break;
452 }
453 case CXComment_HTMLEndTag:
454 printf("CXComment_HTMLEndTag");
455 PrintCXStringWithPrefixAndDispose(
456 "Name",
457 clang_HTMLTagComment_getTagName(Comment));
458 if (clang_InlineContentComment_hasTrailingNewline(Comment))
459 printf(" HasTrailingNewline");
460 break;
461 case CXComment_Paragraph:
462 printf("CXComment_Paragraph");
463 if (clang_Comment_isWhitespace(Comment))
464 printf(" IsWhitespace");
465 break;
466 case CXComment_BlockCommand:
467 printf("CXComment_BlockCommand");
468 PrintCXStringWithPrefixAndDispose(
469 "CommandName",
470 clang_BlockCommandComment_getCommandName(Comment));
471 for (i = 0, e = clang_BlockCommandComment_getNumArgs(Comment);
472 i != e; ++i) {
473 printf(" Arg[%u]=", i);
474 PrintCXStringAndDispose(
475 clang_BlockCommandComment_getArgText(Comment, i));
476 }
477 break;
478 case CXComment_ParamCommand:
479 printf("CXComment_ParamCommand");
480 switch (clang_ParamCommandComment_getDirection(Comment)) {
481 case CXCommentParamPassDirection_In:
482 printf(" in");
483 break;
484 case CXCommentParamPassDirection_Out:
485 printf(" out");
486 break;
487 case CXCommentParamPassDirection_InOut:
488 printf(" in,out");
489 break;
490 }
491 if (clang_ParamCommandComment_isDirectionExplicit(Comment))
492 printf(" explicitly");
493 else
494 printf(" implicitly");
495 PrintCXStringWithPrefixAndDispose(
496 "ParamName",
497 clang_ParamCommandComment_getParamName(Comment));
498 if (clang_ParamCommandComment_isParamIndexValid(Comment))
499 printf(" ParamIndex=%u", clang_ParamCommandComment_getParamIndex(Comment));
500 else
501 printf(" ParamIndex=Invalid");
502 break;
503 case CXComment_TParamCommand:
504 printf("CXComment_TParamCommand");
505 PrintCXStringWithPrefixAndDispose(
506 "ParamName",
507 clang_TParamCommandComment_getParamName(Comment));
508 if (clang_TParamCommandComment_isParamPositionValid(Comment)) {
509 printf(" ParamPosition={");
510 for (i = 0, e = clang_TParamCommandComment_getDepth(Comment);
511 i != e; ++i) {
512 printf("%u", clang_TParamCommandComment_getIndex(Comment, i));
513 if (i != e - 1)
514 printf(", ");
515 }
516 printf("}");
517 } else
518 printf(" ParamPosition=Invalid");
519 break;
520 case CXComment_VerbatimBlockCommand:
521 printf("CXComment_VerbatimBlockCommand");
522 PrintCXStringWithPrefixAndDispose(
523 "CommandName",
524 clang_BlockCommandComment_getCommandName(Comment));
525 break;
526 case CXComment_VerbatimBlockLine:
527 printf("CXComment_VerbatimBlockLine");
528 PrintCXStringWithPrefixAndDispose(
529 "Text",
530 clang_VerbatimBlockLineComment_getText(Comment));
531 break;
532 case CXComment_VerbatimLine:
533 printf("CXComment_VerbatimLine");
534 PrintCXStringWithPrefixAndDispose(
535 "Text",
536 clang_VerbatimLineComment_getText(Comment));
537 break;
538 case CXComment_FullComment:
539 printf("CXComment_FullComment");
540 break;
541 }
542 if (Kind != CXComment_Null) {
543 const unsigned NumChildren = clang_Comment_getNumChildren(Comment);
544 unsigned i;
545 for (i = 0; i != NumChildren; ++i) {
546 printf("\n// %s: ", FileCheckPrefix);
547 DumpCXCommentInternal(Ctx, clang_Comment_getChild(Comment, i));
548 }
549 }
550 printf(")");
551 Ctx->IndentLevel--;
552}
553
554static void DumpCXComment(CXComment Comment) {
555 struct CommentASTDumpingContext Ctx;
556 Ctx.IndentLevel = 1;
557 printf("\n// %s: CommentAST=[\n// %s:", FileCheckPrefix, FileCheckPrefix);
558 DumpCXCommentInternal(&Ctx, Comment);
559 printf("]");
560}
561
562static void ValidateCommentXML(const char *Str, const char *CommentSchemaFile) {
563#ifdef CLANG_HAVE_LIBXML
564 xmlRelaxNGParserCtxtPtr RNGParser;
565 xmlRelaxNGPtr Schema;
566 xmlDocPtr Doc;
567 xmlRelaxNGValidCtxtPtr ValidationCtxt;
568 int status;
569
570 if (!CommentSchemaFile)
571 return;
572
573 RNGParser = xmlRelaxNGNewParserCtxt(CommentSchemaFile);
574 if (!RNGParser) {
575 printf(" libXMLError");
576 return;
577 }
578 Schema = xmlRelaxNGParse(RNGParser);
579
580 Doc = xmlParseDoc((const xmlChar *) Str);
581
582 if (!Doc) {
583 xmlErrorPtr Error = xmlGetLastError();
584 printf(" CommentXMLInvalid [not well-formed XML: %s]", Error->message);
585 return;
586 }
587
588 ValidationCtxt = xmlRelaxNGNewValidCtxt(Schema);
589 status = xmlRelaxNGValidateDoc(ValidationCtxt, Doc);
590 if (!status)
591 printf(" CommentXMLValid");
592 else if (status > 0) {
593 xmlErrorPtr Error = xmlGetLastError();
594 printf(" CommentXMLInvalid [not vaild XML: %s]", Error->message);
595 } else
596 printf(" libXMLError");
597
598 xmlRelaxNGFreeValidCtxt(ValidationCtxt);
599 xmlFreeDoc(Doc);
600 xmlRelaxNGFree(Schema);
601 xmlRelaxNGFreeParserCtxt(RNGParser);
602#endif
603}
604
605static void PrintCursorComments(CXCursor Cursor,
606 const char *CommentSchemaFile) {
607 {
608 CXString RawComment;
609 const char *RawCommentCString;
610 CXString BriefComment;
611 const char *BriefCommentCString;
612
613 RawComment = clang_Cursor_getRawCommentText(Cursor);
614 RawCommentCString = clang_getCString(RawComment);
615 if (RawCommentCString != NULL((void*)0) && RawCommentCString[0] != '\0') {
616 PrintCStringWithPrefix("RawComment", RawCommentCString);
617 PrintRange(clang_Cursor_getCommentRange(Cursor), "RawCommentRange");
618
619 BriefComment = clang_Cursor_getBriefCommentText(Cursor);
620 BriefCommentCString = clang_getCString(BriefComment);
621 if (BriefCommentCString != NULL((void*)0) && BriefCommentCString[0] != '\0')
622 PrintCStringWithPrefix("BriefComment", BriefCommentCString);
623 clang_disposeString(BriefComment);
624 }
625 clang_disposeString(RawComment);
626 }
627
628 {
629 CXComment Comment = clang_Cursor_getParsedComment(Cursor);
630 if (clang_Comment_getKind(Comment) != CXComment_Null) {
631 PrintCXStringWithPrefixAndDispose("FullCommentAsHTML",
632 clang_FullComment_getAsHTML(Comment));
633 {
634 CXString XML;
635 XML = clang_FullComment_getAsXML(Comment);
636 PrintCXStringWithPrefix("FullCommentAsXML", XML);
637 ValidateCommentXML(clang_getCString(XML), CommentSchemaFile);
638 clang_disposeString(XML);
639 }
640
641 DumpCXComment(Comment);
642 }
643 }
644}
645
646typedef struct {
647 unsigned line;
648 unsigned col;
649} LineCol;
650
651static int lineCol_cmp(const void *p1, const void *p2) {
652 const LineCol *lhs = p1;
653 const LineCol *rhs = p2;
654 if (lhs->line != rhs->line)
655 return (int)lhs->line - (int)rhs->line;
656 return (int)lhs->col - (int)rhs->col;
657}
658
659static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) {
660 CXTranslationUnit TU = clang_Cursor_getTranslationUnit(Cursor);
661 if (clang_isInvalid(Cursor.kind)) {
662 CXString ks = clang_getCursorKindSpelling(Cursor.kind);
663 printf("Invalid Cursor => %s", clang_getCString(ks));
664 clang_disposeString(ks);
665 }
666 else {
667 CXString string, ks;
668 CXCursor Referenced;
669 unsigned line, column;
670 CXCursor SpecializationOf;
671 CXCursor *overridden;
672 unsigned num_overridden;
673 unsigned RefNameRangeNr;
674 CXSourceRange CursorExtent;
675 CXSourceRange RefNameRange;
676 int AlwaysUnavailable;
677 int AlwaysDeprecated;
678 CXString UnavailableMessage;
679 CXString DeprecatedMessage;
680 CXPlatformAvailability PlatformAvailability[2];
681 int NumPlatformAvailability;
682 int I;
683
684 ks = clang_getCursorKindSpelling(Cursor.kind);
685 string = want_display_name? clang_getCursorDisplayName(Cursor)
686 : clang_getCursorSpelling(Cursor);
687 printf("%s=%s", clang_getCString(ks),
688 clang_getCString(string));
689 clang_disposeString(ks);
690 clang_disposeString(string);
691
692 Referenced = clang_getCursorReferenced(Cursor);
693 if (!clang_equalCursors(Referenced, clang_getNullCursor())) {
694 if (clang_getCursorKind(Referenced) == CXCursor_OverloadedDeclRef) {
695 unsigned I, N = clang_getNumOverloadedDecls(Referenced);
696 printf("[");
697 for (I = 0; I != N; ++I) {
698 CXCursor Ovl = clang_getOverloadedDecl(Referenced, I);
699 CXSourceLocation Loc;
700 if (I)
701 printf(", ");
702
703 Loc = clang_getCursorLocation(Ovl);
704 clang_getSpellingLocation(Loc, 0, &line, &column, 0);
705 printf("%d:%d", line, column);
706 }
707 printf("]");
708 } else {
709 CXSourceLocation Loc = clang_getCursorLocation(Referenced);
710 clang_getSpellingLocation(Loc, 0, &line, &column, 0);
711 printf(":%d:%d", line, column);
712 }
713
714 if (clang_getCursorKind(Referenced) == CXCursor_TypedefDecl) {
715 CXType T = clang_getCursorType(Referenced);
716 if (clang_Type_isTransparentTagTypedef(T)) {
717 CXType Underlying = clang_getTypedefDeclUnderlyingType(Referenced);
718 CXString S = clang_getTypeSpelling(Underlying);
719 printf(" (Transparent: %s)", clang_getCString(S));
720 clang_disposeString(S);
721 }
722 }
723 }
724
725 if (clang_isCursorDefinition(Cursor))
726 printf(" (Definition)");
727
728 switch (clang_getCursorAvailability(Cursor)) {
729 case CXAvailability_Available:
730 break;
731
732 case CXAvailability_Deprecated:
733 printf(" (deprecated)");
734 break;
735
736 case CXAvailability_NotAvailable:
737 printf(" (unavailable)");
738 break;
739
740 case CXAvailability_NotAccessible:
741 printf(" (inaccessible)");
742 break;
743 }
744
745 NumPlatformAvailability
746 = clang_getCursorPlatformAvailability(Cursor,
747 &AlwaysDeprecated,
748 &DeprecatedMessage,
749 &AlwaysUnavailable,
750 &UnavailableMessage,
751 PlatformAvailability, 2);
752 if (AlwaysUnavailable) {
753 printf(" (always unavailable: \"%s\")",
754 clang_getCString(UnavailableMessage));
755 } else if (AlwaysDeprecated) {
756 printf(" (always deprecated: \"%s\")",
757 clang_getCString(DeprecatedMessage));
758 } else {
759 for (I = 0; I != NumPlatformAvailability; ++I) {
760 if (I >= 2)
761 break;
762
763 printf(" (%s", clang_getCString(PlatformAvailability[I].Platform));
764 if (PlatformAvailability[I].Unavailable)
765 printf(", unavailable");
766 else {
767 printVersion(", introduced=", PlatformAvailability[I].Introduced);
768 printVersion(", deprecated=", PlatformAvailability[I].Deprecated);
769 printVersion(", obsoleted=", PlatformAvailability[I].Obsoleted);
770 }
771 if (clang_getCString(PlatformAvailability[I].Message)[0])
772 printf(", message=\"%s\"",
773 clang_getCString(PlatformAvailability[I].Message));
774 printf(")");
775 }
776 }
777 for (I = 0; I != NumPlatformAvailability; ++I) {
778 if (I >= 2)
779 break;
780 clang_disposeCXPlatformAvailability(PlatformAvailability + I);
781 }
782
783 clang_disposeString(DeprecatedMessage);
784 clang_disposeString(UnavailableMessage);
785
786 if (clang_CXXConstructor_isDefaultConstructor(Cursor))
787 printf(" (default constructor)");
788
789 if (clang_CXXConstructor_isMoveConstructor(Cursor))
790 printf(" (move constructor)");
791 if (clang_CXXConstructor_isCopyConstructor(Cursor))
792 printf(" (copy constructor)");
793 if (clang_CXXConstructor_isConvertingConstructor(Cursor))
794 printf(" (converting constructor)");
795 if (clang_CXXField_isMutable(Cursor))
796 printf(" (mutable)");
797 if (clang_CXXMethod_isDefaulted(Cursor))
798 printf(" (defaulted)");
799 if (clang_CXXMethod_isStatic(Cursor))
800 printf(" (static)");
801 if (clang_CXXMethod_isVirtual(Cursor))
802 printf(" (virtual)");
803 if (clang_CXXMethod_isConst(Cursor))
804 printf(" (const)");
805 if (clang_CXXMethod_isPureVirtual(Cursor))
806 printf(" (pure)");
807 if (clang_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)((void) sizeof ((num_overridden <= 50) ? 1 : 0), __extension__
({ if (num_overridden <= 50) ; else __assert_fail ("num_overridden <= 50"
, "/build/llvm-toolchain-snapshot-6.0~svn320613/tools/clang/tools/c-index-test/c-index-test.c"
, 930, __extension__ __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)((void) sizeof ((TArg.kind == CXType_Invalid) ? 1 : 0), __extension__
({ if (TArg.kind == CXType_Invalid) ; else __assert_fail ("TArg.kind == CXType_Invalid"
, "/build/llvm-toolchain-snapshot-6.0~svn320613/tools/clang/tools/c-index-test/c-index-test.c"
, 1389, __extension__ __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 const char *InvocationPath;
1751
1752 Idx = clang_createIndex(/* excludeDeclsFromPCH */
1753 (!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")
))); })
||
1754 !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,
1755 /* displayDiagnostics=*/1);
1756 InvocationPath = getenv("CINDEXTEST_INVOCATION_EMISSION_PATH");
1757 if (InvocationPath)
1758 clang_CXIndex_setInvocationEmissionPathOption(Idx, InvocationPath);
1759
1760 if ((CommentSchemaFile = parse_comments_schema(argc, argv))) {
1761 argc--;
1762 argv++;
1763 }
1764
1765 if (parse_remapped_files(argc, argv, 0, &unsaved_files, &num_unsaved_files)) {
1766 clang_disposeIndex(Idx);
1767 return -1;
1768 }
1769
1770 if (getenv("CINDEXTEST_EDITING"))
1771 Repeats = 5;
1772
1773 Err = clang_parseTranslationUnit2(Idx, 0,
1774 argv + num_unsaved_files,
1775 argc - num_unsaved_files,
1776 unsaved_files, num_unsaved_files,
1777 getDefaultParsingOptions(), &TU);
1778 if (Err != CXError_Success) {
1779 fprintf(stderrstderr, "Unable to load translation unit!\n");
1780 describeLibclangFailure(Err);
1781 free_remapped_files(unsaved_files, num_unsaved_files);
1782 clang_disposeIndex(Idx);
1783 return 1;
1784 }
1785
1786 for (I = 0; I != Repeats; ++I) {
1787 if (checkForErrors(TU) != 0)
1788 return -1;
1789
1790 if (Repeats > 1) {
1791 clang_suspendTranslationUnit(TU);
1792
1793 Err = clang_reparseTranslationUnit(TU, num_unsaved_files, unsaved_files,
1794 clang_defaultReparseOptions(TU));
1795 if (Err != CXError_Success) {
1796 describeLibclangFailure(Err);
1797 free_remapped_files(unsaved_files, num_unsaved_files);
1798 clang_disposeIndex(Idx);
1799 return 1;
1800 }
1801 }
1802 }
1803
1804 result = perform_test_load(Idx, TU, filter, NULL((void*)0), Visitor, PV,
1805 CommentSchemaFile);
1806 free_remapped_files(unsaved_files, num_unsaved_files);
1807 clang_disposeIndex(Idx);
1808 return result;
1809}
1810
1811int perform_test_reparse_source(int argc, const char **argv, int trials,
1812 const char *filter, CXCursorVisitor Visitor,
1813 PostVisitTU PV) {
1814 CXIndex Idx;
1815 CXTranslationUnit TU;
1816 struct CXUnsavedFile *unsaved_files = 0;
1817 int num_unsaved_files = 0;
1818 int compiler_arg_idx = 0;
1819 enum CXErrorCode Err;
1820 int result, i;
1821 int trial;
1822 int remap_after_trial = 0;
1823 char *endptr = 0;
1824
1825 Idx = clang_createIndex(/* excludeDeclsFromPCH */
1826 !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,
1827 /* displayDiagnostics=*/1);
1828
1829 if (parse_remapped_files(argc, argv, 0, &unsaved_files, &num_unsaved_files)) {
1830 clang_disposeIndex(Idx);
1831 return -1;
1832 }
1833
1834 for (i = 0; i < argc; ++i) {
1835 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)
1836 break;
1837 }
1838 if (i < argc)
1839 compiler_arg_idx = i+1;
1840 if (num_unsaved_files > compiler_arg_idx)
1841 compiler_arg_idx = num_unsaved_files;
1842
1843 /* Load the initial translation unit -- we do this without honoring remapped
1844 * files, so that we have a way to test results after changing the source. */
1845 Err = clang_parseTranslationUnit2(Idx, 0,
1846 argv + compiler_arg_idx,
1847 argc - compiler_arg_idx,
1848 0, 0, getDefaultParsingOptions(), &TU);
1849 if (Err != CXError_Success) {
1850 fprintf(stderrstderr, "Unable to load translation unit!\n");
1851 describeLibclangFailure(Err);
1852 free_remapped_files(unsaved_files, num_unsaved_files);
1853 clang_disposeIndex(Idx);
1854 return 1;
1855 }
1856
1857 if (checkForErrors(TU) != 0)
1858 return -1;
1859
1860 if (getenv("CINDEXTEST_REMAP_AFTER_TRIAL")) {
1861 remap_after_trial =
1862 strtol(getenv("CINDEXTEST_REMAP_AFTER_TRIAL"), &endptr, 10);
1863 }
1864
1865 for (trial = 0; trial < trials; ++trial) {
1866 free_remapped_files(unsaved_files, num_unsaved_files);
1867 if (parse_remapped_files_with_try(trial, argc, argv, 0,
1868 &unsaved_files, &num_unsaved_files)) {
1869 clang_disposeTranslationUnit(TU);
1870 clang_disposeIndex(Idx);
1871 return -1;
1872 }
1873
1874 Err = clang_reparseTranslationUnit(
1875 TU,
1876 trial >= remap_after_trial ? num_unsaved_files : 0,
1877 trial >= remap_after_trial ? unsaved_files : 0,
1878 clang_defaultReparseOptions(TU));
1879 if (Err != CXError_Success) {
1880 fprintf(stderrstderr, "Unable to reparse translation unit!\n");
1881 describeLibclangFailure(Err);
1882 clang_disposeTranslationUnit(TU);
1883 free_remapped_files(unsaved_files, num_unsaved_files);
1884 clang_disposeIndex(Idx);
1885 return -1;
1886 }
1887
1888 if (checkForErrors(TU) != 0)
1889 return -1;
1890 }
1891
1892 result = perform_test_load(Idx, TU, filter, NULL((void*)0), Visitor, PV, NULL((void*)0));
1893
1894 free_remapped_files(unsaved_files, num_unsaved_files);
1895 clang_disposeIndex(Idx);
1896 return result;
1897}
1898
1899static int perform_single_file_parse(const char *filename) {
1900 CXIndex Idx;
1901 CXTranslationUnit TU;
1902 enum CXErrorCode Err;
1903 int result;
1904
1905 Idx = clang_createIndex(/* excludeDeclsFromPCH */1,
1906 /* displayDiagnostics=*/1);
1907
1908 Err = clang_parseTranslationUnit2(Idx, filename,
1909 /*command_line_args=*/NULL((void*)0),
1910 /*num_command_line_args=*/0,
1911 /*unsaved_files=*/NULL((void*)0),
1912 /*num_unsaved_files=*/0,
1913 CXTranslationUnit_SingleFileParse, &TU);
1914 if (Err != CXError_Success) {
1915 fprintf(stderrstderr, "Unable to load translation unit!\n");
1916 describeLibclangFailure(Err);
1917 clang_disposeIndex(Idx);
1918 return 1;
1919 }
1920
1921 result = perform_test_load(Idx, TU, /*filter=*/"all", /*prefix=*/NULL((void*)0), FilteredPrintingVisitor, /*PostVisit=*/NULL((void*)0),
1922 /*CommentSchemaFile=*/NULL((void*)0));
1923 clang_disposeIndex(Idx);
1924 return result;
1925}
1926
1927/******************************************************************************/
1928/* Logic for testing clang_getCursor(). */
1929/******************************************************************************/
1930
1931static void print_cursor_file_scan(CXTranslationUnit TU, CXCursor cursor,
1932 unsigned start_line, unsigned start_col,
1933 unsigned end_line, unsigned end_col,
1934 const char *prefix) {
1935 printf("// %s: ", FileCheckPrefix);
1936 if (prefix)
1937 printf("-%s", prefix);
1938 PrintExtent(stdoutstdout, start_line, start_col, end_line, end_col);
1939 printf(" ");
1940 PrintCursor(cursor, NULL((void*)0));
1941 printf("\n");
1942}
1943
1944static int perform_file_scan(const char *ast_file, const char *source_file,
1945 const char *prefix) {
1946 CXIndex Idx;
1947 CXTranslationUnit TU;
1948 FILE *fp;
1949 CXCursor prevCursor = clang_getNullCursor();
1950 CXFile file;
1951 unsigned line = 1, col = 1;
1952 unsigned start_line = 1, start_col = 1;
1953
1954 if (!(Idx = clang_createIndex(/* excludeDeclsFromPCH */ 1,
1955 /* displayDiagnostics=*/1))) {
1956 fprintf(stderrstderr, "Could not create Index\n");
1957 return 1;
1958 }
1959
1960 if (!CreateTranslationUnit(Idx, ast_file, &TU))
1961 return 1;
1962
1963 if ((fp = fopen(source_file, "r")) == NULL((void*)0)) {
1964 fprintf(stderrstderr, "Could not open '%s'\n", source_file);
1965 clang_disposeTranslationUnit(TU);
1966 return 1;
1967 }
1968
1969 file = clang_getFile(TU, source_file);
1970 for (;;) {
1971 CXCursor cursor;
1972 int c = fgetc(fp);
1973
1974 if (c == '\n') {
1975 ++line;
1976 col = 1;
1977 } else
1978 ++col;
1979
1980 /* Check the cursor at this position, and dump the previous one if we have
1981 * found something new.
1982 */
1983 cursor = clang_getCursor(TU, clang_getLocation(TU, file, line, col));
1984 if ((c == EOF(-1) || !clang_equalCursors(cursor, prevCursor)) &&
1985 prevCursor.kind != CXCursor_InvalidFile) {
1986 print_cursor_file_scan(TU, prevCursor, start_line, start_col,
1987 line, col, prefix);
1988 start_line = line;
1989 start_col = col;
1990 }
1991 if (c == EOF(-1))
1992 break;
1993
1994 prevCursor = cursor;
1995 }
1996
1997 fclose(fp);
1998 clang_disposeTranslationUnit(TU);
1999 clang_disposeIndex(Idx);
2000 return 0;
2001}
2002
2003/******************************************************************************/
2004/* Logic for testing clang code completion. */
2005/******************************************************************************/
2006
2007/* Parse file:line:column from the input string. Returns 0 on success, non-zero
2008 on failure. If successful, the pointer *filename will contain newly-allocated
2009 memory (that will be owned by the caller) to store the file name. */
2010int parse_file_line_column(const char *input, char **filename, unsigned *line,
2011 unsigned *column, unsigned *second_line,
2012 unsigned *second_column) {
2013 /* Find the second colon. */
2014 const char *last_colon = strrchr(input, ':');
2015 unsigned values[4], i;
2016 unsigned num_values = (second_line && second_column)? 4 : 2;
2017
2018 char *endptr = 0;
2019 if (!last_colon || last_colon == input) {
2020 if (num_values == 4)
2021 fprintf(stderrstderr, "could not parse filename:line:column:line:column in "
2022 "'%s'\n", input);
2023 else
2024 fprintf(stderrstderr, "could not parse filename:line:column in '%s'\n", input);
2025 return 1;
2026 }
2027
2028 for (i = 0; i != num_values; ++i) {
2029 const char *prev_colon;
2030
2031 /* Parse the next line or column. */
2032 values[num_values - i - 1] = strtol(last_colon + 1, &endptr, 10);
2033 if (*endptr != 0 && *endptr != ':') {
2034 fprintf(stderrstderr, "could not parse %s in '%s'\n",
2035 (i % 2 ? "column" : "line"), input);
2036 return 1;
2037 }
2038
2039 if (i + 1 == num_values)
2040 break;
2041
2042 /* Find the previous colon. */
2043 prev_colon = last_colon - 1;
2044 while (prev_colon != input && *prev_colon != ':')
2045 --prev_colon;
2046 if (prev_colon == input) {
2047 fprintf(stderrstderr, "could not parse %s in '%s'\n",
2048 (i % 2 == 0? "column" : "line"), input);
2049 return 1;
2050 }
2051
2052 last_colon = prev_colon;
2053 }
2054
2055 *line = values[0];
2056 *column = values[1];
2057
2058 if (second_line && second_column) {
2059 *second_line = values[2];
2060 *second_column = values[3];
2061 }
2062
2063 /* Copy the file name. */
2064 *filename = (char*)malloc(last_colon - input + 1);
2065 memcpy(*filename, input, last_colon - input);
2066 (*filename)[last_colon - input] = 0;
2067 return 0;
2068}
2069
2070const char *
2071clang_getCompletionChunkKindSpelling(enum CXCompletionChunkKind Kind) {
2072 switch (Kind) {
2073 case CXCompletionChunk_Optional: return "Optional";
2074 case CXCompletionChunk_TypedText: return "TypedText";
2075 case CXCompletionChunk_Text: return "Text";
2076 case CXCompletionChunk_Placeholder: return "Placeholder";
2077 case CXCompletionChunk_Informative: return "Informative";
2078 case CXCompletionChunk_CurrentParameter: return "CurrentParameter";
2079 case CXCompletionChunk_LeftParen: return "LeftParen";
2080 case CXCompletionChunk_RightParen: return "RightParen";
2081 case CXCompletionChunk_LeftBracket: return "LeftBracket";
2082 case CXCompletionChunk_RightBracket: return "RightBracket";
2083 case CXCompletionChunk_LeftBrace: return "LeftBrace";
2084 case CXCompletionChunk_RightBrace: return "RightBrace";
2085 case CXCompletionChunk_LeftAngle: return "LeftAngle";
2086 case CXCompletionChunk_RightAngle: return "RightAngle";
2087 case CXCompletionChunk_Comma: return "Comma";
2088 case CXCompletionChunk_ResultType: return "ResultType";
2089 case CXCompletionChunk_Colon: return "Colon";
2090 case CXCompletionChunk_SemiColon: return "SemiColon";
2091 case CXCompletionChunk_Equal: return "Equal";
2092 case CXCompletionChunk_HorizontalSpace: return "HorizontalSpace";
2093 case CXCompletionChunk_VerticalSpace: return "VerticalSpace";
2094 }
2095
2096 return "Unknown";
2097}
2098
2099static int checkForErrors(CXTranslationUnit TU) {
2100 unsigned Num, i;
2101 CXDiagnostic Diag;
2102 CXString DiagStr;
2103
2104 if (!getenv("CINDEXTEST_FAILONERROR"))
2105 return 0;
2106
2107 Num = clang_getNumDiagnostics(TU);
2108 for (i = 0; i != Num; ++i) {
2109 Diag = clang_getDiagnostic(TU, i);
2110 if (clang_getDiagnosticSeverity(Diag) >= CXDiagnostic_Error) {
2111 DiagStr = clang_formatDiagnostic(Diag,
2112 clang_defaultDiagnosticDisplayOptions());
2113 fprintf(stderrstderr, "%s\n", clang_getCString(DiagStr));
2114 clang_disposeString(DiagStr);
2115 clang_disposeDiagnostic(Diag);
2116 return -1;
2117 }
2118 clang_disposeDiagnostic(Diag);
2119 }
2120
2121 return 0;
2122}
2123
2124static void print_completion_string(CXCompletionString completion_string,
2125 FILE *file) {
2126 int I, N;
2127
2128 N = clang_getNumCompletionChunks(completion_string);
2129 for (I = 0; I != N; ++I) {
2130 CXString text;
2131 const char *cstr;
2132 enum CXCompletionChunkKind Kind
2133 = clang_getCompletionChunkKind(completion_string, I);
2134
2135 if (Kind == CXCompletionChunk_Optional) {
2136 fprintf(file, "{Optional ");
2137 print_completion_string(
2138 clang_getCompletionChunkCompletionString(completion_string, I),
2139 file);
2140 fprintf(file, "}");
2141 continue;
2142 }
2143
2144 if (Kind == CXCompletionChunk_VerticalSpace) {
2145 fprintf(file, "{VerticalSpace }");
2146 continue;
2147 }
2148
2149 text = clang_getCompletionChunkText(completion_string, I);
2150 cstr = clang_getCString(text);
2151 fprintf(file, "{%s %s}",
2152 clang_getCompletionChunkKindSpelling(Kind),
2153 cstr ? cstr : "");
2154 clang_disposeString(text);
2155 }
2156
2157}
2158
2159static void print_completion_result(CXCompletionResult *completion_result,
2160 FILE *file) {
2161 CXString ks = clang_getCursorKindSpelling(completion_result->CursorKind);
2162 unsigned annotationCount;
2163 enum CXCursorKind ParentKind;
2164 CXString ParentName;
2165 CXString BriefComment;
2166 CXString Annotation;
2167 const char *BriefCommentCString;
2168
2169 fprintf(file, "%s:", clang_getCString(ks));
2170 clang_disposeString(ks);
2171
2172 print_completion_string(completion_result->CompletionString, file);
2173 fprintf(file, " (%u)",
2174 clang_getCompletionPriority(completion_result->CompletionString));
2175 switch (clang_getCompletionAvailability(completion_result->CompletionString)){
2176 case CXAvailability_Available:
2177 break;
2178
2179 case CXAvailability_Deprecated:
2180 fprintf(file, " (deprecated)");
2181 break;
2182
2183 case CXAvailability_NotAvailable:
2184 fprintf(file, " (unavailable)");
2185 break;
2186
2187 case CXAvailability_NotAccessible:
2188 fprintf(file, " (inaccessible)");
2189 break;
2190 }
2191
2192 annotationCount = clang_getCompletionNumAnnotations(
2193 completion_result->CompletionString);
2194 if (annotationCount) {
2195 unsigned i;
2196 fprintf(file, " (");
2197 for (i = 0; i < annotationCount; ++i) {
2198 if (i != 0)
2199 fprintf(file, ", ");
2200 Annotation =
2201 clang_getCompletionAnnotation(completion_result->CompletionString, i);
2202 fprintf(file, "\"%s\"", clang_getCString(Annotation));
2203 clang_disposeString(Annotation);
2204 }
2205 fprintf(file, ")");
2206 }
2207
2208 if (!getenv("CINDEXTEST_NO_COMPLETION_PARENTS")) {
2209 ParentName = clang_getCompletionParent(completion_result->CompletionString,
2210 &ParentKind);
2211 if (ParentKind != CXCursor_NotImplemented) {
2212 CXString KindSpelling = clang_getCursorKindSpelling(ParentKind);
2213 fprintf(file, " (parent: %s '%s')",
2214 clang_getCString(KindSpelling),
2215 clang_getCString(ParentName));
2216 clang_disposeString(KindSpelling);
2217 }
2218 clang_disposeString(ParentName);
2219 }
2220
2221 BriefComment = clang_getCompletionBriefComment(
2222 completion_result->CompletionString);
2223 BriefCommentCString = clang_getCString(BriefComment);
2224 if (BriefCommentCString && *BriefCommentCString != '\0') {
2225 fprintf(file, "(brief comment: %s)", BriefCommentCString);
2226 }
2227 clang_disposeString(BriefComment);
2228
2229 fprintf(file, "\n");
2230}
2231
2232void print_completion_contexts(unsigned long long contexts, FILE *file) {
2233 fprintf(file, "Completion contexts:\n");
2234 if (contexts == CXCompletionContext_Unknown) {
2235 fprintf(file, "Unknown\n");
2236 }
2237 if (contexts & CXCompletionContext_AnyType) {
2238 fprintf(file, "Any type\n");
2239 }
2240 if (contexts & CXCompletionContext_AnyValue) {
2241 fprintf(file, "Any value\n");
2242 }
2243 if (contexts & CXCompletionContext_ObjCObjectValue) {
2244 fprintf(file, "Objective-C object value\n");
2245 }
2246 if (contexts & CXCompletionContext_ObjCSelectorValue) {
2247 fprintf(file, "Objective-C selector value\n");
2248 }
2249 if (contexts & CXCompletionContext_CXXClassTypeValue) {
2250 fprintf(file, "C++ class type value\n");
2251 }
2252 if (contexts & CXCompletionContext_DotMemberAccess) {
2253 fprintf(file, "Dot member access\n");
2254 }
2255 if (contexts & CXCompletionContext_ArrowMemberAccess) {
2256 fprintf(file, "Arrow member access\n");
2257 }
2258 if (contexts & CXCompletionContext_ObjCPropertyAccess) {
2259 fprintf(file, "Objective-C property access\n");
2260 }
2261 if (contexts & CXCompletionContext_EnumTag) {
2262 fprintf(file, "Enum tag\n");
2263 }
2264 if (contexts & CXCompletionContext_UnionTag) {
2265 fprintf(file, "Union tag\n");
2266 }
2267 if (contexts & CXCompletionContext_StructTag) {
2268 fprintf(file, "Struct tag\n");
2269 }
2270 if (contexts & CXCompletionContext_ClassTag) {
2271 fprintf(file, "Class name\n");
2272 }
2273 if (contexts & CXCompletionContext_Namespace) {
2274 fprintf(file, "Namespace or namespace alias\n");
2275 }
2276 if (contexts & CXCompletionContext_NestedNameSpecifier) {
2277 fprintf(file, "Nested name specifier\n");
2278 }
2279 if (contexts & CXCompletionContext_ObjCInterface) {
2280 fprintf(file, "Objective-C interface\n");
2281 }
2282 if (contexts & CXCompletionContext_ObjCProtocol) {
2283 fprintf(file, "Objective-C protocol\n");
2284 }
2285 if (contexts & CXCompletionContext_ObjCCategory) {
2286 fprintf(file, "Objective-C category\n");
2287 }
2288 if (contexts & CXCompletionContext_ObjCInstanceMessage) {
2289 fprintf(file, "Objective-C instance method\n");
2290 }
2291 if (contexts & CXCompletionContext_ObjCClassMessage) {
2292 fprintf(file, "Objective-C class method\n");
2293 }
2294 if (contexts & CXCompletionContext_ObjCSelectorName) {
2295 fprintf(file, "Objective-C selector name\n");
2296 }
2297 if (contexts & CXCompletionContext_MacroName) {
2298 fprintf(file, "Macro name\n");
2299 }
2300 if (contexts & CXCompletionContext_NaturalLanguage) {
2301 fprintf(file, "Natural language\n");
2302 }
2303}
2304
2305int perform_code_completion(int argc, const char **argv, int timing_only) {
2306 const char *input = argv[1];
2307 char *filename = 0;
2308 unsigned line;
2309 unsigned column;
2310 CXIndex CIdx;
2311 int errorCode;
2312 struct CXUnsavedFile *unsaved_files = 0;
2313 int num_unsaved_files = 0;
2314 CXCodeCompleteResults *results = 0;
2315 enum CXErrorCode Err;
2316 CXTranslationUnit TU;
2317 unsigned I, Repeats = 1;
2318 unsigned completionOptions = clang_defaultCodeCompleteOptions();
2319 const char *InvocationPath;
2320
2321 if (getenv("CINDEXTEST_CODE_COMPLETE_PATTERNS"))
2322 completionOptions |= CXCodeComplete_IncludeCodePatterns;
2323 if (getenv("CINDEXTEST_COMPLETION_BRIEF_COMMENTS"))
2324 completionOptions |= CXCodeComplete_IncludeBriefComments;
2325
2326 if (timing_only)
2327 input += strlen("-code-completion-timing=");
2328 else
2329 input += strlen("-code-completion-at=");
2330
2331 if ((errorCode = parse_file_line_column(input, &filename, &line, &column,
2332 0, 0)))
2333 return errorCode;
2334
2335 if (parse_remapped_files(argc, argv, 2, &unsaved_files, &num_unsaved_files))
2336 return -1;
2337
2338 CIdx = clang_createIndex(0, 0);
2339 InvocationPath = getenv("CINDEXTEST_INVOCATION_EMISSION_PATH");
2340 if (InvocationPath)
2341 clang_CXIndex_setInvocationEmissionPathOption(CIdx, InvocationPath);
2342
2343 if (getenv("CINDEXTEST_EDITING"))
2344 Repeats = 5;
2345
2346 Err = clang_parseTranslationUnit2(CIdx, 0,
2347 argv + num_unsaved_files + 2,
2348 argc - num_unsaved_files - 2,
2349 0, 0, getDefaultParsingOptions(), &TU);
2350 if (Err != CXError_Success) {
2351 fprintf(stderrstderr, "Unable to load translation unit!\n");
2352 describeLibclangFailure(Err);
2353 return 1;
2354 }
2355
2356 Err = clang_reparseTranslationUnit(TU, 0, 0,
2357 clang_defaultReparseOptions(TU));
2358
2359 if (Err != CXError_Success) {
2360 fprintf(stderrstderr, "Unable to reparse translation unit!\n");
2361 describeLibclangFailure(Err);
2362 clang_disposeTranslationUnit(TU);
2363 return 1;
2364 }
2365
2366 for (I = 0; I != Repeats; ++I) {
2367 results = clang_codeCompleteAt(TU, filename, line, column,
2368 unsaved_files, num_unsaved_files,
2369 completionOptions);
2370 if (!results) {
2371 fprintf(stderrstderr, "Unable to perform code completion!\n");
2372 return 1;
2373 }
2374 if (I != Repeats-1)
2375 clang_disposeCodeCompleteResults(results);
2376 }
2377
2378 if (results) {
2379 unsigned i, n = results->NumResults, containerIsIncomplete = 0;
2380 unsigned long long contexts;
2381 enum CXCursorKind containerKind;
2382 CXString objCSelector;
2383 const char *selectorString;
2384 if (!timing_only) {
2385 /* Sort the code-completion results based on the typed text. */
2386 clang_sortCodeCompletionResults(results->Results, results->NumResults);
2387
2388 for (i = 0; i != n; ++i)
2389 print_completion_result(results->Results + i, stdoutstdout);
2390 }
2391 n = clang_codeCompleteGetNumDiagnostics(results);
2392 for (i = 0; i != n; ++i) {
2393 CXDiagnostic diag = clang_codeCompleteGetDiagnostic(results, i);
2394 PrintDiagnostic(diag);
2395 clang_disposeDiagnostic(diag);
2396 }
2397
2398 contexts = clang_codeCompleteGetContexts(results);
2399 print_completion_contexts(contexts, stdoutstdout);
2400
2401 containerKind = clang_codeCompleteGetContainerKind(results,
2402 &containerIsIncomplete);
2403
2404 if (containerKind != CXCursor_InvalidCode) {
2405 /* We have found a container */
2406 CXString containerUSR, containerKindSpelling;
2407 containerKindSpelling = clang_getCursorKindSpelling(containerKind);
2408 printf("Container Kind: %s\n", clang_getCString(containerKindSpelling));
2409 clang_disposeString(containerKindSpelling);
2410
2411 if (containerIsIncomplete) {
2412 printf("Container is incomplete\n");
2413 }
2414 else {
2415 printf("Container is complete\n");
2416 }
2417
2418 containerUSR = clang_codeCompleteGetContainerUSR(results);
2419 printf("Container USR: %s\n", clang_getCString(containerUSR));
2420 clang_disposeString(containerUSR);
2421 }
2422
2423 objCSelector = clang_codeCompleteGetObjCSelector(results);
2424 selectorString = clang_getCString(objCSelector);
2425 if (selectorString && strlen(selectorString) > 0) {
2426 printf("Objective-C selector: %s\n", selectorString);
2427 }
2428 clang_disposeString(objCSelector);
2429
2430 clang_disposeCodeCompleteResults(results);
2431 }
2432 clang_disposeTranslationUnit(TU);
2433 clang_disposeIndex(CIdx);
2434 free(filename);
2435
2436 free_remapped_files(unsaved_files, num_unsaved_files);
2437
2438 return 0;
2439}
2440
2441typedef struct {
2442 char *filename;
2443 unsigned line;
2444 unsigned column;
2445} CursorSourceLocation;
2446
2447typedef void (*cursor_handler_t)(CXCursor cursor);
2448
2449static int inspect_cursor_at(int argc, const char **argv,
2450 const char *locations_flag,
2451 cursor_handler_t handler) {
2452 CXIndex CIdx;
2453 int errorCode;
2454 struct CXUnsavedFile *unsaved_files = 0;
2455 int num_unsaved_files = 0;
2456 enum CXErrorCode Err;
2457 CXTranslationUnit TU;
2458 CXCursor Cursor;
2459 CursorSourceLocation *Locations = 0;
2460 unsigned NumLocations = 0, Loc;
2461 unsigned Repeats = 1;
2462 unsigned I;
2463
2464 /* Count the number of locations. */
2465 while (strstr(argv[NumLocations+1], locations_flag) == argv[NumLocations+1])
2466 ++NumLocations;
2467
2468 /* Parse the locations. */
2469 assert(NumLocations > 0 && "Unable to count locations?")((void) sizeof ((NumLocations > 0 && "Unable to count locations?"
) ? 1 : 0), __extension__ ({ if (NumLocations > 0 &&
"Unable to count locations?") ; else __assert_fail ("NumLocations > 0 && \"Unable to count locations?\""
, "/build/llvm-toolchain-snapshot-6.0~svn320613/tools/clang/tools/c-index-test/c-index-test.c"
, 2469, __extension__ __PRETTY_FUNCTION__); }))
;
2470 Locations = (CursorSourceLocation *)malloc(
2471 NumLocations * sizeof(CursorSourceLocation));
2472 for (Loc = 0; Loc < NumLocations; ++Loc) {
2473 const char *input = argv[Loc + 1] + strlen(locations_flag);
2474 if ((errorCode = parse_file_line_column(input, &Locations[Loc].filename,
2475 &Locations[Loc].line,
2476 &Locations[Loc].column, 0, 0)))
2477 return errorCode;
2478 }
2479
2480 if (parse_remapped_files(argc, argv, NumLocations + 1, &unsaved_files,
2481 &num_unsaved_files))
2482 return -1;
2483
2484 if (getenv("CINDEXTEST_EDITING"))
2485 Repeats = 5;
2486
2487 /* Parse the translation unit. When we're testing clang_getCursor() after
2488 reparsing, don't remap unsaved files until the second parse. */
2489 CIdx = clang_createIndex(1, 1);
2490 Err = clang_parseTranslationUnit2(CIdx, argv[argc - 1],
2491 argv + num_unsaved_files + 1 + NumLocations,
2492 argc - num_unsaved_files - 2 - NumLocations,
2493 unsaved_files,
2494 Repeats > 1? 0 : num_unsaved_files,
2495 getDefaultParsingOptions(), &TU);
2496 if (Err != CXError_Success) {
2497 fprintf(stderrstderr, "unable to parse input\n");
2498 describeLibclangFailure(Err);
2499 return -1;
2500 }
2501
2502 if (checkForErrors(TU) != 0)
2503 return -1;
2504
2505 for (I = 0; I != Repeats; ++I) {
2506 if (Repeats > 1) {
2507 Err = clang_reparseTranslationUnit(TU, num_unsaved_files, unsaved_files,
2508 clang_defaultReparseOptions(TU));
2509 if (Err != CXError_Success) {
2510 describeLibclangFailure(Err);
2511 clang_disposeTranslationUnit(TU);
2512 return 1;
2513 }
2514 }
2515
2516 if (checkForErrors(TU) != 0)
2517 return -1;
2518
2519 for (Loc = 0; Loc < NumLocations; ++Loc) {
2520 CXFile file = clang_getFile(TU, Locations[Loc].filename);
2521 if (!file)
2522 continue;
2523
2524 Cursor = clang_getCursor(TU,
2525 clang_getLocation(TU, file, Locations[Loc].line,
2526 Locations[Loc].column));
2527
2528 if (checkForErrors(TU) != 0)
2529 return -1;
2530
2531 if (I + 1 == Repeats) {
2532 handler(Cursor);
2533 free(Locations[Loc].filename);
2534 }
2535 }
2536 }
2537
2538 PrintDiagnostics(TU);
2539 clang_disposeTranslationUnit(TU);
2540 clang_disposeIndex(CIdx);
2541 free(Locations);
2542 free_remapped_files(unsaved_files, num_unsaved_files);
2543 return 0;
2544}
2545
2546static void inspect_print_cursor(CXCursor Cursor) {
2547 CXTranslationUnit TU = clang_Cursor_getTranslationUnit(Cursor);
2548 CXCompletionString completionString = clang_getCursorCompletionString(
2549 Cursor);
2550 CXSourceLocation CursorLoc = clang_getCursorLocation(Cursor);
2551 CXString Spelling;
2552 const char *cspell;
2553 unsigned line, column;
2554 clang_getSpellingLocation(CursorLoc, 0, &line, &column, 0);
2555 printf("%d:%d ", line, column);
2556 PrintCursor(Cursor, NULL((void*)0));
2557 PrintCursorExtent(Cursor);
2558 Spelling = clang_getCursorSpelling(Cursor);
2559 cspell = clang_getCString(Spelling);
2560 if (cspell && strlen(cspell) != 0) {
2561 unsigned pieceIndex;
2562 printf(" Spelling=%s (", cspell);
2563 for (pieceIndex = 0; ; ++pieceIndex) {
2564 CXSourceRange range =
2565 clang_Cursor_getSpellingNameRange(Cursor, pieceIndex, 0);
2566 if (clang_Range_isNull(range))
2567 break;
2568 PrintRange(range, 0);
2569 }
2570 printf(")");
2571 }
2572 clang_disposeString(Spelling);
2573 if (clang_Cursor_getObjCSelectorIndex(Cursor) != -1)
2574 printf(" Selector index=%d",
2575 clang_Cursor_getObjCSelectorIndex(Cursor));
2576 if (clang_Cursor_isDynamicCall(Cursor))
2577 printf(" Dynamic-call");
2578 if (Cursor.kind == CXCursor_ObjCMessageExpr ||
2579 Cursor.kind == CXCursor_MemberRefExpr) {
2580 CXType T = clang_Cursor_getReceiverType(Cursor);
2581 if (T.kind != CXType_Invalid) {
2582 CXString S = clang_getTypeKindSpelling(T.kind);
2583 printf(" Receiver-type=%s", clang_getCString(S));
2584 clang_disposeString(S);
2585 }
2586 }
2587
2588 {
2589 CXModule mod = clang_Cursor_getModule(Cursor);
2590 CXFile astFile;
2591 CXString name, astFilename;
2592 unsigned i, numHeaders;
2593 if (mod) {
2594 astFile = clang_Module_getASTFile(mod);
2595 astFilename = clang_getFileName(astFile);
2596 name = clang_Module_getFullName(mod);
2597 numHeaders = clang_Module_getNumTopLevelHeaders(TU, mod);
2598 printf(" ModuleName=%s (%s) system=%d Headers(%d):",
2599 clang_getCString(name), clang_getCString(astFilename),
2600 clang_Module_isSystem(mod), numHeaders);
2601 clang_disposeString(name);
2602 clang_disposeString(astFilename);
2603 for (i = 0; i < numHeaders; ++i) {
2604 CXFile file = clang_Module_getTopLevelHeader(TU, mod, i);
2605 CXString filename = clang_getFileName(file);
2606 printf("\n%s", clang_getCString(filename));
2607 clang_disposeString(filename);
2608 }
2609 }
2610 }
2611
2612 if (completionString != NULL((void*)0)) {
2613 printf("\nCompletion string: ");
2614 print_completion_string(completionString, stdoutstdout);
2615 }
2616 printf("\n");
2617}
2618
2619static void display_evaluate_results(CXEvalResult result) {
2620 switch (clang_EvalResult_getKind(result)) {
2621 case CXEval_Int:
2622 {
2623 printf("Kind: Int, ");
2624 if (clang_EvalResult_isUnsignedInt(result)) {
2625 unsigned long long val = clang_EvalResult_getAsUnsigned(result);
2626 printf("unsigned, Value: %llu", val);
2627 } else {
2628 long long val = clang_EvalResult_getAsLongLong(result);
2629 printf("Value: %lld", val);
2630 }
2631 break;
2632 }
2633 case CXEval_Float:
2634 {
2635 double val = clang_EvalResult_getAsDouble(result);
2636 printf("Kind: Float , Value: %f", val);
2637 break;
2638 }
2639 case CXEval_ObjCStrLiteral:
2640 {
2641 const char* str = clang_EvalResult_getAsStr(result);
2642 printf("Kind: ObjCString , Value: %s", str);
2643 break;
2644 }
2645 case CXEval_StrLiteral:
2646 {
2647 const char* str = clang_EvalResult_getAsStr(result);
2648 printf("Kind: CString , Value: %s", str);
2649 break;
2650 }
2651 case CXEval_CFStr:
2652 {
2653 const char* str = clang_EvalResult_getAsStr(result);
2654 printf("Kind: CFString , Value: %s", str);
2655 break;
2656 }
2657 default:
2658 printf("Unexposed");
2659 break;
2660 }
2661}
2662
2663static void inspect_evaluate_cursor(CXCursor Cursor) {
2664 CXSourceLocation CursorLoc = clang_getCursorLocation(Cursor);
2665 CXString Spelling;
2666 const char *cspell;
2667 unsigned line, column;
2668 CXEvalResult ER;
2669
2670 clang_getSpellingLocation(CursorLoc, 0, &line, &column, 0);
2671 printf("%d:%d ", line, column);
2672 PrintCursor(Cursor, NULL((void*)0));
2673 PrintCursorExtent(Cursor);
2674 Spelling = clang_getCursorSpelling(Cursor);
2675 cspell = clang_getCString(Spelling);
2676 if (cspell && strlen(cspell) != 0) {
2677 unsigned pieceIndex;
2678 printf(" Spelling=%s (", cspell);
2679 for (pieceIndex = 0; ; ++pieceIndex) {
2680 CXSourceRange range =
2681 clang_Cursor_getSpellingNameRange(Cursor, pieceIndex, 0);
2682 if (clang_Range_isNull(range))
2683 break;
2684 PrintRange(range, 0);
2685 }
2686 printf(")");
2687 }
2688 clang_disposeString(Spelling);
2689
2690 ER = clang_Cursor_Evaluate(Cursor);
2691 if (!ER) {
2692 printf("Not Evaluatable");
2693 } else {
2694 display_evaluate_results(ER);
2695 clang_EvalResult_dispose(ER);
2696 }
2697 printf("\n");
2698}
2699
2700static void inspect_macroinfo_cursor(CXCursor Cursor) {
2701 CXSourceLocation CursorLoc = clang_getCursorLocation(Cursor);
2702 CXString Spelling;
2703 const char *cspell;
2704 unsigned line, column;
2705 clang_getSpellingLocation(CursorLoc, 0, &line, &column, 0);
2706 printf("%d:%d ", line, column);
2707 PrintCursor(Cursor, NULL((void*)0));
2708 PrintCursorExtent(Cursor);
2709 Spelling = clang_getCursorSpelling(Cursor);
2710 cspell = clang_getCString(Spelling);
2711 if (cspell && strlen(cspell) != 0) {
2712 unsigned pieceIndex;
2713 printf(" Spelling=%s (", cspell);
2714 for (pieceIndex = 0; ; ++pieceIndex) {
2715 CXSourceRange range =
2716 clang_Cursor_getSpellingNameRange(Cursor, pieceIndex, 0);
2717 if (clang_Range_isNull(range))
2718 break;
2719 PrintRange(range, 0);
2720 }
2721 printf(")");
2722 }
2723 clang_disposeString(Spelling);
2724
2725 if (clang_Cursor_isMacroBuiltin(Cursor)) {
2726 printf("[builtin macro]");
2727 } else if (clang_Cursor_isMacroFunctionLike(Cursor)) {
2728 printf("[function macro]");
2729 }
2730 printf("\n");
2731}
2732
2733static enum CXVisitorResult findFileRefsVisit(void *context,
2734 CXCursor cursor, CXSourceRange range) {
2735 if (clang_Range_isNull(range))
2736 return CXVisit_Continue;
2737
2738 PrintCursor(cursor, NULL((void*)0));
2739 PrintRange(range, "");
2740 printf("\n");
2741 return CXVisit_Continue;
2742}
2743
2744static int find_file_refs_at(int argc, const char **argv) {
2745 CXIndex CIdx;
2746 int errorCode;
2747 struct CXUnsavedFile *unsaved_files = 0;
2748 int num_unsaved_files = 0;
2749 enum CXErrorCode Err;
2750 CXTranslationUnit TU;
2751 CXCursor Cursor;
2752 CursorSourceLocation *Locations = 0;
2753 unsigned NumLocations = 0, Loc;
2754 unsigned Repeats = 1;
2755 unsigned I;
2756
2757 /* Count the number of locations. */
2758 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 2762
2759 ++NumLocations;
2760
2761 /* Parse the locations. */
2762 assert(NumLocations > 0 && "Unable to count locations?")((void) sizeof ((NumLocations > 0 && "Unable to count locations?"
) ? 1 : 0), __extension__ ({ if (NumLocations > 0 &&
"Unable to count locations?") ; else __assert_fail ("NumLocations > 0 && \"Unable to count locations?\""
, "/build/llvm-toolchain-snapshot-6.0~svn320613/tools/clang/tools/c-index-test/c-index-test.c"
, 2762, __extension__ __PRETTY_FUNCTION__); }))
;
2763 Locations = (CursorSourceLocation *)malloc(
5
Memory is allocated
2764 NumLocations * sizeof(CursorSourceLocation));
2765 for (Loc = 0; Loc < NumLocations; ++Loc) {
6
Loop condition is true. Entering loop body
2766 const char *input = argv[Loc + 1] + strlen("-file-refs-at=");
2767 if ((errorCode = parse_file_line_column(input, &Locations[Loc].filename,
7
Taking true branch
2768 &Locations[Loc].line,
2769 &Locations[Loc].column, 0, 0)))
2770 return errorCode;
8
Potential leak of memory pointed to by 'Locations'
2771 }
2772
2773 if (parse_remapped_files(argc, argv, NumLocations + 1, &unsaved_files,
2774 &num_unsaved_files))
2775 return -1;
2776
2777 if (getenv("CINDEXTEST_EDITING"))
2778 Repeats = 5;
2779
2780 /* Parse the translation unit. When we're testing clang_getCursor() after
2781 reparsing, don't remap unsaved files until the second parse. */
2782 CIdx = clang_createIndex(1, 1);
2783 Err = clang_parseTranslationUnit2(CIdx, argv[argc - 1],
2784 argv + num_unsaved_files + 1 + NumLocations,
2785 argc - num_unsaved_files - 2 - NumLocations,
2786 unsaved_files,
2787 Repeats > 1? 0 : num_unsaved_files,
2788 getDefaultParsingOptions(), &TU);
2789 if (Err != CXError_Success) {
2790 fprintf(stderrstderr, "unable to parse input\n");
2791 describeLibclangFailure(Err);
2792 clang_disposeTranslationUnit(TU);
2793 return -1;
2794 }
2795
2796 if (checkForErrors(TU) != 0)
2797 return -1;
2798
2799 for (I = 0; I != Repeats; ++I) {
2800 if (Repeats > 1) {
2801 Err = clang_reparseTranslationUnit(TU, num_unsaved_files, unsaved_files,
2802 clang_defaultReparseOptions(TU));
2803 if (Err != CXError_Success) {
2804 describeLibclangFailure(Err);
2805 clang_disposeTranslationUnit(TU);
2806 return 1;
2807 }
2808 }
2809
2810 if (checkForErrors(TU) != 0)
2811 return -1;
2812
2813 for (Loc = 0; Loc < NumLocations; ++Loc) {
2814 CXFile file = clang_getFile(TU, Locations[Loc].filename);
2815 if (!file)
2816 continue;
2817
2818 Cursor = clang_getCursor(TU,
2819 clang_getLocation(TU, file, Locations[Loc].line,
2820 Locations[Loc].column));
2821
2822 if (checkForErrors(TU) != 0)
2823 return -1;
2824
2825 if (I + 1 == Repeats) {
2826 CXCursorAndRangeVisitor visitor = { 0, findFileRefsVisit };
2827 PrintCursor(Cursor, NULL((void*)0));
2828 printf("\n");
2829 clang_findReferencesInFile(Cursor, file, visitor);
2830 free(Locations[Loc].filename);
2831
2832 if (checkForErrors(TU) != 0)
2833 return -1;
2834 }
2835 }
2836 }
2837
2838 PrintDiagnostics(TU);
2839 clang_disposeTranslationUnit(TU);
2840 clang_disposeIndex(CIdx);
2841 free(Locations);
2842 free_remapped_files(unsaved_files, num_unsaved_files);
2843 return 0;
2844}
2845
2846static enum CXVisitorResult findFileIncludesVisit(void *context,
2847 CXCursor cursor, CXSourceRange range) {
2848 PrintCursor(cursor, NULL((void*)0));
2849 PrintRange(range, "");
2850 printf("\n");
2851 return CXVisit_Continue;
2852}
2853
2854static int find_file_includes_in(int argc, const char **argv) {
2855 CXIndex CIdx;
2856 struct CXUnsavedFile *unsaved_files = 0;
2857 int num_unsaved_files = 0;
2858 enum CXErrorCode Err;
2859 CXTranslationUnit TU;
2860 const char **Filenames = 0;
2861 unsigned NumFilenames = 0;
2862 unsigned Repeats = 1;
2863 unsigned I, FI;
2864
2865 /* Count the number of locations. */
2866 while (strstr(argv[NumFilenames+1], "-file-includes-in=") == argv[NumFilenames+1])
2867 ++NumFilenames;
2868
2869 /* Parse the locations. */
2870 assert(NumFilenames > 0 && "Unable to count filenames?")((void) sizeof ((NumFilenames > 0 && "Unable to count filenames?"
) ? 1 : 0), __extension__ ({ if (NumFilenames > 0 &&
"Unable to count filenames?") ; else __assert_fail ("NumFilenames > 0 && \"Unable to count filenames?\""
, "/build/llvm-toolchain-snapshot-6.0~svn320613/tools/clang/tools/c-index-test/c-index-test.c"
, 2870, __extension__ __PRETTY_FUNCTION__); }))
;
2871 Filenames = (const char **)malloc(NumFilenames * sizeof(const char *));
2872 for (I = 0; I < NumFilenames; ++I) {
2873 const char *input = argv[I + 1] + strlen("-file-includes-in=");
2874 /* Copy the file name. */
2875 Filenames[I] = input;
2876 }
2877
2878 if (parse_remapped_files(argc, argv, NumFilenames + 1, &unsaved_files,
2879 &num_unsaved_files))
2880 return -1;
2881
2882 if (getenv("CINDEXTEST_EDITING"))
2883 Repeats = 2;
2884
2885 /* Parse the translation unit. When we're testing clang_getCursor() after
2886 reparsing, don't remap unsaved files until the second parse. */
2887 CIdx = clang_createIndex(1, 1);
2888 Err = clang_parseTranslationUnit2(
2889 CIdx, argv[argc - 1],
2890 argv + num_unsaved_files + 1 + NumFilenames,
2891 argc - num_unsaved_files - 2 - NumFilenames,
2892 unsaved_files,
2893 Repeats > 1 ? 0 : num_unsaved_files, getDefaultParsingOptions(), &TU);
2894
2895 if (Err != CXError_Success) {
2896 fprintf(stderrstderr, "unable to parse input\n");
2897 describeLibclangFailure(Err);
2898 clang_disposeTranslationUnit(TU);
2899 return -1;
2900 }
2901
2902 if (checkForErrors(TU) != 0)
2903 return -1;
2904
2905 for (I = 0; I != Repeats; ++I) {
2906 if (Repeats > 1) {
2907 Err = clang_reparseTranslationUnit(TU, num_unsaved_files, unsaved_files,
2908 clang_defaultReparseOptions(TU));
2909 if (Err != CXError_Success) {
2910 describeLibclangFailure(Err);
2911 clang_disposeTranslationUnit(TU);
2912 return 1;
2913 }
2914 }
2915
2916 if (checkForErrors(TU) != 0)
2917 return -1;
2918
2919 for (FI = 0; FI < NumFilenames; ++FI) {
2920 CXFile file = clang_getFile(TU, Filenames[FI]);
2921 if (!file)
2922 continue;
2923
2924 if (checkForErrors(TU) != 0)
2925 return -1;
2926
2927 if (I + 1 == Repeats) {
2928 CXCursorAndRangeVisitor visitor = { 0, findFileIncludesVisit };
2929 clang_findIncludesInFile(TU, file, visitor);
2930
2931 if (checkForErrors(TU) != 0)
2932 return -1;
2933 }
2934 }
2935 }
2936
2937 PrintDiagnostics(TU);
2938 clang_disposeTranslationUnit(TU);
2939 clang_disposeIndex(CIdx);
2940 free((void *)Filenames);
2941 free_remapped_files(unsaved_files, num_unsaved_files);
2942 return 0;
2943}
2944
2945#define MAX_IMPORTED_ASTFILES200 200
2946
2947typedef struct {
2948 char **filenames;
2949 unsigned num_files;
2950} ImportedASTFilesData;
2951
2952static ImportedASTFilesData *importedASTs_create() {
2953 ImportedASTFilesData *p;
2954 p = malloc(sizeof(ImportedASTFilesData));
2955 p->filenames = malloc(MAX_IMPORTED_ASTFILES200 * sizeof(const char *));
2956 p->num_files = 0;
2957 return p;
2958}
2959
2960static void importedASTs_dispose(ImportedASTFilesData *p) {
2961 unsigned i;
2962 if (!p)
2963 return;
2964
2965 for (i = 0; i < p->num_files; ++i)
2966 free(p->filenames[i]);
2967 free(p->filenames);
2968 free(p);
2969}
2970
2971static void importedASTS_insert(ImportedASTFilesData *p, const char *file) {
2972 unsigned i;
2973 assert(p && file)((void) sizeof ((p && file) ? 1 : 0), __extension__ (
{ if (p && file) ; else __assert_fail ("p && file"
, "/build/llvm-toolchain-snapshot-6.0~svn320613/tools/clang/tools/c-index-test/c-index-test.c"
, 2973, __extension__ __PRETTY_FUNCTION__); }))
;
2974 for (i = 0; i < p->num_files; ++i)
2975 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)
2976 return;
2977 assert(p->num_files + 1 < MAX_IMPORTED_ASTFILES)((void) sizeof ((p->num_files + 1 < 200) ? 1 : 0), __extension__
({ if (p->num_files + 1 < 200) ; else __assert_fail ("p->num_files + 1 < MAX_IMPORTED_ASTFILES"
, "/build/llvm-toolchain-snapshot-6.0~svn320613/tools/clang/tools/c-index-test/c-index-test.c"
, 2977, __extension__ __PRETTY_FUNCTION__); }))
;
2978 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)))
;
2979}
2980
2981typedef struct IndexDataStringList_ {
2982 struct IndexDataStringList_ *next;
2983 char data[1]; /* Dynamically sized. */
2984} IndexDataStringList;
2985
2986typedef struct {
2987 const char *check_prefix;
2988 int first_check_printed;
2989 int fail_for_error;
2990 int abort;
2991 const char *main_filename;
2992 ImportedASTFilesData *importedASTs;
2993 IndexDataStringList *strings;
2994 CXTranslationUnit TU;
2995} IndexData;
2996
2997static void free_client_data(IndexData *index_data) {
2998 IndexDataStringList *node = index_data->strings;
2999 while (node) {
3000 IndexDataStringList *next = node->next;
3001 free(node);
3002 node = next;
3003 }
3004 index_data->strings = NULL((void*)0);
3005}
3006
3007static void printCheck(IndexData *data) {
3008 if (data->check_prefix) {
3009 if (data->first_check_printed) {
3010 printf("// %s-NEXT: ", data->check_prefix);
3011 } else {
3012 printf("// %s : ", data->check_prefix);
3013 data->first_check_printed = 1;
3014 }
3015 }
3016}
3017
3018static void printCXIndexFile(CXIdxClientFile file) {
3019 CXString filename = clang_getFileName((CXFile)file);
3020 printf("%s", clang_getCString(filename));
3021 clang_disposeString(filename);
3022}
3023
3024static void printCXIndexLoc(CXIdxLoc loc, CXClientData client_data) {
3025 IndexData *index_data;
3026 CXString filename;
3027 const char *cname;
3028 CXIdxClientFile file;
3029 unsigned line, column;
3030 int isMainFile;
3031
3032 index_data = (IndexData *)client_data;
3033 clang_indexLoc_getFileLocation(loc, &file, 0, &line, &column, 0);
3034 if (line == 0) {
3035 printf("<invalid>");
3036 return;
3037 }
3038 if (!file) {
3039 printf("<no idxfile>");
3040 return;
3041 }
3042 filename = clang_getFileName((CXFile)file);
3043 cname = clang_getCString(filename);
3044 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)
3045 isMainFile = 1;
3046 else
3047 isMainFile = 0;
3048 clang_disposeString(filename);
3049
3050 if (!isMainFile) {
3051 printCXIndexFile(file);
3052 printf(":");
3053 }
3054 printf("%d:%d", line, column);
3055}
3056
3057static unsigned digitCount(unsigned val) {
3058 unsigned c = 1;
3059 while (1) {
3060 if (val < 10)
3061 return c;
3062 ++c;
3063 val /= 10;
3064 }
3065}
3066
3067static CXIdxClientContainer makeClientContainer(CXClientData *client_data,
3068 const CXIdxEntityInfo *info,
3069 CXIdxLoc loc) {
3070 IndexData *index_data;
3071 IndexDataStringList *node;
3072 const char *name;
3073 char *newStr;
3074 CXIdxClientFile file;
3075 unsigned line, column;
3076
3077 name = info->name;
3078 if (!name)
3079 name = "<anon-tag>";
3080
3081 clang_indexLoc_getFileLocation(loc, &file, 0, &line, &column, 0);
3082
3083 node =
3084 (IndexDataStringList *)malloc(sizeof(IndexDataStringList) + strlen(name) +
3085 digitCount(line) + digitCount(column) + 2);
3086 newStr = node->data;
3087 sprintf(newStr, "%s:%d:%d", name, line, column);
3088
3089 /* Remember string so it can be freed later. */
3090 index_data = (IndexData *)client_data;
3091 node->next = index_data->strings;
3092 index_data->strings = node;
3093
3094 return (CXIdxClientContainer)newStr;
3095}
3096
3097static void printCXIndexContainer(const CXIdxContainerInfo *info) {
3098 CXIdxClientContainer container;
3099 container = clang_index_getClientContainer(info);
3100 if (!container)
3101 printf("[<<NULL>>]");
3102 else
3103 printf("[%s]", (const char *)container);
3104}
3105
3106static const char *getEntityKindString(CXIdxEntityKind kind) {
3107 switch (kind) {
3108 case CXIdxEntity_Unexposed: return "<<UNEXPOSED>>";
3109 case CXIdxEntity_Typedef: return "typedef";
3110 case CXIdxEntity_Function: return "function";
3111 case CXIdxEntity_Variable: return "variable";
3112 case CXIdxEntity_Field: return "field";
3113 case CXIdxEntity_EnumConstant: return "enumerator";
3114 case CXIdxEntity_ObjCClass: return "objc-class";
3115 case CXIdxEntity_ObjCProtocol: return "objc-protocol";
3116 case CXIdxEntity_ObjCCategory: return "objc-category";
3117 case CXIdxEntity_ObjCInstanceMethod: return "objc-instance-method";
3118 case CXIdxEntity_ObjCClassMethod: return "objc-class-method";
3119 case CXIdxEntity_ObjCProperty: return "objc-property";
3120 case CXIdxEntity_ObjCIvar: return "objc-ivar";
3121 case CXIdxEntity_Enum: return "enum";
3122 case CXIdxEntity_Struct: return "struct";
3123 case CXIdxEntity_Union: return "union";
3124 case CXIdxEntity_CXXClass: return "c++-class";
3125 case CXIdxEntity_CXXNamespace: return "namespace";
3126 case CXIdxEntity_CXXNamespaceAlias: return "namespace-alias";
3127 case CXIdxEntity_CXXStaticVariable: return "c++-static-var";
3128 case CXIdxEntity_CXXStaticMethod: return "c++-static-method";
3129 case CXIdxEntity_CXXInstanceMethod: return "c++-instance-method";
3130 case CXIdxEntity_CXXConstructor: return "constructor";
3131 case CXIdxEntity_CXXDestructor: return "destructor";
3132 case CXIdxEntity_CXXConversionFunction: return "conversion-func";
3133 case CXIdxEntity_CXXTypeAlias: return "type-alias";
3134 case CXIdxEntity_CXXInterface: return "c++-__interface";
3135 }
3136 assert(0 && "Garbage entity kind")((void) sizeof ((0 && "Garbage entity kind") ? 1 : 0)
, __extension__ ({ if (0 && "Garbage entity kind") ; else
__assert_fail ("0 && \"Garbage entity kind\"", "/build/llvm-toolchain-snapshot-6.0~svn320613/tools/clang/tools/c-index-test/c-index-test.c"
, 3136, __extension__ __PRETTY_FUNCTION__); }))
;
3137 return 0;
3138}
3139
3140static const char *getEntityTemplateKindString(CXIdxEntityCXXTemplateKind kind) {
3141 switch (kind) {
3142 case CXIdxEntity_NonTemplate: return "";
3143 case CXIdxEntity_Template: return "-template";
3144 case CXIdxEntity_TemplatePartialSpecialization:
3145 return "-template-partial-spec";
3146 case CXIdxEntity_TemplateSpecialization: return "-template-spec";
3147 }
3148 assert(0 && "Garbage entity kind")((void) sizeof ((0 && "Garbage entity kind") ? 1 : 0)
, __extension__ ({ if (0 && "Garbage entity kind") ; else
__assert_fail ("0 && \"Garbage entity kind\"", "/build/llvm-toolchain-snapshot-6.0~svn320613/tools/clang/tools/c-index-test/c-index-test.c"
, 3148, __extension__ __PRETTY_FUNCTION__); }))
;
3149 return 0;
3150}
3151
3152static const char *getEntityLanguageString(CXIdxEntityLanguage kind) {
3153 switch (kind) {
3154 case CXIdxEntityLang_None: return "<none>";
3155 case CXIdxEntityLang_C: return "C";
3156 case CXIdxEntityLang_ObjC: return "ObjC";
3157 case CXIdxEntityLang_CXX: return "C++";
3158 case CXIdxEntityLang_Swift: return "Swift";
3159 }
3160 assert(0 && "Garbage language kind")((void) sizeof ((0 && "Garbage language kind") ? 1 : 0
), __extension__ ({ if (0 && "Garbage language kind")
; else __assert_fail ("0 && \"Garbage language kind\""
, "/build/llvm-toolchain-snapshot-6.0~svn320613/tools/clang/tools/c-index-test/c-index-test.c"
, 3160, __extension__ __PRETTY_FUNCTION__); }))
;
3161 return 0;
3162}
3163
3164static void printEntityInfo(const char *cb,
3165 CXClientData client_data,
3166 const CXIdxEntityInfo *info) {
3167 const char *name;
3168 IndexData *index_data;
3169 unsigned i;
3170 index_data = (IndexData *)client_data;
3171 printCheck(index_data);
3172
3173 if (!info) {
3174 printf("%s: <<NULL>>", cb);
3175 return;
3176 }
3177
3178 name = info->name;
3179 if (!name)
3180 name = "<anon-tag>";
3181
3182 printf("%s: kind: %s%s", cb, getEntityKindString(info->kind),
3183 getEntityTemplateKindString(info->templateKind));
3184 printf(" | name: %s", name);
3185 printf(" | USR: %s", info->USR);
3186 printf(" | lang: %s", getEntityLanguageString(info->lang));
3187
3188 for (i = 0; i != info->numAttributes; ++i) {
3189 const CXIdxAttrInfo *Attr = info->attributes[i];
3190 printf(" <attribute>: ");
3191 PrintCursor(Attr->cursor, NULL((void*)0));
3192 }
3193}
3194
3195static void printBaseClassInfo(CXClientData client_data,
3196 const CXIdxBaseClassInfo *info) {
3197 printEntityInfo(" <base>", client_data, info->base);
3198 printf(" | cursor: ");
3199 PrintCursor(info->cursor, NULL((void*)0));
3200 printf(" | loc: ");
3201 printCXIndexLoc(info->loc, client_data);
3202}
3203
3204static void printProtocolList(const CXIdxObjCProtocolRefListInfo *ProtoInfo,
3205 CXClientData client_data) {
3206 unsigned i;
3207 for (i = 0; i < ProtoInfo->numProtocols; ++i) {
3208 printEntityInfo(" <protocol>", client_data,
3209 ProtoInfo->protocols[i]->protocol);
3210 printf(" | cursor: ");
3211 PrintCursor(ProtoInfo->protocols[i]->cursor, NULL((void*)0));
3212 printf(" | loc: ");
3213 printCXIndexLoc(ProtoInfo->protocols[i]->loc, client_data);
3214 printf("\n");
3215 }
3216}
3217
3218static void index_diagnostic(CXClientData client_data,
3219 CXDiagnosticSet diagSet, void *reserved) {
3220 CXString str;
3221 const char *cstr;
3222 unsigned numDiags, i;
3223 CXDiagnostic diag;
3224 IndexData *index_data;
3225 index_data = (IndexData *)client_data;
3226 printCheck(index_data);
3227
3228 numDiags = clang_getNumDiagnosticsInSet(diagSet);
3229 for (i = 0; i != numDiags; ++i) {
3230 diag = clang_getDiagnosticInSet(diagSet, i);
3231 str = clang_formatDiagnostic(diag, clang_defaultDiagnosticDisplayOptions());
3232 cstr = clang_getCString(str);
3233 printf("[diagnostic]: %s\n", cstr);
3234 clang_disposeString(str);
3235
3236 if (getenv("CINDEXTEST_FAILONERROR") &&
3237 clang_getDiagnosticSeverity(diag) >= CXDiagnostic_Error) {
3238 index_data->fail_for_error = 1;
3239 }
3240 }
3241}
3242
3243static CXIdxClientFile index_enteredMainFile(CXClientData client_data,
3244 CXFile file, void *reserved) {
3245 IndexData *index_data;
3246 CXString filename;
3247
3248 index_data = (IndexData *)client_data;
3249 printCheck(index_data);
3250
3251 filename = clang_getFileName(file);
3252 index_data->main_filename = clang_getCString(filename);
3253 clang_disposeString(filename);
3254
3255 printf("[enteredMainFile]: ");
3256 printCXIndexFile((CXIdxClientFile)file);
3257 printf("\n");
3258
3259 return (CXIdxClientFile)file;
3260}
3261
3262static CXIdxClientFile index_ppIncludedFile(CXClientData client_data,
3263 const CXIdxIncludedFileInfo *info) {
3264 IndexData *index_data;
3265 CXModule Mod;
3266 index_data = (IndexData *)client_data;
3267 printCheck(index_data);
3268
3269 printf("[ppIncludedFile]: ");
3270 printCXIndexFile((CXIdxClientFile)info->file);
3271 printf(" | name: \"%s\"", info->filename);
3272 printf(" | hash loc: ");
3273 printCXIndexLoc(info->hashLoc, client_data);
3274 printf(" | isImport: %d | isAngled: %d | isModule: %d",
3275 info->isImport, info->isAngled, info->isModuleImport);
3276
3277 Mod = clang_getModuleForFile(index_data->TU, (CXFile)info->file);
3278 if (Mod) {
3279 CXString str = clang_Module_getFullName(Mod);
3280 const char *cstr = clang_getCString(str);
3281 printf(" | module: %s", cstr);
3282 clang_disposeString(str);
3283 }
3284
3285 printf("\n");
3286
3287 return (CXIdxClientFile)info->file;
3288}
3289
3290static CXIdxClientFile index_importedASTFile(CXClientData client_data,
3291 const CXIdxImportedASTFileInfo *info) {
3292 IndexData *index_data;
3293 index_data = (IndexData *)client_data;
3294 printCheck(index_data);
3295
3296 if (index_data->importedASTs) {
3297 CXString filename = clang_getFileName(info->file);
3298 importedASTS_insert(index_data->importedASTs, clang_getCString(filename));
3299 clang_disposeString(filename);
3300 }
3301
3302 printf("[importedASTFile]: ");
3303 printCXIndexFile((CXIdxClientFile)info->file);
3304 if (info->module) {
3305 CXString name = clang_Module_getFullName(info->module);
3306 printf(" | loc: ");
3307 printCXIndexLoc(info->loc, client_data);
3308 printf(" | name: \"%s\"", clang_getCString(name));
3309 printf(" | isImplicit: %d\n", info->isImplicit);
3310 clang_disposeString(name);
3311 } else {
3312 /* PCH file, the rest are not relevant. */
3313 printf("\n");
3314 }
3315
3316 return (CXIdxClientFile)info->file;
3317}
3318
3319static CXIdxClientContainer
3320index_startedTranslationUnit(CXClientData client_data, void *reserved) {
3321 IndexData *index_data;
3322 index_data = (IndexData *)client_data;
3323 printCheck(index_data);
3324
3325 printf("[startedTranslationUnit]\n");
3326 return (CXIdxClientContainer)"TU";
3327}
3328
3329static void index_indexDeclaration(CXClientData client_data,
3330 const CXIdxDeclInfo *info) {
3331 IndexData *index_data;
3332 const CXIdxObjCCategoryDeclInfo *CatInfo;
3333 const CXIdxObjCInterfaceDeclInfo *InterInfo;
3334 const CXIdxObjCProtocolRefListInfo *ProtoInfo;
3335 const CXIdxObjCPropertyDeclInfo *PropInfo;
3336 const CXIdxCXXClassDeclInfo *CXXClassInfo;
3337 unsigned i;
3338 index_data = (IndexData *)client_data;
3339
3340 printEntityInfo("[indexDeclaration]", client_data, info->entityInfo);
3341 printf(" | cursor: ");
3342 PrintCursor(info->cursor, NULL((void*)0));
3343 printf(" | loc: ");
3344 printCXIndexLoc(info->loc, client_data);
3345 printf(" | semantic-container: ");
3346 printCXIndexContainer(info->semanticContainer);
3347 printf(" | lexical-container: ");
3348 printCXIndexContainer(info->lexicalContainer);
3349 printf(" | isRedecl: %d", info->isRedeclaration);
3350 printf(" | isDef: %d", info->isDefinition);
3351 if (info->flags & CXIdxDeclFlag_Skipped) {
3352 assert(!info->isContainer)((void) sizeof ((!info->isContainer) ? 1 : 0), __extension__
({ if (!info->isContainer) ; else __assert_fail ("!info->isContainer"
, "/build/llvm-toolchain-snapshot-6.0~svn320613/tools/clang/tools/c-index-test/c-index-test.c"
, 3352, __extension__ __PRETTY_FUNCTION__); }))
;
3353 printf(" | isContainer: skipped");
3354 } else {
3355 printf(" | isContainer: %d", info->isContainer);
3356 }
3357 printf(" | isImplicit: %d\n", info->isImplicit);
3358
3359 for (i = 0; i != info->numAttributes; ++i) {
3360 const CXIdxAttrInfo *Attr = info->attributes[i];
3361 printf(" <attribute>: ");
3362 PrintCursor(Attr->cursor, NULL((void*)0));
3363 printf("\n");
3364 }
3365
3366 if (clang_index_isEntityObjCContainerKind(info->entityInfo->kind)) {
3367 const char *kindName = 0;
3368 CXIdxObjCContainerKind K = clang_index_getObjCContainerDeclInfo(info)->kind;
3369 switch (K) {
3370 case CXIdxObjCContainer_ForwardRef:
3371 kindName = "forward-ref"; break;
3372 case CXIdxObjCContainer_Interface:
3373 kindName = "interface"; break;
3374 case CXIdxObjCContainer_Implementation:
3375 kindName = "implementation"; break;
3376 }
3377 printCheck(index_data);
3378 printf(" <ObjCContainerInfo>: kind: %s\n", kindName);
3379 }
3380
3381 if ((CatInfo = clang_index_getObjCCategoryDeclInfo(info))) {
3382 printEntityInfo(" <ObjCCategoryInfo>: class", client_data,
3383 CatInfo->objcClass);
3384 printf(" | cursor: ");
3385 PrintCursor(CatInfo->classCursor, NULL((void*)0));
3386 printf(" | loc: ");
3387 printCXIndexLoc(CatInfo->classLoc, client_data);
3388 printf("\n");
3389 }
3390
3391 if ((InterInfo = clang_index_getObjCInterfaceDeclInfo(info))) {
3392 if (InterInfo->superInfo) {
3393 printBaseClassInfo(client_data, InterInfo->superInfo);
3394 printf("\n");
3395 }
3396 }
3397
3398 if ((ProtoInfo = clang_index_getObjCProtocolRefListInfo(info))) {
3399 printProtocolList(ProtoInfo, client_data);
3400 }
3401
3402 if ((PropInfo = clang_index_getObjCPropertyDeclInfo(info))) {
3403 if (PropInfo->getter) {
3404 printEntityInfo(" <getter>", client_data, PropInfo->getter);
3405 printf("\n");
3406 }
3407 if (PropInfo->setter) {
3408 printEntityInfo(" <setter>", client_data, PropInfo->setter);
3409 printf("\n");
3410 }
3411 }
3412
3413 if ((CXXClassInfo = clang_index_getCXXClassDeclInfo(info))) {
3414 for (i = 0; i != CXXClassInfo->numBases; ++i) {
3415 printBaseClassInfo(client_data, CXXClassInfo->bases[i]);
3416 printf("\n");
3417 }
3418 }
3419
3420 if (info->declAsContainer)
3421 clang_index_setClientContainer(
3422 info->declAsContainer,
3423 makeClientContainer(client_data, info->entityInfo, info->loc));
3424}
3425
3426static void index_indexEntityReference(CXClientData client_data,
3427 const CXIdxEntityRefInfo *info) {
3428 printEntityInfo("[indexEntityReference]", client_data,
3429 info->referencedEntity);
3430 printf(" | cursor: ");
3431 PrintCursor(info->cursor, NULL((void*)0));
3432 printf(" | loc: ");
3433 printCXIndexLoc(info->loc, client_data);
3434 printEntityInfo(" | <parent>:", client_data, info->parentEntity);
3435 printf(" | container: ");
3436 printCXIndexContainer(info->container);
3437 printf(" | refkind: ");
3438 switch (info->kind) {
3439 case CXIdxEntityRef_Direct: printf("direct"); break;
3440 case CXIdxEntityRef_Implicit: printf("implicit"); break;
3441 }
3442 printf("\n");
3443}
3444
3445static int index_abortQuery(CXClientData client_data, void *reserved) {
3446 IndexData *index_data;
3447 index_data = (IndexData *)client_data;
3448 return index_data->abort;
3449}
3450
3451static IndexerCallbacks IndexCB = {
3452 index_abortQuery,
3453 index_diagnostic,
3454 index_enteredMainFile,
3455 index_ppIncludedFile,
3456 index_importedASTFile,
3457 index_startedTranslationUnit,
3458 index_indexDeclaration,
3459 index_indexEntityReference
3460};
3461
3462static unsigned getIndexOptions(void) {
3463 unsigned index_opts;
3464 index_opts = 0;
3465 if (getenv("CINDEXTEST_SUPPRESSREFS"))
3466 index_opts |= CXIndexOpt_SuppressRedundantRefs;
3467 if (getenv("CINDEXTEST_INDEXLOCALSYMBOLS"))
3468 index_opts |= CXIndexOpt_IndexFunctionLocalSymbols;
3469 if (!getenv("CINDEXTEST_DISABLE_SKIPPARSEDBODIES"))
3470 index_opts |= CXIndexOpt_SkipParsedBodiesInSession;
3471
3472 return index_opts;
3473}
3474
3475static int index_compile_args(int num_args, const char **args,
3476 CXIndexAction idxAction,
3477 ImportedASTFilesData *importedASTs,
3478 const char *check_prefix) {
3479 IndexData index_data;
3480 unsigned index_opts;
3481 int result;
3482
3483 if (num_args == 0) {
3484 fprintf(stderrstderr, "no compiler arguments\n");
3485 return -1;
3486 }
3487
3488 index_data.check_prefix = check_prefix;
3489 index_data.first_check_printed = 0;
3490 index_data.fail_for_error = 0;
3491 index_data.abort = 0;
3492 index_data.main_filename = "";
3493 index_data.importedASTs = importedASTs;
3494 index_data.strings = NULL((void*)0);
3495 index_data.TU = NULL((void*)0);
3496
3497 index_opts = getIndexOptions();
3498 result = clang_indexSourceFile(idxAction, &index_data,
3499 &IndexCB,sizeof(IndexCB), index_opts,
3500 0, args, num_args, 0, 0, 0,
3501 getDefaultParsingOptions());
3502 if (result != CXError_Success)
3503 describeLibclangFailure(result);
3504
3505 if (index_data.fail_for_error)
3506 result = -1;
3507
3508 free_client_data(&index_data);
3509 return result;
3510}
3511
3512static int index_ast_file(const char *ast_file,
3513 CXIndex Idx,
3514 CXIndexAction idxAction,
3515 ImportedASTFilesData *importedASTs,
3516 const char *check_prefix) {
3517 CXTranslationUnit TU;
3518 IndexData index_data;
3519 unsigned index_opts;
3520 int result;
3521
3522 if (!CreateTranslationUnit(Idx, ast_file, &TU))
3523 return -1;
3524
3525 index_data.check_prefix = check_prefix;
3526 index_data.first_check_printed = 0;
3527 index_data.fail_for_error = 0;
3528 index_data.abort = 0;
3529 index_data.main_filename = "";
3530 index_data.importedASTs = importedASTs;
3531 index_data.strings = NULL((void*)0);
3532 index_data.TU = TU;
3533
3534 index_opts = getIndexOptions();
3535 result = clang_indexTranslationUnit(idxAction, &index_data,
3536 &IndexCB,sizeof(IndexCB),
3537 index_opts, TU);
3538 if (index_data.fail_for_error)
3539 result = -1;
3540
3541 clang_disposeTranslationUnit(TU);
3542 free_client_data(&index_data);
3543 return result;
3544}
3545
3546static int index_file(int argc, const char **argv, int full) {
3547 const char *check_prefix;
3548 CXIndex Idx;
3549 CXIndexAction idxAction;
3550 ImportedASTFilesData *importedASTs;
3551 int result;
3552
3553 check_prefix = 0;
3554 if (argc > 0) {
3555 if (strstr(argv[0], "-check-prefix=") == argv[0]) {
3556 check_prefix = argv[0] + strlen("-check-prefix=");
3557 ++argv;
3558 --argc;
3559 }
3560 }
3561
3562 if (!(Idx = clang_createIndex(/* excludeDeclsFromPCH */ 1,
3563 /* displayDiagnostics=*/1))) {
3564 fprintf(stderrstderr, "Could not create Index\n");
3565 return 1;
3566 }
3567 idxAction = clang_IndexAction_create(Idx);
3568 importedASTs = 0;
3569 if (full)
3570 importedASTs = importedASTs_create();
3571
3572 result = index_compile_args(argc, argv, idxAction, importedASTs, check_prefix);
3573 if (result != 0)
3574 goto finished;
3575
3576 if (full) {
3577 unsigned i;
3578 for (i = 0; i < importedASTs->num_files && result == 0; ++i) {
3579 result = index_ast_file(importedASTs->filenames[i], Idx, idxAction,
3580 importedASTs, check_prefix);
3581 }
3582 }
3583
3584finished:
3585 importedASTs_dispose(importedASTs);
3586 clang_IndexAction_dispose(idxAction);
3587 clang_disposeIndex(Idx);
3588 return result;
3589}
3590
3591static int index_tu(int argc, const char **argv) {
3592 const char *check_prefix;
3593 CXIndex Idx;
3594 CXIndexAction idxAction;
3595 int result;
3596
3597 check_prefix = 0;
3598 if (argc > 0) {
3599 if (strstr(argv[0], "-check-prefix=") == argv[0]) {
3600 check_prefix = argv[0] + strlen("-check-prefix=");
3601 ++argv;
3602 --argc;
3603 }
3604 }
3605
3606 if (!(Idx = clang_createIndex(/* excludeDeclsFromPCH */ 1,
3607 /* displayDiagnostics=*/1))) {
3608 fprintf(stderrstderr, "Could not create Index\n");
3609 return 1;
3610 }
3611 idxAction = clang_IndexAction_create(Idx);
3612
3613 result = index_ast_file(argv[0], Idx, idxAction,
3614 /*importedASTs=*/0, check_prefix);
3615
3616 clang_IndexAction_dispose(idxAction);
3617 clang_disposeIndex(Idx);
3618 return result;
3619}
3620
3621static int index_compile_db(int argc, const char **argv) {
3622 const char *check_prefix;
3623 CXIndex Idx;
3624 CXIndexAction idxAction;
3625 int errorCode = 0;
3626
3627 check_prefix = 0;
3628 if (argc > 0) {
3629 if (strstr(argv[0], "-check-prefix=") == argv[0]) {
3630 check_prefix = argv[0] + strlen("-check-prefix=");
3631 ++argv;
3632 --argc;
3633 }
3634 }
3635
3636 if (argc == 0) {
3637 fprintf(stderrstderr, "no compilation database\n");
3638 return -1;
3639 }
3640
3641 if (!(Idx = clang_createIndex(/* excludeDeclsFromPCH */ 1,
3642 /* displayDiagnostics=*/1))) {
3643 fprintf(stderrstderr, "Could not create Index\n");
3644 return 1;
3645 }
3646 idxAction = clang_IndexAction_create(Idx);
3647
3648 {
3649 const char *database = argv[0];
3650 CXCompilationDatabase db = 0;
3651 CXCompileCommands CCmds = 0;
3652 CXCompileCommand CCmd;
3653 CXCompilationDatabase_Error ec;
3654 CXString wd;
3655#define MAX_COMPILE_ARGS512 512
3656 CXString cxargs[MAX_COMPILE_ARGS512];
3657 const char *args[MAX_COMPILE_ARGS512];
3658 char *tmp;
3659 unsigned len;
3660 char *buildDir;
3661 int i, a, numCmds, numArgs;
3662
3663 len = strlen(database);
3664 tmp = (char *) malloc(len+1);
3665 memcpy(tmp, database, len+1);
3666 buildDir = dirname(tmp);
3667
3668 db = clang_CompilationDatabase_fromDirectory(buildDir, &ec);
3669
3670 if (db) {
3671
3672 if (ec!=CXCompilationDatabase_NoError) {
3673 printf("unexpected error %d code while loading compilation database\n", ec);
3674 errorCode = -1;
3675 goto cdb_end;
3676 }
3677
3678 if (chdir(buildDir) != 0) {
3679 printf("Could not chdir to %s\n", buildDir);
3680 errorCode = -1;
3681 goto cdb_end;
3682 }
3683
3684 CCmds = clang_CompilationDatabase_getAllCompileCommands(db);
3685 if (!CCmds) {
3686 printf("compilation db is empty\n");
3687 errorCode = -1;
3688 goto cdb_end;
3689 }
3690
3691 numCmds = clang_CompileCommands_getSize(CCmds);
3692
3693 if (numCmds==0) {
3694 fprintf(stderrstderr, "should not get an empty compileCommand set\n");
3695 errorCode = -1;
3696 goto cdb_end;
3697 }
3698
3699 for (i=0; i<numCmds && errorCode == 0; ++i) {
3700 CCmd = clang_CompileCommands_getCommand(CCmds, i);
3701
3702 wd = clang_CompileCommand_getDirectory(CCmd);
3703 if (chdir(clang_getCString(wd)) != 0) {
3704 printf("Could not chdir to %s\n", clang_getCString(wd));
3705 errorCode = -1;
3706 goto cdb_end;
3707 }
3708 clang_disposeString(wd);
3709
3710 numArgs = clang_CompileCommand_getNumArgs(CCmd);
3711 if (numArgs > MAX_COMPILE_ARGS512){
3712 fprintf(stderrstderr, "got more compile arguments than maximum\n");
3713 errorCode = -1;
3714 goto cdb_end;
3715 }
3716 for (a=0; a<numArgs; ++a) {
3717 cxargs[a] = clang_CompileCommand_getArg(CCmd, a);
3718 args[a] = clang_getCString(cxargs[a]);
3719 }
3720
3721 errorCode = index_compile_args(numArgs, args, idxAction,
3722 /*importedASTs=*/0, check_prefix);
3723
3724 for (a=0; a<numArgs; ++a)
3725 clang_disposeString(cxargs[a]);
3726 }
3727 } else {
3728 printf("database loading failed with error code %d.\n", ec);
3729 errorCode = -1;
3730 }
3731
3732 cdb_end:
3733 clang_CompileCommands_dispose(CCmds);
3734 clang_CompilationDatabase_dispose(db);
3735 free(tmp);
3736
3737 }
3738
3739 clang_IndexAction_dispose(idxAction);
3740 clang_disposeIndex(Idx);
3741 return errorCode;
3742}
3743
3744int perform_token_annotation(int argc, const char **argv) {
3745 const char *input = argv[1];
3746 char *filename = 0;
3747 unsigned line, second_line;
3748 unsigned column, second_column;
3749 CXIndex CIdx;
3750 CXTranslationUnit TU = 0;
3751 int errorCode;
3752 struct CXUnsavedFile *unsaved_files = 0;
3753 int num_unsaved_files = 0;
3754 CXToken *tokens;
3755 unsigned num_tokens;
3756 CXSourceRange range;
3757 CXSourceLocation startLoc, endLoc;
3758 CXFile file = 0;
3759 CXCursor *cursors = 0;
3760 CXSourceRangeList *skipped_ranges = 0;
3761 enum CXErrorCode Err;
3762 unsigned i;
3763
3764 input += strlen("-test-annotate-tokens=");
3765 if ((errorCode = parse_file_line_column(input, &filename, &line, &column,
3766 &second_line, &second_column)))
3767 return errorCode;
3768
3769 if (parse_remapped_files(argc, argv, 2, &unsaved_files, &num_unsaved_files)) {
3770 free(filename);
3771 return -1;
3772 }
3773
3774 CIdx = clang_createIndex(0, 1);
3775 Err = clang_parseTranslationUnit2(CIdx, argv[argc - 1],
3776 argv + num_unsaved_files + 2,
3777 argc - num_unsaved_files - 3,
3778 unsaved_files,
3779 num_unsaved_files,
3780 getDefaultParsingOptions(), &TU);
3781 if (Err != CXError_Success) {
3782 fprintf(stderrstderr, "unable to parse input\n");
3783 describeLibclangFailure(Err);
3784 clang_disposeIndex(CIdx);
3785 free(filename);
3786 free_remapped_files(unsaved_files, num_unsaved_files);
3787 return -1;
3788 }
3789 errorCode = 0;
3790
3791 if (checkForErrors(TU) != 0) {
3792 errorCode = -1;
3793 goto teardown;
3794 }
3795
3796 if (getenv("CINDEXTEST_EDITING")) {
3797 for (i = 0; i < 5; ++i) {
3798 Err = clang_reparseTranslationUnit(TU, num_unsaved_files, unsaved_files,
3799 clang_defaultReparseOptions(TU));
3800 if (Err != CXError_Success) {
3801 fprintf(stderrstderr, "Unable to reparse translation unit!\n");
3802 describeLibclangFailure(Err);
3803 errorCode = -1;
3804 goto teardown;
3805 }
3806 }
3807 }
3808
3809 if (checkForErrors(TU) != 0) {
3810 errorCode = -1;
3811 goto teardown;
3812 }
3813
3814 file = clang_getFile(TU, filename);
3815 if (!file) {
3816 fprintf(stderrstderr, "file %s is not in this translation unit\n", filename);
3817 errorCode = -1;
3818 goto teardown;
3819 }
3820
3821 startLoc = clang_getLocation(TU, file, line, column);
3822 if (clang_equalLocations(clang_getNullLocation(), startLoc)) {
3823 fprintf(stderrstderr, "invalid source location %s:%d:%d\n", filename, line,
3824 column);
3825 errorCode = -1;
3826 goto teardown;
3827 }
3828
3829 endLoc = clang_getLocation(TU, file, second_line, second_column);
3830 if (clang_equalLocations(clang_getNullLocation(), endLoc)) {
3831 fprintf(stderrstderr, "invalid source location %s:%d:%d\n", filename,
3832 second_line, second_column);
3833 errorCode = -1;
3834 goto teardown;
3835 }
3836
3837 range = clang_getRange(startLoc, endLoc);
3838 clang_tokenize(TU, range, &tokens, &num_tokens);
3839
3840 if (checkForErrors(TU) != 0) {
3841 errorCode = -1;
3842 goto teardown;
3843 }
3844
3845 cursors = (CXCursor *)malloc(num_tokens * sizeof(CXCursor));
3846 clang_annotateTokens(TU, tokens, num_tokens, cursors);
3847
3848 if (checkForErrors(TU) != 0) {
3849 errorCode = -1;
3850 goto teardown;
3851 }
3852
3853 skipped_ranges = clang_getSkippedRanges(TU, file);
3854 for (i = 0; i != skipped_ranges->count; ++i) {
3855 unsigned start_line, start_column, end_line, end_column;
3856 clang_getSpellingLocation(clang_getRangeStart(skipped_ranges->ranges[i]),
3857 0, &start_line, &start_column, 0);
3858 clang_getSpellingLocation(clang_getRangeEnd(skipped_ranges->ranges[i]),
3859 0, &end_line, &end_column, 0);
3860 printf("Skipping: ");
3861 PrintExtent(stdoutstdout, start_line, start_column, end_line, end_column);
3862 printf("\n");
3863 }
3864 clang_disposeSourceRangeList(skipped_ranges);
3865
3866 for (i = 0; i != num_tokens; ++i) {
3867 const char *kind = "<unknown>";
3868 CXString spelling = clang_getTokenSpelling(TU, tokens[i]);
3869 CXSourceRange extent = clang_getTokenExtent(TU, tokens[i]);
3870 unsigned start_line, start_column, end_line, end_column;
3871
3872 switch (clang_getTokenKind(tokens[i])) {
3873 case CXToken_Punctuation: kind = "Punctuation"; break;
3874 case CXToken_Keyword: kind = "Keyword"; break;
3875 case CXToken_Identifier: kind = "Identifier"; break;
3876 case CXToken_Literal: kind = "Literal"; break;
3877 case CXToken_Comment: kind = "Comment"; break;
3878 }
3879 clang_getSpellingLocation(clang_getRangeStart(extent),
3880 0, &start_line, &start_column, 0);
3881 clang_getSpellingLocation(clang_getRangeEnd(extent),
3882 0, &end_line, &end_column, 0);
3883 printf("%s: \"%s\" ", kind, clang_getCString(spelling));
3884 clang_disposeString(spelling);
3885 PrintExtent(stdoutstdout, start_line, start_column, end_line, end_column);
3886 if (!clang_isInvalid(cursors[i].kind)) {
3887 printf(" ");
3888 PrintCursor(cursors[i], NULL((void*)0));
3889 }
3890 printf("\n");
3891 }
3892 free(cursors);
3893 clang_disposeTokens(TU, tokens, num_tokens);
3894
3895 teardown:
3896 PrintDiagnostics(TU);
3897 clang_disposeTranslationUnit(TU);
3898 clang_disposeIndex(CIdx);
3899 free(filename);
3900 free_remapped_files(unsaved_files, num_unsaved_files);
3901 return errorCode;
3902}
3903
3904static int
3905perform_test_compilation_db(const char *database, int argc, const char **argv) {
3906 CXCompilationDatabase db;
3907 CXCompileCommands CCmds;
3908 CXCompileCommand CCmd;
3909 CXCompilationDatabase_Error ec;
3910 CXString wd;
3911 CXString arg;
3912 int errorCode = 0;
3913 char *tmp;
3914 unsigned len;
3915 char *buildDir;
3916 int i, j, a, numCmds, numArgs;
3917
3918 len = strlen(database);
3919 tmp = (char *) malloc(len+1);
3920 memcpy(tmp, database, len+1);
3921 buildDir = dirname(tmp);
3922
3923 db = clang_CompilationDatabase_fromDirectory(buildDir, &ec);
3924
3925 if (db) {
3926
3927 if (ec!=CXCompilationDatabase_NoError) {
3928 printf("unexpected error %d code while loading compilation database\n", ec);
3929 errorCode = -1;
3930 goto cdb_end;
3931 }
3932
3933 for (i=0; i<argc && errorCode==0; ) {
3934 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){
3935 CCmds = clang_CompilationDatabase_getCompileCommands(db, argv[i+1]);
3936
3937 if (!CCmds) {
3938 printf("file %s not found in compilation db\n", argv[i+1]);
3939 errorCode = -1;
3940 break;
3941 }
3942
3943 numCmds = clang_CompileCommands_getSize(CCmds);
3944
3945 if (numCmds==0) {
3946 fprintf(stderrstderr, "should not get an empty compileCommand set for file"
3947 " '%s'\n", argv[i+1]);
3948 errorCode = -1;
3949 break;
3950 }
3951
3952 for (j=0; j<numCmds; ++j) {
3953 CCmd = clang_CompileCommands_getCommand(CCmds, j);
3954
3955 wd = clang_CompileCommand_getDirectory(CCmd);
3956 printf("workdir:'%s'", clang_getCString(wd));
3957 clang_disposeString(wd);
3958
3959 printf(" cmdline:'");
3960 numArgs = clang_CompileCommand_getNumArgs(CCmd);
3961 for (a=0; a<numArgs; ++a) {
3962 if (a) printf(" ");
3963 arg = clang_CompileCommand_getArg(CCmd, a);
3964 printf("%s", clang_getCString(arg));
3965 clang_disposeString(arg);
3966 }
3967 printf("'\n");
3968 }
3969
3970 clang_CompileCommands_dispose(CCmds);
3971
3972 i += 2;
3973 }
3974 }
3975 clang_CompilationDatabase_dispose(db);
3976 } else {
3977 printf("database loading failed with error code %d.\n", ec);
3978 errorCode = -1;
3979 }
3980
3981cdb_end:
3982 free(tmp);
3983
3984 return errorCode;
3985}
3986
3987/******************************************************************************/
3988/* USR printing. */
3989/******************************************************************************/
3990
3991static int insufficient_usr(const char *kind, const char *usage) {
3992 fprintf(stderrstderr, "USR for '%s' requires: %s\n", kind, usage);
3993 return 1;
3994}
3995
3996static unsigned isUSR(const char *s) {
3997 return s[0] == 'c' && s[1] == ':';
3998}
3999
4000static int not_usr(const char *s, const char *arg) {
4001 fprintf(stderrstderr, "'%s' argument ('%s') is not a USR\n", s, arg);
4002 return 1;
4003}
4004
4005static void print_usr(CXString usr) {
4006 const char *s = clang_getCString(usr);
4007 printf("%s\n", s);
4008 clang_disposeString(usr);
4009}
4010
4011static void display_usrs() {
4012 fprintf(stderrstderr, "-print-usrs options:\n"
4013 " ObjCCategory <class name> <category name>\n"
4014 " ObjCClass <class name>\n"
4015 " ObjCIvar <ivar name> <class USR>\n"
4016 " ObjCMethod <selector> [0=class method|1=instance method] "
4017 "<class USR>\n"
4018 " ObjCProperty <property name> <class USR>\n"
4019 " ObjCProtocol <protocol name>\n");
4020}
4021
4022int print_usrs(const char **I, const char **E) {
4023 while (I != E) {
4024 const char *kind = *I;
4025 unsigned len = strlen(kind);
4026 switch (len) {
4027 case 8:
4028 if (memcmp(kind, "ObjCIvar", 8) == 0) {
4029 if (I + 2 >= E)
4030 return insufficient_usr(kind, "<ivar name> <class USR>");
4031 if (!isUSR(I[2]))
4032 return not_usr("<class USR>", I[2]);
4033 else {
4034 CXString x;
4035 x.data = (void*) I[2];
4036 x.private_flags = 0;
4037 print_usr(clang_constructUSR_ObjCIvar(I[1], x));
4038 }
4039
4040 I += 3;
4041 continue;
4042 }
4043 break;
4044 case 9:
4045 if (memcmp(kind, "ObjCClass", 9) == 0) {
4046 if (I + 1 >= E)
4047 return insufficient_usr(kind, "<class name>");
4048 print_usr(clang_constructUSR_ObjCClass(I[1]));
4049 I += 2;
4050 continue;
4051 }
4052 break;
4053 case 10:
4054 if (memcmp(kind, "ObjCMethod", 10) == 0) {
4055 if (I + 3 >= E)
4056 return insufficient_usr(kind, "<method selector> "
4057 "[0=class method|1=instance method] <class USR>");
4058 if (!isUSR(I[3]))
4059 return not_usr("<class USR>", I[3]);
4060 else {
4061 CXString x;
4062 x.data = (void*) I[3];
4063 x.private_flags = 0;
4064 print_usr(clang_constructUSR_ObjCMethod(I[1], atoi(I[2]), x));
4065 }
4066 I += 4;
4067 continue;
4068 }
4069 break;
4070 case 12:
4071 if (memcmp(kind, "ObjCCategory", 12) == 0) {
4072 if (I + 2 >= E)
4073 return insufficient_usr(kind, "<class name> <category name>");
4074 print_usr(clang_constructUSR_ObjCCategory(I[1], I[2]));
4075 I += 3;
4076 continue;
4077 }
4078 if (memcmp(kind, "ObjCProtocol", 12) == 0) {
4079 if (I + 1 >= E)
4080 return insufficient_usr(kind, "<protocol name>");
4081 print_usr(clang_constructUSR_ObjCProtocol(I[1]));
4082 I += 2;
4083 continue;
4084 }
4085 if (memcmp(kind, "ObjCProperty", 12) == 0) {
4086 if (I + 2 >= E)
4087 return insufficient_usr(kind, "<property name> <class USR>");
4088 if (!isUSR(I[2]))
4089 return not_usr("<class USR>", I[2]);
4090 else {
4091 CXString x;
4092 x.data = (void*) I[2];
4093 x.private_flags = 0;
4094 print_usr(clang_constructUSR_ObjCProperty(I[1], x));
4095 }
4096 I += 3;
4097 continue;
4098 }
4099 break;
4100 default:
4101 break;
4102 }
4103 break;
4104 }
4105
4106 if (I != E) {
4107 fprintf(stderrstderr, "Invalid USR kind: %s\n", *I);
4108 display_usrs();
4109 return 1;
4110 }
4111 return 0;
4112}
4113
4114int print_usrs_file(const char *file_name) {
4115 char line[2048];
4116 const char *args[128];
4117 unsigned numChars = 0;
4118
4119 FILE *fp = fopen(file_name, "r");
4120 if (!fp) {
4121 fprintf(stderrstderr, "error: cannot open '%s'\n", file_name);
4122 return 1;
4123 }
4124
4125 /* This code is not really all that safe, but it works fine for testing. */
4126 while (!feof(fp)) {
4127 char c = fgetc(fp);
4128 if (c == '\n') {
4129 unsigned i = 0;
4130 const char *s = 0;
4131
4132 if (numChars == 0)
4133 continue;
4134
4135 line[numChars] = '\0';
4136 numChars = 0;
4137
4138 if (line[0] == '/' && line[1] == '/')
4139 continue;
4140
4141 s = strtok(line, " ");
4142 while (s) {
4143 args[i] = s;
4144 ++i;
4145 s = strtok(0, " ");
4146 }
4147 if (print_usrs(&args[0], &args[i]))
4148 return 1;
4149 }
4150 else
4151 line[numChars++] = c;
4152 }
4153
4154 fclose(fp);
4155 return 0;
4156}
4157
4158/******************************************************************************/
4159/* Command line processing. */
4160/******************************************************************************/
4161int write_pch_file(const char *filename, int argc, const char *argv[]) {
4162 CXIndex Idx;
4163 CXTranslationUnit TU;
4164 struct CXUnsavedFile *unsaved_files = 0;
4165 int num_unsaved_files = 0;
4166 enum CXErrorCode Err;
4167 int result = 0;
4168
4169 Idx = clang_createIndex(/* excludeDeclsFromPCH */1, /* displayDiagnostics=*/1);
4170
4171 if (parse_remapped_files(argc, argv, 0, &unsaved_files, &num_unsaved_files)) {
4172 clang_disposeIndex(Idx);
4173 return -1;
4174 }
4175
4176 Err = clang_parseTranslationUnit2(
4177 Idx, 0, argv + num_unsaved_files, argc - num_unsaved_files,
4178 unsaved_files, num_unsaved_files,
4179 CXTranslationUnit_Incomplete |
4180 CXTranslationUnit_DetailedPreprocessingRecord |
4181 CXTranslationUnit_ForSerialization,
4182 &TU);
4183 if (Err != CXError_Success) {
4184 fprintf(stderrstderr, "Unable to load translation unit!\n");
4185 describeLibclangFailure(Err);
4186 free_remapped_files(unsaved_files, num_unsaved_files);
4187 clang_disposeTranslationUnit(TU);
4188 clang_disposeIndex(Idx);
4189 return 1;
4190 }
4191
4192 switch (clang_saveTranslationUnit(TU, filename,
4193 clang_defaultSaveOptions(TU))) {
4194 case CXSaveError_None:
4195 break;
4196
4197 case CXSaveError_TranslationErrors:
4198 fprintf(stderrstderr, "Unable to write PCH file %s: translation errors\n",
4199 filename);
4200 result = 2;
4201 break;
4202
4203 case CXSaveError_InvalidTU:
4204 fprintf(stderrstderr, "Unable to write PCH file %s: invalid translation unit\n",
4205 filename);
4206 result = 3;
4207 break;
4208
4209 case CXSaveError_Unknown:
4210 default:
4211 fprintf(stderrstderr, "Unable to write PCH file %s: unknown error \n", filename);
4212 result = 1;
4213 break;
4214 }
4215
4216 clang_disposeTranslationUnit(TU);
4217 free_remapped_files(unsaved_files, num_unsaved_files);
4218 clang_disposeIndex(Idx);
4219 return result;
4220}
4221
4222/******************************************************************************/
4223/* Serialized diagnostics. */
4224/******************************************************************************/
4225
4226static const char *getDiagnosticCodeStr(enum CXLoadDiag_Error error) {
4227 switch (error) {
4228 case CXLoadDiag_CannotLoad: return "Cannot Load File";
4229 case CXLoadDiag_None: break;
4230 case CXLoadDiag_Unknown: return "Unknown";
4231 case CXLoadDiag_InvalidFile: return "Invalid File";
4232 }
4233 return "None";
4234}
4235
4236static const char *getSeverityString(enum CXDiagnosticSeverity severity) {
4237 switch (severity) {
4238 case CXDiagnostic_Note: return "note";
4239 case CXDiagnostic_Error: return "error";
4240 case CXDiagnostic_Fatal: return "fatal";
4241 case CXDiagnostic_Ignored: return "ignored";
4242 case CXDiagnostic_Warning: return "warning";
4243 }
4244 return "unknown";
4245}
4246
4247static void printIndent(unsigned indent) {
4248 if (indent == 0)
4249 return;
4250 fprintf(stderrstderr, "+");
4251 --indent;
4252 while (indent > 0) {
4253 fprintf(stderrstderr, "-");
4254 --indent;
4255 }
4256}
4257
4258static void printLocation(CXSourceLocation L) {
4259 CXFile File;
4260 CXString FileName;
4261 unsigned line, column, offset;
4262
4263 clang_getExpansionLocation(L, &File, &line, &column, &offset);
4264 FileName = clang_getFileName(File);
4265
4266 fprintf(stderrstderr, "%s:%d:%d", clang_getCString(FileName), line, column);
4267 clang_disposeString(FileName);
4268}
4269
4270static void printRanges(CXDiagnostic D, unsigned indent) {
4271 unsigned i, n = clang_getDiagnosticNumRanges(D);
4272
4273 for (i = 0; i < n; ++i) {
4274 CXSourceLocation Start, End;
4275 CXSourceRange SR = clang_getDiagnosticRange(D, i);
4276 Start = clang_getRangeStart(SR);
4277 End = clang_getRangeEnd(SR);
4278
4279 printIndent(indent);
4280 fprintf(stderrstderr, "Range: ");
4281 printLocation(Start);
4282 fprintf(stderrstderr, " ");
4283 printLocation(End);
4284 fprintf(stderrstderr, "\n");
4285 }
4286}
4287
4288static void printFixIts(CXDiagnostic D, unsigned indent) {
4289 unsigned i, n = clang_getDiagnosticNumFixIts(D);
4290 fprintf(stderrstderr, "Number FIXITs = %d\n", n);
4291 for (i = 0 ; i < n; ++i) {
4292 CXSourceRange ReplacementRange;
4293 CXString text;
4294 text = clang_getDiagnosticFixIt(D, i, &ReplacementRange);
4295
4296 printIndent(indent);
4297 fprintf(stderrstderr, "FIXIT: (");
4298 printLocation(clang_getRangeStart(ReplacementRange));
4299 fprintf(stderrstderr, " - ");
4300 printLocation(clang_getRangeEnd(ReplacementRange));
4301 fprintf(stderrstderr, "): \"%s\"\n", clang_getCString(text));
4302 clang_disposeString(text);
4303 }
4304}
4305
4306static void printDiagnosticSet(CXDiagnosticSet Diags, unsigned indent) {
4307 unsigned i, n;
4308
4309 if (!Diags)
4310 return;
4311
4312 n = clang_getNumDiagnosticsInSet(Diags);
4313 for (i = 0; i < n; ++i) {
4314 CXSourceLocation DiagLoc;
4315 CXDiagnostic D;
4316 CXFile File;
4317 CXString FileName, DiagSpelling, DiagOption, DiagCat;
4318 unsigned line, column, offset;
4319 const char *DiagOptionStr = 0, *DiagCatStr = 0;
4320
4321 D = clang_getDiagnosticInSet(Diags, i);
4322 DiagLoc = clang_getDiagnosticLocation(D);
4323 clang_getExpansionLocation(DiagLoc, &File, &line, &column, &offset);
4324 FileName = clang_getFileName(File);
4325 DiagSpelling = clang_getDiagnosticSpelling(D);
4326
4327 printIndent(indent);
4328
4329 fprintf(stderrstderr, "%s:%d:%d: %s: %s",
4330 clang_getCString(FileName),
4331 line,
4332 column,
4333 getSeverityString(clang_getDiagnosticSeverity(D)),
4334 clang_getCString(DiagSpelling));
4335
4336 DiagOption = clang_getDiagnosticOption(D, 0);
4337 DiagOptionStr = clang_getCString(DiagOption);
4338 if (DiagOptionStr) {
4339 fprintf(stderrstderr, " [%s]", DiagOptionStr);
4340 }
4341
4342 DiagCat = clang_getDiagnosticCategoryText(D);
4343 DiagCatStr = clang_getCString(DiagCat);
4344 if (DiagCatStr) {
4345 fprintf(stderrstderr, " [%s]", DiagCatStr);
4346 }
4347
4348 fprintf(stderrstderr, "\n");
4349
4350 printRanges(D, indent);
4351 printFixIts(D, indent);
4352
4353 /* Print subdiagnostics. */
4354 printDiagnosticSet(clang_getChildDiagnostics(D), indent+2);
4355
4356 clang_disposeString(FileName);
4357 clang_disposeString(DiagSpelling);
4358 clang_disposeString(DiagOption);
4359 clang_disposeString(DiagCat);
4360 }
4361}
4362
4363static int read_diagnostics(const char *filename) {
4364 enum CXLoadDiag_Error error;
4365 CXString errorString;
4366 CXDiagnosticSet Diags = 0;
4367
4368 Diags = clang_loadDiagnostics(filename, &error, &errorString);
4369 if (!Diags) {
4370 fprintf(stderrstderr, "Trouble deserializing file (%s): %s\n",
4371 getDiagnosticCodeStr(error),
4372 clang_getCString(errorString));
4373 clang_disposeString(errorString);
4374 return 1;
4375 }
4376
4377 printDiagnosticSet(Diags, 0);
4378 fprintf(stderrstderr, "Number of diagnostics: %d\n",
4379 clang_getNumDiagnosticsInSet(Diags));
4380 clang_disposeDiagnosticSet(Diags);
4381 return 0;
4382}
4383
4384static int perform_print_build_session_timestamp(void) {
4385 printf("%lld\n", clang_getBuildSessionTimestamp());
4386 return 0;
4387}
4388
4389/******************************************************************************/
4390/* Command line processing. */
4391/******************************************************************************/
4392
4393static CXCursorVisitor GetVisitor(const char *s) {
4394 if (s[0] == '\0')
4395 return FilteredPrintingVisitor;
4396 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)
4397 return USRVisitor;
4398 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)
4399 return GetVisitor(s + 13);
4400 return NULL((void*)0);
4401}
4402
4403static void print_usage(void) {
4404 fprintf(stderrstderr,
4405 "usage: c-index-test -code-completion-at=<site> <compiler arguments>\n"
4406 " c-index-test -code-completion-timing=<site> <compiler arguments>\n"
4407 " c-index-test -cursor-at=<site> <compiler arguments>\n"
4408 " c-index-test -evaluate-cursor-at=<site> <compiler arguments>\n"
4409 " c-index-test -get-macro-info-cursor-at=<site> <compiler arguments>\n"
4410 " c-index-test -file-refs-at=<site> <compiler arguments>\n"
4411 " c-index-test -file-includes-in=<filename> <compiler arguments>\n");
4412 fprintf(stderrstderr,
4413 " c-index-test -index-file [-check-prefix=<FileCheck prefix>] <compiler arguments>\n"
4414 " c-index-test -index-file-full [-check-prefix=<FileCheck prefix>] <compiler arguments>\n"
4415 " c-index-test -index-tu [-check-prefix=<FileCheck prefix>] <AST file>\n"
4416 " c-index-test -index-compile-db [-check-prefix=<FileCheck prefix>] <compilation database>\n"
4417 " c-index-test -test-file-scan <AST file> <source file> "
4418 "[FileCheck prefix]\n");
4419 fprintf(stderrstderr,
4420 " c-index-test -test-load-tu <AST file> <symbol filter> "
4421 "[FileCheck prefix]\n"
4422 " c-index-test -test-load-tu-usrs <AST file> <symbol filter> "
4423 "[FileCheck prefix]\n"
4424 " c-index-test -test-load-source <symbol filter> {<args>}*\n");
4425 fprintf(stderrstderr,
4426 " c-index-test -test-load-source-memory-usage "
4427 "<symbol filter> {<args>}*\n"
4428 " c-index-test -test-load-source-reparse <trials> <symbol filter> "
4429 " {<args>}*\n"
4430 " c-index-test -test-load-source-usrs <symbol filter> {<args>}*\n"
4431 " c-index-test -test-load-source-usrs-memory-usage "
4432 "<symbol filter> {<args>}*\n"
4433 " c-index-test -test-annotate-tokens=<range> {<args>}*\n"
4434 " c-index-test -test-inclusion-stack-source {<args>}*\n"
4435 " c-index-test -test-inclusion-stack-tu <AST file>\n");
4436 fprintf(stderrstderr,
4437 " c-index-test -test-print-linkage-source {<args>}*\n"
4438 " c-index-test -test-print-visibility {<args>}*\n"
4439 " c-index-test -test-print-type {<args>}*\n"
4440 " c-index-test -test-print-type-size {<args>}*\n"
4441 " c-index-test -test-print-bitwidth {<args>}*\n"
4442 " c-index-test -test-print-target-info {<args>}*\n"
4443 " c-index-test -test-print-type-declaration {<args>}*\n"
4444 " c-index-test -print-usr [<CursorKind> {<args>}]*\n"
4445 " c-index-test -print-usr-file <file>\n");
4446 fprintf(stderrstderr,
4447 " c-index-test -write-pch <file> <compiler arguments>\n"
4448 " c-index-test -compilation-db [lookup <filename>] database\n");
4449 fprintf(stderrstderr,
4450 " c-index-test -print-build-session-timestamp\n");
4451 fprintf(stderrstderr,
4452 " c-index-test -read-diagnostics <file>\n\n");
4453 fprintf(stderrstderr,
4454 " <symbol filter> values:\n%s",
4455 " all - load all symbols, including those from PCH\n"
4456 " local - load all symbols except those in PCH\n"
4457 " category - only load ObjC categories (non-PCH)\n"
4458 " interface - only load ObjC interfaces (non-PCH)\n"
4459 " protocol - only load ObjC protocols (non-PCH)\n"
4460 " function - only load functions (non-PCH)\n"
4461 " typedef - only load typdefs (non-PCH)\n"
4462 " scan-function - scan function bodies (non-PCH)\n\n");
4463}
4464
4465/***/
4466
4467int cindextest_main(int argc, const char **argv) {
4468 clang_enableStackTraces();
4469 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)
4470 return read_diagnostics(argv[2]);
4471 if (argc > 2 && strstr(argv[1], "-code-completion-at=") == argv[1])
4472 return perform_code_completion(argc, argv, 0);
4473 if (argc > 2 && strstr(argv[1], "-code-completion-timing=") == argv[1])
4474 return perform_code_completion(argc, argv, 1);
4475 if (argc > 2 && strstr(argv[1], "-cursor-at=") == argv[1])
4476 return inspect_cursor_at(argc, argv, "-cursor-at=", inspect_print_cursor);
4477 if (argc > 2 && strstr(argv[1], "-evaluate-cursor-at=") == argv[1])
4478 return inspect_cursor_at(argc, argv, "-evaluate-cursor-at=",
4479 inspect_evaluate_cursor);
4480 if (argc > 2 && strstr(argv[1], "-get-macro-info-cursor-at=") == argv[1])
4481 return inspect_cursor_at(argc, argv, "-get-macro-info-cursor-at=",
4482 inspect_macroinfo_cursor);
4483 if (argc > 2 && strstr(argv[1], "-file-refs-at=") == argv[1])
4484 return find_file_refs_at(argc, argv);
4485 if (argc > 2 && strstr(argv[1], "-file-includes-in=") == argv[1])
4486 return find_file_includes_in(argc, argv);
4487 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)
4488 return index_file(argc - 2, argv + 2, /*full=*/0);
4489 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)
4490 return index_file(argc - 2, argv + 2, /*full=*/1);
4491 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)
4492 return index_tu(argc - 2, argv + 2);
4493 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)
4494 return index_compile_db(argc - 2, argv + 2);
4495 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) {
4496 CXCursorVisitor I = GetVisitor(argv[1] + 13);
4497 if (I)
4498 return perform_test_load_tu(argv[2], argv[3], argc >= 5 ? argv[4] : 0, I,
4499 NULL((void*)0));
4500 }
4501 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){
4502 CXCursorVisitor I = GetVisitor(argv[1] + 25);
4503 if (I) {
4504 int trials = atoi(argv[2]);
4505 return perform_test_reparse_source(argc - 4, argv + 4, trials, argv[3], I,
4506 NULL((void*)0));
4507 }
4508 }
4509 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) {
4510 CXCursorVisitor I = GetVisitor(argv[1] + 17);
4511
4512 PostVisitTU postVisit = 0;
4513 if (strstr(argv[1], "-memory-usage"))
4514 postVisit = PrintMemoryUsage;
4515
4516 if (I)
4517 return perform_test_load_source(argc - 3, argv + 3, argv[2], I,
4518 postVisit);
4519 }
4520 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)
4521 return perform_single_file_parse(argv[2]);
4522 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)
4523 return perform_file_scan(argv[2], argv[3],
4524 argc >= 5 ? argv[4] : 0);
4525 else if (argc > 2 && strstr(argv[1], "-test-annotate-tokens=") == argv[1])
4526 return perform_token_annotation(argc, argv);
4527 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)
4528 return perform_test_load_source(argc - 2, argv + 2, "all", NULL((void*)0),
4529 PrintInclusionStack);
4530 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)
4531 return perform_test_load_tu(argv[2], "all", NULL((void*)0), NULL((void*)0),
4532 PrintInclusionStack);
4533 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)
4534 return perform_test_load_source(argc - 2, argv + 2, "all", PrintLinkage,
4535 NULL((void*)0));
4536 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)
4537 return perform_test_load_source(argc - 2, argv + 2, "all", PrintVisibility,
4538 NULL((void*)0));
4539 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)
4540 return perform_test_load_source(argc - 2, argv + 2, "all",
4541 PrintType, 0);
4542 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)
4543 return perform_test_load_source(argc - 2, argv + 2, "all",
4544 PrintTypeSize, 0);
4545 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)
4546 return perform_test_load_source(argc - 2, argv + 2, "all",
4547 PrintTypeDeclaration, 0);
4548 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)
4549 return perform_test_load_source(argc - 2, argv + 2, "all",
4550 PrintBitWidth, 0);
4551 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)
4552 return perform_test_load_tu(argv[2], "all", NULL((void*)0), PrintMangledName, NULL((void*)0));
4553 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)
4554 return perform_test_load_tu(argv[2], "all", NULL((void*)0), PrintManglings, NULL((void*)0));
4555 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)
4556 return print_target_info(argc - 2, argv + 2);
4557 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) {
4558 if (argc > 2)
4559 return print_usrs(argv + 2, argv + argc);
4560 else {
4561 display_usrs();
4562 return 1;
4563 }
4564 }
4565 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)
4566 return print_usrs_file(argv[2]);
4567 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)
4568 return write_pch_file(argv[2], argc - 3, argv + 3);
4569 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)
4570 return perform_test_compilation_db(argv[argc-1], argc - 3, argv + 2);
4571 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)
4572 return perform_print_build_session_timestamp();
4573
4574 print_usage();
4575 return 1;
4576}
4577
4578/***/
4579
4580/* We intentionally run in a separate thread to ensure we at least minimal
4581 * testing of a multithreaded environment (for example, having a reduced stack
4582 * size). */
4583
4584typedef struct thread_info {
4585 int (*main_func)(int argc, const char **argv);
4586 int argc;
4587 const char **argv;
4588 int result;
4589} thread_info;
4590void thread_runner(void *client_data_v) {
4591 thread_info *client_data = client_data_v;
4592 client_data->result = client_data->main_func(client_data->argc,
4593 client_data->argv);
4594}
4595
4596static void flush_atexit(void) {
4597 /* stdout, and surprisingly even stderr, are not always flushed on process
4598 * and thread exit, particularly when the system is under heavy load. */
4599 fflush(stdoutstdout);
4600 fflush(stderrstderr);
4601}
4602
4603int main(int argc, const char **argv) {
4604 thread_info client_data;
4605
4606 atexit(flush_atexit);
4607
4608#ifdef CLANG_HAVE_LIBXML
4609 LIBXML_TEST_VERSION
4610#endif
4611
4612 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)
4613 return indextest_core_main(argc, argv);
4614
4615 client_data.main_func = cindextest_main;
4616 client_data.argc = argc;
4617 client_data.argv = argv;
4618
4619 if (getenv("CINDEXTEST_NOTHREADS"))
4620 return client_data.main_func(client_data.argc, client_data.argv);
4621
4622 clang_executeOnThread(thread_runner, &client_data, 0);
4623 return client_data.result;
4624}