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