]> granicus.if.org Git - clang/commitdiff
Clean up the CIndex API slightly.
authorDouglas Gregor <dgregor@apple.com>
Mon, 18 Jan 2010 22:13:09 +0000 (22:13 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 18 Jan 2010 22:13:09 +0000 (22:13 +0000)
Renamed CXSourceFileLine to CXSourceLocation and added a CXFile, to
better match Clang's SourceLocation. Teach clang_getDeclExtent to fill
in the CXFile properly.

Renamed CXSourceExtent to CXSourceRange, to better match Clang's
SourceLocation.

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

include/clang-c/Index.h
tools/CIndex/CIndex.cpp
tools/c-index-test/c-index-test.c

index c7b0a5197c6c39dc41052f7370a1123f7a301fa3..380dec7796669e8cbc53ce63e23e36054a981193 100644 (file)
@@ -339,22 +339,34 @@ CINDEX_LINKAGE unsigned clang_getDeclColumn(CXDecl);
 CINDEX_LINKAGE const char *clang_getDeclSource(CXDecl); /* deprecate */
 CINDEX_LINKAGE CXFile clang_getDeclSourceFile(CXDecl);
 
-typedef struct CXSourceLineColumn {
+/**
+ * \brief Identifies a specific source location given its file, line, and 
+ * column.
+ */
+typedef struct {
+  CXFile file;
   unsigned line;
   unsigned column;
-} CXSourceLineColumn;
+} CXSourceLocation;
 
-typedef struct CXDeclExtent {
-  CXSourceLineColumn begin;
-  CXSourceLineColumn end;
-} CXSourceExtent;
+/**
+ * \brief Identifies a range of source locations identified by the starting and
+ * ending locations of that range.
+ *
+ * The \c begin location points to the first character in the range and the
+ * \c end location points to the last character in the range.
+ */
+typedef struct {
+  CXSourceLocation begin;
+  CXSourceLocation end;
+} CXSourceRange;
 
 /* clang_getDeclExtent() returns the physical extent of a declaration.  The
  * beginning line/column pair points to the start of the first token in the
  * declaration, and the ending line/column pair points to the last character in
  * the last token of the declaration.
  */
-CINDEX_LINKAGE CXSourceExtent clang_getDeclExtent(CXDecl);
+CINDEX_LINKAGE CXSourceRange clang_getDeclExtent(CXDecl);
 
 /*
  * CXCursor Operations.
index c5c7409ffcfb10751509a1386627fc80539d753b..a11f54b8793e59960b86848bd6d74c1e4306d34d 100644 (file)
@@ -643,7 +643,7 @@ unsigned clang_getDeclColumn(CXDecl AnonDecl) {
   return SourceMgr.getSpellingColumnNumber(ND->getLocation());
 }
   
-CXDeclExtent clang_getDeclExtent(CXDecl AnonDecl) {
+CXSourceRange clang_getDeclExtent(CXDecl AnonDecl) {
   assert(AnonDecl && "Passed null CXDecl");
   NamedDecl *ND = static_cast<NamedDecl *>(AnonDecl);
   SourceManager &SM = ND->getASTContext().getSourceManager();
@@ -653,7 +653,7 @@ CXDeclExtent clang_getDeclExtent(CXDecl AnonDecl) {
   SourceLocation End = SM.getInstantiationLoc(R.getEnd());
 
   if (!Begin.isValid()) {
-    CXDeclExtent extent = { { 0, 0 }, { 0, 0 } };
+    CXSourceRange extent = { { 0, 0, 0 }, { 0, 0, 0 } };
     return extent;
   }
   
@@ -691,8 +691,9 @@ CXDeclExtent clang_getDeclExtent(CXDecl AnonDecl) {
   }
 
   // Package up the line/column data and return to the caller.
-  CXDeclExtent extent = { { StartLineNo, StartColNo },
-                          { EndLineNo, EndColNo } };
+  const FileEntry *FEntry = SM.getFileEntryForID(SM.getFileID(Begin));
+  CXSourceRange extent = { { (void *)FEntry, StartLineNo, StartColNo },
+                           { (void *)FEntry, EndLineNo, EndColNo } };
   return extent;  
 }
 
index db95644c4cf4c6667fcc2bcee15e70f0e3215ad1..e3d6ad88bb8faa5353ddf07d52a3d203eba3bd2a 100644 (file)
@@ -74,7 +74,7 @@ static const char* GetCursorSource(CXCursor Cursor) {
 static const char *FileCheckPrefix = "CHECK";
 
 static void PrintDeclExtent(CXDecl Dcl) {
-  CXSourceExtent extent; 
+  CXSourceRange extent; 
   if (!Dcl)
     return;
   extent = clang_getDeclExtent(Dcl);