r316279 - Reverting r316278 due to failing build bots.

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 21 14:52:48 PDT 2017


Author: aaronballman
Date: Sat Oct 21 14:52:48 2017
New Revision: 316279

URL: http://llvm.org/viewvc/llvm-project?rev=316279&view=rev
Log:
Reverting r316278 due to failing build bots.

http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/11896
http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/12380

Modified:
    cfe/trunk/bindings/python/clang/cindex.py
    cfe/trunk/bindings/python/tests/cindex/test_location.py
    cfe/trunk/tools/libclang/CXSourceLocation.cpp

Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=316279&r1=316278&r2=316279&view=diff
==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Sat Oct 21 14:52:48 2017
@@ -214,45 +214,25 @@ class _CXString(Structure):
         assert isinstance(res, _CXString)
         return conf.lib.clang_getCString(res)
 
-class Location(object):
-    """A Location is a specific kind of source location.  A SourceLocation
-    refers to several kinds of locations (e.g.  spelling location vs. expansion
-    location)."""
-
-    def __init__(self, file, line, column, offset):
-        self._file   = File(file) if file else None
-        self._line   = int(line.value)
-        self._column = int(column.value)
-        self._offset = int(offset.value)
-
-
-    @property
-    def file(self):
-        """Get the file represented by this source location."""
-        return self._file
-
-    @property
-    def line(self):
-        """Get the line represented by this source location."""
-        return self._line
-
-    @property
-    def column(self):
-        """Get the column represented by this source location."""
-        return self._column
-
-    @property
-    def offset(self):
-        """Get the file offset represented by this source location."""
-        return self._offset
 
 class SourceLocation(Structure):
     """
     A SourceLocation represents a particular location within a source file.
     """
     _fields_ = [("ptr_data", c_void_p * 2), ("int_data", c_uint)]
-    _expansion = None
-    _spelling = None
+    _data = None
+
+    def _get_instantiation(self):
+        if self._data is None:
+            f, l, c, o = c_object_p(), c_uint(), c_uint(), c_uint()
+            conf.lib.clang_getInstantiationLocation(self, byref(f), byref(l),
+                    byref(c), byref(o))
+            if f:
+                f = File(f)
+            else:
+                f = None
+            self._data = (f, int(l.value), int(c.value), int(o.value))
+        return self._data
 
     @staticmethod
     def from_position(tu, file, line, column):
@@ -273,72 +253,24 @@ class SourceLocation(Structure):
         return conf.lib.clang_getLocationForOffset(tu, file, offset)
 
     @property
-    def expansion(self):
-        """
-        The source location where then entity this object is referring to is
-        expanded.
-        """
-        if not self._expansion:
-            file   = c_object_p()
-            line   = c_uint()
-            column = c_uint()
-            offset = c_uint()
-            conf.lib.clang_getExpansionLocation(self,
-                                                byref(file),
-                                                byref(line),
-                                                byref(column),
-                                                byref(offset))
-
-            self._expansion = Location(file, line, column, offset)
-        return self._expansion
-
-    @property
-    def spelling(self):
-        """
-        The source location where then entity this object is referring to is
-        written.
-        """
-        if not self._spelling:
-            file   = c_object_p()
-            line   = c_uint()
-            column = c_uint()
-            offset = c_uint()
-            conf.lib.clang_getSpellingLocation(self,
-                                               byref(file),
-                                               byref(line),
-                                               byref(column),
-                                               byref(offset))
-
-            self._spelling = Location(file, line, column, offset)
-        return self._spelling
-
-    @property
     def file(self):
-        """Get the file represented by this source location.
-
-        DEPRECATED: use expansion.file."""
-        return self.expansion.file
+        """Get the file represented by this source location."""
+        return self._get_instantiation()[0]
 
     @property
     def line(self):
-        """Get the line represented by this source location.
-
-        DEPRECATED: use expansion.line."""
-        return self.expansion.line
+        """Get the line represented by this source location."""
+        return self._get_instantiation()[1]
 
     @property
     def column(self):
-        """Get the column represented by this source location.
-
-        DEPRECATED: use expansion.column."""
-        return self.expansion.column
+        """Get the column represented by this source location."""
+        return self._get_instantiation()[2]
 
     @property
     def offset(self):
-        """Get the file offset represented by this source location.
-
-        DEPRECATED: use expansion.offset."""
-        return self.expansion.offset
+        """Get the file offset represented by this source location."""
+        return self._get_instantiation()[3]
 
     def __eq__(self, other):
         return conf.lib.clang_equalLocations(self, other)
@@ -1611,7 +1543,8 @@ class Cursor(Structure):
     @property
     def location(self):
         """
-        Return the source locations of the entity pointed at by the cursor.
+        Return the source location (the starting character) of the entity
+        pointed at by the cursor.
         """
         if not hasattr(self, '_loc'):
             self._loc = conf.lib.clang_getCursorLocation(self)
@@ -3759,11 +3692,7 @@ functionList = [
   ("clang_getInclusions",
    [TranslationUnit, callbacks['translation_unit_includes'], py_object]),
 
-  ("clang_getExpansionLocation",
-   [SourceLocation, POINTER(c_object_p), POINTER(c_uint), POINTER(c_uint),
-    POINTER(c_uint)]),
-
-  ("clang_getSpellingLocation",
+  ("clang_getInstantiationLocation",
    [SourceLocation, POINTER(c_object_p), POINTER(c_uint), POINTER(c_uint),
     POINTER(c_uint)]),
 
@@ -4225,7 +4154,6 @@ __all__ = [
     'FixIt',
     'Index',
     'LinkageKind',
-    'Location',
     'SourceLocation',
     'SourceRange',
     'TLSKind',

Modified: cfe/trunk/bindings/python/tests/cindex/test_location.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_location.py?rev=316279&r1=316278&r2=316279&view=diff
==============================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_location.py (original)
+++ cfe/trunk/bindings/python/tests/cindex/test_location.py Sat Oct 21 14:52:48 2017
@@ -93,10 +93,3 @@ def test_extent():
     location3 = SourceLocation.from_position(tu, file, 1, 6)
     range3 = SourceRange.from_locations(location1, location3)
     assert range1 != range3
-
-def test_spelling_location():
-    tu = get_tu('''#define ONE int one
-ONE;''')
-    one = get_cursor(tu, 'one')
-    assert one.location.spelling.line == 1
-    assert one.location.expansion.line == 2

Modified: cfe/trunk/tools/libclang/CXSourceLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXSourceLocation.cpp?rev=316279&r1=316278&r2=316279&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXSourceLocation.cpp (original)
+++ cfe/trunk/tools/libclang/CXSourceLocation.cpp Sat Oct 21 14:52:48 2017
@@ -318,7 +318,8 @@ void clang_getSpellingLocation(CXSourceL
   
   const SourceManager &SM =
   *static_cast<const SourceManager*>(location.ptr_data[0]);
-  SourceLocation SpellLoc = SM.getSpellingLoc(Loc);
+  // FIXME: This should call SourceManager::getSpellingLoc().
+  SourceLocation SpellLoc = SM.getFileLoc(Loc);
   std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(SpellLoc);
   FileID FID = LocInfo.first;
   unsigned FileOffset = LocInfo.second;




More information about the cfe-commits mailing list