Skip to content

feat: support macros#1192

Open
gennaroprota wants to merge 1 commit intocppalliance:developfrom
gennaroprota:feat/support_macros
Open

feat: support macros#1192
gennaroprota wants to merge 1 commit intocppalliance:developfrom
gennaroprota:feat/support_macros

Conversation

@gennaroprota
Copy link
Copy Markdown
Collaborator

@gennaroprota gennaroprota commented Apr 30, 2026

This adds support for preprocessing macros: #define directives are captured via a clang::PPCallbacks subclass and exposed as MacroSymbol instances at the corpus root (macros aren't in any C++ scope, so they sit alongside the global namespace rather than under it).

Doc-comment association: Clang doesn't link comments to macros, so we look up a preceding doc-comment by source location. A comment is attached only when the lines between it and the directive are blank.

Filters apply to macros, too:

  • extract-all: when off, undocumented macros are dropped.
  • exclude-symbols, include-symbols, implementation-defined, see-below: matched against the macro name.
  • File-pattern filters: matched against the directive's source location.

Schema additions: <macro> is a new top-level element in mrdocs.rnc, sibling of <namespace>, with <source> carrying the verbatim definition (modulo a minor normalization).

New output pages: multipage mode now produces macros.{ext} at the output root, listing every macro with a link to its per-symbol page. The global-namespace page gains a "See also: Macros" navigation hint at the bottom (multipage-only) so the new page is discoverable.

Macro @param blocks are validated.

Golden tests also cover the three filter paths (extract-all: false, include-symbols, exclude-symbols).

Closes issue #1127.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 30, 2026

🚧 Danger.js checks for MrDocs are experimental; expect some rough edges while we tune the rules.

✨ Highlights

  • 🧪 New golden tests added

🧾 Changes by Scope

Scope Lines Δ% Lines Δ Lines + Lines - Files Δ Files + Files ~ Files ↔ Files -
🥇 Golden Tests 78% 3800 3800 - 53 53 - - -
🛠️ Source 22% 1087 1062 25 35 6 29 - -
🏗️ Build <1% 13 13 - 1 - 1 - -
Total 100% 4900 4875 25 89 59 30 - -

Legend: Files + (added), Files ~ (modified), Files ↔ (renamed), Files - (removed)

🔝 Top Files

  • test-files/golden-tests/symbols/macro/macros.xml (Golden Tests): 649 lines Δ (+649 / -0)
  • test-files/golden-tests/symbols/macro/macros.html (Golden Tests): 531 lines Δ (+531 / -0)
  • test-files/golden-tests/symbols/macro/macros.adoc (Golden Tests): 397 lines Δ (+397 / -0)

Generated by 🚫 dangerJS against a42ad72

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

❌ Patch coverage is 86.72840% with 43 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.38%. Comparing base (966e652) to head (a42ad72).

Files with missing lines Patch % Lines
src/lib/AST/MacroCollector.cpp 73.84% 5 Missing and 12 partials ⚠️
src/lib/Gen/hbs/HandlebarsGenerator.cpp 66.66% 5 Missing and 6 partials ⚠️
src/lib/AST/ASTVisitor.cpp 89.58% 3 Missing and 7 partials ⚠️
src/lib/Corpus.cpp 90.00% 1 Missing and 1 partial ⚠️
src/lib/Gen/hbs/Builder.cpp 97.50% 0 Missing and 1 partial ⚠️
...rc/lib/Metadata/Finalizers/DocComment/Function.hpp 50.00% 0 Missing and 1 partial ⚠️
...rc/lib/Metadata/Finalizers/DocCommentFinalizer.cpp 97.61% 0 Missing and 1 partial ⚠️

❌ Your patch check has failed because the patch coverage (86.72%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1192      +/-   ##
===========================================
+ Coverage    79.20%   79.38%   +0.18%     
===========================================
  Files          308      311       +3     
  Lines        32332    32644     +312     
  Branches      6493     6568      +75     
===========================================
+ Hits         25607    25914     +307     
+ Misses        4355     4335      -20     
- Partials      2370     2395      +25     
Flag Coverage Δ
bootstrap 81.89% <ø> (ø)
cpp 79.13% <86.72%> (+0.20%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cppalliance-bot
Copy link
Copy Markdown

cppalliance-bot commented Apr 30, 2026

An automated preview of the documentation is available at https://1192.mrdocs.prtest2.cppalliance.org/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2026-05-01 16:15:00 UTC

@gennaroprota gennaroprota force-pushed the feat/support_macros branch 4 times, most recently from 2c90a7c to c1ce891 Compare May 1, 2026 15:24
This adds support for preprocessing macros: `#define` directives are
captured via a `clang::PPCallbacks` subclass and exposed as
`MacroSymbol` instances at the corpus root (macros aren't in any C++
scope, so they sit alongside the global namespace rather than under it).

Doc-comment association: Clang doesn't link comments to macros, so we
look up a preceding doc-comment by source location. A comment is
attached only when the lines between it and the directive are blank.

Filters apply to macros, too:

- `extract-all`: when off, undocumented macros are dropped.
- `exclude-symbols`, `include-symbols`, `implementation-defined`,
  `see-below`: matched against the macro name.
- File-pattern filters: matched against the directive's source location.

Schema additions: `<macro>` is a new top-level element in mrdocs.rnc,
sibling of `<namespace>`, with `<source>` carrying the verbatim
definition (modulo a minor normalization).

New output pages: multipage mode now produces `macros.{ext}` at the
output root, listing every macro with a link to its per-symbol page. The
global-namespace page gains a "See also: Macros" navigation hint at the
bottom (multipage-only) so the new page is discoverable.

Macro `@param` blocks are validated.

Golden tests also cover the three filter paths (`extract-all: false`,
`include-symbols`, `exclude-symbols`).

Closes issue cppalliance#1127.
@gennaroprota gennaroprota force-pushed the feat/support_macros branch from c1ce891 to a42ad72 Compare May 1, 2026 16:00
@alandefreitas
Copy link
Copy Markdown
Collaborator

Thanks for exploring this. This is a complex issue.

This adds support for preprocessing macros: #define directives are captured via a clang::PPCallbacks

Interesting. I thought it would be easier to have a preprocessor step just for macros.

so we look up a preceding doc-comment by source location

This seems extremely problematic because the counterexamples where it doesn't work would be kind of obvious. Clang doesn't even attach comments to anything if there's not close to a symbol, which is probably the case when there's a macro.

My intuition is we can't really implement this feature unless clang wants to attach comments to macros or we implement our own parser (which we also intend to).

Filters apply to macros, too

How do these compare to doxygen? Shouldn't we have some special options for macros? I'm not sure. I assume macros are somewhat special in terms of what's typically hidden or shown, but I haven't thought too much about it.

I think @mizvekov would probably be more qualified to review this issue and PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants