From 8aa6bccf7987d082244de94cbc1dda0ab8a3cbab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com> Date: Tue, 5 Jul 2022 11:18:17 +0200 Subject: [PATCH] Sort functions and types alphabetically when using getModuleInfo --- src/language/modules/ModuleRepository.cpp | 24 +++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/language/modules/ModuleRepository.cpp b/src/language/modules/ModuleRepository.cpp index 74a8cb2d9..557947aad 100644 --- a/src/language/modules/ModuleRepository.cpp +++ b/src/language/modules/ModuleRepository.cpp @@ -19,6 +19,7 @@ #include <utils/PugsAssert.hpp> #include <algorithm> +#include <set> void ModuleRepository::_subscribe(std::unique_ptr<IModule> m) @@ -219,20 +220,31 @@ ModuleRepository::getModuleInfo(const std::string& module_name) const os << rang::fgB::yellow << "Module '" << rang::fgB::blue << module_name << rang::fgB::yellow << "' provides" << rang::style::reset << '\n'; const auto& builtin_function_map = i_module->second->getNameBuiltinFunctionMap(); - if (builtin_function_map.size() > 0) { + std::map<std::string, std::pair<std::string, std::string>> sorted_builtin_function_map; + for (auto& [mangled_name, function] : builtin_function_map) { + sorted_builtin_function_map[mangled_name] = + std::make_pair(dataTypeName(function->getParameterDataTypes()), dataTypeName(function->getReturnDataType())); + } + Assert(sorted_builtin_function_map.size() == builtin_function_map.size()); + if (sorted_builtin_function_map.size() > 0) { os << " functions\n"; - for (auto& [mangled_name, function] : builtin_function_map) { + for (auto& [mangled_name, domain_to_codomain] : sorted_builtin_function_map) { os << " " << rang::fgB::green << demangleBuiltinFunction(mangled_name) << rang::style::reset << ": "; - os << dataTypeName(function->getParameterDataTypes()); + os << domain_to_codomain.first; os << rang::fgB::yellow << " -> " << rang::style::reset; - os << dataTypeName(function->getReturnDataType()) << '\n'; + os << domain_to_codomain.second << '\n'; } } const auto& builtin_type_map = i_module->second->getNameTypeMap(); - if (builtin_type_map.size() > 0) { + std::set<std::string> sorted_builtin_type_map; + for (auto& [name, descriptor] : builtin_type_map) { + sorted_builtin_type_map.insert(name); + } + Assert(sorted_builtin_type_map.size() == builtin_type_map.size()); + if (sorted_builtin_type_map.size() > 0) { os << " types\n"; - for (auto& [name, descriptor] : builtin_type_map) { + for (auto& name : sorted_builtin_type_map) { os << " " << rang::fgB::green << name << rang::style::reset << '\n'; } } -- GitLab