Skip to content

Commit

Permalink
Fix not being able to include multiple flatdata schemas if they use t…
Browse files Browse the repository at this point in the history
…he same multivector bit width (#224)

* Move __builtin into the same namespace as the archive using it

Signed-off-by: Christian Vetter <[email protected]>

* Adjust README

Signed-off-by: Christian Vetter <[email protected]>
  • Loading branch information
VeaaC authored Feb 16, 2022
1 parent a28f971 commit a4b100c
Show file tree
Hide file tree
Showing 17 changed files with 629 additions and 318 deletions.
6 changes: 5 additions & 1 deletion flatdata-cpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ flatdata_generate_source(generate_flatdata_test_code
${CMAKE_CURRENT_SOURCE_DIR}/test_structures.flatdata
${CMAKE_CURRENT_BINARY_DIR}/generated/test_structures.hpp)

flatdata_generate_source(generate_flatdata_test_code2
${CMAKE_CURRENT_SOURCE_DIR}/test_structures2.flatdata
${CMAKE_CURRENT_BINARY_DIR}/generated/test_structures2.hpp)

flatdata_generate_source(generate_flatdata_test_case_ranges
${CMAKE_CURRENT_SOURCE_DIR}/../../test_cases/archives/ranges.flatdata
${CMAKE_CURRENT_BINARY_DIR}/generated/ranges.hpp)

add_executable(flatdata_test ${TEST_FLATDATA_SOURCES})
add_dependencies(flatdata_test generate_flatdata_test_code generate_flatdata_test_case_ranges)
add_dependencies(flatdata_test generate_flatdata_test_code generate_flatdata_test_code2 generate_flatdata_test_case_ranges)

target_include_directories(flatdata_test
PRIVATE ${Boost_INCLUDE_DIRS}
Expand Down
4 changes: 4 additions & 0 deletions flatdata-cpp/test/GeneratedArchiveTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

#include "test_structures.hpp"

// include to make sure we can compile if we have two identical multivector resources in different
// namespaces
#include "test_structures2.hpp"

#include <flatdata/FileResourceStorage.h>
#include <flatdata/MemoryResourceStorage.h>
#include <boost/filesystem.hpp>
Expand Down
12 changes: 12 additions & 0 deletions flatdata-cpp/test/test_structures2.flatdata
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace test_structures2 {

struct AStruct {
value : u64 : 8;
}

// A 1:1 copy of the same multivector as in test-structures, makes sure we do not have clashes in builtins
archive SimpleResources {
multivector_resource: multivector< 33, AStruct >;
}

} // namespace test_structures2
2 changes: 1 addition & 1 deletion flatdata-generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The `flatdata` generator works in several stages which are clearly separated fro

- **Add builtin structures** if any of the resources require them. For
example, `multivector< N, ... >` requires
`_builtin.multivector.IndexTypeN` to be available.
`_builtin.multivector.IndexTypeN` to be available in the parent namespace.
- **Add constant references** to all archives so that constants are
available for schema resolution.

Expand Down
5 changes: 3 additions & 2 deletions flatdata-generator/flatdata/generator/tree/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ def _build_node_tree(definition):


def _append_builtin_structures(root):
for node in root.iterate(Multivector):
namespace = _ensure_namespace(root, "._builtin.multivector")
multivectors = list(root.iterate(Multivector))
for node in multivectors:
namespace = _ensure_namespace(root, node.parent.parent.path + "._builtin.multivector")
for builtin in node.builtins:
found = namespace.get_relative(builtin.name)
if found is None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using DataType = flatdata::MultiArrayView< ::_builtin::multivector::IndexType8, ::n::S, ::n::T >;
using DataType = flatdata::MultiArrayView< ::n::_builtin::multivector::IndexType8, ::n::S, ::n::T >;
const DataType& data( ) const;

using OptionalDataType = flatdata::MultiArrayView< ::_builtin::multivector::IndexType16, ::n::S, ::n::T >;
using OptionalDataType = flatdata::MultiArrayView< ::n::_builtin::multivector::IndexType16, ::n::S, ::n::T >;
const boost::optional< OptionalDataType >& optional_data( ) const;

using DataU64IndexType = flatdata::MultiArrayView< ::_builtin::multivector::IndexType64, ::n::S, ::n::T >;
using DataU64IndexType = flatdata::MultiArrayView< ::n::_builtin::multivector::IndexType64, ::n::S, ::n::T >;
const DataU64IndexType& data_u64_index( ) const;
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using DataType = flatdata::MultiVector< ::_builtin::multivector::IndexType8, ::n::S, ::n::T >;
using DataReaderType = flatdata::MultiArrayView< ::_builtin::multivector::IndexType8, ::n::S, ::n::T >;
using DataType = flatdata::MultiVector< ::n::_builtin::multivector::IndexType8, ::n::S, ::n::T >;
using DataReaderType = flatdata::MultiArrayView< ::n::_builtin::multivector::IndexType8, ::n::S, ::n::T >;
DataType start_data( );

using OptionalDataType = flatdata::MultiVector< ::_builtin::multivector::IndexType16, ::n::S, ::n::T >;
using OptionalDataReaderType = flatdata::MultiArrayView< ::_builtin::multivector::IndexType16, ::n::S, ::n::T >;
using OptionalDataType = flatdata::MultiVector< ::n::_builtin::multivector::IndexType16, ::n::S, ::n::T >;
using OptionalDataReaderType = flatdata::MultiArrayView< ::n::_builtin::multivector::IndexType16, ::n::S, ::n::T >;
OptionalDataType start_optional_data( );

using DataU64IndexType = flatdata::MultiVector< ::_builtin::multivector::IndexType64, ::n::S, ::n::T >;
using DataU64IndexReaderType = flatdata::MultiArrayView< ::_builtin::multivector::IndexType64, ::n::S, ::n::T >;
using DataU64IndexType = flatdata::MultiVector< ::n::_builtin::multivector::IndexType64, ::n::S, ::n::T >;
using DataU64IndexReaderType = flatdata::MultiArrayView< ::n::_builtin::multivector::IndexType64, ::n::S, ::n::T >;
DataU64IndexType start_data_u64_index( );
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ class XBuilder : public flatdata::ArchiveBuilder

} // namespace m

namespace a {
namespace _builtin {
namespace multivector {

Expand Down Expand Up @@ -299,7 +300,7 @@ union IndexType32Template
typedef IndexType32Template< flatdata::Reader > IndexType32;
typedef IndexType32Template< flatdata::Writer > IndexType32Mutator;

}} // namespace _builtin.multivector
}}} // namespace a._builtin.multivector

namespace a {

Expand Down Expand Up @@ -328,7 +329,7 @@ class A : public flatdata::Archive
using ListType = flatdata::ArrayView< ::m::S >;
const ListType& list( ) const;

using MultiType = flatdata::MultiArrayView< ::_builtin::multivector::IndexType32, ::n::S >;
using MultiType = flatdata::MultiArrayView< ::a::_builtin::multivector::IndexType32, ::n::S >;
const MultiType& multi( ) const;

using InnerType = ::n::X;
Expand Down Expand Up @@ -374,8 +375,8 @@ class ABuilder : public flatdata::ArchiveBuilder
ListType start_list( );
bool set_list( ListReaderType data );

using MultiType = flatdata::MultiVector< ::_builtin::multivector::IndexType32, ::n::S >;
using MultiReaderType = flatdata::MultiArrayView< ::_builtin::multivector::IndexType32, ::n::S >;
using MultiType = flatdata::MultiVector< ::a::_builtin::multivector::IndexType32, ::n::S >;
using MultiReaderType = flatdata::MultiArrayView< ::a::_builtin::multivector::IndexType32, ::n::S >;
MultiType start_multi( );


Expand Down Expand Up @@ -887,6 +888,7 @@ XBuilder::set_payload( PayloadReaderType data )

} // namespace m

namespace a {
namespace _builtin {
namespace multivector {
namespace internal
Expand Down Expand Up @@ -994,7 +996,7 @@ std::string IndexType32Template< Member >::describe( size_t /*unused*/ ) const
}
return ss.str( );
}
}} // namespace _builtin.multivector
}}} // namespace a._builtin.multivector

namespace a {
namespace internal
Expand Down Expand Up @@ -1238,7 +1240,7 @@ ABuilder::set_list( ListReaderType data )
inline auto ABuilder::start_multi( ) -> MultiType
{
check_created( );
return storage( ).create_multi_vector< ::_builtin::multivector::IndexType32, ::n::S >( "multi", internal::A__multi__schema__ );
return storage( ).create_multi_vector< ::a::_builtin::multivector::IndexType32, ::n::S >( "multi", internal::A__multi__schema__ );
}

inline auto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ subgraph cluster__n_A_data
fillcolor="#C4E6F8";


_n_A_data__builtin_multivector_IndexType8 [label=<
_n_A_data_n__builtin_multivector_IndexType8 [label=<
<table border="0" cellborder="0" cellspacing="1" cellpadding="1" color="#516D7B">
<tr>
<td bgcolor="#257FAD">
<b><font color="#EBF8FF">IndexType8</font></b>
</td>
</tr>
<tr>
<td bgcolor="#EBF8FF" port="port__n_A_data__builtin_multivector_IndexType8_value">
<td bgcolor="#EBF8FF" port="port__n_A_data_n__builtin_multivector_IndexType8_value">
<b><font color="#516D7B">value</font></b>:<font color="#568C3B">u64</font>:<font color="#D22D72">8</font>
</td>
</tr>
Expand Down Expand Up @@ -71,15 +71,15 @@ subgraph cluster__n_A_optional_data
fillcolor="#C4E6F8";


_n_A_optional_data__builtin_multivector_IndexType16 [label=<
_n_A_optional_data_n__builtin_multivector_IndexType16 [label=<
<table border="0" cellborder="0" cellspacing="1" cellpadding="1" color="#516D7B">
<tr>
<td bgcolor="#257FAD">
<b><font color="#EBF8FF">IndexType16</font></b>
</td>
</tr>
<tr>
<td bgcolor="#EBF8FF" port="port__n_A_optional_data__builtin_multivector_IndexType16_value">
<td bgcolor="#EBF8FF" port="port__n_A_optional_data_n__builtin_multivector_IndexType16_value">
<b><font color="#516D7B">value</font></b>:<font color="#568C3B">u64</font>:<font color="#D22D72">16</font>
</td>
</tr>
Expand Down Expand Up @@ -124,15 +124,15 @@ subgraph cluster__n_A_data_u64_index
fillcolor="#C4E6F8";


_n_A_data_u64_index__builtin_multivector_IndexType64 [label=<
_n_A_data_u64_index_n__builtin_multivector_IndexType64 [label=<
<table border="0" cellborder="0" cellspacing="1" cellpadding="1" color="#516D7B">
<tr>
<td bgcolor="#257FAD">
<b><font color="#EBF8FF">IndexType64</font></b>
</td>
</tr>
<tr>
<td bgcolor="#EBF8FF" port="port__n_A_data_u64_index__builtin_multivector_IndexType64_value">
<td bgcolor="#EBF8FF" port="port__n_A_data_u64_index_n__builtin_multivector_IndexType64_value">
<b><font color="#516D7B">value</font></b>:<font color="#568C3B">u64</font>:<font color="#D22D72">64</font>
</td>
</tr>
Expand Down Expand Up @@ -170,15 +170,13 @@ _n_A_data_u64_index_n_T [label=<
}

}
}

subgraph cluster___builtin
subgraph cluster__n__builtin
{
penwidth=0;
fontcolor="#516D7B";
fillcolor="#F7F7F7";
label=<<b>_builtin</b>>
subgraph cluster___builtin_multivector
subgraph cluster__n__builtin_multivector
{
penwidth=0;
fontcolor="#516D7B";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ subgraph cluster__a_A_multi
fillcolor="#C4E6F8";


_a_A_multi__builtin_multivector_IndexType32 [label=<
_a_A_multi_a__builtin_multivector_IndexType32 [label=<
<table border="0" cellborder="0" cellspacing="1" cellpadding="1" color="#516D7B">
<tr>
<td bgcolor="#257FAD">
<b><font color="#EBF8FF">IndexType32</font></b>
</td>
</tr>
<tr>
<td bgcolor="#EBF8FF" port="port__a_A_multi__builtin_multivector_IndexType32_value">
<td bgcolor="#EBF8FF" port="port__a_A_multi_a__builtin_multivector_IndexType32_value">
<b><font color="#516D7B">value</font></b>:<font color="#568C3B">u64</font>:<font color="#D22D72">32</font>
</td>
</tr>
Expand Down Expand Up @@ -166,15 +166,13 @@ _a_A_inner [style=invisible, fixedsize="true", width="0", height="0", label=""];
}

}
}

subgraph cluster___builtin
subgraph cluster__a__builtin
{
penwidth=0;
fontcolor="#516D7B";
fillcolor="#F7F7F7";
label=<<b>_builtin</b>>
subgraph cluster___builtin_multivector
subgraph cluster__a__builtin_multivector
{
penwidth=0;
fontcolor="#516D7B";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ subgraph cluster__n_A_multilist2
fillcolor="#C4E6F8";


_n_A_multilist2__builtin_multivector_IndexType32 [label=<
_n_A_multilist2_n__builtin_multivector_IndexType32 [label=<
<table border="0" cellborder="0" cellspacing="1" cellpadding="1" color="#516D7B">
<tr>
<td bgcolor="#257FAD">
<b><font color="#EBF8FF">IndexType32</font></b>
</td>
</tr>
<tr>
<td bgcolor="#EBF8FF" port="port__n_A_multilist2__builtin_multivector_IndexType32_value">
<td bgcolor="#EBF8FF" port="port__n_A_multilist2_n__builtin_multivector_IndexType32_value">
<b><font color="#516D7B">value</font></b>:<font color="#568C3B">u64</font>:<font color="#D22D72">32</font>
</td>
</tr>
Expand Down Expand Up @@ -117,15 +117,15 @@ subgraph cluster__n_A_multirefs
fillcolor="#C4E6F8";


_n_A_multirefs__builtin_multivector_IndexType32 [label=<
_n_A_multirefs_n__builtin_multivector_IndexType32 [label=<
<table border="0" cellborder="0" cellspacing="1" cellpadding="1" color="#516D7B">
<tr>
<td bgcolor="#257FAD">
<b><font color="#EBF8FF">IndexType32</font></b>
</td>
</tr>
<tr>
<td bgcolor="#EBF8FF" port="port__n_A_multirefs__builtin_multivector_IndexType32_value">
<td bgcolor="#EBF8FF" port="port__n_A_multirefs_n__builtin_multivector_IndexType32_value">
<b><font color="#516D7B">value</font></b>:<font color="#568C3B">u64</font>:<font color="#D22D72">32</font>
</td>
</tr>
Expand Down Expand Up @@ -189,15 +189,15 @@ _n_A_all_lists_n_S [label=<
</tr>
</table>>];

_n_A_all_lists__builtin_multivector_IndexType32 [label=<
_n_A_all_lists_n__builtin_multivector_IndexType32 [label=<
<table border="0" cellborder="0" cellspacing="1" cellpadding="1" color="#516D7B">
<tr>
<td bgcolor="#257FAD">
<b><font color="#EBF8FF">IndexType32</font></b>
</td>
</tr>
<tr>
<td bgcolor="#EBF8FF" port="port__n_A_all_lists__builtin_multivector_IndexType32_value">
<td bgcolor="#EBF8FF" port="port__n_A_all_lists_n__builtin_multivector_IndexType32_value">
<b><font color="#516D7B">value</font></b>:<font color="#568C3B">u64</font>:<font color="#D22D72">32</font>
</td>
</tr>
Expand All @@ -221,15 +221,13 @@ _n_A_all_lists_n_S [label=<
}

}
}

subgraph cluster___builtin
subgraph cluster__n__builtin
{
penwidth=0;
fontcolor="#516D7B";
fillcolor="#F7F7F7";
label=<<b>_builtin</b>>
subgraph cluster___builtin_multivector
subgraph cluster__n__builtin_multivector
{
penwidth=0;
fontcolor="#516D7B";
Expand All @@ -239,6 +237,7 @@ subgraph cluster___builtin_multivector

}

}



Expand All @@ -258,7 +257,7 @@ subgraph cluster___builtin_multivector



_n_A_refs_n_R:port__n_A_refs_n_R_ref2 -> _n_A_multilist2__builtin_multivector_IndexType32 [lhead=cluster__n_A_multilist2];
_n_A_refs_n_R:port__n_A_refs_n_R_ref2 -> _n_A_multilist2_n__builtin_multivector_IndexType32 [lhead=cluster__n_A_multilist2];



Expand Down
Loading

0 comments on commit a4b100c

Please sign in to comment.