Declaration introspection: shapes, overload counts, template parameters and TU enumeration - #1102
Open
conrade-ctc wants to merge 5 commits into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1102 +/- ##
==========================================
+ Coverage 87.74% 88.06% +0.31%
==========================================
Files 23 23
Lines 6429 6601 +172
==========================================
+ Hits 5641 5813 +172
Misses 788 788
🚀 New features to boost your workflow:
|
conrade-ctc
force-pushed
the
pr-g-decl-introspection
branch
from
September 1, 2026 18:27
048e263 to
9131998
Compare
conrade-ctc
force-pushed
the
pr-g-decl-introspection
branch
from
September 1, 2026 21:11
9131998 to
0060fd4
Compare
added 2 commits
September 2, 2026 08:14
The API could report a specialisation's template arguments but not the parameters a template declares, which a caller mirroring a declaration needs: the parameter's name, whether it stands for a type, a value or a template, and its default if it has one. GetNumTemplateParameters and GetTemplateParameter accept either the template or the class or function it describes, so a caller that walked to a CXXRecordDecl does not have to find the ClassTemplateDecl first. Parameters come back as declarations, so the ordinary name accessors apply to them.
Five shapes a consumer mirroring declarations has to distinguish had no accessor: scoped vs unscoped enum, union vs class, alias template vs class template, parameter packs, and a definition vs a forward declaration. GetOverloadCount counts function templates too, which GetFunctionsUsingName drops.
conrade-ctc
force-pushed
the
pr-g-decl-introspection
branch
from
September 2, 2026 13:31
0060fd4 to
352b51f
Compare
added 3 commits
September 3, 2026 11:58
EnumerateTranslationUnitDecls walks every partial translation unit the interpreter has parsed, descending through namespaces, classes and language linkage blocks. A linkage block is unnamed, so filtering to named declarations at the top level alone drops extern "C" declarations entirely. GetDeclFile, GetDeclLine and IsInSystemHeader attribute a declaration to its source. They screen the location first. An interpreter accumulates declarations whose offset lands in the loaded half of the SLoc space with no external source behind it. Expanding one of those reads unallocated memory instead of reporting a bad location. Measured against a libclang parse of the same closure: the same declarations, 0.04s against 8.49s. Naming follows clang's qualified names, which differ from a namespace-path walk in two ways -- inline namespaces are not spelled, and an out-of-line member template definition is named for its class rather than its lexical namespace.
Enumeration now descends class-template bodies and reports the PTU chain in declaration order; GetNumTemplateParameters answers for partial specializations; new predicates IsClassTemplate, IsImplicitDecl and IsFriendDeclared. Co-developed-with-the-help-of: Claude Code (Fable 5, human in the loop)
LLVM now registers each interpreter input buffer as a virtual FileEntry with overridden contents. The no-FileEntry check no longer identifies interpreter inputs, so also return "" for content-overridden entries. Co-developed-with-the-help-of: Claude Code (Fable 5, human in the loop)
conrade-ctc
force-pushed
the
pr-g-decl-introspection
branch
from
September 3, 2026 16:59
352b51f to
905b63e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A consumer that mirrors C++ declarations meets five gaps in the API today. It reads a specialisation's template arguments, but cannot read the parameters a template declares. It cannot tell a scoped enum from an unscoped one, a union from a class, or an alias template from a class template. It cannot tell a definition from a forward declaration, nor see that a template parameter is a pack. It cannot count overloads, because GetFunctionsUsingName drops function templates. It cannot list what the interpreter has parsed, nor say which file and line a declaration comes from.
These five commits close the gaps and add tests to ScopeReflectionTest. Enumeration also replaces a separate parse: measured against a libclang parse of the same closure, the same declarations, 0.04s against 8.49s. The additions follow the API-extension style of #810, #1090, #1087 and #1093. The last commit is a small fix for llvm's virtual-FileEntry change; take it on its own if that merges faster.