Repository navigation
Description
Problem
Macro-introduced C/C++ definitions (#5461, slices #5483 + #5545) are now found and measured correctly: against libclang on the 29 most macro-dense files of 8 DOOM ports (engine 61500bb5f), engine and clang agree on a function at 2,154 of 2,195 macro lines, and all 2,154 end on the same line (LOC/complexity/calls are on the right body). Corpus-wide, 6,395 of 6,449 column-0 macro definitions are recorded and named by an argument (round 2: 181).
The name is a lexical guess, not the expansion: the only argument; of several, the second; plus a hand list (C_MACRO_FIRST_ARG_NAMES). Two defects follow:
- Wrong argument picked. eternity
#define CONSOLE_COMMAND(name, flags),CONSOLE_VARIABLE(name, variable, flags),CONSOLE_NETCMD(name, flags, netcmd),CONSOLE_NETVAR: whenever the 2nd argument is an identifier, the engine names the flag or the variable. 77 of 240 eternityCONSOLE_*definitions are misnamed. Examples (engine → clang):source/mn_menus.cpp:372cf_notnet→Handler_mn_episode;source/g_cmd.cpp:213mouseSensitivity_c→Handler_sens_combined;source/g_cmd.cpp:346cf_server→Handler_map. Every new family needs another list entry today. - Qualifier dropped.
DEFINE_ACTION_FUNCTION(AActor, GetZAt)→GetZAt(clang:AF_AActor_GetZAt). In gzdoom, 78 action-function names are shared by more than one class (Clearon 13:FDynArray_I32,FCanvas,DShape2D...;DrawTextureon 3). Name-keyed consumers (call graph, duplicate detection) can merge them. zandronum: 0.
Proposed
- Name from the
#define, repo-wide. Build a per-repo macro table (macro name → parameter list + replacement text) from first-party headers and sources before per-file extraction (today the lookup is same-file only, C/C++: function-defining macros (CCMD, DEFINE_ACTION_FUNCTION, FUNC, TEST) are functions (Part of #5461) #5483 limit, because scan workers are per-file). The function's name is the parameter that is token-pasted into, or is, the declarator identifier of the expanded function (Handler_##name→name;AF_##cls##_##name→name, qualifiercls). Fall back to the current rule when no#defineis found (gtestTESTfrom an absent header, etc.), and keep the hand list only as a fallback. - Keep the qualifier. When another parameter is pasted into the same declarator or names a class (
clsabove), record it (AActor::GetZAt, or a qualifier field), so same-named handlers stay distinct. - Out of scope / document: one invocation expanding to several entities (odamex
BEGIN_COMMAND= class +Run+ registrar) stays one function.
Acceptance
- eternity: 0 misnamed
CONSOLE_*definitions (checked against the first argument / the#define). - gzdoom:
DEFINE_ACTION_FUNCTION*names unique per (class, name); the 78 shared names resolved by qualifier. - No regression elsewhere: goldens zero drift;
tree_sitter_accuracy_audit --lang c/cpp --ciOK; corpus count of named macro definitions ≥ 6,395 / 6,449. - Rescan with the DOOM harness and repeat the libclang comparison (name contained in clang's symbol, per macro family) in the PR body.
Evidence
Method and scripts (local to nyx): macro_audit.py (source ^[A-Z][A-Z0-9_]{2,}\(args\) { vs function_data start lines), clang_macro.py (libclang expansion-location definitions per macro line, same flags as tests/tools/doom_speedrun/doom_clang.py). Scans: DOOM harness work dir scans/61500bb5f/<port>. Clang sample caveat: no build flags, all 29 files had some parse errors; macros expanded where their headers were found; D_CMD (doomsday, 39) and gtest TEST (97) did not expand and are unverified by clang.
Part of #5457. Follow-up to #5461.
🤖 Generated with Claude Code
Activity
squid-protocol commentedon Oct 19, 2026
Claimed by promoter-bot host
nyx, lease renewed 2026-10-19T04:51Z. It lapses after 6 h without a renewal. To take it back, assign someone or remove theclaim:nyxlabel.WIP: read headers via read_source for the repo-wide macro table (Part…
c/cpp: name macro-defined functions from the #define, repo-wide, keep…
calls_out_to: drop calls in dead preprocessor branches (#6770) (#6870)