|
| 1 | +// |
| 2 | +// Licensed under the Apache License v2.0 with LLVM Exceptions. |
| 3 | +// See https://llvm.org/LICENSE.txt for license information. |
| 4 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 5 | +// |
| 6 | +// Copyright (c) 2026 Gennaro Prota (gennaro.prota@gmail.com) |
| 7 | +// |
| 8 | +// Official repository: https://github.com/cppalliance/mrdocs |
| 9 | +// |
| 10 | + |
| 11 | +#ifndef MRDOCS_API_METADATA_SYMBOL_MACRO_HPP |
| 12 | +#define MRDOCS_API_METADATA_SYMBOL_MACRO_HPP |
| 13 | + |
| 14 | +#include <mrdocs/Metadata/Symbol.hpp> |
| 15 | +#include <mrdocs/Support/Describe.hpp> |
| 16 | +#include <string> |
| 17 | +#include <vector> |
| 18 | + |
| 19 | +namespace mrdocs { |
| 20 | + |
| 21 | +/** Info for preprocessor macros. |
| 22 | +
|
| 23 | + Covers both object-like and function-like macros. |
| 24 | +*/ |
| 25 | +struct MacroSymbol final |
| 26 | + : SymbolCommonBase<SymbolKind::Macro> |
| 27 | +{ |
| 28 | + /** Whether this is a function-like macro. |
| 29 | + */ |
| 30 | + bool IsFunctionLike = false; |
| 31 | + |
| 32 | + /** The names of the macro's parameters. |
| 33 | +
|
| 34 | + Empty for object-like macros. For variadic |
| 35 | + function-like macros, this lists only the |
| 36 | + named parameters; variadicness is indicated |
| 37 | + by @ref IsVariadic. |
| 38 | + */ |
| 39 | + std::vector<std::string> Parameters; |
| 40 | + |
| 41 | + /** Whether the macro takes a variadic argument list. |
| 42 | +
|
| 43 | + True for macros declared with `...`, such as |
| 44 | + `#define LOG(fmt, ...) ...`. |
| 45 | + */ |
| 46 | + bool IsVariadic = false; |
| 47 | + |
| 48 | + /** The full source of the macro definition. |
| 49 | +
|
| 50 | + Captured from the start of the line containing |
| 51 | + the `#define` directive through the end of the |
| 52 | + macro definition, line continuations and all, |
| 53 | + with one normalization: whitespace between `#` |
| 54 | + and `define` (typically used when the macro |
| 55 | + definition is in a `#if`/`#ifdef`/`#ifndef`), |
| 56 | + and the matching leading whitespace on |
| 57 | + continuation lines, is stripped; so the |
| 58 | + definition in the synopsis reads as a |
| 59 | + top-level directive without a surrounding |
| 60 | + `#if`/`#ifdef`/`#ifndef`. |
| 61 | + */ |
| 62 | + std::string Source; |
| 63 | + |
| 64 | + //-------------------------------------------- |
| 65 | + |
| 66 | + /** Create a macro symbol bound to an ID. |
| 67 | + */ |
| 68 | + explicit MacroSymbol(SymbolID const& ID) noexcept |
| 69 | + : SymbolCommonBase(ID) |
| 70 | + { |
| 71 | + } |
| 72 | +}; |
| 73 | + |
| 74 | +MRDOCS_DESCRIBE_STRUCT( |
| 75 | + MacroSymbol, |
| 76 | + (SymbolCommonBase<SymbolKind::Macro>), |
| 77 | + (IsFunctionLike, Parameters, IsVariadic, Source) |
| 78 | +) |
| 79 | + |
| 80 | +} // mrdocs |
| 81 | + |
| 82 | +#endif // MRDOCS_API_METADATA_SYMBOL_MACRO_HPP |
0 commit comments