Skip to content

Refresh the list of Mozilla annotation macros in mozcpp - #1270

Draft
marco-c wants to merge 1 commit into
mozcpp-format-macrosfrom
mozcpp-annotation-macros
Draft

marco-c wants to merge 1 commit into
mozcpp-format-macrosfrom
mozcpp-annotation-macros

Conversation

@marco-c

@marco-c marco-c commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1267. Part of #1142.

Stacked on #1269 (both regenerate tree-sitter-mozcpp/src/parser.c and bump tree-sitter-mozcpp to 0.20.7). Only the second commit belongs to this PR; I'll rebase onto master once #1269 lands.

Adds 46 macros to macro_annotation in tree-sitter-mozcpp/grammar.js and sorts the list. These are the object-like macros from mfbt/Attributes.h, mfbt/Types.h, mfbt/MemoryChecking.h, mfbt/ThreadSafety.h, xpcom/base/nscore.h and js/src/jstypes.h that expand to an attribute, __declspec or visibility specifier and were missing; the full list is in #1267. Without them, declarations like these produced ERROR nodes:

MFBT_API void f();
MOZ_RUNINIT static Foo sFoo;
class A { MOZ_KNOWN_LIVE RefPtr<B> mB; };
class NS_NO_VTABLE nsIFoo : public nsISupports {};

Macros that no longer exist in mozilla-central (MOZ_MUST_USE, MOZ_FALLTHROUGH, ...) are kept, so older code still parses. Making the names keywords doesn't break their use in #define, #ifdef or #if defined(...); I checked those with tree-sitter parse.

Two positions still don't parse with any annotation macro, old or new, because the grammar only accepts annotations in storage-class position, after class/struct, and right after a parameter list:

  • after a const method qualifier: const T& get() const MOZ_LIFETIME_BOUND { ... }
  • after a parameter's declarator: void f(const T& aX MOZ_LIFETIME_BOUND);

They'd need changes to the grammar's structure rather than to the list, so I've left them for a follow-up.

Added test_annotation_macros and test_annotation_macros_cpp. All workspace tests pass, including the DeepSpeech/pdf.js/serde snapshot tests, with no snapshot changes.

Add the object-like macros from mfbt, xpcom/base/nscore.h and
js/src/jstypes.h that expand to an attribute, a __declspec or a
visibility specifier and were missing from the list, like MFBT_API,
MOZ_RUNINIT, MOZ_KNOWN_LIVE, MOZ_UNANNOTATED and NS_NO_VTABLE. Without
them, declarations using these macros produced ERROR nodes.

Fixes #1267.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.50%. Comparing base (921a34c) to head (7cb2a37).

Additional details and impacted files
@@                   Coverage Diff                    @@
##           mozcpp-format-macros    #1270      +/-   ##
========================================================
+ Coverage                 90.46%   90.50%   +0.03%     
========================================================
  Files                        62       62              
  Lines                     16462    16527      +65     
========================================================
+ Hits                      14892    14957      +65     
  Misses                     1570     1570              

☔ View full report in Codecov by Harness.
📢 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.

This branch has not been deployed

No deployments
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.

2 participants