Skip to content

Commit 8a4a53c

Browse files
committed
Don't declare unused names or values for enums
1 parent a929795 commit 8a4a53c

File tree

4 files changed

+102
-112
lines changed

4 files changed

+102
-112
lines changed

samples/client/multiple/MultipleQueriesClient.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,6 @@ const peg::ast& GetRequestObject() noexcept
121121
return s_request;
122122
}
123123

124-
static const std::array<std::string_view, 4> s_namesTaskState = {
125-
R"gql(New)gql"sv,
126-
R"gql(Started)gql"sv,
127-
R"gql(Complete)gql"sv,
128-
R"gql(Unassigned)gql"sv
129-
};
130-
131-
static const std::array<std::pair<std::string_view, TaskState>, 4> s_valuesTaskState = {
132-
std::make_pair(R"gql(New)gql"sv, TaskState::New),
133-
std::make_pair(R"gql(Started)gql"sv, TaskState::Started),
134-
std::make_pair(R"gql(Complete)gql"sv, TaskState::Complete),
135-
std::make_pair(R"gql(Unassigned)gql"sv, TaskState::Unassigned)
136-
};
137-
138124
CompleteTaskInput::CompleteTaskInput(
139125
response::IdType idArg,
140126
std::optional<TaskState> testTaskStateArg,
@@ -530,6 +516,13 @@ Response parseResponse(response::Value&& response)
530516

531517
} // namespace query::UnreadCounts
532518

519+
static const std::array<std::pair<std::string_view, TaskState>, 4> s_valuesTaskState = {
520+
std::make_pair(R"gql(New)gql"sv, TaskState::New),
521+
std::make_pair(R"gql(Started)gql"sv, TaskState::Started),
522+
std::make_pair(R"gql(Complete)gql"sv, TaskState::Complete),
523+
std::make_pair(R"gql(Unassigned)gql"sv, TaskState::Unassigned)
524+
};
525+
533526
template <>
534527
TaskState ModifiedResponse<TaskState>::parse(response::Value&& value)
535528
{
@@ -644,6 +637,13 @@ Response parseResponse(response::Value&& response)
644637

645638
} // namespace query::Miscellaneous
646639

640+
static const std::array<std::string_view, 4> s_namesTaskState = {
641+
R"gql(New)gql"sv,
642+
R"gql(Started)gql"sv,
643+
R"gql(Complete)gql"sv,
644+
R"gql(Unassigned)gql"sv
645+
};
646+
647647
template <>
648648
response::Value ModifiedVariable<TaskState>::serialize(TaskState&& value)
649649
{

samples/client/mutate/MutateClient.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,6 @@ const peg::ast& GetRequestObject() noexcept
5454
return s_request;
5555
}
5656

57-
static const std::array<std::string_view, 4> s_namesTaskState = {
58-
R"gql(New)gql"sv,
59-
R"gql(Started)gql"sv,
60-
R"gql(Complete)gql"sv,
61-
R"gql(Unassigned)gql"sv
62-
};
63-
64-
static const std::array<std::pair<std::string_view, TaskState>, 4> s_valuesTaskState = {
65-
std::make_pair(R"gql(New)gql"sv, TaskState::New),
66-
std::make_pair(R"gql(Started)gql"sv, TaskState::Started),
67-
std::make_pair(R"gql(Complete)gql"sv, TaskState::Complete),
68-
std::make_pair(R"gql(Unassigned)gql"sv, TaskState::Unassigned)
69-
};
70-
7157
CompleteTaskInput::CompleteTaskInput(
7258
response::IdType idArg,
7359
std::optional<TaskState> testTaskStateArg,
@@ -119,6 +105,13 @@ CompleteTaskInput& CompleteTaskInput::operator=(CompleteTaskInput&& other) noexc
119105

120106
using namespace mutate;
121107

108+
static const std::array<std::string_view, 4> s_namesTaskState = {
109+
R"gql(New)gql"sv,
110+
R"gql(Started)gql"sv,
111+
R"gql(Complete)gql"sv,
112+
R"gql(Unassigned)gql"sv
113+
};
114+
122115
template <>
123116
response::Value ModifiedVariable<TaskState>::serialize(TaskState&& value)
124117
{
@@ -142,6 +135,13 @@ response::Value ModifiedVariable<CompleteTaskInput>::serialize(CompleteTaskInput
142135
return result;
143136
}
144137

138+
static const std::array<std::pair<std::string_view, TaskState>, 4> s_valuesTaskState = {
139+
std::make_pair(R"gql(New)gql"sv, TaskState::New),
140+
std::make_pair(R"gql(Started)gql"sv, TaskState::Started),
141+
std::make_pair(R"gql(Complete)gql"sv, TaskState::Complete),
142+
std::make_pair(R"gql(Unassigned)gql"sv, TaskState::Unassigned)
143+
};
144+
145145
template <>
146146
TaskState ModifiedResponse<TaskState>::parse(response::Value&& value)
147147
{

samples/client/query/QueryClient.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,9 @@ const peg::ast& GetRequestObject() noexcept
102102
return s_request;
103103
}
104104

105-
static const std::array<std::string_view, 4> s_namesTaskState = {
106-
R"gql(New)gql"sv,
107-
R"gql(Started)gql"sv,
108-
R"gql(Complete)gql"sv,
109-
R"gql(Unassigned)gql"sv
110-
};
105+
} // namespace query
106+
107+
using namespace query;
111108

112109
static const std::array<std::pair<std::string_view, TaskState>, 4> s_valuesTaskState = {
113110
std::make_pair(R"gql(New)gql"sv, TaskState::New),
@@ -116,10 +113,6 @@ static const std::array<std::pair<std::string_view, TaskState>, 4> s_valuesTaskS
116113
std::make_pair(R"gql(Unassigned)gql"sv, TaskState::Unassigned)
117114
};
118115

119-
} // namespace query
120-
121-
using namespace query;
122-
123116
template <>
124117
TaskState ModifiedResponse<TaskState>::parse(response::Value&& value)
125118
{

src/ClientGenerator.cpp

Lines changed: 71 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -601,75 +601,8 @@ using namespace std::literals;
601601
outputGetRequestImplementation(sourceFile);
602602

603603
const auto& operations = _requestLoader.getOperations();
604-
std::unordered_set<std::string_view> outputEnumNames;
605604
std::unordered_set<std::string_view> outputInputMethods;
606605

607-
for (const auto& operation : operations)
608-
{
609-
for (const auto& enumType : _requestLoader.getReferencedEnums(operation))
610-
{
611-
const auto cppType = _schemaLoader.getCppType(enumType->name());
612-
613-
if (!outputEnumNames.insert(cppType).second)
614-
{
615-
continue;
616-
}
617-
618-
pendingSeparator.reset();
619-
620-
const auto& enumValues = enumType->enumValues();
621-
622-
sourceFile << R"cpp(static const std::array<std::string_view, )cpp" << enumValues.size()
623-
<< R"cpp(> s_names)cpp" << cppType << R"cpp( = {)cpp";
624-
625-
bool firstValue = true;
626-
627-
for (const auto& enumValue : enumValues)
628-
{
629-
if (!firstValue)
630-
{
631-
sourceFile << R"cpp(,)cpp";
632-
}
633-
634-
firstValue = false;
635-
sourceFile << R"cpp(
636-
R"gql()cpp" << enumValue->name()
637-
<< R"cpp()gql"sv)cpp";
638-
pendingSeparator.add();
639-
}
640-
641-
pendingSeparator.reset();
642-
sourceFile << R"cpp(};
643-
644-
static const std::array<std::pair<std::string_view, )cpp"
645-
<< cppType << R"cpp(>, )cpp" << enumValues.size() << R"cpp(> s_values)cpp"
646-
<< cppType << R"cpp( = {)cpp";
647-
648-
firstValue = true;
649-
650-
for (const auto& enumValue : enumValues)
651-
{
652-
if (!firstValue)
653-
{
654-
sourceFile << R"cpp(,)cpp";
655-
}
656-
657-
firstValue = false;
658-
sourceFile << R"cpp(
659-
std::make_pair(R"gql()cpp"
660-
<< enumValue->name() << R"cpp()gql"sv, )cpp" << cppType << R"cpp(::)cpp"
661-
<< SchemaLoader::getSafeCppName(enumValue->name()) << R"cpp())cpp";
662-
pendingSeparator.add();
663-
}
664-
665-
pendingSeparator.reset();
666-
sourceFile << R"cpp(};
667-
)cpp";
668-
669-
pendingSeparator.add();
670-
}
671-
}
672-
673606
for (const auto& operation : operations)
674607
{
675608
for (const auto& inputType : _requestLoader.getReferencedInputTypes(operation))
@@ -808,8 +741,10 @@ using namespace )cpp"
808741

809742
pendingSeparator.add();
810743

744+
std::unordered_set<std::string_view> outputEnumNames;
811745
std::unordered_set<std::string_view> outputModifiedVariableEnum;
812746
std::unordered_set<std::string_view> outputModifiedVariableInput;
747+
std::unordered_set<std::string_view> outputEnumValues;
813748
std::unordered_set<std::string_view> outputModifiedResponseEnum;
814749

815750
for (const auto& operation : operations)
@@ -827,24 +762,52 @@ using namespace )cpp"
827762
continue;
828763
}
829764

765+
if (outputEnumNames.insert(cppType).second)
766+
{
767+
pendingSeparator.reset();
768+
769+
const auto& enumValues = enumType->enumValues();
770+
771+
sourceFile << R"cpp(static const std::array<std::string_view, )cpp"
772+
<< enumValues.size() << R"cpp(> s_names)cpp" << cppType
773+
<< R"cpp( = {)cpp";
774+
775+
bool firstValue = true;
776+
777+
for (const auto& enumValue : enumValues)
778+
{
779+
if (!firstValue)
780+
{
781+
sourceFile << R"cpp(,)cpp";
782+
}
783+
784+
firstValue = false;
785+
sourceFile << R"cpp(
786+
R"gql()cpp" << enumValue->name()
787+
<< R"cpp()gql"sv)cpp";
788+
pendingSeparator.add();
789+
}
790+
791+
pendingSeparator.reset();
792+
sourceFile << R"cpp(};
793+
794+
)cpp";
795+
}
796+
830797
pendingSeparator.reset();
831798

832-
if (!variables.empty())
833-
{
834-
sourceFile << R"cpp(template <>
799+
sourceFile << R"cpp(template <>
835800
response::Value ModifiedVariable<)cpp"
836-
<< cppType << R"cpp(>::serialize()cpp" << cppType << R"cpp(&& value)
801+
<< cppType << R"cpp(>::serialize()cpp" << cppType << R"cpp(&& value)
837802
{
838803
response::Value result { response::Type::EnumValue };
839804
840805
result.set<std::string>(std::string { s_names)cpp"
841-
<< cppType << R"cpp([static_cast<size_t>(value)] });
806+
<< cppType << R"cpp([static_cast<size_t>(value)] });
842807
843808
return result;
844809
}
845810
)cpp";
846-
}
847-
848811
pendingSeparator.add();
849812
}
850813

@@ -900,6 +863,40 @@ response::Value ModifiedVariable<)cpp"
900863
continue;
901864
}
902865

866+
if (outputEnumValues.insert(cppType).second)
867+
{
868+
pendingSeparator.reset();
869+
870+
const auto& enumValues = enumType->enumValues();
871+
872+
sourceFile << R"cpp(static const std::array<std::pair<std::string_view, )cpp"
873+
<< cppType << R"cpp(>, )cpp" << enumValues.size()
874+
<< R"cpp(> s_values)cpp" << cppType << R"cpp( = {)cpp";
875+
876+
bool firstValue = true;
877+
878+
for (const auto& enumValue : enumValues)
879+
{
880+
if (!firstValue)
881+
{
882+
sourceFile << R"cpp(,)cpp";
883+
}
884+
885+
firstValue = false;
886+
sourceFile << R"cpp(
887+
std::make_pair(R"gql()cpp" << enumValue->name()
888+
<< R"cpp()gql"sv, )cpp" << cppType << R"cpp(::)cpp"
889+
<< SchemaLoader::getSafeCppName(enumValue->name()) << R"cpp())cpp";
890+
pendingSeparator.add();
891+
}
892+
893+
pendingSeparator.reset();
894+
sourceFile << R"cpp(};
895+
)cpp";
896+
897+
pendingSeparator.add();
898+
}
899+
903900
pendingSeparator.reset();
904901

905902
sourceFile << R"cpp(template <>

0 commit comments

Comments
 (0)