Skip to content

Commit

Permalink
fixed dotted kvps being unable to add subtables (fixes #61)
Browse files Browse the repository at this point in the history
also:
- fixed extremely weird linker error on linux ICC (fixes #83)
- added some missing GNU attributes
- added additional tests
  • Loading branch information
marzer committed Jan 16, 2021
1 parent 5a9166b commit b11f28a
Show file tree
Hide file tree
Showing 12 changed files with 403 additions and 178 deletions.
2 changes: 1 addition & 1 deletion docs/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ PREDEFINED = \
"TOML_EXTERNAL_LINKAGE=" \
"TOML_TRIVIAL_ABI=" \
"TOML_EMPTY_BASES=" \
"TOML_INTERFACE" \
"TOML_ABSTRACT_BASE" \
"TOML_INTERNAL_LINKAGE=static"
EXPAND_AS_DEFINED =
SKIP_FUNCTION_MACROS = NO
Expand Down
2 changes: 1 addition & 1 deletion include/toml++/toml.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ TOML_POP_WARNINGS // TOML_DISABLE_SPAM_WARNINGS
#undef TOML_ABI_NAMESPACE_BOOL
#undef TOML_ABI_NAMESPACE_END
#undef TOML_ABI_NAMESPACE_START
#undef TOML_ABSTRACT_BASE
#undef TOML_ALWAYS_INLINE
#undef TOML_ANON_NAMESPACE
#undef TOML_ANON_NAMESPACE_END
Expand Down Expand Up @@ -100,7 +101,6 @@ TOML_POP_WARNINGS // TOML_DISABLE_SPAM_WARNINGS
#undef TOML_IMPL_NAMESPACE_START
#undef TOML_INT128
#undef TOML_INTELLISENSE
#undef TOML_INTERFACE
#undef TOML_INTERNAL_LINKAGE
#undef TOML_INT_CHARCONV
#undef TOML_LANG_AT_LEAST
Expand Down
6 changes: 6 additions & 0 deletions include/toml++/toml_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ TOML_IMPL_NAMESPACE_START

mutable raw_iterator raw_;

TOML_NODISCARD_CTOR
array_iterator(raw_mutable_iterator raw) noexcept
: raw_{ raw }
{}
Expand All @@ -40,8 +41,12 @@ TOML_IMPL_NAMESPACE_START
using difference_type = ptrdiff_t;
using iterator_category = typename std::iterator_traits<raw_iterator>::iterator_category;

TOML_NODISCARD_CTOR
array_iterator() noexcept = default;

TOML_NODISCARD_CTOR
array_iterator(const array_iterator&) noexcept = default;

array_iterator& operator = (const array_iterator&) noexcept = default;

array_iterator& operator++() noexcept // ++pre
Expand Down Expand Up @@ -429,6 +434,7 @@ TOML_NAMESPACE_START
[[nodiscard]] bool is_homogeneous(node_type ntype) const noexcept override;
[[nodiscard]] bool is_homogeneous(node_type ntype, node*& first_nonmatch) noexcept override;
[[nodiscard]] bool is_homogeneous(node_type ntype, const node*& first_nonmatch) const noexcept override;

template <typename ElemType = void>
[[nodiscard]]
bool is_homogeneous() const noexcept
Expand Down
30 changes: 29 additions & 1 deletion include/toml++/toml_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TOML_NAMESPACE_START
///
/// \detail A parsed TOML document forms a tree made up of tables, arrays and values.
/// This type is the base of each of those, providing a lot of the polymorphic plumbing.
class TOML_INTERFACE TOML_API node
class TOML_ABSTRACT_BASE TOML_API node
{
private:
friend class TOML_PARSER_TYPENAME;
Expand All @@ -78,6 +78,7 @@ TOML_NAMESPACE_START
template <typename T>
[[nodiscard]]
TOML_ALWAYS_INLINE
TOML_ATTR(pure)
impl::wrap_node<T>& ref_cast() & noexcept
{
return *reinterpret_cast<impl::wrap_node<T>*>(this);
Expand All @@ -86,6 +87,7 @@ TOML_NAMESPACE_START
template <typename T>
[[nodiscard]]
TOML_ALWAYS_INLINE
TOML_ATTR(pure)
impl::wrap_node<T>&& ref_cast() && noexcept
{
return std::move(*reinterpret_cast<impl::wrap_node<T>*>(this));
Expand All @@ -94,6 +96,7 @@ TOML_NAMESPACE_START
template <typename T>
[[nodiscard]]
TOML_ALWAYS_INLINE
TOML_ATTR(pure)
const impl::wrap_node<T>& ref_cast() const & noexcept
{
return *reinterpret_cast<const impl::wrap_node<T>*>(this);
Expand All @@ -106,9 +109,26 @@ TOML_NAMESPACE_START

virtual ~node() noexcept = default;



#if defined(DOXYGEN) || !TOML_ICC || TOML_ICC_CL

/// \brief Returns the node's type identifier.
[[nodiscard]] virtual node_type type() const noexcept = 0;

#else

[[nodiscard]] virtual node_type type() const noexcept
{
// Q: "what the fuck?"
// A: https://github.com/marzer/tomlplusplus/issues/83
// tl,dr: go home ICC, you're drunk.

return type();
}

#endif

/// \brief Returns true if this node is a table.
[[nodiscard]] virtual bool is_table() const noexcept = 0;
/// \brief Returns true if this node is an array.
Expand Down Expand Up @@ -142,6 +162,7 @@ TOML_NAMESPACE_START
/// \returns Returns true if this node is an instance of the specified type.
template <typename T>
[[nodiscard]]
TOML_ATTR(pure)
bool is() const noexcept
{
using type = impl::unwrap_node<T>;
Expand Down Expand Up @@ -278,6 +299,7 @@ TOML_NAMESPACE_START
/// \remarks Always returns `false` for empty tables and arrays.
template <typename ElemType = void>
[[nodiscard]]
TOML_ATTR(pure)
bool is_homogeneous() const noexcept
{
using type = impl::unwrap_node<ElemType>;
Expand Down Expand Up @@ -501,6 +523,7 @@ TOML_NAMESPACE_START
/// \returns A pointer to the node as the given type, or nullptr if it was a different type.
template <typename T>
[[nodiscard]]
TOML_ATTR(pure)
impl::wrap_node<T>* as() noexcept
{
using type = impl::unwrap_node<T>;
Expand All @@ -524,6 +547,7 @@ TOML_NAMESPACE_START
/// \brief Gets a pointer to the node as a more specific node type (const overload).
template <typename T>
[[nodiscard]]
TOML_ATTR(pure)
const impl::wrap_node<T>* as() const noexcept
{
using type = impl::unwrap_node<T>;
Expand Down Expand Up @@ -702,6 +726,7 @@ TOML_NAMESPACE_START

template <typename T, typename N>
[[nodiscard]]
TOML_ATTR(pure)
static decltype(auto) do_ref(N&& n) noexcept
{
using type = impl::unwrap_node<T>;
Expand Down Expand Up @@ -794,6 +819,7 @@ TOML_NAMESPACE_START
/// \returns A reference to the underlying data.
template <typename T>
[[nodiscard]]
TOML_ATTR(pure)
impl::unwrap_node<T>& ref() & noexcept
{
return do_ref<T>(*this);
Expand All @@ -802,6 +828,7 @@ TOML_NAMESPACE_START
/// \brief Gets a raw reference to a value node's underlying data (rvalue overload).
template <typename T>
[[nodiscard]]
TOML_ATTR(pure)
impl::unwrap_node<T>&& ref() && noexcept
{
return do_ref<T>(std::move(*this));
Expand All @@ -810,6 +837,7 @@ TOML_NAMESPACE_START
/// \brief Gets a raw reference to a value node's underlying data (const lvalue overload).
template <typename T>
[[nodiscard]]
TOML_ATTR(pure)
const impl::unwrap_node<T>& ref() const& noexcept
{
return do_ref<T>(*this);
Expand Down
8 changes: 6 additions & 2 deletions include/toml++/toml_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2659,6 +2659,9 @@ TOML_IMPL_NAMESPACE_START
return_if_error();

TOML_ASSERT(kvp.key.segments.size() >= 1_sz);

// if it's a dotted kvp we need to spawn the sub-tables if necessary,
// and set the target table to the second-to-last one in the chain
if (kvp.key.segments.size() > 1_sz)
{
for (size_t i = 0; i < kvp.key.segments.size() - 1_sz; i++)
Expand All @@ -2671,13 +2674,14 @@ TOML_IMPL_NAMESPACE_START
new toml::table{}
).first->second.get();
dotted_key_tables.push_back(&child->ref_cast<table>());
dotted_key_tables.back()->inline_ = true;
child->source_ = kvp.value.get()->source_;
}
else if (!child->is_table() || !find(dotted_key_tables, &child->ref_cast<table>()))
else if (!child->is_table()
|| !(find(dotted_key_tables, &child->ref_cast<table>()) || find(implicit_tables, &child->ref_cast<table>())))
set_error("cannot redefine existing "sv, to_sv(child->type()), " as dotted key-value pair"sv);
else
child->source_.end = kvp.value.get()->source_.end;

return_if_error();
tab = &child->ref_cast<table>();
}
Expand Down
8 changes: 4 additions & 4 deletions include/toml++/toml_preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
#if defined(_MSC_VER) // msvc compat mode
#ifdef __has_declspec_attribute
#if __has_declspec_attribute(novtable)
#define TOML_INTERFACE __declspec(novtable)
#define TOML_ABSTRACT_BASE __declspec(novtable)
#endif
#if __has_declspec_attribute(empty_bases)
#define TOML_EMPTY_BASES __declspec(empty_bases)
Expand Down Expand Up @@ -125,7 +125,7 @@
#define TOML_NEVER_INLINE __declspec(noinline)
#define TOML_ASSUME(cond) __assume(cond)
#define TOML_UNREACHABLE __assume(0)
#define TOML_INTERFACE __declspec(novtable)
#define TOML_ABSTRACT_BASE __declspec(novtable)
#define TOML_EMPTY_BASES __declspec(empty_bases)

#endif // msvc
Expand Down Expand Up @@ -374,8 +374,8 @@ is no longer necessary.
#define TOML_ATTR(...)
#endif

#ifndef TOML_INTERFACE
#define TOML_INTERFACE
#ifndef TOML_ABSTRACT_BASE
#define TOML_ABSTRACT_BASE
#endif

#ifndef TOML_EMPTY_BASES
Expand Down
3 changes: 3 additions & 0 deletions include/toml++/toml_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ TOML_IMPL_NAMESPACE_START
return TOML_LAUNDER(reinterpret_cast<proxy_type*>(&proxy));
}

TOML_NODISCARD_CTOR
table_iterator(raw_mutable_iterator raw) noexcept
: raw_{ raw }
{}
Expand All @@ -59,8 +60,10 @@ TOML_IMPL_NAMESPACE_START

public:

TOML_NODISCARD_CTOR
table_iterator() noexcept = default;

TOML_NODISCARD_CTOR
table_iterator(const table_iterator& other) noexcept
: raw_{ other.raw_ }
{}
Expand Down
2 changes: 1 addition & 1 deletion include/toml++/toml_utf8_streams.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ TOML_IMPL_NAMESPACE_START
#define TOML_ERROR err.emplace
#endif

struct TOML_INTERFACE utf8_reader_interface
struct TOML_ABSTRACT_BASE utf8_reader_interface
{
[[nodiscard]]
virtual const source_path_ptr& source_path() const noexcept = 0;
Expand Down
2 changes: 1 addition & 1 deletion include/toml++/toml_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#define TOML_LIB_MAJOR 2
#define TOML_LIB_MINOR 3
#define TOML_LIB_PATCH 0
#define TOML_LIB_PATCH 1

#define TOML_LANG_MAJOR 1
#define TOML_LANG_MINOR 0
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project(
'tomlplusplus',
'cpp',
version : '2.3.0',
version : '2.3.1',
meson_version : '>=0.53.0',
license : 'MIT',
default_options : [ # https://mesonbuild.com/Builtin-options.html
Expand Down
Loading

0 comments on commit b11f28a

Please sign in to comment.