mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-12-23 19:14:53 +08:00
xmethods.py: Add xmethods for std::array, std::deque, std::forward_list, std::list, std::vector.
2014-10-13 Siva Chandra Reddy <sivachandra@google.com> * python/libstdcxx/v6/xmethods.py: Add xmethods for std::array, std::deque, std::forward_list, std::list, std::vector. * testsuite/libstdc++-xmethods/array.cc: New file. * testsuite/libstdc++-xmethods/deque.cc: Likewise. * testsuite/libstdc++-xmethods/forwardlist.cc: Likewise. * testsuite/libstdc++-xmethods/list.cc: Likewise. * testsuite/libstdc++-xmethods/vector.cc: Add tests. From-SVN: r216145
This commit is contained in:
parent
913f32a121
commit
4027b0158d
@ -1,3 +1,13 @@
|
||||
2014-10-13 Siva Chandra Reddy <sivachandra@google.com>
|
||||
|
||||
* python/libstdcxx/v6/xmethods.py: Add xmethods for std::array,
|
||||
std::deque, std::forward_list, std::list, std::vector.
|
||||
* testsuite/libstdc++-xmethods/array.cc: New file.
|
||||
* testsuite/libstdc++-xmethods/deque.cc: Likewise.
|
||||
* testsuite/libstdc++-xmethods/forwardlist.cc: Likewise.
|
||||
* testsuite/libstdc++-xmethods/list.cc: Likewise.
|
||||
* testsuite/libstdc++-xmethods/vector.cc: Add tests.
|
||||
|
||||
2014-10-13 Rüdiger Sonderfeld <ruediger@c-plusplus.de>
|
||||
|
||||
* include/std/memory (align): Define.
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Xmethods for libstc++.
|
||||
# Xmethods for libstdc++.
|
||||
|
||||
# Copyright (C) 2014 Free Software Foundation, Inc.
|
||||
|
||||
@ -21,45 +21,406 @@ import re
|
||||
|
||||
matcher_name_prefix = 'libstdc++::'
|
||||
|
||||
# Xmethods for std::vector
|
||||
class LibStdCxxXMethod(gdb.xmethod.XMethod):
|
||||
def __init__(self, name, worker_class):
|
||||
gdb.xmethod.XMethod.__init__(self, name)
|
||||
self.worker_class = worker_class
|
||||
|
||||
class VectorSizeWorker(gdb.xmethod.XMethodWorker):
|
||||
def __init__(self):
|
||||
self.name = 'size'
|
||||
self.enabled = True
|
||||
# Xmethods for std::array
|
||||
|
||||
class ArrayWorkerBase(gdb.xmethod.XMethodWorker):
|
||||
def __init__(self, valtype, size):
|
||||
self._valtype = valtype
|
||||
self._size = size
|
||||
|
||||
def null_value(self):
|
||||
nullptr = gdb.parse_and_eval('(void *) 0')
|
||||
return nullptr.cast(self._valtype.pointer()).dereference()
|
||||
|
||||
class ArraySizeWorker(ArrayWorkerBase):
|
||||
def __init__(self, valtype, size):
|
||||
ArrayWorkerBase.__init__(self, valtype, size)
|
||||
|
||||
def get_arg_types(self):
|
||||
return None
|
||||
|
||||
def __call__(self, obj):
|
||||
return obj['_M_impl']['_M_finish'] - obj['_M_impl']['_M_start']
|
||||
return self._size
|
||||
|
||||
class VectorSubscriptWorker(gdb.xmethod.XMethodWorker):
|
||||
def __init__(self):
|
||||
self.name = 'operator[]'
|
||||
self.enabled = True
|
||||
class ArrayEmptyWorker(ArrayWorkerBase):
|
||||
def __init__(self, valtype, size):
|
||||
ArrayWorkerBase.__init__(self, valtype, size)
|
||||
|
||||
def get_arg_types(self):
|
||||
return None
|
||||
|
||||
def __call__(self, obj):
|
||||
return (int(self._size) == 0)
|
||||
|
||||
class ArrayFrontWorker(ArrayWorkerBase):
|
||||
def __init__(self, valtype, size):
|
||||
ArrayWorkerBase.__init__(self, valtype, size)
|
||||
|
||||
def get_arg_types(self):
|
||||
return None
|
||||
|
||||
def __call__(self, obj):
|
||||
if int(self._size) > 0:
|
||||
return obj['_M_elems'][0]
|
||||
else:
|
||||
return self.null_value()
|
||||
|
||||
class ArrayBackWorker(ArrayWorkerBase):
|
||||
def __init__(self, valtype, size):
|
||||
ArrayWorkerBase.__init__(self, valtype, size)
|
||||
|
||||
def get_arg_types(self):
|
||||
return None
|
||||
|
||||
def __call__(self, obj):
|
||||
if int(self._size) > 0:
|
||||
return obj['_M_elems'][self._size - 1]
|
||||
else:
|
||||
return self.null_value()
|
||||
|
||||
class ArrayAtWorker(ArrayWorkerBase):
|
||||
def __init__(self, valtype, size):
|
||||
ArrayWorkerBase.__init__(self, valtype, size)
|
||||
|
||||
def get_arg_types(self):
|
||||
return gdb.lookup_type('std::size_t')
|
||||
|
||||
def __call__(self, obj, index):
|
||||
if int(index) >= int(self._size):
|
||||
raise IndexError('Array index "%d" should not be >= %d.' %
|
||||
((int(index), self._size)))
|
||||
return obj['_M_elems'][index]
|
||||
|
||||
class ArraySubscriptWorker(ArrayWorkerBase):
|
||||
def __init__(self, valtype, size):
|
||||
ArrayWorkerBase.__init__(self, valtype, size)
|
||||
|
||||
def get_arg_types(self):
|
||||
return gdb.lookup_type('std::size_t')
|
||||
|
||||
def __call__(self, obj, index):
|
||||
if int(self._size) > 0:
|
||||
return obj['_M_elems'][index]
|
||||
else:
|
||||
return self.null_value()
|
||||
|
||||
class ArrayMethodsMatcher(gdb.xmethod.XMethodMatcher):
|
||||
def __init__(self):
|
||||
gdb.xmethod.XMethodMatcher.__init__(self,
|
||||
matcher_name_prefix + 'array')
|
||||
self._method_dict = {
|
||||
'size': LibStdCxxXMethod('size', ArraySizeWorker),
|
||||
'empty': LibStdCxxXMethod('empty', ArrayEmptyWorker),
|
||||
'front': LibStdCxxXMethod('front', ArrayFrontWorker),
|
||||
'back': LibStdCxxXMethod('back', ArrayBackWorker),
|
||||
'at': LibStdCxxXMethod('at', ArrayAtWorker),
|
||||
'operator[]': LibStdCxxXMethod('operator[]', ArraySubscriptWorker),
|
||||
}
|
||||
self.methods = [self._method_dict[m] for m in self._method_dict]
|
||||
|
||||
def match(self, class_type, method_name):
|
||||
if not re.match('^std::array<.*>$', class_type.tag):
|
||||
return None
|
||||
method = self._method_dict.get(method_name)
|
||||
if method is None or not method.enabled:
|
||||
return None
|
||||
try:
|
||||
value_type = class_type.template_argument(0)
|
||||
size = class_type.template_argument(1)
|
||||
except:
|
||||
return None
|
||||
return method.worker_class(value_type, size)
|
||||
|
||||
# Xmethods for std::deque
|
||||
|
||||
class DequeWorkerBase(gdb.xmethod.XMethodWorker):
|
||||
def __init__(self, elemtype):
|
||||
self._bufsize = (512 / elemtype.sizeof) or 1
|
||||
|
||||
def size(self, obj):
|
||||
first_node = obj['_M_impl']['_M_start']['_M_node']
|
||||
last_node = obj['_M_impl']['_M_finish']['_M_node']
|
||||
cur = obj['_M_impl']['_M_finish']['_M_cur']
|
||||
first = obj['_M_impl']['_M_finish']['_M_first']
|
||||
return (last_node - first_node) * self._bufsize + (cur - first)
|
||||
|
||||
def index(self, obj, index):
|
||||
first_node = obj['_M_impl']['_M_start']['_M_node']
|
||||
index_node = first_node + index / self._bufsize
|
||||
return index_node[0][index % self._bufsize]
|
||||
|
||||
class DequeEmptyWorker(DequeWorkerBase):
|
||||
def get_arg_types(self):
|
||||
return None
|
||||
|
||||
def __call__(self, obj):
|
||||
return (obj['_M_impl']['_M_start']['_M_cur'] ==
|
||||
obj['_M_impl']['_M_finish']['_M_cur'])
|
||||
|
||||
class DequeSizeWorker(DequeWorkerBase):
|
||||
def get_arg_types(self):
|
||||
return None
|
||||
|
||||
def __call__(self, obj):
|
||||
return self.size(obj)
|
||||
|
||||
class DequeFrontWorker(DequeWorkerBase):
|
||||
def get_arg_types(self):
|
||||
return None
|
||||
|
||||
def __call__(self, obj):
|
||||
return obj['_M_impl']['_M_start']['_M_cur'][0]
|
||||
|
||||
class DequeBackWorker(DequeWorkerBase):
|
||||
def get_arg_types(self):
|
||||
return None
|
||||
|
||||
def __call__(self, obj):
|
||||
if (obj['_M_impl']['_M_finish']['_M_cur'] ==
|
||||
obj['_M_impl']['_M_finish']['_M_first']):
|
||||
prev_node = obj['_M_impl']['_M_finish']['_M_node'] - 1
|
||||
return prev_node[0][self._bufsize - 1]
|
||||
else:
|
||||
return obj['_M_impl']['_M_finish']['_M_cur'][-1]
|
||||
|
||||
class DequeSubscriptWorker(DequeWorkerBase):
|
||||
def get_arg_types(self):
|
||||
return gdb.lookup_type('std::size_t')
|
||||
|
||||
def __call__(self, obj, subscript):
|
||||
return obj['_M_impl']['_M_start'][subscript]
|
||||
return self.index(obj, subscript)
|
||||
|
||||
class DequeAtWorker(DequeWorkerBase):
|
||||
def get_arg_types(self):
|
||||
return gdb.lookup_type('std::size_t')
|
||||
|
||||
def __call__(self, obj, index):
|
||||
deque_size = int(self.size(obj))
|
||||
if int(index) >= deque_size:
|
||||
raise IndexError('Deque index "%d" should not be >= %d.' %
|
||||
(int(index), deque_size))
|
||||
else:
|
||||
return self.index(obj, index)
|
||||
|
||||
class DequeMethodsMatcher(gdb.xmethod.XMethodMatcher):
|
||||
def __init__(self):
|
||||
gdb.xmethod.XMethodMatcher.__init__(self,
|
||||
matcher_name_prefix + 'deque')
|
||||
self._method_dict = {
|
||||
'empty': LibStdCxxXMethod('empty', DequeEmptyWorker),
|
||||
'size': LibStdCxxXMethod('size', DequeSizeWorker),
|
||||
'front': LibStdCxxXMethod('front', DequeFrontWorker),
|
||||
'back': LibStdCxxXMethod('back', DequeBackWorker),
|
||||
'operator[]': LibStdCxxXMethod('operator[]', DequeSubscriptWorker),
|
||||
'at': LibStdCxxXMethod('at', DequeAtWorker)
|
||||
}
|
||||
self.methods = [self._method_dict[m] for m in self._method_dict]
|
||||
|
||||
def match(self, class_type, method_name):
|
||||
if not re.match('^std::deque<.*>$', class_type.tag):
|
||||
return None
|
||||
method = self._method_dict.get(method_name)
|
||||
if method is None or not method.enabled:
|
||||
return None
|
||||
return method.worker_class(class_type.template_argument(0))
|
||||
|
||||
# Xmethods for std::forward_list
|
||||
|
||||
class ForwardListWorkerBase(gdb.xmethod.XMethodMatcher):
|
||||
def __init__(self, elem_type, node_type):
|
||||
self._elem_type = elem_type
|
||||
self._node_type = node_type
|
||||
|
||||
def get_arg_types(self):
|
||||
return None
|
||||
|
||||
class ForwardListEmptyWorker(ForwardListWorkerBase):
|
||||
def __call__(self, obj):
|
||||
return obj['_M_impl']['_M_head']['_M_next'] == 0
|
||||
|
||||
class ForwardListFrontWorker(ForwardListWorkerBase):
|
||||
def __call__(self, obj):
|
||||
node = obj['_M_impl']['_M_head']['_M_next'].cast(self._node_type)
|
||||
elem_address = node['_M_storage']['_M_storage'].address
|
||||
return elem_address.cast(self._elem_type.pointer()).dereference()
|
||||
|
||||
class ForwardListMethodsMatcher(gdb.xmethod.XMethodMatcher):
|
||||
def __init__(self):
|
||||
matcher_name = matcher_name_prefix + 'forward_list'
|
||||
gdb.xmethod.XMethodMatcher.__init__(self, matcher_name)
|
||||
self._method_dict = {
|
||||
'empty': LibStdCxxXMethod('empty', ForwardListEmptyWorker),
|
||||
'front': LibStdCxxXMethod('front', ForwardListFrontWorker)
|
||||
}
|
||||
self.methods = [self._method_dict[m] for m in self._method_dict]
|
||||
|
||||
def match(self, class_type, method_name):
|
||||
if not re.match('^std::forward_list<.*>$', class_type.tag):
|
||||
return None
|
||||
method = self._method_dict.get(method_name)
|
||||
if method is None or not method.enabled:
|
||||
return None
|
||||
elem_type = class_type.template_argument(0)
|
||||
node_type = gdb.lookup_type(str(class_type) + '::_Node').pointer()
|
||||
return method.worker_class(elem_type, node_type)
|
||||
|
||||
# Xmethods for std::list
|
||||
|
||||
class ListWorkerBase(gdb.xmethod.XMethodWorker):
|
||||
def __init__(self, node_type):
|
||||
self._node_type = node_type
|
||||
|
||||
def get_arg_types(self):
|
||||
return None
|
||||
|
||||
class ListEmptyWorker(ListWorkerBase):
|
||||
def __call__(self, obj):
|
||||
base_node = obj['_M_impl']['_M_node']
|
||||
if base_node['_M_next'] == base_node.address:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
class ListSizeWorker(ListWorkerBase):
|
||||
def __call__(self, obj):
|
||||
begin_node = obj['_M_impl']['_M_node']['_M_next']
|
||||
end_node = obj['_M_impl']['_M_node'].address
|
||||
size = 0
|
||||
while begin_node != end_node:
|
||||
begin_node = begin_node['_M_next']
|
||||
size += 1
|
||||
return size
|
||||
|
||||
class ListFrontWorker(ListWorkerBase):
|
||||
def __call__(self, obj):
|
||||
node = obj['_M_impl']['_M_node']['_M_next'].cast(self._node_type)
|
||||
return node['_M_data']
|
||||
|
||||
class ListBackWorker(ListWorkerBase):
|
||||
def __call__(self, obj):
|
||||
prev_node = obj['_M_impl']['_M_node']['_M_prev'].cast(self._node_type)
|
||||
return prev_node['_M_data']
|
||||
|
||||
class ListMethodsMatcher(gdb.xmethod.XMethodMatcher):
|
||||
def __init__(self):
|
||||
gdb.xmethod.XMethodMatcher.__init__(self,
|
||||
matcher_name_prefix + 'list')
|
||||
self._method_dict = {
|
||||
'empty': LibStdCxxXMethod('empty', ListEmptyWorker),
|
||||
'size': LibStdCxxXMethod('size', ListSizeWorker),
|
||||
'front': LibStdCxxXMethod('front', ListFrontWorker),
|
||||
'back': LibStdCxxXMethod('back', ListBackWorker)
|
||||
}
|
||||
self.methods = [self._method_dict[m] for m in self._method_dict]
|
||||
|
||||
def match(self, class_type, method_name):
|
||||
if not re.match('^std::list<.*>$', class_type.tag):
|
||||
return None
|
||||
method = self._method_dict.get(method_name)
|
||||
if method is None or not method.enabled:
|
||||
return None
|
||||
node_type = gdb.lookup_type(str(class_type) + '::_Node').pointer()
|
||||
return method.worker_class(node_type)
|
||||
|
||||
# Xmethods for std::vector
|
||||
|
||||
class VectorWorkerBase(gdb.xmethod.XMethodWorker):
|
||||
def __init__(self, elemtype):
|
||||
self._elemtype = elemtype
|
||||
|
||||
def size(self, obj):
|
||||
if self._elemtype.code == gdb.TYPE_CODE_BOOL:
|
||||
start = obj['_M_impl']['_M_start']['_M_p']
|
||||
finish = obj['_M_impl']['_M_finish']['_M_p']
|
||||
finish_offset = obj['_M_impl']['_M_finish']['_M_offset']
|
||||
bit_size = start.dereference().type.sizeof * 8
|
||||
return (finish - start) * bit_size + finish_offset
|
||||
else:
|
||||
return obj['_M_impl']['_M_finish'] - obj['_M_impl']['_M_start']
|
||||
|
||||
def get(self, obj, index):
|
||||
if self._elemtype.code == gdb.TYPE_CODE_BOOL:
|
||||
start = obj['_M_impl']['_M_start']['_M_p']
|
||||
bit_size = start.dereference().type.sizeof * 8
|
||||
valp = start + index / bit_size
|
||||
offset = index % bit_size
|
||||
return (valp.dereference() & (1 << offset)) > 0
|
||||
else:
|
||||
return obj['_M_impl']['_M_start'][index]
|
||||
|
||||
class VectorEmptyWorker(VectorWorkerBase):
|
||||
def get_arg_types(self):
|
||||
return None
|
||||
|
||||
def __call__(self, obj):
|
||||
return int(self.size(obj)) == 0
|
||||
|
||||
class VectorSizeWorker(VectorWorkerBase):
|
||||
def get_arg_types(self):
|
||||
return None
|
||||
|
||||
def __call__(self, obj):
|
||||
return self.size(obj)
|
||||
|
||||
class VectorFrontWorker(VectorWorkerBase):
|
||||
def get_arg_types(self):
|
||||
return None
|
||||
|
||||
def __call__(self, obj):
|
||||
return self.get(obj, 0)
|
||||
|
||||
class VectorBackWorker(VectorWorkerBase):
|
||||
def get_arg_types(self):
|
||||
return None
|
||||
|
||||
def __call__(self, obj):
|
||||
return self.get(obj, int(self.size(obj)) - 1)
|
||||
|
||||
class VectorAtWorker(VectorWorkerBase):
|
||||
def get_arg_types(self):
|
||||
return gdb.lookup_type('std::size_t')
|
||||
|
||||
def __call__(self, obj, index):
|
||||
size = int(self.size(obj))
|
||||
if int(index) >= size:
|
||||
raise IndexError('Vector index "%d" should not be >= %d.' %
|
||||
((int(index), size)))
|
||||
return self.get(obj, int(index))
|
||||
|
||||
class VectorSubscriptWorker(VectorWorkerBase):
|
||||
def get_arg_types(self):
|
||||
return gdb.lookup_type('std::size_t')
|
||||
|
||||
def __call__(self, obj, subscript):
|
||||
return self.get(obj, int(subscript))
|
||||
|
||||
class VectorMethodsMatcher(gdb.xmethod.XMethodMatcher):
|
||||
def __init__(self):
|
||||
gdb.xmethod.XMethodMatcher.__init__(self,
|
||||
matcher_name_prefix + 'vector')
|
||||
self._subscript_worker = VectorSubscriptWorker()
|
||||
self._size_worker = VectorSizeWorker()
|
||||
self.methods = [self._subscript_worker, self._size_worker]
|
||||
self._method_dict = {
|
||||
'size': LibStdCxxXMethod('size', VectorSizeWorker),
|
||||
'empty': LibStdCxxXMethod('empty', VectorEmptyWorker),
|
||||
'front': LibStdCxxXMethod('front', VectorFrontWorker),
|
||||
'back': LibStdCxxXMethod('back', VectorBackWorker),
|
||||
'at': LibStdCxxXMethod('at', VectorAtWorker),
|
||||
'operator[]': LibStdCxxXMethod('operator[]',
|
||||
VectorSubscriptWorker),
|
||||
}
|
||||
self.methods = [self._method_dict[m] for m in self._method_dict]
|
||||
|
||||
def match(self, class_type, method_name):
|
||||
if not re.match('^std::vector<.*>$', class_type.tag):
|
||||
return None
|
||||
if method_name == 'operator[]' and self._subscript_worker.enabled:
|
||||
return self._subscript_worker
|
||||
elif method_name == 'size' and self._size_worker.enabled:
|
||||
return self._size_worker
|
||||
method = self._method_dict.get(method_name)
|
||||
if method is None or not method.enabled:
|
||||
return None
|
||||
return method.worker_class(class_type.template_argument(0))
|
||||
|
||||
# Xmethods for std::unique_ptr
|
||||
|
||||
@ -99,5 +460,9 @@ class UniquePtrMethodsMatcher(gdb.xmethod.XMethodMatcher):
|
||||
return self._get_worker
|
||||
|
||||
def register_libstdcxx_xmethods(locus):
|
||||
gdb.xmethod.register_xmethod_matcher(locus, ArrayMethodsMatcher())
|
||||
gdb.xmethod.register_xmethod_matcher(locus, ForwardListMethodsMatcher())
|
||||
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, UniquePtrMethodsMatcher())
|
||||
|
46
libstdc++-v3/testsuite/libstdc++-xmethods/array.cc
Normal file
46
libstdc++-v3/testsuite/libstdc++-xmethods/array.cc
Normal file
@ -0,0 +1,46 @@
|
||||
// { dg-do run }
|
||||
// { dg-options "-std=gnu++11 -g -O0" }
|
||||
|
||||
// Copyright (C) 2014 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 3, or (at your option)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING3. If not see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <array>
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
std::array<int, 10> a;
|
||||
std::array<int, 0> a1;
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
a[i] = 100 + i;
|
||||
|
||||
// { dg-final { note-test a.size() 10 } }
|
||||
// { dg-final { note-test a.empty() false } }
|
||||
// { dg-final { note-test a1.empty() true } }
|
||||
// { dg-final { note-test a1.size() 0 } }
|
||||
// { dg-final { note-test a.front() 100 } }
|
||||
// { dg-final { note-test a.back() 109 } }
|
||||
// { dg-final { note-test a.at(5) 105 } }
|
||||
// { dg-final { note-test a\[0\] 100 } }
|
||||
// { dg-final { note-test a\[4\] 104 } }
|
||||
// { dg-final { note-test a\[9\] 109 } }
|
||||
|
||||
return 0; // Mark SPOT
|
||||
}
|
||||
|
||||
// { dg-final { gdb-test SPOT {} 1 } }
|
67
libstdc++-v3/testsuite/libstdc++-xmethods/deque.cc
Normal file
67
libstdc++-v3/testsuite/libstdc++-xmethods/deque.cc
Normal file
@ -0,0 +1,67 @@
|
||||
// { dg-do run }
|
||||
// { dg-options "-g -O0" }
|
||||
|
||||
// Copyright (C) 2014 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 3, or (at your option)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING3. If not see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <deque>
|
||||
|
||||
const int max_deque_node_size = 512;
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
std::deque<int> q0, q1, q2, q3;
|
||||
int int_size = sizeof (int);
|
||||
|
||||
// The xmethod logic is exercised differently for deques of different size.
|
||||
// Let q1 be a deque requiring only 1 node. Let q2 be a deque filling up
|
||||
// exactly 2 nodes. Let q3 be of size which would require 1 node and part
|
||||
// of the second node.
|
||||
int q1_size = max_deque_node_size / int_size / 2;
|
||||
int q2_size = max_deque_node_size / int_size * 2;
|
||||
int q3_size = max_deque_node_size / int_size * 3 / 2;
|
||||
|
||||
for (int i = 0; i < q1_size; i++)
|
||||
q1.push_back (100 + i);
|
||||
|
||||
for (int i = 0; i < q2_size; i++)
|
||||
q2.push_back (200 + i);
|
||||
|
||||
for (int i = 0; i < q3_size; i++)
|
||||
q3.push_back (300 + i);
|
||||
|
||||
// { dg-final { note-test q0.empty() true } }
|
||||
// { dg-final { note-test q1.empty() false } }
|
||||
// { dg-final { note-test q0.size() 0 } }
|
||||
// { dg-final { note-test q1.size()==q1_size true } }
|
||||
// { dg-final { note-test q2.size()==q2_size true } }
|
||||
// { dg-final { note-test q3.size()==q3_size true } }
|
||||
// { dg-final { note-test q1.front() 100 } }
|
||||
// { dg-final { note-test q2.front() 200 } }
|
||||
// { dg-final { note-test q3.front() 300 } }
|
||||
// { dg-final { note-test q1.back()==(100+q1_size-1) true } }
|
||||
// { dg-final { note-test q2.back()==(200+q2_size-1) true } }
|
||||
// { dg-final { note-test q3.back()==(300+q3_size-1) true } }
|
||||
// { dg-final { note-test q3\[0\] 300 } }
|
||||
// { dg-final { note-test q3\[q3_size/2\]==(300+q3_size/2) true } }
|
||||
// { dg-final { note-test q3\[q3_size-1]==(300+q3_size-1) true } }
|
||||
|
||||
return 0; // Mark SPOT
|
||||
}
|
||||
|
||||
// { dg-final { gdb-test SPOT {} 1 } }
|
40
libstdc++-v3/testsuite/libstdc++-xmethods/forwardlist.cc
Normal file
40
libstdc++-v3/testsuite/libstdc++-xmethods/forwardlist.cc
Normal file
@ -0,0 +1,40 @@
|
||||
// { dg-do run }
|
||||
// { dg-options "-std=gnu++11 -g -O0" }
|
||||
|
||||
// Copyright (C) 2014 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 3, or (at your option)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING3. If not see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <forward_list>
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
std::forward_list<int> l0, l1;
|
||||
|
||||
l1.push_front (0);
|
||||
l1.push_front (1);
|
||||
l1.push_front (2);
|
||||
l1.push_front (11011);
|
||||
|
||||
// { dg-final { note-test l0.empty() true } }
|
||||
// { dg-final { note-test l1.empty() false } }
|
||||
// { dg-final { note-test l1.front() 11011 } }
|
||||
|
||||
return 0; // Mark SPOT
|
||||
}
|
||||
|
||||
// { dg-final { gdb-test SPOT {} 1 } }
|
42
libstdc++-v3/testsuite/libstdc++-xmethods/list.cc
Normal file
42
libstdc++-v3/testsuite/libstdc++-xmethods/list.cc
Normal file
@ -0,0 +1,42 @@
|
||||
// { dg-do run }
|
||||
// { dg-options "-g -O0" }
|
||||
|
||||
// Copyright (C) 2014 Free Software Foundation, Inc.
|
||||
//
|
||||
// This file is part of the GNU ISO C++ Library. This library is free
|
||||
// software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the
|
||||
// Free Software Foundation; either version 3, or (at your option)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING3. If not see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <list>
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
std::list<int> l0, l1;
|
||||
|
||||
l1.push_back (123);
|
||||
l1.push_back (456);
|
||||
l1.push_back (789);
|
||||
|
||||
// { dg-final { note-test l0.empty() true } }
|
||||
// { dg-final { note-test l1.empty() false } }
|
||||
// { dg-final { note-test l1.size() 3 } }
|
||||
// { dg-final { note-test l1.front() 123 } }
|
||||
// { dg-final { note-test l1.back() 789 } }
|
||||
|
||||
|
||||
return 0; // Mark SPOT
|
||||
}
|
||||
|
||||
// { dg-final { gdb-test SPOT {} 1 } }
|
@ -23,14 +23,65 @@
|
||||
int
|
||||
main ()
|
||||
{
|
||||
std::vector<int> v;
|
||||
v.push_back(1);
|
||||
v.push_back(2);
|
||||
v.push_back(3);
|
||||
// { dg-final { note-test v\[0\] 1 } }
|
||||
// { dg-final { note-test v\[1\] 2 } }
|
||||
// { dg-final { note-test v\[2\] 3 } }
|
||||
// { dg-final { note-test v.size() 3 } }
|
||||
std::vector<int> v0, v1;
|
||||
std::vector<bool> bv0, bv1, bv2, bv3;
|
||||
|
||||
v1.push_back (1);
|
||||
v1.push_back (2);
|
||||
v1.push_back (3);
|
||||
|
||||
for (int i = 0; i < 15; i++)
|
||||
bv1.push_back (i % 3);
|
||||
|
||||
for (int i = 0; i < 64; i++)
|
||||
bv2.push_back (i % 2);
|
||||
|
||||
for (int i = 0; i < 65; i++)
|
||||
bv3.push_back (i % 2);
|
||||
|
||||
// { dg-final { note-test v1\[0\] 1 } }
|
||||
// { dg-final { note-test v1\[1\] 2 } }
|
||||
// { dg-final { note-test v1\[2\] 3 } }
|
||||
// { dg-final { note-test bv1\[0\] false } }
|
||||
// { dg-final { note-test bv1\[1\] true } }
|
||||
// { dg-final { note-test bv1\[14\] true } }
|
||||
// { dg-final { note-test bv2\[0\] false } }
|
||||
// { dg-final { note-test bv2\[1\] true } }
|
||||
// { dg-final { note-test bv2\[63\] true } }
|
||||
// { dg-final { note-test bv3\[0\] false } }
|
||||
// { dg-final { note-test bv3\[1\] true } }
|
||||
// { dg-final { note-test bv3\[63\] true } }
|
||||
// { dg-final { note-test v0.size() 0 } }
|
||||
// { dg-final { note-test bv0.size() 0 } }
|
||||
// { dg-final { note-test v1.size() 3 } }
|
||||
// { dg-final { note-test bv1.size() 15 } }
|
||||
// { dg-final { note-test bv2.size() 64 } }
|
||||
// { dg-final { note-test bv3.size() 65 } }
|
||||
// { dg-final { note-test v0.empty() true } }
|
||||
// { dg-final { note-test v1.empty() false } }
|
||||
// { dg-final { note-test bv0.empty() true } }
|
||||
// { dg-final { note-test bv1.empty() false } }
|
||||
// { dg-final { note-test bv2.empty() false } }
|
||||
// { dg-final { note-test bv3.empty() false } }
|
||||
// { dg-final { note-test v1.front() 1 } }
|
||||
// { dg-final { note-test v1.back() 3 } }
|
||||
// { dg-final { note-test bv1.front() false } }
|
||||
// { dg-final { note-test bv1.back() true } }
|
||||
// { dg-final { note-test bv2.front() false } }
|
||||
// { dg-final { note-test bv2.back() true } }
|
||||
// { dg-final { note-test bv3.front() false } }
|
||||
// { dg-final { note-test bv3.back() false } }
|
||||
// { dg-final { note-test v1.at(1) 2 } }
|
||||
// { dg-final { note-test bv1.at(0) false } }
|
||||
// { dg-final { note-test bv1.at(1) true } }
|
||||
// { dg-final { note-test bv1.at(14) true } }
|
||||
// { dg-final { note-test bv2.at(0) false } }
|
||||
// { dg-final { note-test bv2.at(1) true } }
|
||||
// { dg-final { note-test bv2.at(63) true } }
|
||||
// { dg-final { note-test bv3.at(0) false } }
|
||||
// { dg-final { note-test bv3.at(1) true } }
|
||||
// { dg-final { note-test bv3.at(63) true } }
|
||||
// { dg-final { note-test bv3.at(64) false } }
|
||||
|
||||
return 0; // Mark SPOT
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user