From 410ca805aa4dfc11dfa9f01bbed7a29e395b5adf Mon Sep 17 00:00:00 2001 From: SirLynix Date: Sat, 6 May 2023 15:48:15 +0200 Subject: [PATCH] DocGen: Store enums --- documentation/generator/src/main.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/documentation/generator/src/main.cpp b/documentation/generator/src/main.cpp index 053e19e67..40b2093ba 100644 --- a/documentation/generator/src/main.cpp +++ b/documentation/generator/src/main.cpp @@ -15,6 +15,7 @@ #include nlohmann::ordered_json buildClass(const std::string& scope, const cppast::cpp_class& classNode); +nlohmann::ordered_json buildEnum(const std::string& scope, const cppast::cpp_enum& enumNode); class simpleCodeGenerator : public cppast::code_generator { @@ -192,6 +193,9 @@ int main() } std::cout << "found " << (enumNode.is_scoped() ? "enum class" : "enum") << " " << prefix() << e.name() << std::endl; + nlohmann::ordered_json enumDoc = buildEnum(prefix(), enumNode); + std::unique_lock lock(jsonMutex); + moduleEntryDoc["enums"].push_back(std::move(enumDoc)); break; } @@ -366,4 +370,22 @@ nlohmann::ordered_json buildClass(const std::string& scope, const cppast::cpp_cl } return classDoc; -} \ No newline at end of file +} + +nlohmann::ordered_json buildEnum(const std::string& scope, const cppast::cpp_enum& enumNode) +{ + nlohmann::ordered_json enumDoc; + enumDoc["name"] = scope + enumNode.name(); + enumDoc["scoped"] = enumNode.is_scoped(); + if (enumNode.has_explicit_type()) + enumDoc["underlying_type"] = cppast::to_string(enumNode.underlying_type()); + + for (const auto& entry : enumNode) + { + auto& valueDoc = enumDoc["values"].emplace_back(); + valueDoc["name"] = entry.name(); + if (const auto& exprOpt = entry.value()) + + return enumDoc; +} +