[cfe-commits] r94573 - in /cfe/trunk: include/clang-c/Index.h tools/CIndex/CIndex.cpp tools/CIndex/CIndex.exports tools/c-index-test/c-index-test.c

Douglas Gregor dgregor at apple.com
Tue Jan 26 11:19:08 PST 2010


Author: dgregor
Date: Tue Jan 26 13:19:08 2010
New Revision: 94573

URL: http://llvm.org/viewvc/llvm-project?rev=94573&view=rev
Log:
Eliminate clang_getInstantiationLocationOffset(), and instead add an
offset parameter to clang_getInstantiationLocation(). 

Modified:
    cfe/trunk/include/clang-c/Index.h
    cfe/trunk/tools/CIndex/CIndex.cpp
    cfe/trunk/tools/CIndex/CIndex.exports
    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=94573&r1=94572&r2=94573&view=diff

==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Tue Jan 26 13:19:08 2010
@@ -352,8 +352,8 @@
                                             CXSourceLocation end);
 
 /**
- * \brief Retrieve the file, line, and column represented by the given source
- * location.
+ * \brief Retrieve the file, line, column, and offset represented by
+ * the given source location.
  *
  * \param location the location within a source file that will be decomposed
  * into its parts.
@@ -366,29 +366,15 @@
  *
  * \param column [out] if non-NULL, will be set to the column to which the given
  * source location points.
+ *
+ * \param offset [out] if non-NULL, will be set to the offset into the
+ * buffer to which the given source location points.
  */
 CINDEX_LINKAGE void clang_getInstantiationLocation(CXSourceLocation location,
                                                    CXFile *file,
                                                    unsigned *line,
-                                                   unsigned *column);
-
-/**
- * \brief Retrieve the file and offset within that file represented by
- * the given source location.
- *
- * \param location the location within a source file that will be decomposed
- * into its parts.
- *
- * \param file [out] if non-NULL, will be set to the file to which the
- * given source location points.
- *
- * \param offset [out] if non-NULL, will be set to the offset into the
- * \p file to which the given source location points.
- */
-CINDEX_LINKAGE void clang_getInstantiationLocationOffset(
-                                                     CXSourceLocation location,
-                                                     CXFile *File,
-                                                     unsigned *Offset);
+                                                   unsigned *column,
+                                                   unsigned *offset);
 
 /**
  * \brief Retrieve a source location representing the first character within a

Modified: cfe/trunk/tools/CIndex/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=94573&r1=94572&r2=94573&view=diff

==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Tue Jan 26 13:19:08 2010
@@ -1123,11 +1123,27 @@
   return Result;
 }
 
-static SourceLocation getAdjustedSourceLocation(CXSourceLocation location) {
+void clang_getInstantiationLocation(CXSourceLocation location,
+                                    CXFile *file,
+                                    unsigned *line,
+                                    unsigned *column,
+                                    unsigned *offset) {
   cxloc::CXSourceLocationPtr Ptr
     = cxloc::CXSourceLocationPtr::getFromOpaqueValue(location.ptr_data);
   SourceLocation Loc = SourceLocation::getFromRawEncoding(location.int_data);
 
+  if (!Ptr.getPointer() || Loc.isInvalid()) {
+    if (file)
+      *file = 0;
+    if (line)
+      *line = 0;
+    if (column)
+      *column = 0;
+    if (offset)
+      *offset = 0;
+    return;
+  }
+
   // FIXME: This is largely copy-paste from
   ///TextDiagnosticPrinter::HighlightRange.  When it is clear that this is
   // what we want the two routines should be refactored.  
@@ -1159,53 +1175,14 @@
       InstLoc = InstLoc.getFileLocWithOffset(Length - 1);
   }
 
-  return InstLoc;
-}
-
-void clang_getInstantiationLocation(CXSourceLocation location,
-                                    CXFile *file,
-                                    unsigned *line,
-                                    unsigned *column) {
-  cxloc::CXSourceLocationPtr Ptr
-    = cxloc::CXSourceLocationPtr::getFromOpaqueValue(location.ptr_data);
-  SourceLocation Loc = SourceLocation::getFromRawEncoding(location.int_data);
-
-  if (!Ptr.getPointer() || Loc.isInvalid()) {
-    if (file)
-      *file = 0;
-    if (line)
-      *line = 0;
-    if (column)
-      *column = 0;
-    return;
-  }
-
-  SourceLocation InstLoc = getAdjustedSourceLocation(location);
-  ASTContext &Context = *Ptr.getPointer();
-  SourceManager &SM = Context.getSourceManager();
   if (file)
     *file = (void *)SM.getFileEntryForID(SM.getFileID(InstLoc));
   if (line)
     *line = SM.getInstantiationLineNumber(InstLoc);
   if (column)
     *column = SM.getInstantiationColumnNumber(InstLoc);
-}
-
-void clang_getInstantiationLocationOffset(CXSourceLocation location,
-                                          CXFile *file,
-                                          unsigned *offset) {
-  cxloc::CXSourceLocationPtr Ptr
-    = cxloc::CXSourceLocationPtr::getFromOpaqueValue(location.ptr_data);
-  SourceLocation Loc = SourceLocation::getFromRawEncoding(location.int_data);
-
-  ASTContext &Context = *Ptr.getPointer();
-  SourceManager &SM = Context.getSourceManager();
-  SourceLocation InstLoc = getAdjustedSourceLocation(location);
-  std::pair<FileID, unsigned> Decomposed = SM.getDecomposedLoc(InstLoc);
-  if (file)
-    *file = (void *)SM.getFileEntryForID(Decomposed.first);
   if (offset)
-    *offset = Decomposed.second;
+    *offset = SM.getDecomposedLoc(InstLoc).second;
 }
 
 CXSourceLocation clang_getRangeStart(CXSourceRange range) {

Modified: cfe/trunk/tools/CIndex/CIndex.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.exports?rev=94573&r1=94572&r2=94573&view=diff

==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.exports (original)
+++ cfe/trunk/tools/CIndex/CIndex.exports Tue Jan 26 13:19:08 2010
@@ -29,7 +29,6 @@
 _clang_getFileName
 _clang_getFileTime
 _clang_getInstantiationLocation
-_clang_getInstantiationLocationOffset
 _clang_getLocation
 _clang_getNullCursor
 _clang_getNullLocation

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=94573&r1=94572&r2=94573&view=diff

==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Tue Jan 26 13:19:08 2010
@@ -151,7 +151,7 @@
     Referenced = clang_getCursorReferenced(Cursor);
     if (!clang_equalCursors(Referenced, clang_getNullCursor())) {
       CXSourceLocation Loc = clang_getCursorLocation(Referenced);
-      clang_getInstantiationLocation(Loc, 0, &line, &column);
+      clang_getInstantiationLocation(Loc, 0, &line, &column, 0);
       printf(":%d:%d", line, column);
     }
 
@@ -164,7 +164,7 @@
   CXSourceLocation Loc = clang_getCursorLocation(Cursor);
   const char *source;
   CXFile file;
-  clang_getInstantiationLocation(Loc, &file, 0, 0);
+  clang_getInstantiationLocation(Loc, &file, 0, 0, 0);
   source = clang_getFileName(file);
   if (!source)
     return "<invalid loc>";  
@@ -189,9 +189,9 @@
   unsigned begin_line, begin_column, end_line, end_column;
   
   clang_getInstantiationLocation(clang_getRangeStart(extent),
-                                 &begin_file, &begin_line, &begin_column);
+                                 &begin_file, &begin_line, &begin_column, 0);
   clang_getInstantiationLocation(clang_getRangeEnd(extent),
-                                 &end_file, &end_line, &end_column);
+                                 &end_file, &end_line, &end_column, 0);
   if (!begin_file || !end_file)
     return;
 
@@ -213,7 +213,7 @@
   if (!Data->Filter || (Cursor.kind == *(enum CXCursorKind *)Data->Filter)) {
     CXSourceLocation Loc = clang_getCursorLocation(Cursor);
     unsigned line, column;
-    clang_getInstantiationLocation(Loc, 0, &line, &column);
+    clang_getInstantiationLocation(Loc, 0, &line, &column, 0);
     printf("// %s: %s:%d:%d: ", FileCheckPrefix,
            GetCursorSource(Cursor), line, column);
     PrintCursor(Cursor);
@@ -257,7 +257,7 @@
       curColumn++;
           
     Loc = clang_getCursorLocation(Cursor);
-    clang_getInstantiationLocation(Loc, &file, 0, 0);
+    clang_getInstantiationLocation(Loc, &file, 0, 0, 0);
     source = clang_getFileName(file);
     if (source) {
       CXSourceLocation RefLoc
@@ -807,9 +807,9 @@
     case CXToken_Comment: kind = "Comment"; break;
     }
     clang_getInstantiationLocation(clang_getRangeStart(extent), 
-                                   0, &start_line, &start_column);
+                                   0, &start_line, &start_column, 0);
     clang_getInstantiationLocation(clang_getRangeEnd(extent),
-                                   0, &end_line, &end_column);
+                                   0, &end_line, &end_column, 0);
     printf("%s: \"%s\" [%d:%d - %d:%d]", kind, clang_getCString(spelling),
            start_line, start_column, end_line, end_column);
     if (!clang_isInvalid(cursors[i].kind)) {





More information about the cfe-commits mailing list