- Debugged more PrettyPrinters, all implemented thus far work in testing

- Fixed implementation of tuple.h, TODO: Still need to complete
 - Wrote a PrettyPrinter for tuple.h
This commit is contained in:
2025-08-10 23:46:36 -04:00
parent 9f96155856
commit b9de039a10
12 changed files with 170 additions and 44 deletions

View File

@@ -48,7 +48,7 @@ PROJECT_NAME = fennec
# could be handy for archiving the generated documentation or if some version # could be handy for archiving the generated documentation or if some version
# control system is used. # control system is used.
PROJECT_NUMBER = 1.0.2 PROJECT_NUMBER =
# Using the PROJECT_BRIEF tag one can provide an optional one line description # Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a # for a project that appears at the top of each page and should give viewer a

View File

@@ -24,6 +24,7 @@ import gdb
from . import containers from . import containers
from . import strings from . import strings
from . import memory from . import memory
from . import utility
def register_printers(obj): def register_printers(obj):
gdb.printing.register_pretty_printer(obj, containers.printer) gdb.printing.register_pretty_printer(obj, containers.printer)

View File

@@ -19,6 +19,7 @@
import gdb import gdb
import re import re
from collections import deque from collections import deque
from . import utility
# OPTIONAL ============================================================================================================= # OPTIONAL =============================================================================================================
class OptionalPrinter: class OptionalPrinter:
@@ -34,7 +35,7 @@ class OptionalPrinter:
else: else:
return "{ empty }" return "{ empty }"
# OPTIONAL ============================================================================================================= # PAIR =================================================================================================================
class PairPrinter: class PairPrinter:
"""Print a fennec::optional""" """Print a fennec::optional"""
@@ -48,8 +49,28 @@ class PairPrinter:
return ("first", self.val['first']), ("second", self.val['second']) return ("first", self.val['first']), ("second", self.val['second'])
# TUPLE ================================================================================================================
class TuplePrinter:
"""Print a fennec::tuple"""
def __init__(self, val):
self.fields = val.type.fields()[0].type.fields()
self.elems = val
self.count = len(self.fields)
def to_string(self):
return " { size = " + str(len(self.fields)) + " }"
def children(self):
return (('[{}]'.format(i), self.elems.cast(self.fields[i].type)['value']) for i in range(self.count))
# ARRAY ================================================================================================================ # ARRAY ================================================================================================================
class ArrayPrinter: class ArrayPrinter:
"""Print a fennec::array"""
def __init__(self, val): def __init__(self, val):
self.val = val self.val = val
@@ -66,6 +87,8 @@ class ArrayPrinter:
# DYNARRAY ============================================================================================================= # DYNARRAY =============================================================================================================
class DynArrayPrinter: class DynArrayPrinter:
"""Print a fennec::dynarray"""
def __init__(self, val): def __init__(self, val):
self.val = val self.val = val
@@ -201,6 +224,7 @@ class RDTreePrinter:
# SET ================================================================================================================== # SET ==================================================================================================================
class SetPrinter: class SetPrinter:
"""Print a fennec::set"""
class Iterator: class Iterator:
def __init__(self, table, capacity): def __init__(self, table, capacity):
@@ -244,6 +268,7 @@ class SetPrinter:
# MAP ================================================================================================================== # MAP ==================================================================================================================
class MapPrinter: class MapPrinter:
"""Print a fennec::map"""
class Iterator: class Iterator:
def __init__(self, table, capacity): def __init__(self, table, capacity):
@@ -272,12 +297,12 @@ class MapPrinter:
if not self.move: if not self.move:
self.move = True self.move = True
return ('key' + str(i), key) return 'key' + str(i), key
else: else:
self.move = False self.move = False
self.index = self.index + 1 self.index = self.index + 1
self.node = self.node + 1 self.node = self.node + 1
return ('value' + str(i), val) return 'value' + str(i), val
def __init__(self, val): def __init__(self, val):
self.table = val['_set']['_alloc']['_data'] self.table = val['_set']['_alloc']['_data']
@@ -303,6 +328,7 @@ def register_printers():
pp = gdb.printing.RegexpCollectionPrettyPrinter("fennec::containers") pp = gdb.printing.RegexpCollectionPrettyPrinter("fennec::containers")
pp.add_printer('optional', '^fennec::optional<.*>$', OptionalPrinter) pp.add_printer('optional', '^fennec::optional<.*>$', OptionalPrinter)
pp.add_printer('pair', '^fennec::pair<.*>$', PairPrinter) pp.add_printer('pair', '^fennec::pair<.*>$', PairPrinter)
pp.add_printer('tuple', '^fennec::tuple<.*>$', TuplePrinter)
pp.add_printer('array', '^fennec::array<.*>$', ArrayPrinter) pp.add_printer('array', '^fennec::array<.*>$', ArrayPrinter)
pp.add_printer('dynarray', '^fennec::dynarray<.*>$', DynArrayPrinter) pp.add_printer('dynarray', '^fennec::dynarray<.*>$', DynArrayPrinter)
pp.add_printer('list', '^fennec::list<.*>$', ListPrinter) pp.add_printer('list', '^fennec::list<.*>$', ListPrinter)

20
gdb/fennec/utility.py Normal file
View File

@@ -0,0 +1,20 @@
# ======================================================================================================================
# fennec, a free and open source game engine
# Copyright © 2025 Medusa Slockbower
#
# This program 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 of the License, or
# (at your option) any later version.
#
# This program 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 program. If not, see <https://www.gnu.org/licenses/>.
# ======================================================================================================================
def printMembers(obj):
print(str(dir(obj)))

View File

@@ -24,34 +24,28 @@
namespace fennec::detail namespace fennec::detail
{ {
// leaves
template<size_t i, typename T> template <std::size_t I, typename T>
struct _tuple_leaf { struct _tuple_leaf
{
template <typename ArgT>
_tuple_leaf(ArgT&& arg) : value(fennec::forward<ArgT>(arg)) {}
~_tuple_leaf() = default;
T value; T value;
template<typename...ArgsT>
_tuple_leaf(ArgsT&&...args) : value(args...) {
}
constexpr operator T&() {
return value;
}
constexpr operator const T&() const {
return value;
}
}; };
// proxy template <typename, typename...>
template<typename, typename...TypesT>
struct _tuple; struct _tuple;
template<size_t...i, typename...TypesT> template <size_t...IndicesV, typename...TypesT>
struct _tuple<index_sequence<i...>, TypesT...> : _tuple_leaf<i, TypesT>... { struct _tuple<index_sequence<IndicesV...>, TypesT...> : _tuple_leaf<IndicesV, TypesT>...
{
template <typename...ArgsT> template <typename...ArgsT>
_tuple(ArgsT&&...args) : _tuple_leaf<i, TypesT>(args)... { _tuple(ArgsT&&... args) : _tuple_leaf<IndicesV, TypesT>(fennec::forward<ArgsT>(args))... {}
}
~_tuple() = default;
}; };
} }

View File

@@ -36,32 +36,44 @@ template<typename...TypesT> struct tuple;
template<size_t i, typename...TypesT> template<size_t i, typename...TypesT>
constexpr typename tuple<TypesT...>::template elem_t<i>& get(tuple<TypesT...>& x) { constexpr typename tuple<TypesT...>::template elem_t<i>& get(tuple<TypesT...>& x) {
using elem_t = typename tuple<TypesT...>::template elem_t<i>; using elem_t = typename tuple<TypesT...>::template elem_t<i>;
auto& it = static_cast<detail::_tuple_leaf<i, elem_t>>(x); auto& it = *static_cast<detail::_tuple_leaf<i, elem_t>*>(&x);
return it; return it.value;
} }
template<size_t i, typename...TypesT> template<size_t i, typename...TypesT>
constexpr const typename tuple<TypesT...>::template elem_t<i>& get(tuple<TypesT...>& x) { constexpr const typename tuple<TypesT...>::template elem_t<i>& get(const tuple<TypesT...>& x) {
using elem_t = typename tuple<TypesT...>::template elem_t<i>; using elem_t = typename tuple<TypesT...>::template elem_t<i>;
auto& it = static_cast<detail::_tuple_leaf<i, elem_t>>(x); const auto& it = *static_cast<const detail::_tuple_leaf<i, elem_t>*>(&x);
return it; return it.value;
} }
template<typename ...TypesT> template<typename ...TypesT>
struct tuple : detail::_tuple<make_index_sequence<sizeof...(TypesT)>, TypesT...> { struct tuple : public detail::_tuple<make_index_sequence_t<sizeof...(TypesT)>, TypesT...>
{
public: using base_t = detail::_tuple<make_index_sequence_t<sizeof...(TypesT)>, TypesT...>;
using base_t = detail::_tuple<make_index_sequence<sizeof...(TypesT)>, TypesT...>;
template<size_t i> template<size_t i>
using elem_t = nth_element<i, TypesT...>; using elem_t = typename nth_element<i, TypesT...>::type;
template<typename...ArgsT> template<typename...ArgsT>
constexpr tuple(ArgsT&&...args) : base_t(args...) { tuple(ArgsT&&...args)
: base_t(fennec::forward<ArgsT>(args)...) {
}
tuple(const tuple& cpy)
: base_t(cpy) {
}
tuple(tuple&& cpy)
: base_t(cpy) {
} }
}; };
// This is needed for
template<typename...TypesT>
tuple(TypesT...) -> tuple<TypesT...>;
} }
#endif // FENNEC_CONTAINERS_TUPLE_H #endif // FENNEC_CONTAINERS_TUPLE_H

View File

@@ -32,8 +32,8 @@ namespace fennec::detail
template<size_t n, size_t i, typename HeadT, typename...RestT> template<size_t n, size_t i, typename HeadT, typename...RestT>
struct _nth_element<n, i, HeadT, RestT...> : conditional< struct _nth_element<n, i, HeadT, RestT...> : conditional<
n == i, type_identity<HeadT>, n == i, HeadT,
_nth_element<n, i + 1, RestT...> typename _nth_element<n, i + 1, RestT...>::type
> {}; > {};
} }

View File

@@ -86,10 +86,10 @@ public:
/// ///
/// \details adds additional character for null termination. Ignores whether str is null-terminated. /// \details adds additional character for null termination. Ignores whether str is null-terminated.
/// This constructor makes the assumption that `n` is the intended number of characters. /// This constructor makes the assumption that `n` is the intended number of characters.
constexpr _string(const char* str, size_t n) constexpr _string(char* str, size_t n)
: _str(n + 1) { : _str(str[n - 1] == '\0' ? n : n + 1) {
fennec::memcpy(_str.data(), str, n); fennec::memcpy(_str.data(), str, n);
_str[n] = '\0'; if (str[n - 1] != '\0') _str[n] = '\0';
} }
/// ///
@@ -97,7 +97,30 @@ public:
/// \param str the buffer to wrap /// \param str the buffer to wrap
/// \tparam n the number of characters in the buffer plus the null terminator /// \tparam n the number of characters in the buffer plus the null terminator
template<size_t n> template<size_t n>
constexpr _string(char(&str)[n]) explicit constexpr _string(char(&str)[n])
: _str(str, n) {
assert(_str[n - 1] == '\0', "Invalid NTBS.");
}
///
/// \brief Buffer Copy Constructor
/// \param str the buffer to copy
/// \param n number of characters in the buffer
///
/// \details adds additional character for null termination. Ignores whether str is null-terminated.
/// This constructor makes the assumption that `n` is the intended number of characters.
constexpr _string(const char* str, size_t n)
: _str(str[n - 1] == '\0' ? n : n + 1) {
fennec::memcpy(_str.data(), str, n);
if (str[n - 1] != '\0') _str[n] = '\0';
}
///
/// \brief Buffer Constructor, wraps the provided C-Style string
/// \param str the buffer to wrap
/// \tparam n the number of characters in the buffer plus the null terminator
template<size_t n>
explicit constexpr _string(const char(&str)[n])
: _str(str, n) { : _str(str, n) {
assert(_str[n - 1] == '\0', "Invalid NTBS."); assert(_str[n - 1] == '\0', "Invalid NTBS.");
} }
@@ -385,7 +408,7 @@ public:
/// \returns /// \returns
constexpr _string operator+(char c) const { constexpr _string operator+(char c) const {
// Copy contents with one additional byte. // Copy contents with one additional byte.
_string res(_str.data(), _str.size()); _string res(_str.data(), _str.size() + 1);
res[size()] = c; // Set the last character to c res[size()] = c; // Set the last character to c
return res; return res;
} }

View File

@@ -29,7 +29,7 @@ Library and Template Library.
| Symbol | Implemented | Passed | | Symbol | Implemented | Passed |
|:-------------------------------------|:-----------:|:------:| |:-------------------------------------|:-----------:|:------:|
| pair | ✔ | ✔ | | pair | ✔ | ✔ |
| tuple | ⭕ | | | tuple | ⭕ | |
| optional | ✔ | ✔ | | optional | ✔ | ✔ |
| variant | ❌ | ❌ | | variant | ❌ | ❌ |
| any | ❌ | ❌ | | any | ❌ | ❌ |

View File

@@ -34,6 +34,7 @@ add_executable(fennec-test main.cpp
tests/containers/test_map.h tests/containers/test_map.h
tests/containers/test_rdtree.h tests/containers/test_rdtree.h
tests/containers/test_list.h tests/containers/test_list.h
tests/containers/test_tuple.h
) )
target_compile_definitions(fennec-test PUBLIC FENNEC_TEST_CWD="${CMAKE_SOURCE_DIR}/bin/${FENNEC_BUILD_NAME}" target_compile_definitions(fennec-test PUBLIC FENNEC_TEST_CWD="${CMAKE_SOURCE_DIR}/bin/${FENNEC_BUILD_NAME}"

View File

@@ -0,0 +1,43 @@
// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright © 2025 Medusa Slockbower
//
// This program 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 of the License, or
// (at your option) any later version.
//
// This program 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 program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
#ifndef FENNEC_TEST_CONTAINERS_TUPLE_H
#define FENNEC_TEST_CONTAINERS_TUPLE_H
#include <fennec/containers/tuple.h>
#include <fennec/langproc/strings/string.h>
namespace fennec
{
namespace test
{
inline void fennec_test_containers_tuple() {
string str{ "Hello World!" };
tuple test { 0, 0.5f, str };
fennec_test_run(get<0>(test), 0);
fennec_test_run(get<1>(test), 0.5f);
fennec_test_run(get<2>(test), str);
}
}
}
#endif // FENNEC_TEST_CONTAINERS_TUPLE_H

View File

@@ -26,6 +26,7 @@
#include "containers/test_optional.h" #include "containers/test_optional.h"
#include "containers/test_rdtree.h" #include "containers/test_rdtree.h"
#include "containers/test_set.h" #include "containers/test_set.h"
#include "containers/test_tuple.h"
namespace fennec::test namespace fennec::test
{ {
@@ -37,6 +38,11 @@ namespace fennec::test
fennec_test_containers_optional(); fennec_test_containers_optional();
fennec_test_spacer(3); fennec_test_spacer(3);
fennec_test_subheader("tuple tests");
fennec_test_spacer(2);
fennec_test_containers_tuple();
fennec_test_spacer(3);
fennec_test_subheader("array tests"); fennec_test_subheader("array tests");
fennec_test_spacer(2); fennec_test_spacer(2);
fennec_test_containers_array(); fennec_test_containers_array();