aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSiva Chandra Reddy <sivachandra@google.com>2014-11-11 11:35:34 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2014-11-11 11:35:34 +0000
commita5281f1796c6c2e77400e621253b409280180a2c (patch)
tree6d783066519413aa3c376dc99370de8e6867f861
parente9c51193eaa1ccb0fd3dd1b66629e2001f3bdb35 (diff)
downloadgcc-a5281f1796c6c2e77400e621253b409280180a2c.zip
gcc-a5281f1796c6c2e77400e621253b409280180a2c.tar.gz
gcc-a5281f1796c6c2e77400e621253b409280180a2c.tar.bz2
xmethods.py: Add xmethods for associative containers.
2014-11-11 Siva Chandra Reddy <sivachandra@google.com> * python/libstdcxx/v6/xmethods.py: Add xmethods for associative containers. * testsuite/libstdc++-xmethods/associative-containers.cc: New file. From-SVN: r217344
-rw-r--r--libstdc++-v3/ChangeLog6
-rw-r--r--libstdc++-v3/python/libstdcxx/v6/xmethods.py60
2 files changed, 66 insertions, 0 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 2a8fb6c..dd810a9 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,9 @@
+2014-11-11 Siva Chandra Reddy <sivachandra@google.com>
+
+ * python/libstdcxx/v6/xmethods.py: Add xmethods for associative
+ containers.
+ * testsuite/libstdc++-xmethods/associative-containers.cc: New file.
+
2014-11-11 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/63811
diff --git a/libstdc++-v3/python/libstdcxx/v6/xmethods.py b/libstdc++-v3/python/libstdcxx/v6/xmethods.py
index 6af1c95..2198411 100644
--- a/libstdc++-v3/python/libstdcxx/v6/xmethods.py
+++ b/libstdc++-v3/python/libstdcxx/v6/xmethods.py
@@ -422,6 +422,50 @@ class VectorMethodsMatcher(gdb.xmethod.XMethodMatcher):
return None
return method.worker_class(class_type.template_argument(0))
+# Xmethods for associative containers
+
+class AssociativeContainerWorkerBase(gdb.xmethod.XMethodWorker):
+ def __init__(self, unordered):
+ self._unordered = unordered
+
+ def node_count(self, obj):
+ if self._unordered:
+ return obj['_M_h']['_M_element_count']
+ else:
+ return obj['_M_t']['_M_impl']['_M_node_count']
+
+ def get_arg_types(self):
+ return None
+
+class AssociativeContainerEmptyWorker(AssociativeContainerWorkerBase):
+ def __call__(self, obj):
+ return int(self.node_count(obj)) == 0
+
+class AssociativeContainerSizeWorker(AssociativeContainerWorkerBase):
+ def __call__(self, obj):
+ return self.node_count(obj)
+
+class AssociativeContainerMethodsMatcher(gdb.xmethod.XMethodMatcher):
+ def __init__(self, name):
+ gdb.xmethod.XMethodMatcher.__init__(self,
+ matcher_name_prefix + name)
+ self._name = name
+ self._method_dict = {
+ 'size': LibStdCxxXMethod('size', AssociativeContainerSizeWorker),
+ 'empty': LibStdCxxXMethod('empty',
+ AssociativeContainerEmptyWorker),
+ }
+ self.methods = [self._method_dict[m] for m in self._method_dict]
+
+ def match(self, class_type, method_name):
+ if not re.match('^std::%s<.*>$' % self._name, class_type.tag):
+ return None
+ method = self._method_dict.get(method_name)
+ if method is None or not method.enabled:
+ return None
+ unordered = 'unordered' in self._name
+ return method.worker_class(unordered)
+
# Xmethods for std::unique_ptr
class UniquePtrGetWorker(gdb.xmethod.XMethodWorker):
@@ -465,4 +509,20 @@ def register_libstdcxx_xmethods(locus):
gdb.xmethod.register_xmethod_matcher(locus, DequeMethodsMatcher())
gdb.xmethod.register_xmethod_matcher(locus, ListMethodsMatcher())
gdb.xmethod.register_xmethod_matcher(locus, VectorMethodsMatcher())
+ gdb.xmethod.register_xmethod_matcher(
+ locus, AssociativeContainerMethodsMatcher('set'))
+ gdb.xmethod.register_xmethod_matcher(
+ locus, AssociativeContainerMethodsMatcher('map'))
+ gdb.xmethod.register_xmethod_matcher(
+ locus, AssociativeContainerMethodsMatcher('multiset'))
+ gdb.xmethod.register_xmethod_matcher(
+ locus, AssociativeContainerMethodsMatcher('multimap'))
+ gdb.xmethod.register_xmethod_matcher(
+ locus, AssociativeContainerMethodsMatcher('unordered_set'))
+ gdb.xmethod.register_xmethod_matcher(
+ locus, AssociativeContainerMethodsMatcher('unordered_map'))
+ gdb.xmethod.register_xmethod_matcher(
+ locus, AssociativeContainerMethodsMatcher('unordered_multiset'))
+ gdb.xmethod.register_xmethod_matcher(
+ locus, AssociativeContainerMethodsMatcher('unordered_multimap'))
gdb.xmethod.register_xmethod_matcher(locus, UniquePtrMethodsMatcher())