Skip to content

Support name mangling#21

Open
zhihaoy wants to merge 17 commits intowhitequark:masterfrom
zhihaoy:mangle
Open

Support name mangling#21
zhihaoy wants to merge 17 commits intowhitequark:masterfrom
zhihaoy:mangle

Conversation

@zhihaoy
Copy link
Copy Markdown

@zhihaoy zhihaoy commented Aug 17, 2025

Add the functionality to perform name mangling from an AST.

Introduced three types of nodes to assist this purpose better:

  1. Node('abominable'): Handle function type with cv and ref qualifiers, distinguishing that from a cv/ref-qualified type. The associated change also fixes a bug when formatting methods.
  2. CastNode('entity'): Still calling it a cast since it spells L...E. Passing a function as a non-type & can be supported by this without introducing the full-expression.
  3. Node('oper_unary'): Need that to mangle unary +, -, &, * differently.

Unsupported features:

  1. Template argument substitution (need to access _Cursor, or analysis identity of Python objects)
  2. Template parameter pack (need to distinguish that in the AST)
  3. Special entities (the patch focuses on exported APIs)

Unverified:

  1. Exported variables (may be a low-hanging fruit)
  2. Certain Clang-specific extensions

Future improvements:

  1. Allow users to provide the standard library names in the AST without __1 but still get name mangling that suits libc++ using some knob.

The change also moved the project to use pyproject.toml, locked pytest in a test group using uv, and migrated the tests to pytest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant