-
Notifications
You must be signed in to change notification settings - Fork 0
マクロ定義名が識別子として登録される #92
Copy link
Copy link
Open
Labels
Kind/EnhancementImprove existing functionalityImprove existing functionalityModule: LibraryThe library registration domainThe library registration domainPriority/LowThe priority is lowThe priority is lowQuick FixFix is obvious and small in scopeFix is obvious and small in scope
Description
Metadata
Metadata
Assignees
Labels
Kind/EnhancementImprove existing functionalityImprove existing functionalityModule: LibraryThe library registration domainThe library registration domainPriority/LowThe priority is lowThe priority is lowQuick FixFix is obvious and small in scopeFix is obvious and small in scope
現象
src/library/identifiers.rsのcollect_definitions/collect_leafは、宣言ノードのname/declaratorフィールドを型で場合分けせず一律に辿るため、プリプロセッサのマクロ定義 (#define FOO .../#define FOO(x) ...) もそのマクロ名を「定義識別子」としてtags.jsonのfilesに記録してしまう。なぜ無意味な過剰検出と言えるか
detect.rs) は-Eでプリプロセスした後の、<file>由来の行だけを見る。オブジェクト形式マクロ (#define FOO 42) はトークンが現れた時点で必ず展開されるため、FOOという生の識別子がユーザーコード側に残ることはない。#define REP(i, n) ...) も同様に、REP(...)の形で呼び出せば展開される。「間接的にリネームして(を伴わず参照すれば展開を逃れるのでは」という仮説も検証したが、プリプロセッサの再走査 (rescanning) により#define MYREP REP経由でも最終的にREP(として再展開されるため成立しない。影響
過剰検出自体は risundle の「取りこぼしより過剰検出を優先する」設計方針の範囲内であり、正しさには影響しない (
architecture.mdの「tree-shaking は過剰検出側に倒す」参照)。実害は次の 2 点のみ:tags.jsonのfilesにマクロ名が無駄に混ざり、レコードが肥大化する。risundle library show <id> -vの出力がマクロ名で埋まり、実際の型・関数名を確認する際のノイズになる。原因: tree-sitter-cpp がプリプロセッサ指令に宣言と同じフィールド名を使っている
tree-sitter-cppのnode-types.jsonを確認すると:プリプロセッサのマクロ定義ノードが、C++ の宣言ノードと同じ
nameフィールド名を使っている。risundle 側が「宣言ノードはname/declaratorを持つ」という規約に一律で乗っかっているのは正当だが、C++ の宣言とは別の文法層であるプリプロセッサ指令にまで同じフィールド名を流用しているのは tree-sitter-cpp の設計であり、risundle の走査ロジックが雑というわけではない。提案
risundle にはすでに
SKIP_DESCENT(降りても C++ の定義が得られないノードを除外する既存のリスト。compound_statement等) がある。preproc_defとpreproc_function_defをこのリストに加えるだけで解決できる。これは「単純さを崩す特別扱いの追加」ではなく、「そもそも C++ の宣言ではないものを対象外にする、既存機構の本来の適用範囲に収める」変更であり、新しい分岐ロジックは増えない。🤖 Generated with Claude Code