Skip to content

Commit d87aa96

Browse files
committed
More work on objects
1 parent 88dbc6d commit d87aa96

File tree

160 files changed

+908
-3342
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+908
-3342
lines changed

Src/FastData.Generator.CPlusPlus.Shared/CPlusPlusCompiler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private bool HasMSVC()
8484

8585
private int CompileMSVC(string src, string dst) =>
8686
RunProcess("cmd.exe", $"""
87-
/c ""{_path}" -arch=x86 && cl.exe "{src}" {(_release ? "/O2 /GL /GS-" : "/O1")} /utf-8 /std:c++20 /DNDEBUG /permissive- /MD /DBENCHMARK_STATIC_DEFINE /I "{_includesPath}" /Fe:"{dst}" "{_libsPath}\benchmark.lib" shlwapi.lib"
87+
/c ""{_path}" -arch=x86 && cl.exe "{src}" {(_release ? "/O2 /GL /GS-" : "/O1")} /utf-8 /std:c++17 /DNDEBUG /permissive- /MD /DBENCHMARK_STATIC_DEFINE /I "{_includesPath}" /Fe:"{dst}" "{_libsPath}\benchmark.lib" shlwapi.lib"
8888
""");
8989

9090
public string Compile(string fileId, string source)

Src/FastData.Generator.CPlusPlus.Tests/FeatureTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ public async Task ObjectSupportTest<T>(TestVector<T> vector)
2525

2626
GeneratorSpec spec = Generate(id => CPlusPlusCodeGenerator.Create(new CPlusPlusCodeGeneratorConfig(id)), vector, values);
2727

28+
string id = $"{nameof(ObjectSupportTest)}-{spec.Identifier}";
29+
2830
await Verify(spec.Source)
29-
.UseFileName(spec.Identifier)
31+
.UseFileName(id)
3032
.UseDirectory("Features")
3133
.DisableDiff();
3234

@@ -51,7 +53,7 @@ int main()
5153
}
5254
""";
5355

54-
string executable = context.Compiler.Compile(spec.Identifier, testSource);
56+
string executable = context.Compiler.Compile(id, testSource);
5557
Assert.Equal(1, RunProcess(executable));
5658
}
5759

Src/FastData.Generator.CPlusPlus.Tests/Features/ArrayStructure_Int32_3.verified.txt renamed to Src/FastData.Generator.CPlusPlus.Tests/Features/ObjectSupportTest-ArrayStructure_Int32_3.verified.txt

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-

2-
struct Person {
3-
const int32_t Age;
4-
const std::u32string_view Name;
5-
const Person* Other;
6-
7-
Person(const int32_t age, const std::u32string_view name, const Person* other) : Age(age), Name(name), Other(other) { }
8-
};
9-
10-
// This file is auto-generated. Do not edit manually.
1+
// This file is auto-generated. Do not edit manually.
112
// Structure: Array
123
#pragma once
134
#include <array>
145
#include <cstdint>
156
#include <limits>
167
#include <string_view>
178

9+
struct Person {
10+
int32_t age;
11+
std::u32string_view name;
12+
const Person* other;
13+
14+
Person(const int32_t age, const std::u32string_view name, const Person* other) : age(age), name(name), other(other) { }
15+
};
1816
class ArrayStructure_Int32_3 final
1917
{
2018
static constexpr std::array<int32_t, 3> keys = {
@@ -35,7 +33,9 @@ public:
3533
}
3634
return false;
3735
}
38-
static std::array<Person*, 3> values;
36+
static inline std::array<Person*, 3> values = {
37+
new Person(1, U"Bob", new Person(4, U"Anna", nullptr)), new Person(2, U"Billy", nullptr), new Person(3, U"Bibi", nullptr)
38+
};
3939

4040
[[nodiscard]]
4141
static bool try_lookup(const int32_t key, const Person*& value) noexcept
@@ -66,10 +66,4 @@ public:
6666
ArrayStructure_Int32_3& operator=(const ArrayStructure_Int32_3&) = delete;
6767
ArrayStructure_Int32_3(ArrayStructure_Int32_3&&) = delete;
6868
ArrayStructure_Int32_3& operator=(ArrayStructure_Int32_3&&) = delete;
69-
};
70-
std::array<Person*, 3> ArrayStructure_Int32_3::values = {
71-
new Person(1, U"Bob", new Person(4, U"Anna", nullptr)),
72-
new Person(2, U"Billy", nullptr),
73-
new Person(3, U"Bibi", nullptr),
74-
75-
};
69+
};

Src/FastData.Generator.CPlusPlus.Tests/Features/BinarySearchStructure_Int32_3.verified.txt renamed to Src/FastData.Generator.CPlusPlus.Tests/Features/ObjectSupportTest-BinarySearchStructure_Int32_3.verified.txt

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-

2-
struct Person {
3-
const int32_t Age;
4-
const std::u32string_view Name;
5-
const Person* Other;
6-
7-
Person(const int32_t age, const std::u32string_view name, const Person* other) : Age(age), Name(name), Other(other) { }
8-
};
9-
10-
// This file is auto-generated. Do not edit manually.
1+
// This file is auto-generated. Do not edit manually.
112
// Structure: BinarySearch
123
#pragma once
134
#include <array>
145
#include <cstdint>
156
#include <limits>
167
#include <string_view>
178

9+
struct Person {
10+
int32_t age;
11+
std::u32string_view name;
12+
const Person* other;
13+
14+
Person(const int32_t age, const std::u32string_view name, const Person* other) : age(age), name(name), other(other) { }
15+
};
1816
class BinarySearchStructure_Int32_3 final
1917
{
2018
static constexpr std::array<int32_t, 3> keys = {
@@ -45,7 +43,9 @@ public:
4543

4644
return false;
4745
}
48-
static std::array<Person*, 3> values;
46+
static inline std::array<Person*, 3> values = {
47+
new Person(1, U"Bob", new Person(4, U"Anna", nullptr)), new Person(2, U"Billy", nullptr), new Person(3, U"Bibi", nullptr)
48+
};
4949

5050
[[nodiscard]]
5151
static bool try_lookup(const int32_t key, const Person*& value) noexcept
@@ -85,10 +85,4 @@ public:
8585
BinarySearchStructure_Int32_3& operator=(const BinarySearchStructure_Int32_3&) = delete;
8686
BinarySearchStructure_Int32_3(BinarySearchStructure_Int32_3&&) = delete;
8787
BinarySearchStructure_Int32_3& operator=(BinarySearchStructure_Int32_3&&) = delete;
88-
};
89-
std::array<Person*, 3> BinarySearchStructure_Int32_3::values = {
90-
new Person(1, U"Bob", new Person(4, U"Anna", nullptr)),
91-
new Person(2, U"Billy", nullptr),
92-
new Person(3, U"Bibi", nullptr),
93-
94-
};
88+
};

Src/FastData.Generator.CPlusPlus.Tests/Features/ConditionalStructure_Int32_3.verified.txt renamed to Src/FastData.Generator.CPlusPlus.Tests/Features/ObjectSupportTest-ConditionalStructure_Int32_3.verified.txt

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-

2-
struct Person {
3-
const int32_t Age;
4-
const std::u32string_view Name;
5-
const Person* Other;
6-
7-
Person(const int32_t age, const std::u32string_view name, const Person* other) : Age(age), Name(name), Other(other) { }
8-
};
9-
10-
// This file is auto-generated. Do not edit manually.
1+
// This file is auto-generated. Do not edit manually.
112
// Structure: Conditional
123
#pragma once
134
#include <array>
145
#include <cstdint>
156
#include <limits>
167
#include <string_view>
178

9+
struct Person {
10+
int32_t age;
11+
std::u32string_view name;
12+
const Person* other;
13+
14+
Person(const int32_t age, const std::u32string_view name, const Person* other) : age(age), name(name), other(other) { }
15+
};
1816
class ConditionalStructure_Int32_3 final
1917
{
2018
public:
@@ -28,7 +26,9 @@ public:
2826

2927
return false;
3028
}
31-
static std::array<Person*, 3> values;
29+
static inline std::array<Person*, 3> values = {
30+
new Person(1, U"Bob", new Person(4, U"Anna", nullptr)), new Person(2, U"Billy", nullptr), new Person(3, U"Bibi", nullptr)
31+
};
3232

3333
[[nodiscard]]
3434
static bool try_lookup(const int32_t key, const Person*& value) noexcept
@@ -66,10 +66,4 @@ public:
6666
ConditionalStructure_Int32_3& operator=(const ConditionalStructure_Int32_3&) = delete;
6767
ConditionalStructure_Int32_3(ConditionalStructure_Int32_3&&) = delete;
6868
ConditionalStructure_Int32_3& operator=(ConditionalStructure_Int32_3&&) = delete;
69-
};
70-
std::array<Person*, 3> ConditionalStructure_Int32_3::values = {
71-
new Person(1, U"Bob", new Person(4, U"Anna", nullptr)),
72-
new Person(2, U"Billy", nullptr),
73-
new Person(3, U"Bibi", nullptr),
74-
75-
};
69+
};

Src/FastData.Generator.CPlusPlus.Tests/Features/HashTablePerfectStructure_Int32_3.verified.txt renamed to Src/FastData.Generator.CPlusPlus.Tests/Features/ObjectSupportTest-HashTablePerfectStructure_Int32_3.verified.txt

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,26 @@
66
#include <limits>
77
#include <string_view>
88

9+
struct Person {
10+
int32_t age;
11+
std::u32string_view name;
12+
const Person* other;
13+
14+
Person(const int32_t age, const std::u32string_view name, const Person* other) : age(age), name(name), other(other) { }
15+
};
916
class HashTablePerfectStructure_Int32_3 final
1017
{
11-
inline static const std::array<int32_t, 3> entries = {
12-
3, 1, 2
18+
struct e
19+
{
20+
int32_t key;
21+
22+
const Person* value;
23+
24+
e(const int32_t key, const Person* value)
25+
: key(key), value(value) {}
26+
};
27+
inline static const std::array<e, 3> entries = {
28+
e(3, new Person(1, U"Bob", new Person(4, U"Anna", nullptr))), e(1, new Person(2, U"Billy", nullptr)), e(2, new Person(3, U"Bibi", nullptr))
1329
};
1430

1531
static constexpr uint64_t get_hash(const int32_t value) noexcept
@@ -26,8 +42,28 @@ public:
2642

2743
const uint64_t hash = get_hash(key);
2844
const size_t index = hash % 3;
45+
const auto& entry = entries[index];
46+
47+
return key == entry.key;
48+
}
49+
[[nodiscard]]
50+
static bool try_lookup(const int32_t key, const Person*& value) noexcept
51+
{
52+
if (key < 1 || key > 3)
53+
return false;
54+
55+
const uint64_t hash = get_hash(key);
56+
const size_t index = hash % 3;
57+
const auto& entry = entries[index];
58+
59+
if (key == entry.key)
60+
{
61+
value = entry.value;
62+
return true;
63+
}
2964

30-
return key == entries[index];
65+
value = nullptr;
66+
return false;
3167
}
3268

3369
static constexpr size_t item_count = 3;

Src/FastData.Generator.CPlusPlus.Tests/Features/HashTableChainStructure_Int32_3.verified.txt renamed to Src/FastData.Generator.CPlusPlus.Tests/Features/ObjectSupportTest-HashTableStructure_Int32_3.verified.txt

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,36 @@
1-

2-
struct Person {
3-
const int32_t Age;
4-
const std::u32string_view Name;
5-
const Person* Other;
6-
7-
Person(const int32_t age, const std::u32string_view name, const Person* other) : Age(age), Name(name), Other(other) { }
8-
};
9-
10-
// This file is auto-generated. Do not edit manually.
11-
// Structure: HashTable (HashTableChain)
1+
// This file is auto-generated. Do not edit manually.
2+
// Structure: HashTable
123
#pragma once
134
#include <array>
145
#include <cstdint>
156
#include <limits>
167
#include <string_view>
178

18-
class HashTableChainStructure_Int32_3 final
9+
struct Person {
10+
int32_t age;
11+
std::u32string_view name;
12+
const Person* other;
13+
14+
Person(const int32_t age, const std::u32string_view name, const Person* other) : age(age), name(name), other(other) { }
15+
};
16+
class HashTableStructure_Int32_3 final
1917
{
2018
struct e
2119
{
22-
23-
int8_t next;
2420
int32_t key;
25-
26-
e(const int8_t next, const int32_t key)
27-
: next(next), key(key) {}
21+
int8_t next;
22+
23+
const Person* value;
24+
e(const int8_t next, const int32_t key, const Person* value)
25+
: next(next), key(key), value(value) {}
2826
};
2927

3028
static constexpr std::array<int8_t, 3> buckets = {
3129
3, 1, 2
3230
};
3331

3432
inline static const std::array<e, 3> entries = {
35-
e(-1, 1), e(-1, 2), e(-1, 3)
33+
e(-1, 1, new Person(1, U"Bob", new Person(4, U"Anna", nullptr))), e(-1, 2, new Person(2, U"Billy", nullptr)), e(-1, 3, new Person(3, U"Bibi", nullptr))
3634
};
3735

3836
static constexpr uint64_t get_hash(const int32_t value) noexcept
@@ -53,18 +51,16 @@ public:
5351

5452
while (i >= 0)
5553
{
56-
const auto& [next, key1] = entries[i];
54+
const auto& entry = entries[i];
5755

58-
if (key1 == key)
56+
if (entry.key == key)
5957
return true;
6058

61-
i = next;
59+
i = entry.next;
6260
}
6361

6462
return false;
6563
}
66-
static std::array<Person*, 3> values;
67-
6864
[[nodiscard]]
6965
static bool try_lookup(const int32_t key, const Person*& value) noexcept
7066
{
@@ -77,12 +73,15 @@ public:
7773

7874
while (i >= 0)
7975
{
80-
const auto& [next, key1] = entries[i];
76+
const auto& entry = entries[i];
8177

82-
if (key1 == key)
78+
if (entry.key == key)
79+
{
80+
value = entry.value;
8381
return true;
82+
}
8483

85-
i = next;
84+
i = entry.next;
8685
}
8786

8887
value = nullptr;
@@ -94,15 +93,9 @@ public:
9493
static constexpr int32_t max_key = 3;
9594

9695
public:
97-
HashTableChainStructure_Int32_3() = delete;
98-
HashTableChainStructure_Int32_3(const HashTableChainStructure_Int32_3&) = delete;
99-
HashTableChainStructure_Int32_3& operator=(const HashTableChainStructure_Int32_3&) = delete;
100-
HashTableChainStructure_Int32_3(HashTableChainStructure_Int32_3&&) = delete;
101-
HashTableChainStructure_Int32_3& operator=(HashTableChainStructure_Int32_3&&) = delete;
102-
};
103-
std::array<Person*, 3> HashTableChainStructure_Int32_3::values = {
104-
new Person(1, U"Bob", new Person(4, U"Anna", nullptr)),
105-
new Person(2, U"Billy", nullptr),
106-
new Person(3, U"Bibi", nullptr),
107-
108-
};
96+
HashTableStructure_Int32_3() = delete;
97+
HashTableStructure_Int32_3(const HashTableStructure_Int32_3&) = delete;
98+
HashTableStructure_Int32_3& operator=(const HashTableStructure_Int32_3&) = delete;
99+
HashTableStructure_Int32_3(HashTableStructure_Int32_3&&) = delete;
100+
HashTableStructure_Int32_3& operator=(HashTableStructure_Int32_3&&) = delete;
101+
};

Src/FastData.Generator.CPlusPlus.Tests/Features/KeyLengthStructure_String_3.verified.txt renamed to Src/FastData.Generator.CPlusPlus.Tests/Features/ObjectSupportTest-KeyLengthStructure_String_3.verified.txt

File renamed without changes.

0 commit comments

Comments
 (0)