forked from OSchip/llvm-project
c-index-test: Simplify file scanning code.
llvm-svn: 96159
This commit is contained in:
parent
98c07e0e23
commit
eb27e7d999
|
@ -579,12 +579,10 @@ static int perform_file_scan(const char *ast_file, const char *source_file,
|
||||||
CXIndex Idx;
|
CXIndex Idx;
|
||||||
CXTranslationUnit TU;
|
CXTranslationUnit TU;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
unsigned line;
|
CXCursor prevCursor = clang_getNullCursor();
|
||||||
CXCursor prevCursor;
|
|
||||||
CXFile file;
|
CXFile file;
|
||||||
unsigned printed;
|
unsigned line = 1, col = 1;
|
||||||
unsigned start_line, start_col, last_line, last_col;
|
unsigned start_line = 1, start_col = 1, prev_line = 0, prev_col = 0;
|
||||||
size_t i;
|
|
||||||
|
|
||||||
if (!(Idx = clang_createIndex(/* excludeDeclsFromPCH */ 1))) {
|
if (!(Idx = clang_createIndex(/* excludeDeclsFromPCH */ 1))) {
|
||||||
fprintf(stderr, "Could not create Index\n");
|
fprintf(stderr, "Could not create Index\n");
|
||||||
|
@ -599,50 +597,34 @@ static int perform_file_scan(const char *ast_file, const char *source_file,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
line = 0;
|
|
||||||
prevCursor = clang_getNullCursor();
|
|
||||||
printed = 0;
|
|
||||||
start_line = last_line = 1;
|
|
||||||
start_col = last_col = 1;
|
|
||||||
|
|
||||||
file = clang_getFile(TU, source_file);
|
file = clang_getFile(TU, source_file);
|
||||||
while (!feof(fp)) {
|
for (;;) {
|
||||||
size_t len = 0;
|
|
||||||
int c;
|
|
||||||
|
|
||||||
while ((c = fgetc(fp)) != EOF) {
|
|
||||||
len++;
|
|
||||||
if (c == '\n')
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
++line;
|
|
||||||
|
|
||||||
for (i = 0; i < len ; ++i) {
|
|
||||||
CXCursor cursor;
|
CXCursor cursor;
|
||||||
cursor = clang_getCursor(TU, clang_getLocation(TU, file, line, i+1));
|
int c = fgetc(fp);
|
||||||
|
|
||||||
if (!clang_equalCursors(cursor, prevCursor) &&
|
if (c == '\n') {
|
||||||
|
++line;
|
||||||
|
col = 1;
|
||||||
|
} else
|
||||||
|
++col;
|
||||||
|
|
||||||
|
/* Check the cursor at this position, and dump the previous one if we have
|
||||||
|
* found something new.
|
||||||
|
*/
|
||||||
|
cursor = clang_getCursor(TU, clang_getLocation(TU, file, line, col));
|
||||||
|
if ((c == EOF || !clang_equalCursors(cursor, prevCursor)) &&
|
||||||
prevCursor.kind != CXCursor_InvalidFile) {
|
prevCursor.kind != CXCursor_InvalidFile) {
|
||||||
print_cursor_file_scan(prevCursor, start_line, start_col,
|
print_cursor_file_scan(prevCursor, start_line, start_col,
|
||||||
last_line, last_col, prefix);
|
prev_line, prev_col, prefix);
|
||||||
printed = 1;
|
|
||||||
start_line = line;
|
start_line = line;
|
||||||
start_col = (unsigned) i+1;
|
start_col = col;
|
||||||
}
|
|
||||||
else {
|
|
||||||
printed = 0;
|
|
||||||
}
|
}
|
||||||
|
if (c == EOF)
|
||||||
|
break;
|
||||||
|
|
||||||
prevCursor = cursor;
|
prevCursor = cursor;
|
||||||
last_line = line;
|
prev_line = line;
|
||||||
last_col = (unsigned) i+1;
|
prev_col = col;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!printed && prevCursor.kind != CXCursor_InvalidFile) {
|
|
||||||
print_cursor_file_scan(prevCursor, start_line, start_col,
|
|
||||||
last_line, last_col, prefix);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
Loading…
Reference in New Issue