Change clang_getFileName() to return a 'CXString' instead of 'const char *'.

llvm-svn: 96424
This commit is contained in:
Ted Kremenek 2010-02-17 00:41:20 +00:00
parent 5cca6ebae9
commit c560b6835e
3 changed files with 31 additions and 13 deletions

View File

@ -207,7 +207,7 @@ typedef void *CXFile;
/** /**
* \brief Retrieve the complete file and path name of the given file. * \brief Retrieve the complete file and path name of the given file.
*/ */
CINDEX_LINKAGE const char *clang_getFileName(CXFile SFile); CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile);
/** /**
* \brief Retrieve the last modification time of the given file. * \brief Retrieve the last modification time of the given file.

View File

@ -1223,12 +1223,12 @@ CXSourceLocation clang_getRangeEnd(CXSourceRange range) {
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
extern "C" { extern "C" {
const char *clang_getFileName(CXFile SFile) { CXString clang_getFileName(CXFile SFile) {
if (!SFile) if (!SFile)
return 0; return createCXString(NULL);
FileEntry *FEnt = static_cast<FileEntry *>(SFile); FileEntry *FEnt = static_cast<FileEntry *>(SFile);
return FEnt->getName(); return createCXString(FEnt->getName());
} }
time_t clang_getFileTime(CXFile SFile) { time_t clang_getFileTime(CXFile SFile) {

View File

@ -172,13 +172,19 @@ static void PrintCursor(CXCursor Cursor) {
static const char* GetCursorSource(CXCursor Cursor) { static const char* GetCursorSource(CXCursor Cursor) {
CXSourceLocation Loc = clang_getCursorLocation(Cursor); CXSourceLocation Loc = clang_getCursorLocation(Cursor);
const char *source; CXString source;
CXFile file; CXFile file;
clang_getInstantiationLocation(Loc, &file, 0, 0, 0); clang_getInstantiationLocation(Loc, &file, 0, 0, 0);
source = clang_getFileName(file); source = clang_getFileName(file);
if (!source) if (!source.Spelling) {
return "<invalid loc>"; clang_disposeString(source);
return basename(source); return "<invalid loc>";
}
else {
const char *b = basename(source.Spelling);
clang_disposeString(source);
return b;
}
} }
/******************************************************************************/ /******************************************************************************/
@ -205,8 +211,11 @@ static void PrintDiagnosticCallback(CXDiagnostic Diagnostic,
if (file) { if (file) {
unsigned i, n; unsigned i, n;
unsigned printed_any_ranges = 0; unsigned printed_any_ranges = 0;
CXString fname;
fprintf(out, "%s:%d:%d:", clang_getFileName(file), line, column); fname = clang_getFileName(file);
fprintf(out, "%s:%d:%d:", fname.Spelling, line, column);
clang_disposeString(fname);
n = clang_getDiagnosticNumRanges(Diagnostic); n = clang_getDiagnosticNumRanges(Diagnostic);
for (i = 0; i != n; ++i) { for (i = 0; i != n; ++i) {
@ -376,7 +385,7 @@ static enum CXChildVisitResult FunctionScanVisitor(CXCursor Cursor,
while (startBuf < endBuf) { while (startBuf < endBuf) {
CXSourceLocation Loc; CXSourceLocation Loc;
CXFile file; CXFile file;
const char *source = 0; CXString source;
if (*startBuf == '\n') { if (*startBuf == '\n') {
startBuf++; startBuf++;
@ -387,8 +396,9 @@ static enum CXChildVisitResult FunctionScanVisitor(CXCursor Cursor,
Loc = clang_getCursorLocation(Cursor); Loc = clang_getCursorLocation(Cursor);
clang_getInstantiationLocation(Loc, &file, 0, 0, 0); clang_getInstantiationLocation(Loc, &file, 0, 0, 0);
source = clang_getFileName(file); source = clang_getFileName(file);
if (source) { if (source.Spelling) {
CXSourceLocation RefLoc CXSourceLocation RefLoc
= clang_getLocation(Data->TU, file, curLine, curColumn); = clang_getLocation(Data->TU, file, curLine, curColumn);
Ref = clang_getCursor(Data->TU, RefLoc); Ref = clang_getCursor(Data->TU, RefLoc);
@ -401,6 +411,7 @@ static enum CXChildVisitResult FunctionScanVisitor(CXCursor Cursor,
printf("\n"); printf("\n");
} }
} }
clang_disposeString(source);
startBuf++; startBuf++;
} }
@ -439,13 +450,20 @@ void InclusionVisitor(CXFile includedFile, CXSourceLocation *includeStack,
unsigned includeStackLen, CXClientData data) { unsigned includeStackLen, CXClientData data) {
unsigned i; unsigned i;
printf("file: %s\nincluded by:\n", clang_getFileName(includedFile)); CXString fname;
fname = clang_getFileName(includedFile);
printf("file: %s\nincluded by:\n", fname.Spelling);
clang_disposeString(fname);
for (i = 0; i < includeStackLen; ++i) { for (i = 0; i < includeStackLen; ++i) {
CXFile includingFile; CXFile includingFile;
unsigned line, column; unsigned line, column;
clang_getInstantiationLocation(includeStack[i], &includingFile, &line, clang_getInstantiationLocation(includeStack[i], &includingFile, &line,
&column, 0); &column, 0);
printf(" %s:%d:%d\n", clang_getFileName(includingFile), line, column); fname = clang_getFileName(includingFile);
printf(" %s:%d:%d\n", fname.Spelling, line, column);
clang_disposeString(fname);
} }
printf("\n"); printf("\n");
} }