Skip to content

Commit 754ba6d

Browse files
authored
Add Docs for Qualified Name (#276)
This PR is a follow up of #274, adds documentation for qualified name. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Added comprehensive documentation for the qualified names attribute, detailing derivation details, edge case handling, and a complete reference of supported argument types with practical examples. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Michael Wang <isVoid@users.noreply.github.com>
1 parent 4415c79 commit 754ba6d

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

docs/source/supported_declarations.rst

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,63 @@ Example mapping
7777
- N/A (serialization only)
7878
- Template parameters/signature captured; specializations/instantiations recorded when present
7979

80+
Qualified names (``qual_name``)
81+
-------------------------------
82+
83+
Many serialized declaration objects expose a ``qual_name`` attribute: the C++
84+
*qualified name* including enclosing scopes (namespaces and record scopes),
85+
using ``::`` as the separator.
86+
87+
This is derived from Clang's ``Decl::getQualifiedNameAsString()`` with small
88+
stability tweaks for anonymous records so downstream consumers always have a
89+
printable identifier.
90+
91+
.. list-table::
92+
:header-rows: 1
93+
94+
* - Declaration kind
95+
- Example ``qual_name``
96+
* - Function / method
97+
- ``ns1::ns2::S::m``
98+
* - Record (struct/class)
99+
- ``ns1::ns2::S``
100+
* - Enum
101+
- ``ns1::ns2::E``
102+
* - Typedef
103+
- ``ns1::ns2::Alias``
104+
* - Function template / class template
105+
- ``ns1::ns2::tf`` / ``ns1::ns2::Tpl``
106+
107+
Notes and edge cases
108+
^^^^^^^^^^^^^^^^^^^^
109+
110+
- **Global scope**: in the global scope (no namespace), ``qual_name`` is
111+
typically the unqualified identifier (e.g., ``GlobalS``).
112+
113+
- **Anonymous namespace**: Clang typically renders anonymous namespaces as
114+
``(anonymous namespace)`` in qualified names. For example, a declaration
115+
``AnonNS_S`` inside ``namespace { ... }`` may have a qualified name like
116+
``(anonymous namespace)::AnonNS_S``.
117+
118+
- **Anonymous records in C-style typedefs**: for patterns like
119+
120+
.. code-block:: cpp
121+
122+
typedef struct { int a; int b; } CStyleAnon;
123+
124+
the underlying record has no tag name and Clang may report an empty name.
125+
ast_canopy falls back to a placeholder ``unnamed<ID>`` for the *record's*
126+
``name`` so downstream always has something printable (note: ``<ID>`` is a
127+
Clang internal decl id and is not stable across runs).
128+
129+
In this common pattern, Clang often treats the typedef name as the record's
130+
user-visible qualified name; in that case you may observe:
131+
132+
- ``Typedef.qual_name == "CStyleAnon"``
133+
- ``Typedef.underlying_name`` matching ``unnamed<ID>``
134+
- ``Record.name`` matching ``unnamed<ID>``
135+
- ``Record.qual_name == "CStyleAnon"``
136+
80137
Supported argument types
81138
------------------------
82139

0 commit comments

Comments
 (0)