diff --git a/Benchmarks/IndexBuffers/addressbook.ibs b/Benchmarks/IndexBuffers/addressbook.ibs index bb0282f..11c507c 100644 --- a/Benchmarks/IndexBuffers/addressbook.ibs +++ b/Benchmarks/IndexBuffers/addressbook.ibs @@ -6,21 +6,21 @@ enum PhoneNumberType: uint16 { work } struct PhoneNumber: uint16 { - bytes number + bytes number[] PhoneNumberType type } union Employment: uint16 { uint8 unemployed - bytes employer - bytes school + bytes employer[] + bytes school[] uint8 selfEmployed } struct Person: uint16 { uint32 id - bytes name - bytes email + bytes name[] + bytes email[] PhoneNumber phones[] Employment employment } diff --git a/Benchmarks/IndexBuffers/addressbook_generated.hpp b/Benchmarks/IndexBuffers/addressbook_generated.hpp index b54bac0..f48657a 100644 --- a/Benchmarks/IndexBuffers/addressbook_generated.hpp +++ b/Benchmarks/IndexBuffers/addressbook_generated.hpp @@ -19,8 +19,8 @@ enum _ : uint16_t { work = 2, _SPECIAL_ = 3 }; -static const char* to_string(const _ enum_value) { - switch(enum_value) { +static const char* to_string(const _ __value__) { + switch(__value__) { case mobile: return "mobile"; case home: return "home"; case work: return "work"; @@ -29,20 +29,20 @@ static const char* to_string(const _ enum_value) { return nullptr; } template -static _ from_string(const string_t& string_value) { +static _ from_string(const string_t& __value__) { static const std::unordered_map map = { { "mobile", mobile }, { "home", home }, { "work", work } }; - const auto it = map.find(string_value); + const auto it = map.find(__value__); if (it == map.end()) { return _SPECIAL_; } return it->second; } -static _ from_string(const char* string_value) { - return from_string(std::string(string_value)); +static _ from_string(const char* __value__) { + return from_string(std::string(__value__)); } static constexpr _ min() { return mobile; @@ -53,8 +53,8 @@ static constexpr _ max() { static constexpr uint16_t count() { return 3; } -static _ at(const uint16_t index) { - switch (index) { +static _ at(const uint16_t __value__) { + switch (__value__) { case 0: return mobile; case 1: return home; case 2: return work; @@ -174,8 +174,8 @@ class PhoneNumber { // struct PhoneNumber type = 1, _SPECIAL_ = 2 }; - static const char* to_string(const _ enum_value) { - switch(enum_value) { + static const char* to_string(const _ __value__) { + switch(__value__) { case number: return "number"; case type: return "type"; default: break; @@ -183,19 +183,19 @@ class PhoneNumber { // struct PhoneNumber return nullptr; } template - static _ from_string(const string_t& string_value) { + static _ from_string(const string_t& __value__) { static const std::unordered_map map = { { "number", number }, { "type", type } }; - const auto it = map.find(string_value); + const auto it = map.find(__value__); if (it == map.end()) { return _SPECIAL_; } return it->second; } - static _ from_string(const char* string_value) { - return from_string(std::string(string_value)); + static _ from_string(const char* __value__) { + return from_string(std::string(__value__)); } static constexpr _ min() { return number; @@ -206,8 +206,8 @@ class PhoneNumber { // struct PhoneNumber static constexpr uint16_t count() { return 2; } - static _ at(const uint16_t index) { - switch (index) { + static _ at(const uint16_t __value__) { + switch (__value__) { case 0: return number; case 1: return type; default: break; @@ -488,8 +488,8 @@ class Employment { // union Employment selfEmployed = 3, _SPECIAL_ = 4 }; - static const char* to_string(const _ enum_value) { - switch(enum_value) { + static const char* to_string(const _ __value__) { + switch(__value__) { case unemployed: return "unemployed"; case employer: return "employer"; case school: return "school"; @@ -499,21 +499,21 @@ class Employment { // union Employment return nullptr; } template - static _ from_string(const string_t& string_value) { + static _ from_string(const string_t& __value__) { static const std::unordered_map map = { { "unemployed", unemployed }, { "employer", employer }, { "school", school }, { "selfEmployed", selfEmployed } }; - const auto it = map.find(string_value); + const auto it = map.find(__value__); if (it == map.end()) { return _SPECIAL_; } return it->second; } - static _ from_string(const char* string_value) { - return from_string(std::string(string_value)); + static _ from_string(const char* __value__) { + return from_string(std::string(__value__)); } static constexpr _ min() { return unemployed; @@ -524,8 +524,8 @@ class Employment { // union Employment static constexpr uint16_t count() { return 4; } - static _ at(const uint16_t index) { - switch (index) { + static _ at(const uint16_t __value__) { + switch (__value__) { case 0: return unemployed; case 1: return employer; case 2: return school; @@ -857,8 +857,8 @@ class Person { // struct Person employment = 4, _SPECIAL_ = 5 }; - static const char* to_string(const _ enum_value) { - switch(enum_value) { + static const char* to_string(const _ __value__) { + switch(__value__) { case id: return "id"; case name: return "name"; case email: return "email"; @@ -869,7 +869,7 @@ class Person { // struct Person return nullptr; } template - static _ from_string(const string_t& string_value) { + static _ from_string(const string_t& __value__) { static const std::unordered_map map = { { "id", id }, { "name", name }, @@ -877,14 +877,14 @@ class Person { // struct Person { "phones", phones }, { "employment", employment } }; - const auto it = map.find(string_value); + const auto it = map.find(__value__); if (it == map.end()) { return _SPECIAL_; } return it->second; } - static _ from_string(const char* string_value) { - return from_string(std::string(string_value)); + static _ from_string(const char* __value__) { + return from_string(std::string(__value__)); } static constexpr _ min() { return id; @@ -895,8 +895,8 @@ class Person { // struct Person static constexpr uint16_t count() { return 5; } - static _ at(const uint16_t index) { - switch (index) { + static _ at(const uint16_t __value__) { + switch (__value__) { case 0: return id; case 1: return name; case 2: return email; @@ -1262,26 +1262,26 @@ class AddressBook { // struct AddressBook people = 0, _SPECIAL_ = 1 }; - static const char* to_string(const _ enum_value) { - switch(enum_value) { + static const char* to_string(const _ __value__) { + switch(__value__) { case people: return "people"; default: break; } return nullptr; } template - static _ from_string(const string_t& string_value) { + static _ from_string(const string_t& __value__) { static const std::unordered_map map = { { "people", people } }; - const auto it = map.find(string_value); + const auto it = map.find(__value__); if (it == map.end()) { return _SPECIAL_; } return it->second; } - static _ from_string(const char* string_value) { - return from_string(std::string(string_value)); + static _ from_string(const char* __value__) { + return from_string(std::string(__value__)); } static constexpr _ min() { return people; @@ -1292,8 +1292,8 @@ class AddressBook { // struct AddressBook static constexpr uint16_t count() { return 1; } - static _ at(const uint16_t index) { - switch (index) { + static _ at(const uint16_t __value__) { + switch (__value__) { case 0: return people; default: break; } diff --git a/Compiler/ibc_cpp.cpp b/Compiler/ibc_cpp.cpp index 7a252a7..e8bb9c6 100644 --- a/Compiler/ibc_cpp.cpp +++ b/Compiler/ibc_cpp.cpp @@ -122,8 +122,8 @@ namespace { << enumMeta->valuesVec.back().second + 1 << std::endl; output << writingMeta.spacing << "};" << std::endl; output << writingMeta.spacing - << "static const char* to_string(const _ enum_value) {" << std::endl; - output << writingMeta.spacing << " " << "switch(enum_value) {" << std::endl; + << "static const char* to_string(const _ __value__) {" << std::endl; + output << writingMeta.spacing << " " << "switch(__value__) {" << std::endl; for (const auto& value : enumMeta->valuesVec) { output << writingMeta.spacing << " " << "case " << value.first << ": return \"" << value.first << "\";" << std::endl; @@ -134,7 +134,7 @@ namespace { output << writingMeta.spacing << "}" << std::endl; output << writingMeta.spacing << "template " << std::endl; output << writingMeta.spacing - << "static _ from_string(const string_t& string_value) {" << std::endl; + << "static _ from_string(const string_t& __value__) {" << std::endl; output << writingMeta.spacing << " " << "static const std::unordered_map map = {" << std::endl; for (uint32_t i = 0; i < enumMeta->valuesVec.size(); ++i) { @@ -148,7 +148,7 @@ namespace { } output << writingMeta.spacing << " " << "};" << std::endl; output << writingMeta.spacing << " " - << "const auto it = map.find(string_value);" << std::endl; + << "const auto it = map.find(__value__);" << std::endl; output << writingMeta.spacing << " " << "if (it == map.end()) {" << std::endl; output << writingMeta.spacing << " " @@ -157,9 +157,9 @@ namespace { output << writingMeta.spacing << " " << "return it->second;" << std::endl; output << writingMeta.spacing << "}" << std::endl; - output << writingMeta.spacing << "static _ from_string(const char* string_value) {" << std::endl; + output << writingMeta.spacing << "static _ from_string(const char* __value__) {" << std::endl; output << writingMeta.spacing << " " << - "return from_string(std::string(string_value));" << std::endl; + "return from_string(std::string(__value__));" << std::endl; output << writingMeta.spacing << "}" << std::endl; output << writingMeta.spacing << "static constexpr _ min() {" << std::endl; output << writingMeta.spacing << " " @@ -175,8 +175,8 @@ namespace { << enumMeta->valuesVec.size() << ";" << std::endl; output << writingMeta.spacing << "}" << std::endl; output << writingMeta.spacing << "static _ at(const " - << kw_to_domain_specific(enumMeta->type) << " index) {" << std::endl; - output << writingMeta.spacing << " " << "switch (index) {" << std::endl; + << kw_to_domain_specific(enumMeta->type) << " __value__) {" << std::endl; + output << writingMeta.spacing << " " << "switch (__value__) {" << std::endl; for (uint32_t i = 0; i < enumMeta->valuesVec.size(); ++i) { output << writingMeta.spacing << " " << "case " << i << ": return " << enumMeta->valuesVec[i].first << ";" << std::endl; diff --git a/Tests/additional_generated.hpp b/Tests/additional_generated.hpp index 400104f..86c625f 100644 --- a/Tests/additional_generated.hpp +++ b/Tests/additional_generated.hpp @@ -125,8 +125,8 @@ class SomeType { // struct SomeType def = 1, _SPECIAL_ = 2 }; - static const char* to_string(const _ enum_value) { - switch(enum_value) { + static const char* to_string(const _ __value__) { + switch(__value__) { case var: return "var"; case def: return "def"; default: break; @@ -134,19 +134,19 @@ class SomeType { // struct SomeType return nullptr; } template - static _ from_string(const string_t& string_value) { + static _ from_string(const string_t& __value__) { static const std::unordered_map map = { { "var", var }, { "def", def } }; - const auto it = map.find(string_value); + const auto it = map.find(__value__); if (it == map.end()) { return _SPECIAL_; } return it->second; } - static _ from_string(const char* string_value) { - return from_string(std::string(string_value)); + static _ from_string(const char* __value__) { + return from_string(std::string(__value__)); } static constexpr _ min() { return var; @@ -157,8 +157,8 @@ class SomeType { // struct SomeType static constexpr uint32_t count() { return 2; } - static _ at(const uint32_t index) { - switch (index) { + static _ at(const uint32_t __value__) { + switch (__value__) { case 0: return var; case 1: return def; default: break; @@ -309,8 +309,8 @@ enum _ : uint32_t { three = 4, _SPECIAL_ = 5 }; -static const char* to_string(const _ enum_value) { - switch(enum_value) { +static const char* to_string(const _ __value__) { + switch(__value__) { case one: return "one"; case two: return "two"; case three: return "three"; @@ -319,20 +319,20 @@ static const char* to_string(const _ enum_value) { return nullptr; } template -static _ from_string(const string_t& string_value) { +static _ from_string(const string_t& __value__) { static const std::unordered_map map = { { "one", one }, { "two", two }, { "three", three } }; - const auto it = map.find(string_value); + const auto it = map.find(__value__); if (it == map.end()) { return _SPECIAL_; } return it->second; } -static _ from_string(const char* string_value) { - return from_string(std::string(string_value)); +static _ from_string(const char* __value__) { + return from_string(std::string(__value__)); } static constexpr _ min() { return one; @@ -343,8 +343,8 @@ static constexpr _ max() { static constexpr uint32_t count() { return 3; } -static _ at(const uint32_t index) { - switch (index) { +static _ at(const uint32_t __value__) { + switch (__value__) { case 0: return one; case 1: return two; case 2: return three; diff --git a/Tests/debug_/debug_generated.hpp b/Tests/debug_/debug_generated.hpp index 0c3e0b0..ba48ef4 100644 --- a/Tests/debug_/debug_generated.hpp +++ b/Tests/debug_/debug_generated.hpp @@ -18,8 +18,8 @@ enum _ : uint32_t { value2 = 1, _SPECIAL_ = 2 }; -static const char* to_string(const _ enum_value) { - switch(enum_value) { +static const char* to_string(const _ __value__) { + switch(__value__) { case value1: return "value1"; case value2: return "value2"; default: break; @@ -27,19 +27,19 @@ static const char* to_string(const _ enum_value) { return nullptr; } template -static _ from_string(const string_t& string_value) { +static _ from_string(const string_t& __value__) { static const std::unordered_map map = { { "value1", value1 }, { "value2", value2 } }; - const auto it = map.find(string_value); + const auto it = map.find(__value__); if (it == map.end()) { return _SPECIAL_; } return it->second; } -static _ from_string(const char* string_value) { - return from_string(std::string(string_value)); +static _ from_string(const char* __value__) { + return from_string(std::string(__value__)); } static constexpr _ min() { return value1; @@ -50,8 +50,8 @@ static constexpr _ max() { static constexpr uint32_t count() { return 2; } -static _ at(const uint32_t index) { - switch (index) { +static _ at(const uint32_t __value__) { + switch (__value__) { case 0: return value1; case 1: return value2; default: break; @@ -171,26 +171,26 @@ class DebugStruct { // struct DebugStruct field1 = 0, _SPECIAL_ = 1 }; - static const char* to_string(const _ enum_value) { - switch(enum_value) { + static const char* to_string(const _ __value__) { + switch(__value__) { case field1: return "field1"; default: break; } return nullptr; } template - static _ from_string(const string_t& string_value) { + static _ from_string(const string_t& __value__) { static const std::unordered_map map = { { "field1", field1 } }; - const auto it = map.find(string_value); + const auto it = map.find(__value__); if (it == map.end()) { return _SPECIAL_; } return it->second; } - static _ from_string(const char* string_value) { - return from_string(std::string(string_value)); + static _ from_string(const char* __value__) { + return from_string(std::string(__value__)); } static constexpr _ min() { return field1; @@ -201,8 +201,8 @@ class DebugStruct { // struct DebugStruct static constexpr uint32_t count() { return 1; } - static _ at(const uint32_t index) { - switch (index) { + static _ at(const uint32_t __value__) { + switch (__value__) { case 0: return field1; default: break; } diff --git a/Tests/schema_generated.hpp b/Tests/schema_generated.hpp index a435e99..1f033fe 100644 --- a/Tests/schema_generated.hpp +++ b/Tests/schema_generated.hpp @@ -21,8 +21,8 @@ enum _ : uint8_t { BLUE = 4, _SPECIAL_ = 5 }; -static const char* to_string(const _ enum_value) { - switch(enum_value) { +static const char* to_string(const _ __value__) { + switch(__value__) { case RED: return "RED"; case GREEN: return "GREEN"; case BLUE: return "BLUE"; @@ -31,20 +31,20 @@ static const char* to_string(const _ enum_value) { return nullptr; } template -static _ from_string(const string_t& string_value) { +static _ from_string(const string_t& __value__) { static const std::unordered_map map = { { "RED", RED }, { "GREEN", GREEN }, { "BLUE", BLUE } }; - const auto it = map.find(string_value); + const auto it = map.find(__value__); if (it == map.end()) { return _SPECIAL_; } return it->second; } -static _ from_string(const char* string_value) { - return from_string(std::string(string_value)); +static _ from_string(const char* __value__) { + return from_string(std::string(__value__)); } static constexpr _ min() { return RED; @@ -55,8 +55,8 @@ static constexpr _ max() { static constexpr uint8_t count() { return 3; } -static _ at(const uint8_t index) { - switch (index) { +static _ at(const uint8_t __value__) { + switch (__value__) { case 0: return RED; case 1: return GREEN; case 2: return BLUE; @@ -185,8 +185,8 @@ class ScalarTypes { // struct ScalarTypes f = 5, _SPECIAL_ = 6 }; - static const char* to_string(const _ enum_value) { - switch(enum_value) { + static const char* to_string(const _ __value__) { + switch(__value__) { case a: return "a"; case b: return "b"; case c: return "c"; @@ -198,7 +198,7 @@ class ScalarTypes { // struct ScalarTypes return nullptr; } template - static _ from_string(const string_t& string_value) { + static _ from_string(const string_t& __value__) { static const std::unordered_map map = { { "a", a }, { "b", b }, @@ -207,14 +207,14 @@ class ScalarTypes { // struct ScalarTypes { "e", e }, { "f", f } }; - const auto it = map.find(string_value); + const auto it = map.find(__value__); if (it == map.end()) { return _SPECIAL_; } return it->second; } - static _ from_string(const char* string_value) { - return from_string(std::string(string_value)); + static _ from_string(const char* __value__) { + return from_string(std::string(__value__)); } static constexpr _ min() { return a; @@ -225,8 +225,8 @@ class ScalarTypes { // struct ScalarTypes static constexpr uint8_t count() { return 6; } - static _ at(const uint8_t index) { - switch (index) { + static _ at(const uint8_t __value__) { + switch (__value__) { case 0: return a; case 1: return b; case 2: return c; @@ -557,8 +557,8 @@ class Vec3f { // struct Vec3f z = 2, _SPECIAL_ = 3 }; - static const char* to_string(const _ enum_value) { - switch(enum_value) { + static const char* to_string(const _ __value__) { + switch(__value__) { case x: return "x"; case y: return "y"; case z: return "z"; @@ -567,20 +567,20 @@ class Vec3f { // struct Vec3f return nullptr; } template - static _ from_string(const string_t& string_value) { + static _ from_string(const string_t& __value__) { static const std::unordered_map map = { { "x", x }, { "y", y }, { "z", z } }; - const auto it = map.find(string_value); + const auto it = map.find(__value__); if (it == map.end()) { return _SPECIAL_; } return it->second; } - static _ from_string(const char* string_value) { - return from_string(std::string(string_value)); + static _ from_string(const char* __value__) { + return from_string(std::string(__value__)); } static constexpr _ min() { return x; @@ -591,8 +591,8 @@ class Vec3f { // struct Vec3f static constexpr uint32_t count() { return 3; } - static _ at(const uint32_t index) { - switch (index) { + static _ at(const uint32_t __value__) { + switch (__value__) { case 0: return x; case 1: return y; case 2: return z; @@ -867,8 +867,8 @@ class Arrays { // struct Arrays v = 3, _SPECIAL_ = 4 }; - static const char* to_string(const _ enum_value) { - switch(enum_value) { + static const char* to_string(const _ __value__) { + switch(__value__) { case f: return "f"; case b: return "b"; case m: return "m"; @@ -878,21 +878,21 @@ class Arrays { // struct Arrays return nullptr; } template - static _ from_string(const string_t& string_value) { + static _ from_string(const string_t& __value__) { static const std::unordered_map map = { { "f", f }, { "b", b }, { "m", m }, { "v", v } }; - const auto it = map.find(string_value); + const auto it = map.find(__value__); if (it == map.end()) { return _SPECIAL_; } return it->second; } - static _ from_string(const char* string_value) { - return from_string(std::string(string_value)); + static _ from_string(const char* __value__) { + return from_string(std::string(__value__)); } static constexpr _ min() { return f; @@ -903,8 +903,8 @@ class Arrays { // struct Arrays static constexpr uint16_t count() { return 4; } - static _ at(const uint16_t index) { - switch (index) { + static _ at(const uint16_t __value__) { + switch (__value__) { case 0: return f; case 1: return b; case 2: return m; @@ -1242,8 +1242,8 @@ class Variant { // union Variant arr = 2, _SPECIAL_ = 3 }; - static const char* to_string(const _ enum_value) { - switch(enum_value) { + static const char* to_string(const _ __value__) { + switch(__value__) { case color: return "color"; case data: return "data"; case arr: return "arr"; @@ -1252,20 +1252,20 @@ class Variant { // union Variant return nullptr; } template - static _ from_string(const string_t& string_value) { + static _ from_string(const string_t& __value__) { static const std::unordered_map map = { { "color", color }, { "data", data }, { "arr", arr } }; - const auto it = map.find(string_value); + const auto it = map.find(__value__); if (it == map.end()) { return _SPECIAL_; } return it->second; } - static _ from_string(const char* string_value) { - return from_string(std::string(string_value)); + static _ from_string(const char* __value__) { + return from_string(std::string(__value__)); } static constexpr _ min() { return color; @@ -1276,8 +1276,8 @@ class Variant { // union Variant static constexpr uint8_t count() { return 3; } - static _ at(const uint8_t index) { - switch (index) { + static _ at(const uint8_t __value__) { + switch (__value__) { case 0: return color; case 1: return data; case 2: return arr; @@ -1568,8 +1568,8 @@ class AnotherOne { // struct AnotherOne someData = 4, _SPECIAL_ = 5 }; - static const char* to_string(const _ enum_value) { - switch(enum_value) { + static const char* to_string(const _ __value__) { + switch(__value__) { case string: return "string"; case variant: return "variant"; case colorChannels: return "colorChannels"; @@ -1580,7 +1580,7 @@ class AnotherOne { // struct AnotherOne return nullptr; } template - static _ from_string(const string_t& string_value) { + static _ from_string(const string_t& __value__) { static const std::unordered_map map = { { "string", string }, { "variant", variant }, @@ -1588,14 +1588,14 @@ class AnotherOne { // struct AnotherOne { "colorMask", colorMask }, { "someData", someData } }; - const auto it = map.find(string_value); + const auto it = map.find(__value__); if (it == map.end()) { return _SPECIAL_; } return it->second; } - static _ from_string(const char* string_value) { - return from_string(std::string(string_value)); + static _ from_string(const char* __value__) { + return from_string(std::string(__value__)); } static constexpr _ min() { return string; @@ -1606,8 +1606,8 @@ class AnotherOne { // struct AnotherOne static constexpr uint32_t count() { return 5; } - static _ at(const uint32_t index) { - switch (index) { + static _ at(const uint32_t __value__) { + switch (__value__) { case 0: return string; case 1: return variant; case 2: return colorChannels;