Bug Summary

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

Annotated Source Code

Press '?' to see keyboard shortcuts

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