<div dir="ltr">Thanks, I will take a look.</div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Oct 21, 2017 at 5:53 PM, Aaron Ballman <span dir="ltr"><<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I've reverted back to green in r316279 due to more bots failing.<br>
<span class="HOEnZb"><font color="#888888"><br>
~Aaron<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Sat, Oct 21, 2017 at 5:35 PM, Aaron Ballman <<a href="mailto:aaron@aaronballman.com">aaron@aaronballman.com</a>> wrote:<br>
> This commit appears to have broken several bots. Can you revert or<br>
> quickly fix the issue?<br>
><br>
> <a href="http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/11896" rel="noreferrer" target="_blank">http://lab.llvm.org:8011/<wbr>builders/clang-ppc64be-linux/<wbr>builds/11896</a><br>
> <a href="http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/12380" rel="noreferrer" target="_blank">http://lab.llvm.org:8011/<wbr>builders/clang-s390x-linux/<wbr>builds/12380</a><br>
><br>
> Thanks!<br>
><br>
> ~Aaron<br>
><br>
> On Sat, Oct 21, 2017 at 4:53 PM, Masud Rahman via cfe-commits<br>
> <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br>
>> Author: frutiger<br>
>> Date: Sat Oct 21 13:53:49 2017<br>
>> New Revision: 316278<br>
>><br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=316278&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=316278&view=rev</a><br>
>> Log:<br>
>> [libclang, bindings]: add spelling location<br>
>><br>
>>  o) Add a 'Location' class that represents the four properties of a<br>
>>     physical location<br>
>><br>
>>  o) Enhance 'SourceLocation' to provide 'expansion' and 'spelling'<br>
>>     locations, maintaining backwards compatibility with existing code by<br>
>>     forwarding the four properties to 'expansion'.<br>
>><br>
>>  o) Update the implementation to use 'clang_getExpansionLocation'<br>
>>     instead of the deprecated 'clang_<wbr>getInstantiationLocation', which<br>
>>     has been present since 2011.<br>
>><br>
>>  o) Update the implementation of 'clang_getSpellingLocation' to actually<br>
>>     obtain spelling location instead of file location.<br>
>><br>
>> Modified:<br>
>>     cfe/trunk/bindings/python/<wbr>clang/cindex.py<br>
>>     cfe/trunk/bindings/python/<wbr>tests/cindex/test_location.py<br>
>>     cfe/trunk/tools/libclang/<wbr>CXSourceLocation.cpp<br>
>><br>
>> Modified: cfe/trunk/bindings/python/<wbr>clang/cindex.py<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=316278&r1=316277&r2=316278&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/bindings/<wbr>python/clang/cindex.py?rev=<wbr>316278&r1=316277&r2=316278&<wbr>view=diff</a><br>
>> ==============================<wbr>==============================<wbr>==================<br>
>> --- cfe/trunk/bindings/python/<wbr>clang/cindex.py (original)<br>
>> +++ cfe/trunk/bindings/python/<wbr>clang/cindex.py Sat Oct 21 13:53:49 2017<br>
>> @@ -214,25 +214,45 @@ class _CXString(Structure):<br>
>>          assert isinstance(res, _CXString)<br>
>>          return conf.lib.clang_getCString(res)<br>
>><br>
>> +class Location(object):<br>
>> +    """A Location is a specific kind of source location.  A SourceLocation<br>
>> +    refers to several kinds of locations (e.g.  spelling location vs. expansion<br>
>> +    location)."""<br>
>> +<br>
>> +    def __init__(self, file, line, column, offset):<br>
>> +        self._file   = File(file) if file else None<br>
>> +        self._line   = int(line.value)<br>
>> +        self._column = int(column.value)<br>
>> +        self._offset = int(offset.value)<br>
>> +<br>
>> +<br>
>> +    @property<br>
>> +    def file(self):<br>
>> +        """Get the file represented by this source location."""<br>
>> +        return self._file<br>
>> +<br>
>> +    @property<br>
>> +    def line(self):<br>
>> +        """Get the line represented by this source location."""<br>
>> +        return self._line<br>
>> +<br>
>> +    @property<br>
>> +    def column(self):<br>
>> +        """Get the column represented by this source location."""<br>
>> +        return self._column<br>
>> +<br>
>> +    @property<br>
>> +    def offset(self):<br>
>> +        """Get the file offset represented by this source location."""<br>
>> +        return self._offset<br>
>><br>
>>  class SourceLocation(Structure):<br>
>>      """<br>
>>      A SourceLocation represents a particular location within a source file.<br>
>>      """<br>
>>      _fields_ = [("ptr_data", c_void_p * 2), ("int_data", c_uint)]<br>
>> -    _data = None<br>
>> -<br>
>> -    def _get_instantiation(self):<br>
>> -        if self._data is None:<br>
>> -            f, l, c, o = c_object_p(), c_uint(), c_uint(), c_uint()<br>
>> -            conf.lib.clang_<wbr>getInstantiationLocation(self, byref(f), byref(l),<br>
>> -                    byref(c), byref(o))<br>
>> -            if f:<br>
>> -                f = File(f)<br>
>> -            else:<br>
>> -                f = None<br>
>> -            self._data = (f, int(l.value), int(c.value), int(o.value))<br>
>> -        return self._data<br>
>> +    _expansion = None<br>
>> +    _spelling = None<br>
>><br>
>>      @staticmethod<br>
>>      def from_position(tu, file, line, column):<br>
>> @@ -253,24 +273,72 @@ class SourceLocation(Structure):<br>
>>          return conf.lib.clang_<wbr>getLocationForOffset(tu, file, offset)<br>
>><br>
>>      @property<br>
>> +    def expansion(self):<br>
>> +        """<br>
>> +        The source location where then entity this object is referring to is<br>
>> +        expanded.<br>
>> +        """<br>
>> +        if not self._expansion:<br>
>> +            file   = c_object_p()<br>
>> +            line   = c_uint()<br>
>> +            column = c_uint()<br>
>> +            offset = c_uint()<br>
>> +            conf.lib.clang_<wbr>getExpansionLocation(self,<br>
>> +                                                byref(file),<br>
>> +                                                byref(line),<br>
>> +                                                byref(column),<br>
>> +                                                byref(offset))<br>
>> +<br>
>> +            self._expansion = Location(file, line, column, offset)<br>
>> +        return self._expansion<br>
>> +<br>
>> +    @property<br>
>> +    def spelling(self):<br>
>> +        """<br>
>> +        The source location where then entity this object is referring to is<br>
>> +        written.<br>
>> +        """<br>
>> +        if not self._spelling:<br>
>> +            file   = c_object_p()<br>
>> +            line   = c_uint()<br>
>> +            column = c_uint()<br>
>> +            offset = c_uint()<br>
>> +            conf.lib.clang_<wbr>getSpellingLocation(self,<br>
>> +                                               byref(file),<br>
>> +                                               byref(line),<br>
>> +                                               byref(column),<br>
>> +                                               byref(offset))<br>
>> +<br>
>> +            self._spelling = Location(file, line, column, offset)<br>
>> +        return self._spelling<br>
>> +<br>
>> +    @property<br>
>>      def file(self):<br>
>> -        """Get the file represented by this source location."""<br>
>> -        return self._get_instantiation()[0]<br>
>> +        """Get the file represented by this source location.<br>
>> +<br>
>> +        DEPRECATED: use expansion.file."""<br>
>> +        return self.expansion.file<br>
>><br>
>>      @property<br>
>>      def line(self):<br>
>> -        """Get the line represented by this source location."""<br>
>> -        return self._get_instantiation()[1]<br>
>> +        """Get the line represented by this source location.<br>
>> +<br>
>> +        DEPRECATED: use expansion.line."""<br>
>> +        return self.expansion.line<br>
>><br>
>>      @property<br>
>>      def column(self):<br>
>> -        """Get the column represented by this source location."""<br>
>> -        return self._get_instantiation()[2]<br>
>> +        """Get the column represented by this source location.<br>
>> +<br>
>> +        DEPRECATED: use expansion.column."""<br>
>> +        return self.expansion.column<br>
>><br>
>>      @property<br>
>>      def offset(self):<br>
>> -        """Get the file offset represented by this source location."""<br>
>> -        return self._get_instantiation()[3]<br>
>> +        """Get the file offset represented by this source location.<br>
>> +<br>
>> +        DEPRECATED: use expansion.offset."""<br>
>> +        return self.expansion.offset<br>
>><br>
>>      def __eq__(self, other):<br>
>>          return conf.lib.clang_equalLocations(<wbr>self, other)<br>
>> @@ -1543,8 +1611,7 @@ class Cursor(Structure):<br>
>>      @property<br>
>>      def location(self):<br>
>>          """<br>
>> -        Return the source location (the starting character) of the entity<br>
>> -        pointed at by the cursor.<br>
>> +        Return the source locations of the entity pointed at by the cursor.<br>
>>          """<br>
>>          if not hasattr(self, '_loc'):<br>
>>              self._loc = conf.lib.clang_<wbr>getCursorLocation(self)<br>
>> @@ -3692,7 +3759,11 @@ functionList = [<br>
>>    ("clang_getInclusions",<br>
>>     [TranslationUnit, callbacks['translation_unit_<wbr>includes'], py_object]),<br>
>><br>
>> -  ("clang_<wbr>getInstantiationLocation",<br>
>> +  ("clang_getExpansionLocation",<br>
>> +   [SourceLocation, POINTER(c_object_p), POINTER(c_uint), POINTER(c_uint),<br>
>> +    POINTER(c_uint)]),<br>
>> +<br>
>> +  ("clang_getSpellingLocation",<br>
>>     [SourceLocation, POINTER(c_object_p), POINTER(c_uint), POINTER(c_uint),<br>
>>      POINTER(c_uint)]),<br>
>><br>
>> @@ -4154,6 +4225,7 @@ __all__ = [<br>
>>      'FixIt',<br>
>>      'Index',<br>
>>      'LinkageKind',<br>
>> +    'Location',<br>
>>      'SourceLocation',<br>
>>      'SourceRange',<br>
>>      'TLSKind',<br>
>><br>
>> Modified: cfe/trunk/bindings/python/<wbr>tests/cindex/test_location.py<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_location.py?rev=316278&r1=316277&r2=316278&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/bindings/<wbr>python/tests/cindex/test_<wbr>location.py?rev=316278&r1=<wbr>316277&r2=316278&view=diff</a><br>
>> ==============================<wbr>==============================<wbr>==================<br>
>> --- cfe/trunk/bindings/python/<wbr>tests/cindex/test_location.py (original)<br>
>> +++ cfe/trunk/bindings/python/<wbr>tests/cindex/test_location.py Sat Oct 21 13:53:49 2017<br>
>> @@ -93,3 +93,10 @@ def test_extent():<br>
>>      location3 = SourceLocation.from_position(<wbr>tu, file, 1, 6)<br>
>>      range3 = SourceRange.from_locations(<wbr>location1, location3)<br>
>>      assert range1 != range3<br>
>> +<br>
>> +def test_spelling_location():<br>
>> +    tu = get_tu('''#define ONE int one<br>
>> +ONE;''')<br>
>> +    one = get_cursor(tu, 'one')<br>
>> +    assert one.location.spelling.line == 1<br>
>> +    assert one.location.expansion.line == 2<br>
>><br>
>> Modified: cfe/trunk/tools/libclang/<wbr>CXSourceLocation.cpp<br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXSourceLocation.cpp?rev=316278&r1=316277&r2=316278&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/tools/<wbr>libclang/CXSourceLocation.cpp?<wbr>rev=316278&r1=316277&r2=<wbr>316278&view=diff</a><br>
>> ==============================<wbr>==============================<wbr>==================<br>
>> --- cfe/trunk/tools/libclang/<wbr>CXSourceLocation.cpp (original)<br>
>> +++ cfe/trunk/tools/libclang/<wbr>CXSourceLocation.cpp Sat Oct 21 13:53:49 2017<br>
>> @@ -318,8 +318,7 @@ void clang_getSpellingLocation(<wbr>CXSourceL<br>
>><br>
>>    const SourceManager &SM =<br>
>>    *static_cast<const SourceManager*>(location.ptr_<wbr>data[0]);<br>
>> -  // FIXME: This should call SourceManager::getSpellingLoc(<wbr>).<br>
>> -  SourceLocation SpellLoc = SM.getFileLoc(Loc);<br>
>> +  SourceLocation SpellLoc = SM.getSpellingLoc(Loc);<br>
>>    std::pair<FileID, unsigned> LocInfo = SM.getDecomposedLoc(SpellLoc);<br>
>>    FileID FID = LocInfo.first;<br>
>>    unsigned FileOffset = LocInfo.second;<br>
>><br>
>><br>
>> ______________________________<wbr>_________________<br>
>> cfe-commits mailing list<br>
>> <a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div>