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