Supported declarations#
ast_canopy recognizes and serializes a subset of CUDA C++ declarations for downstream consumers.
Concrete structs and classes#
Constructors generate typing and lowering for instantiation
Conversion operators are mapped to Python conversions
Public fields are exposed for read access
Functions and operators#
Free functions receive typing and lowering for all overloads
Operator overloads are mapped to Python operators (e.g.,
operator+→operator.add)
Templates#
Class templates (e.g.,
template<class T> struct Vec) are serialized with template parameters and their declaration bodies for downstream specialization/instantiation.Function templates (e.g.,
template<typename T> T add(T, T)) are serialized with parameter lists and signatures so consumers can materialize concrete overloads.Where present, explicit specializations and explicit instantiations are captured as distinct declarations.
Example mapping#
Kind |
C++ Declaration |
C++ Usage |
Numba Usage |
Notes |
|---|---|---|---|---|
Concrete Struct Constructor |
|
|
|
Generates type, data model, typing, lowering |
Conversion Operator |
|
|
|
Conversion operator mapping |
Public Attribute |
|
|
|
Read-only access |
Regular Struct Method |
|
|
|
Instance method typing/lowering (non-mutative methods only; mutative methods are not supported) |
Function |
|
|
|
Typing/lowering for overloads |
Operator overload |
|
|
|
Mapped to appropriate Python operator |
Class template |
|
|
N/A (serialization only) |
Template parameters and body captured for downstream specialization |
Function template |
|
|
N/A (serialization only) |
Template parameters/signature captured; specializations/instantiations recorded when present |
Qualified names (qual_name)#
Many serialized declaration objects expose a qual_name attribute: the C++
qualified name including enclosing scopes (namespaces and record scopes),
using :: as the separator.
This is derived from Clang’s Decl::getQualifiedNameAsString() with small
stability tweaks for anonymous records so downstream consumers always have a
printable identifier.
Declaration kind |
Example |
|---|---|
Function / method |
|
Record (struct/class) |
|
Enum |
|
Typedef |
|
Function template / class template |
|
Notes and edge cases#
Global scope: in the global scope (no namespace),
qual_nameis typically the unqualified identifier (e.g.,GlobalS).Anonymous namespace: Clang typically renders anonymous namespaces as
(anonymous namespace)in qualified names. For example, a declarationAnonNS_Sinsidenamespace { ... }may have a qualified name like(anonymous namespace)::AnonNS_S.Anonymous records in C-style typedefs: for patterns like
typedef struct { int a; int b; } CStyleAnon;
the underlying record has no tag name and Clang may report an empty name. ast_canopy falls back to a placeholder
unnamed<ID>for the record’snameso downstream always has something printable (note:<ID>is a Clang internal decl id and is not stable across runs).In this common pattern, Clang often treats the typedef name as the record’s user-visible qualified name; in that case you may observe:
Typedef.qual_name == "CStyleAnon"Typedef.underlying_namematchingunnamed<ID>Record.namematchingunnamed<ID>Record.qual_name == "CStyleAnon"
Supported argument types#
The following argument types are supported for both standalone functions and struct/class methods.
Type |
Description |
Examples |
|---|---|---|
C++ native types |
Built-in arithmetic and boolean types. |
|
Pointers to supported types |
Raw pointers to the above types (including const-qualified). |
|
Struct types (numbast) |
Structs generated by numbast bindings. |
|
Enums (numbast) |
Enums generated by numbast bindings. |
|