]> granicus.if.org Git - clang/commitdiff
Add support for 'CXFile' (<rdar://problem/7303360>).
authorSteve Naroff <snaroff@apple.com>
Tue, 27 Oct 2009 14:35:18 +0000 (14:35 +0000)
committerSteve Naroff <snaroff@apple.com>
Tue, 27 Oct 2009 14:35:18 +0000 (14:35 +0000)
- 4 new functions (clang_getCursorSourceFile, clang_getDeclSourceFile, clang_getFileName, clang_getFileTime).

- Should remove clang_getDeclSource() and clang_getCursorSource(). For now, just put 'deprecate' comment in header.

- Also changed CXX style comment to C style (to eliminate warning).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85238 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang-c/Index.h
tools/CIndex/CIndex.cpp
tools/CIndex/CIndex.exports

index cbc1df9fa3ab79353ed5b97d840642f288594647..0d41edb2e01623b29743f81102a3a1b544e51301 100644 (file)
 #ifndef CLANG_C_INDEX_H
 #define CLANG_C_INDEX_H
 
+#include <sys/stat.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-// MSVC DLL import/export.
+/* MSVC DLL import/export. */
 #ifdef _MSC_VER
   #ifdef _CINDEX_LIB_
     #define CINDEX_LINKAGE __declspec(dllexport)
@@ -44,6 +46,7 @@ typedef void *CXIndex;            /* An indexing instance. */
 
 typedef void *CXTranslationUnit;  /* A translation unit instance. */
 
+typedef void *CXFile;    /* A source file */
 typedef void *CXDecl;    /* A specific declaration within a translation unit. */
 typedef void *CXStmt;    /* A specific statement within a function/method */
 
@@ -240,6 +243,12 @@ typedef void (*CXDeclIterator)(CXDecl, CXCursor, CXClientData);
 
 CINDEX_LINKAGE void clang_loadDeclaration(CXDecl, CXDeclIterator, CXClientData);
 
+/*
+ * CXFile Operations.
+ */
+const char *clang_getFileName(CXFile SFile);
+time_t clang_getFileTime(CXFile SFile);
+
 /*
  * CXEntity Operations.
  */
@@ -254,7 +263,8 @@ CINDEX_LINKAGE CXEntity clang_getEntityFromDecl(CXDecl);
 CINDEX_LINKAGE const char *clang_getDeclSpelling(CXDecl);
 CINDEX_LINKAGE unsigned clang_getDeclLine(CXDecl);
 CINDEX_LINKAGE unsigned clang_getDeclColumn(CXDecl);
-CINDEX_LINKAGE const char *clang_getDeclSource(CXDecl);
+CINDEX_LINKAGE const char *clang_getDeclSource(CXDecl); /* deprecate */
+CINDEX_LINKAGE CXFile clang_getDeclSourceFile(CXDecl);
 
 /*
  * CXCursor Operations.
@@ -289,8 +299,9 @@ CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
 
 CINDEX_LINKAGE unsigned clang_getCursorLine(CXCursor);
 CINDEX_LINKAGE unsigned clang_getCursorColumn(CXCursor);
-CINDEX_LINKAGE const char *clang_getCursorSource(CXCursor);
 CINDEX_LINKAGE const char *clang_getCursorSpelling(CXCursor);
+CINDEX_LINKAGE const char *clang_getCursorSource(CXCursor); /* deprecate */
+CINDEX_LINKAGE CXFile clang_getCursorSourceFile(CXCursor);
 
 /* for debug/testing */
 CINDEX_LINKAGE const char *clang_getCursorKindSpelling(enum CXCursorKind Kind); 
index f044f89c4ae10ff6924ae66a86a4cf831d69c60a..5ffa6d78e8623d078e925bdca123ca4dd1365847 100644 (file)
@@ -569,11 +569,42 @@ unsigned clang_getDeclColumn(CXDecl AnonDecl)
 }
 
 const char *clang_getDeclSource(CXDecl AnonDecl) 
+{
+  assert(AnonDecl && "Passed null CXDecl");
+  FileEntry *FEnt = static_cast<FileEntry *>(clang_getDeclSourceFile(AnonDecl));
+  assert (FEnt && "Cannot find FileEntry for Decl");
+  return clang_getFileName(FEnt);
+}
+
+static const FileEntry *getFileEntryFromSourceLocation(SourceManager &SMgr,
+                                                       SourceLocation SLoc) 
+{
+  FileID FID;
+  if (SLoc.isFileID())
+    FID = SMgr.getFileID(SLoc);
+  else
+    FID = SMgr.getDecomposedSpellingLoc(SLoc).first;
+  return SMgr.getFileEntryForID(FID);
+}
+
+CXFile clang_getDeclSourceFile(CXDecl AnonDecl) 
 {
   assert(AnonDecl && "Passed null CXDecl");
   NamedDecl *ND = static_cast<NamedDecl *>(AnonDecl);
   SourceManager &SourceMgr = ND->getASTContext().getSourceManager();
-  return SourceMgr.getBufferName(ND->getLocation());
+  return (void *)getFileEntryFromSourceLocation(SourceMgr, ND->getLocation());
+}
+
+const char *clang_getFileName(CXFile SFile) {
+  assert(SFile && "Passed null CXFile");
+  FileEntry *FEnt = static_cast<FileEntry *>(SFile);
+  return FEnt->getName();
+}
+
+time_t clang_getFileTime(CXFile SFile) {
+  assert(SFile && "Passed null CXFile");
+  FileEntry *FEnt = static_cast<FileEntry *>(SFile);
+  return FEnt->getModificationTime();
 }
 
 const char *clang_getCursorSpelling(CXCursor C)
@@ -930,6 +961,16 @@ const char *clang_getCursorSource(CXCursor C)
   return Buffer->getBufferIdentifier();
 }
 
+CXFile clang_getCursorSourceFile(CXCursor C)
+{
+  assert(C.decl && "CXCursor has null decl");
+  NamedDecl *ND = static_cast<NamedDecl *>(C.decl);
+  SourceManager &SourceMgr = ND->getASTContext().getSourceManager();
+  
+  return (void *)getFileEntryFromSourceLocation(SourceMgr,
+                                        getLocationFromCursor(C,SourceMgr, ND));
+}
+
 void clang_getDefinitionSpellingAndExtent(CXCursor C, 
                                           const char **startBuf,
                                           const char **endBuf,
index e9d44a0dc918f4fcf0d19921aa87191ad4f5050d..b726aa00e98c59693014cd446db5cc2f2558f7fa 100644 (file)
@@ -30,3 +30,7 @@ _clang_getCursorSpelling
 _clang_getCursorKindSpelling
 _clang_getDefinitionSpellingAndExtent
 _clang_getTranslationUnitSpelling
+_clang_getCursorSourceFile
+_clang_getDeclSourceFile
+_clang_getFileName
+_clang_getFileTime