mirror of
https://github.com/colbymchenry/codegraph.git
synced 2026-10-17 05:07:37 +08:00
fix(c,cpp): a struct, class, union or enum defined in a variable declaration is indexed (#2446)
`struct Foo { … } foo;`, `class Bar { … } bar;` and `static struct { … } SPT;`
outside any function or class body went to the variable extractor, which
skipped the declaration's children, so the type, its methods and its
enumerators were never indexed in either extraction engine.
Both engines now walk such a type before the variables: in C always, and in
C++ when the tree has no errors or the file is walked in brace scopes. This
converges with #2426's walk for erroring C++ files; a C++ file whose braces
don't balance is still left alone, since error recovery can run a class past
its own `}` there. The declaration's function-as-value scan skips the walked
type, which captured its own. An unnamed struct, union or enum takes the name
of the first variable its declaration declares (also inside function bodies,
where it was `<anonymous>`), as `typedef struct { … } Name;` already takes the
typedef name, and the comment above the declaration is the type's docstring.
cDeclaratorIdentifier moves to languages/c-cpp.ts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -178,7 +178,7 @@ type_identifier + ≥2 params + NO other lone-identifier param; gtest
|
||||
recoverMangledCppName (line 406 — only already-mangled names, `Ret (name)`
|
||||
idiom left alone, last token before `(`, primitive/keyword guard);
|
||||
stripCppTemplateArgs (line 157 — depth-counted removal of every balanced
|
||||
`<…>`); cDeclaratorIdentifier (tree-sitter.ts:234 — declarator chain walk,
|
||||
`<…>`); cDeclaratorIdentifier (languages/c-cpp.ts — declarator chain walk,
|
||||
function_declarator → null, 12-hop guard).
|
||||
|
||||
## tree-sitter.ts branches (anchors as of `705e501`)
|
||||
@@ -188,6 +188,7 @@ function_declarator → null, 12-hop guard).
|
||||
| 962 | cpp namespace prefix stack (#1291) | named `namespace_definition` pushes its name (C++17 `a::b` as written) onto the QN prefix while walking children; anonymous falls through bare |
|
||||
| — | cpp brace scopes (erroring trees only) | when the tree has errors, every visitNode takes its namespace prefix from the source's braces, and at declaration level (only class scopes above the file node) its enclosing classes: `languages/cpp-brace-scopes.ts` ↔ `ccpp/brace_scopes.rs`. A class-like node's end is its body's `}`; a class-like `type` of a namespace-level `declaration` is walked as a class. Reachable in the kernel only under `CODEGRAPH_KERNEL_CCPP_ERROR_EXTRACT=1` (every other erroring file defers) — kept parity-true there |
|
||||
| 2795 | C file-scope variables | only when NO function ancestor; iterate declarators; accept ONLY init_declarator / pointer_declarator / array_declarator — a BARE identifier declarator is a macro-prototype misparse, skip (loses uninit scalars by design); name via cDeclaratorIdentifier; signature `= <first 100 chars>`; kind constant/variable via isConst |
|
||||
| — | class-like types defined in declarations | a `declaration` outside any body whose `type` is a class/struct/union/enum specifier WITH a body: visit the type before extracting the variables, in C always and in C++ when the tree has no errors or the file is walked in brace scopes (the row above) — not in an erroring C++ file whose braces don't balance (`walkDeclaredTypes` ↔ `walk_declared_types`); the declaration's fn-ref scan skips the walked type. An unnamed specifier whose parent declaration has it as `type` takes the first declarator's cDeclaratorIdentifier name — in function bodies too (the c/cpp `resolveName` ↔ `extract_name_raw`) — and the declaration's preceding comment is its docstring (`getDeclarationWrapper` ↔ `class_like_docstring`) |
|
||||
| 4313 | explicit operator calls (#1247) | callee = `function` field + ERROR-wrapped `operator_name` sibling; compact symbolic spacing (`operator *`→`operator*`, word forms keep space); receiver `->`→`.`; DROP unless receiver is `this` (bare name) or simple identifier/member chain (silent miss over wrong edge) |
|
||||
| ~4340 | field_expression method calls | `recv.method`/`ptr->method` → `recv.method`; SKIP_RECEIVERS {self,this,cls,super} → bare name; LITERAL receiver → emit nothing (#1230) |
|
||||
| 4398 | call-result receivers (#645/#608) | receiver is call_expression → `<innerCallee>().<method>` re-encode (c AND cpp in the gate list) |
|
||||
|
||||
Reference in New Issue
Block a user