[cfe-commits] r96424 - in /cfe/trunk: include/clang-c/Index.h tools/CIndex/CIndex.cpp tools/c-index-test/c-index-test.c
Ted Kremenek
kremenek at apple.com
Tue Feb 16 16:41:20 PST 2010
Author: kremenek
Date: Tue Feb 16 18:41:20 2010
New Revision: 96424
URL: http://llvm.org/viewvc/llvm-project?rev=96424&view=rev
Log:
Change clang_getFileName() to return a 'CXString' instead of 'const char *'.
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/tools/CIndex/CIndex.cpp
cfe/trunk/tools/c-index-test/c-index-test.c
Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=96424&r1=96423&r2=96424&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Tue Feb 16 18:41:20 2010
@@ -207,7 +207,7 @@
/**
* \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.
Modified: cfe/trunk/tools/CIndex/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=96424&r1=96423&r2=96424&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Tue Feb 16 18:41:20 2010
@@ -1223,12 +1223,12 @@
//===----------------------------------------------------------------------===//
extern "C" {
-const char *clang_getFileName(CXFile SFile) {
+CXString clang_getFileName(CXFile SFile) {
if (!SFile)
- return 0;
+ return createCXString(NULL);
FileEntry *FEnt = static_cast<FileEntry *>(SFile);
- return FEnt->getName();
+ return createCXString(FEnt->getName());
}
time_t clang_getFileTime(CXFile SFile) {
Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=96424&r1=96423&r2=96424&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Tue Feb 16 18:41:20 2010
@@ -172,13 +172,19 @@
static const char* GetCursorSource(CXCursor Cursor) {
CXSourceLocation Loc = clang_getCursorLocation(Cursor);
- const char *source;
+ CXString source;
CXFile file;
clang_getInstantiationLocation(Loc, &file, 0, 0, 0);
source = clang_getFileName(file);
- if (!source)
- return "<invalid loc>";
- return basename(source);
+ if (!source.Spelling) {
+ clang_disposeString(source);
+ return "<invalid loc>";
+ }
+ else {
+ const char *b = basename(source.Spelling);
+ clang_disposeString(source);
+ return b;
+ }
}
/******************************************************************************/
@@ -205,8 +211,11 @@
if (file) {
unsigned i, n;
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);
for (i = 0; i != n; ++i) {
@@ -376,7 +385,7 @@
while (startBuf < endBuf) {
CXSourceLocation Loc;
CXFile file;
- const char *source = 0;
+ CXString source;
if (*startBuf == '\n') {
startBuf++;
@@ -387,8 +396,9 @@
Loc = clang_getCursorLocation(Cursor);
clang_getInstantiationLocation(Loc, &file, 0, 0, 0);
+
source = clang_getFileName(file);
- if (source) {
+ if (source.Spelling) {
CXSourceLocation RefLoc
= clang_getLocation(Data->TU, file, curLine, curColumn);
Ref = clang_getCursor(Data->TU, RefLoc);
@@ -401,6 +411,7 @@
printf("\n");
}
}
+ clang_disposeString(source);
startBuf++;
}
@@ -439,13 +450,20 @@
unsigned includeStackLen, CXClientData data) {
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) {
CXFile includingFile;
unsigned line, column;
clang_getInstantiationLocation(includeStack[i], &includingFile, &line,
&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");
}
More information about the cfe-commits
mailing list