|
4 | 4 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
5 | 5 | //
|
6 | 6 | // Copyright (c) 2023 Vinnie Falco ([email protected])
|
| 7 | +// Copyright (c) 2023 Krystian Stasiowski ([email protected]) |
7 | 8 | //
|
8 | 9 | // Official repository: https://github.com/cppalliance/mrdox
|
9 | 10 | //
|
|
12 | 13 | #include <atomic>
|
13 | 14 | #include <memory>
|
14 | 15 |
|
| 16 | +#ifdef MRDOX_HAS_CXX20_FORMAT |
| 17 | + #include "Support/Radix.hpp" |
| 18 | + #include <mrdox/Metadata/Access.hpp> |
| 19 | + #include <mrdox/Metadata/Reference.hpp> |
| 20 | + #include <mrdox/Metadata/Symbols.hpp> |
| 21 | + #include <mrdox/Metadata/Info.hpp> |
| 22 | +#endif |
| 23 | + |
15 | 24 | #if defined(_MSC_VER) && ! defined(NDEBUG)
|
16 | 25 |
|
17 | 26 | #define WIN32_LEAN_AND_MEAN
|
@@ -124,3 +133,133 @@ void debugEnableHeapChecking()
|
124 | 133 | } // clang
|
125 | 134 |
|
126 | 135 | #endif
|
| 136 | + |
| 137 | +#ifdef MRDOX_HAS_CXX20_FORMAT |
| 138 | + std::format_context::iterator |
| 139 | + std::formatter<clang::mrdox::SymbolID>:: |
| 140 | + format( |
| 141 | + const clang::mrdox::SymbolID& s, |
| 142 | + std::format_context& ctx) const |
| 143 | + { |
| 144 | + std::string str = s == clang::mrdox::EmptySID ? |
| 145 | + "<empty SymbolID>" : clang::mrdox::toBase64(s); |
| 146 | + return std::formatter<std::string>::format(std::move(str), ctx); |
| 147 | + } |
| 148 | + |
| 149 | + std::format_context::iterator |
| 150 | + std::formatter<clang::mrdox::OptionalSymbolID>:: |
| 151 | + format( |
| 152 | + const clang::mrdox::OptionalSymbolID& s, |
| 153 | + std::format_context& ctx) const |
| 154 | + { |
| 155 | + return std::formatter<clang::mrdox::SymbolID>::format(*s, ctx); |
| 156 | + } |
| 157 | + |
| 158 | + std::format_context::iterator |
| 159 | + std::formatter<clang::mrdox::InfoType>:: |
| 160 | + format( |
| 161 | + clang::mrdox::InfoType t, |
| 162 | + std::format_context& ctx) const |
| 163 | + { |
| 164 | + const char* str = "<unknown InfoType>"; |
| 165 | + switch(t) |
| 166 | + { |
| 167 | + case clang::mrdox::InfoType::IT_default: |
| 168 | + str = "default"; |
| 169 | + break; |
| 170 | + case clang::mrdox::InfoType::IT_namespace: |
| 171 | + str = "namespace"; |
| 172 | + break; |
| 173 | + case clang::mrdox::InfoType::IT_record: |
| 174 | + str = "record"; |
| 175 | + break; |
| 176 | + case clang::mrdox::InfoType::IT_function: |
| 177 | + str = "function"; |
| 178 | + break; |
| 179 | + case clang::mrdox::InfoType::IT_enum: |
| 180 | + str = "enum"; |
| 181 | + break; |
| 182 | + case clang::mrdox::InfoType::IT_typedef: |
| 183 | + str = "typedef"; |
| 184 | + break; |
| 185 | + case clang::mrdox::InfoType::IT_variable: |
| 186 | + str = "variable"; |
| 187 | + break; |
| 188 | + default: |
| 189 | + break; |
| 190 | + } |
| 191 | + return std::formatter<std::string>::format(str, ctx); |
| 192 | + } |
| 193 | + |
| 194 | + std::format_context::iterator |
| 195 | + std::formatter<clang::mrdox::Access>:: |
| 196 | + format( |
| 197 | + clang::mrdox::Access a, |
| 198 | + std::format_context& ctx) const |
| 199 | + { |
| 200 | + const char* str = "<unknown Access>"; |
| 201 | + switch(a) |
| 202 | + { |
| 203 | + case clang::mrdox::Access::Public: |
| 204 | + str = "public"; |
| 205 | + break; |
| 206 | + case clang::mrdox::Access::Protected: |
| 207 | + str = "protected"; |
| 208 | + break; |
| 209 | + case clang::mrdox::Access::Private: |
| 210 | + str = "private"; |
| 211 | + break; |
| 212 | + default: |
| 213 | + break; |
| 214 | + } |
| 215 | + return std::formatter<std::string>::format(str, ctx); |
| 216 | + } |
| 217 | + |
| 218 | + std::format_context::iterator |
| 219 | + std::formatter<clang::mrdox::Reference>:: |
| 220 | + format( |
| 221 | + const clang::mrdox::Reference& r, |
| 222 | + std::format_context& ctx) const |
| 223 | + { |
| 224 | + std::string str = std::format("Reference: type = {}", r.RefType); |
| 225 | + if(! r.Name.empty()) |
| 226 | + str += std::format(", name = '{}'", std::string(r.Name)); |
| 227 | + str += std::format(", ID = {}", r.id); |
| 228 | + return std::formatter<std::string>::format(std::move(str), ctx); |
| 229 | + } |
| 230 | + |
| 231 | + std::format_context::iterator |
| 232 | + std::formatter<clang::mrdox::RefWithAccess>:: |
| 233 | + format( |
| 234 | + const clang::mrdox::RefWithAccess& r, |
| 235 | + std::format_context& ctx) const |
| 236 | + { |
| 237 | + std::string str = std::format("RefWithAccess: access = {}, ID = {}", |
| 238 | + r.access, r.id); |
| 239 | + return std::formatter<std::string>::format(std::move(str), ctx); |
| 240 | + } |
| 241 | + |
| 242 | + std::format_context::iterator |
| 243 | + std::formatter<clang::mrdox::Info>:: |
| 244 | + format( |
| 245 | + const clang::mrdox::Info& i, |
| 246 | + std::format_context& ctx) const |
| 247 | + { |
| 248 | + std::string str = std::format("Info: type = {}", i.IT); |
| 249 | + if(! i.Name.empty()) |
| 250 | + str += std::format(", name = '{}'", i.Name); |
| 251 | + str += std::format(", ID = {}", i.id); |
| 252 | + if(! i.Namespace.empty()) |
| 253 | + { |
| 254 | + std::string namespaces; |
| 255 | + namespaces += i.Namespace[0].Name; |
| 256 | + for(std::size_t idx = 1; idx < i.Namespace.size(); ++idx) |
| 257 | + { |
| 258 | + namespaces += "::"; |
| 259 | + namespaces += i.Namespace[0].Name; |
| 260 | + } |
| 261 | + str += std::format(", namespace = {}", namespaces); |
| 262 | + } |
| 263 | + return std::formatter<std::string>::format(std::move(str), ctx); |
| 264 | + } |
| 265 | +#endif |
0 commit comments