Browse Source

chore(pretty-printer): show iterator

greatbridf 2 years ago
parent
commit
56bf9be365
2 changed files with 45 additions and 5 deletions
  1. 2 5
      include/types/map.hpp
  2. 43 0
      pretty-print.py

+ 2 - 5
include/types/map.hpp

@@ -319,12 +319,9 @@ public:
 
     template <bool Const>
     class iterator {
-    private:
-        static constexpr bool _is_const_iterator = Const;
-
     public:
-        using node_pointer_type = typename traits::condition<_is_const_iterator, const node*, node*>::type;
-        using value_type = typename traits::condition<_is_const_iterator, const pair_type, pair_type>::type;
+        using node_pointer_type = typename traits::condition<Const, const node*, node*>::type;
+        using value_type = typename traits::condition<Const, const pair_type, pair_type>::type;
         using pointer_type = typename traits::add_pointer<value_type>::type;
         using reference_type = typename traits::add_reference<value_type>::type;
 

+ 43 - 0
pretty-print.py

@@ -136,6 +136,37 @@ class listPrinter:
             idx += 1
             node = node['next']
 
+class listIteratorPrinter:
+    def __init__(self, val):
+        self.val = val
+    
+    def children(self):
+        yield '[addr]', self.val['n']
+        if self.val['n'] == 0:
+            return
+
+        for field in self.val['n']['value'].type.fields():
+            yield field.name, self.val['n']['value'][field.name]
+
+class mapIteratorPrinter:
+    def __init__(self, val):
+        self.val = val
+    
+    def children(self):
+        yield '[addr]', self.val['p']
+        if self.val['p'] == 0:
+            return
+        
+        yield '[key]', self.val['p']['v']['key']
+        yield '[value]', self.val['p']['v']['value']
+
+class vectorIteratorPrinter:
+    def __init__(self, val):
+        self.val = val
+    
+    def children(self):
+        yield 'value', self.val['p'].dereference()
+
 def build_pretty_printer(val):
     type = val.type
 
@@ -149,7 +180,19 @@ def build_pretty_printer(val):
 
     if typename == None:
         return None
+
+    if re.compile(r"^types::list<.*?>::node<.*?>$").match(typename):
+        return None
+
+    if re.compile(r"^types::map<.*?,.*?,.*?>::iterator<.*?>$").match(typename):
+        return mapIteratorPrinter(val)
     
+    if re.compile(r"^types::list<.*?>::iterator<.*?>$").match(typename):
+        return listIteratorPrinter(val)
+
+    if re.compile(r"^types::vector<.*?>::iterator<.*?>$").match(typename):
+        return vectorIteratorPrinter(val)
+
     if re.compile(r"^types::list<.*?>$").match(typename):
         return listPrinter(val)