MCPcopy Create free account
hub / github.com/chronoxor/FastBinaryEncoding / GenerateEnum

Method GenerateEnum

source/generator_kotlin.cpp:4748–4894  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4746}
4747
4748void GeneratorKotlin::GenerateEnum(const std::shared_ptr<Package>& p, const std::shared_ptr<EnumType>& e, const CppCommon::Path& path)
4749{
4750 std::string enum_name = *e->name + "Enum";
4751
4752 // Generate the output file
4753 CppCommon::Path output = path / (enum_name + ".kt");
4754 WriteBegin();
4755
4756 // Generate enum header
4757 GenerateHeader(CppCommon::Path(_input).filename().string());
4758 GenerateImports(p);
4759
4760 std::string enum_type = (e->base && !e->base->empty()) ? *e->base : "int32";
4761 std::string enum_base_type = ConvertEnumType(enum_type);
4762 std::string enum_mapping_type = ConvertEnumBase(enum_type);
4763 std::string enum_to = ConvertEnumTo(enum_type);
4764
4765 // Generate enum body
4766 WriteLine();
4767 WriteLineIndent("@Suppress(\"EnumEntryName\", \"MemberVisibilityCanBePrivate\", \"RemoveRedundantCallsOfConversionMethods\")");
4768 WriteLineIndent("enum class " + enum_name);
4769 WriteLineIndent("{");
4770 Indent(1);
4771 if (e->body)
4772 {
4773 int index = 0;
4774 bool first = true;
4775 std::string last = ConvertEnumConstant(enum_type, enum_type, "0", false);
4776 for (const auto& value : e->body->values)
4777 {
4778 WriteIndent(std::string(first ? "" : ", ") + *value->name + "(");
4779 if (value->value)
4780 {
4781 if (value->value->constant && !value->value->constant->empty())
4782 {
4783 index = 0;
4784 last = ConvertEnumConstant(enum_type, enum_type, *value->value->constant, false);
4785 Write(last + " + " + std::to_string(index++) + (IsUnsignedType(enum_type) ? "u" : ""));
4786 }
4787 else if (value->value->reference && !value->value->reference->empty())
4788 {
4789 index = 0;
4790 last = ConvertEnumConstant(enum_type, "", *value->value->reference, false);
4791 Write(last);
4792 }
4793 }
4794 else
4795 Write(last + " + " + std::to_string(index++) + (IsUnsignedType(enum_type) ? "u" : ""));
4796 WriteLine(")");
4797 first = false;
4798 }
4799 WriteLineIndent(";");
4800 WriteLine();
4801 }
4802
4803 // Generate enum value
4804 WriteLineIndent("var raw: " + enum_mapping_type + " = " + ConvertEnumConstant(enum_type, enum_type, "0", false));
4805 Indent(1);

Callers

nothing calls this directly

Calls 2

stringMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected