Skip to content

C/C++ macro-defined functions: name from the #define (repo-wide), keep the class qualifier (eternity CONSOLE_* 77/240 misnamed; gzdoom 78 cross-class name collisions) #5563

Closed

Description

@squid-protocol

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:

  1. 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 eternity CONSOLE_* definitions are misnamed. Examples (engine → clang): source/mn_menus.cpp:372 cf_notnet → Handler_mn_episode; source/g_cmd.cpp:213 mouseSensitivity_c → Handler_sens_combined; source/g_cmd.cpp:346 cf_server → Handler_map. Every new family needs another list entry today.
  2. 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 (Clear on 13: FDynArray_I32, FCanvas, DShape2D...; DrawTexture on 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, qualifier cls). Fall back to the current rule when no #define is found (gtest TEST from 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 (cls above), 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 --ci OK; 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

  1. added
    bug
    metrics
    core-engine
    scope:core
    needs:doom-corpus
    on Oct 19, 2026
  2. squid-protocol commented on Oct 19, 2026

    @squid-protocol
    OwnerAuthor

    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 the claim:nyx label.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugclaim:nyxcore-enginemetricsneeds:doom-corpuspriority: mediumscope:core

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions