fs_path.h (path::_List): Use vector instead of list.
authorJonathan Wakely <jwakely@redhat.com>
Fri, 1 May 2015 19:47:55 +0000 (20:47 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 1 May 2015 19:47:55 +0000 (20:47 +0100)
* include/experimental/fs_path.h (path::_List): Use vector instead of
list.
* python/libstdcxx/v6/printers.py (StdExpPathPrinter): Adapt.
* src/filesystem/path.cc: Use std::prev instead of decrementing
rvalues. Fix whitespace.
* testsuite/experimental/filesystem/path/decompose/parent_path.cc:
Do not decrement iterators before begin.

From-SVN: r222702

libstdc++-v3/ChangeLog
libstdc++-v3/include/experimental/fs_path.h
libstdc++-v3/python/libstdcxx/v6/printers.py
libstdc++-v3/src/filesystem/path.cc
libstdc++-v3/testsuite/experimental/filesystem/path/decompose/parent_path.cc

index 5428727a198c7e4e35ea1326db6ab0fa291b4a1e..8d559eb0975527357d8009715ecdfd1ec067cebd 100644 (file)
@@ -1,5 +1,13 @@
 2015-05-01  Jonathan Wakely  <jwakely@redhat.com>
 
+       * include/experimental/fs_path.h (path::_List): Use vector instead of
+       list.
+       * python/libstdcxx/v6/printers.py (StdExpPathPrinter): Adapt.
+       * src/filesystem/path.cc: Use std::prev instead of decrementing
+       rvalues. Fix whitespace.
+       * testsuite/experimental/filesystem/path/decompose/parent_path.cc:
+       Do not decrement iterators before begin.
+
        * include/experimental/fs_dir.h: Fix use of non-reserved names.
        * include/experimental/fs_ops.h: Likewise.
        * include/experimental/fs_path.h: Likewise.
index 11b056161507f2b06076ed923e3964b082a0f1a6..e57a08bb35dc5876e584b97f54a273ab9af3e3a1 100644 (file)
@@ -36,7 +36,7 @@
 
 #include <utility>
 #include <type_traits>
-#include <list>
+#include <vector>
 #include <locale>
 #include <iosfwd>
 #include <codecvt>
@@ -430,7 +430,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
     string_type _M_pathname;
 
     struct _Cmpt;
-    using _List = std::list<_Cmpt>;
+    using _List = _GLIBCXX_STD_C::vector<_Cmpt>;
     _List _M_cmpts; // empty unless _M_type == _Type::_Multi
     _Type _M_type = _Type::_Multi;
   };
index 37c3b9bf29750012b25badcf001f48f350b706d7..c6f96d737a4fba63093bd425bfd328008ced1c1f 100644 (file)
@@ -984,16 +984,51 @@ class StdExpPathPrinter:
 
     def __init__ (self, typename, val):
         self.val = val
-        self.list_visualizer = gdb.default_visualizer(val['_M_cmpts'])
+        start = self.val['_M_cmpts']['_M_impl']['_M_start']
+        finish = self.val['_M_cmpts']['_M_impl']['_M_finish']
+        self.num_cmpts = int (finish - start)
+
+    def _path_type(self):
+        t = str(self.val['_M_type'])
+        if t[-9:] == '_Root_dir':
+            return "root-directory"
+        if t[-10:] == '_Root_name':
+            return "root-name"
+        return None
 
     def to_string (self):
-        path = self.val ['_M_pathname']
-        if self.list_visualizer:
-            list_head = self.val['_M_cmpts']['_M_impl']['_M_node']
-            if list_head.address != list_head['_M_next']:
-                cmpts = self.list_visualizer.to_string()
-                path = "%s [Components %s]" % (path, cmpts)
-        return path
+        path = "%s" % self.val ['_M_pathname']
+        if self.num_cmpts == 0:
+            t = self._path_type()
+            if t:
+                path = '%s [%s]' % (path, t)
+        return "filesystem::path %s" % path
+
+    class _iterator(Iterator):
+        def __init__(self, cmpts):
+            self.item = cmpts['_M_impl']['_M_start']
+            self.finish = cmpts['_M_impl']['_M_finish']
+            self.count = 0
+
+        def __iter__(self):
+            return self
+
+        def __next__(self):
+            if self.item == self.finish:
+                raise StopIteration
+            item = self.item.dereference()
+            count = self.count
+            self.count = self.count + 1
+            self.item = self.item + 1
+            path = item['_M_pathname']
+            t = StdExpPathPrinter(item.type.name, item)._path_type()
+            if not t:
+                t = count
+            return ('[%s]' % t, path)
+
+    def children(self):
+        return self._iterator(self.val['_M_cmpts'])
+
 
 # A "regular expression" printer which conforms to the
 # "SubPrettyPrinter" protocol from gdb.printing.
@@ -1383,7 +1418,7 @@ def build_libstdcxx_dictionary ():
     # Filesystem TS components
     libstdcxx_printer.add_version('std::experimental::filesystem::v1::',
                                   'path', StdExpPathPrinter)
-    libstdcxx_printer.add_version('std::experimental::filesystem::v1::__cxx11',
+    libstdcxx_printer.add_version('std::experimental::filesystem::v1::__cxx11::',
                                   'path', StdExpPathPrinter)
 
     # Extensions.
index db58f3bdb7088c8576a63899310e38cf64e7bc4c..cc5780f1e145bc1978a48cf308da429e7a6300c8 100644 (file)
@@ -35,7 +35,7 @@ path::remove_filename()
     {
       if (!_M_cmpts.empty())
        {
-         auto cmpt = --_M_cmpts.end();
+         auto cmpt = std::prev(_M_cmpts.end());
          _M_pathname.erase(cmpt->_M_pos);
          _M_cmpts.erase(cmpt);
          _M_trim();
@@ -109,7 +109,7 @@ path::compare(const path& p) const noexcept
 {
   if (_M_type == _Type::_Multi && p._M_type == _Type::_Multi)
     return do_compare(_M_cmpts.begin(), _M_cmpts.end(),
-                  p._M_cmpts.begin(), p._M_cmpts.end());
+                     p._M_cmpts.begin(), p._M_cmpts.end());
   else if (_M_type == _Type::_Multi)
     {
       _Cmpt c[1] = { { p._M_pathname, p._M_type, 0 } };
@@ -130,8 +130,7 @@ path::root_name() const
   path __ret;
   if (_M_type == _Type::_Root_name)
     __ret = *this;
-  else if (_M_cmpts.size()
-      && _M_cmpts.begin()->_M_type == _Type::_Root_name)
+  else if (_M_cmpts.size() && _M_cmpts.begin()->_M_type == _Type::_Root_name)
     __ret = *_M_cmpts.begin();
   return __ret;
 }
@@ -203,8 +202,8 @@ path::parent_path() const
   path __ret;
   if (_M_cmpts.size() < 2)
     return __ret;
-  for (auto __it = _M_cmpts.begin(), __end = --_M_cmpts.end();
-      __it != __end; ++__it)
+  for (auto __it = _M_cmpts.begin(), __end = std::prev(_M_cmpts.end());
+       __it != __end; ++__it)
     {
       __ret /= *__it;
     }
index 2c21f6ff6993c938996465d4170a6b64238c7013..41df1bfb59c3eeb6501e87ea3795e8720e030a7e 100644 (file)
@@ -44,6 +44,8 @@ test02()
 {
   for (const path& p : __gnu_test::test_paths)
   {
+    if (p.begin() == p.end())
+      continue;
     path pp;
     for (auto i = p.begin(), end = --p.end(); i != end; ++i)
     {