Skip to content

Commit

Permalink
More unique name: Enum::index,enum_value,string_value -> Enum::__valu…
Browse files Browse the repository at this point in the history
…e__.
  • Loading branch information
Yurii.Blok authored and yurablok committed Jan 3, 2020
1 parent 6065105 commit 365dc59
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 133 deletions.
10 changes: 5 additions & 5 deletions Benchmarks/IndexBuffers/addressbook.ibs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
80 changes: 40 additions & 40 deletions Benchmarks/IndexBuffers/addressbook_generated.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -29,20 +29,20 @@ static const char* to_string(const _ enum_value) {
return nullptr;
}
template <typename string_t>
static _ from_string(const string_t& string_value) {
static _ from_string(const string_t& __value__) {
static const std::unordered_map<string_t, _> 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;
Expand All @@ -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;
Expand Down Expand Up @@ -174,28 +174,28 @@ 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;
}
return nullptr;
}
template <typename string_t>
static _ from_string(const string_t& string_value) {
static _ from_string(const string_t& __value__) {
static const std::unordered_map<string_t, _> 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;
Expand All @@ -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;
Expand Down Expand Up @@ -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";
Expand All @@ -499,21 +499,21 @@ class Employment { // union Employment
return nullptr;
}
template <typename string_t>
static _ from_string(const string_t& string_value) {
static _ from_string(const string_t& __value__) {
static const std::unordered_map<string_t, _> 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;
Expand All @@ -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;
Expand Down Expand Up @@ -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";
Expand All @@ -869,22 +869,22 @@ class Person { // struct Person
return nullptr;
}
template <typename string_t>
static _ from_string(const string_t& string_value) {
static _ from_string(const string_t& __value__) {
static const std::unordered_map<string_t, _> map = {
{ "id", id },
{ "name", name },
{ "email", email },
{ "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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 <typename string_t>
static _ from_string(const string_t& string_value) {
static _ from_string(const string_t& __value__) {
static const std::unordered_map<string_t, _> 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;
Expand All @@ -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;
}
Expand Down
16 changes: 8 additions & 8 deletions Compiler/ibc_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -134,7 +134,7 @@ namespace {
output << writingMeta.spacing << "}" << std::endl;
output << writingMeta.spacing << "template <typename string_t>" << 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<string_t, _> map = {" << std::endl;
for (uint32_t i = 0; i < enumMeta->valuesVec.size(); ++i) {
Expand All @@ -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 << " "
Expand All @@ -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 << " "
Expand All @@ -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;
Expand Down
Loading

0 comments on commit 365dc59

Please sign in to comment.