diff options
Diffstat (limited to 'gcc/selftest-logical-location.cc')
-rw-r--r-- | gcc/selftest-logical-location.cc | 77 |
1 files changed, 62 insertions, 15 deletions
diff --git a/gcc/selftest-logical-location.cc b/gcc/selftest-logical-location.cc index 6c1c757..5f33b48 100644 --- a/gcc/selftest-logical-location.cc +++ b/gcc/selftest-logical-location.cc @@ -21,49 +21,96 @@ along with GCC; see the file COPYING3. If not see #include "config.h" #include "system.h" #include "coretypes.h" +#include "selftest.h" #include "selftest-logical-location.h" #if CHECKING_P namespace selftest { -/* class test_logical_location : public logical_location. */ +/* class test_logical_location_manager : public logical_location_manager. */ -test_logical_location::test_logical_location (enum logical_location_kind kind, - const char *name) -: m_kind (kind), - m_name (name) +test_logical_location_manager::~test_logical_location_manager () { + for (auto iter : m_name_to_item_map) + delete iter.second; } const char * -test_logical_location::get_short_name () const +test_logical_location_manager::get_short_name (key k) const { - return m_name; + auto item = item_from_key (k); + if (!item) + return nullptr; + return item->m_name; } const char * -test_logical_location::get_name_with_scope () const +test_logical_location_manager::get_name_with_scope (key k) const { - return m_name; + auto item = item_from_key (k); + return item->m_name; } const char * -test_logical_location::get_internal_name () const +test_logical_location_manager::get_internal_name (key k) const { - return m_name; + auto item = item_from_key (k); + return item->m_name; } enum logical_location_kind -test_logical_location::get_kind () const +test_logical_location_manager::get_kind (key k) const { - return m_kind; + auto item = item_from_key (k); + return item->m_kind; } label_text -test_logical_location::get_name_for_path_output () const +test_logical_location_manager::get_name_for_path_output (key k) const { - return label_text::borrow (m_name); + auto item = item_from_key (k); + return label_text::borrow (item->m_name); +} + +logical_location +test_logical_location_manager:: +logical_location_from_funcname (const char *funcname) +{ + const item *i = item_from_funcname (funcname); + return key::from_ptr (i); +} + +const test_logical_location_manager::item * +test_logical_location_manager::item_from_funcname (const char *funcname) +{ + if (!funcname) + return nullptr; + + if (item **slot = m_name_to_item_map.get (funcname)) + return *slot; + + item *i = new item (LOGICAL_LOCATION_KIND_FUNCTION, funcname); + m_name_to_item_map.put (funcname, i); + return i; +} + +/* Run all of the selftests within this file. */ + +void +selftest_logical_location_cc_tests () +{ + test_logical_location_manager mgr; + + ASSERT_FALSE (mgr.logical_location_from_funcname (nullptr)); + + logical_location loc_foo = mgr.logical_location_from_funcname ("foo"); + logical_location loc_bar = mgr.logical_location_from_funcname ("bar"); + + ASSERT_NE (loc_foo, loc_bar); + + ASSERT_STREQ (mgr.get_short_name (loc_foo), "foo"); + ASSERT_STREQ (mgr.get_short_name (loc_bar), "bar"); } } // namespace selftest |