fix(cpp): emit instantiates edge for stack-allocation constructor syntax#1036
fix(cpp): emit instantiates edge for stack-allocation constructor syntax#1036Dshuishui wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4de2d123cb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const typeName = typeNode | ||
| ? normalizeCppReturnType(getNodeText(typeNode, this.source)) | ||
| : undefined; |
There was a problem hiding this comment.
Preserve pointer qualifiers before emitting instantiations
Computing the target from only the declaration type field, and with a return-type normalizer that strips pointers/references and unwraps smart pointers, makes direct-initialized holders look like object construction. In C++ declarations such as Foo *p(nullptr), Foo &r(existing), or std::unique_ptr<Foo> p(nullptr), the later argument_list check still passes and this records instantiates Foo even though no Foo object is constructed at that declaration, polluting "what instantiates Foo" results in common pointer/RAII code. Please inspect the declarator shape and avoid unwrapping holder types for this extraction path.
Useful? React with 👍 / 👎.
Summary
C++ stack-allocation syntax (
ClassName var(args)) does not produce aninstantiatesedge. Heap allocation (new ClassName(args)) works correctlybecause
new_expressionis inINSTANTIATION_KINDS, but the stack form isparsed by tree-sitter as a
declarationnode, which is never matched.This fix adds a branch inside
visitFunctionBody's body walker that detectsthe pattern: a
declarationnode whosetypefield resolves to a class name(via the existing
normalizeCppReturnTypeprimitive filter) and whoseinit_declaratorchild contains anargument_list. When matched, aninstantiatesunresolved reference is pushed — the same shape thatextractInstantiationproduces fornew_expression.What's covered
Calculator calc(0)→caller --[instantiates]--> Calculator✓int x(5)→ skipped (intis inCPP_NON_CLASS_RETURN) ✓Calculator calc = other→ skipped (noargument_listin declarator) ✓Known limitations
Calculator calc;) — noinit_declaratorchild,so no edge is emitted. Can be addressed in a follow-up.
Calculator calc{0}) — usesinitializer_listrather than
argument_list, not covered here.Closes #1035