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