Skip to content

Add optional STL template-name simplification for undecorated C++ names - #49

Open
chen3feng wants to merge 1 commit into
hfiref0x:masterfrom
chen3feng:feature/stl-name-simplify
Open

Add optional STL template-name simplification for undecorated C++ names#49
chen3feng wants to merge 1 commit into
hfiref0x:masterfrom
chen3feng:feature/stl-name-simplify

Conversation

@chen3feng

Copy link
Copy Markdown

Summary

Adds an optional, display-only simplification of undecorated C++ names that
collapses the canonical default-argument forms emitted by the MSVC demangler
into their conventional STL spellings, e.g.

Demangled Simplified
std::basic_string<char,std::char_traits<char>,std::allocator<char> > std::string
std::basic_string_view<char,std::char_traits<char> > std::string_view
std::vector<T,std::allocator<T> > std::vector<T>
std::map<K,V,std::less<K>,std::allocator<std::pair<const K,V> > > std::map<K,V>
std::unordered_map<K,V,std::hash<K>,std::equal_to<K>,std::allocator<...> > std::unordered_map<K,V>

This makes long, allocator-/comparator-heavy template names far easier to read
in the imports/exports lists — the common request that motivated stl-filt.

Scope and design

  • Only the default-value template forms of the standard library are matched:
    basic_string/basic_string_view, vector/list/deque/forward_list,
    set/multiset, map/multimap, unordered_*, and unique_ptr.
    User templates and non-default arguments are left untouched.
  • The transform is bracket-aware (walks balanced angle brackets and folds
    bottom-up) rather than regex-based, because nested template argument lists
    (std::map<int,std::vector<std::string> >, allocators wrapping std::pair
    with commas) cannot be split reliably with regular expressions.
  • operator< / operator<<, lambda names, and unbalanced input are guarded;
    any unexpected input is returned unchanged so a displayed name can never be
    corrupted.

UX

New "Simplify STL Template Names" checkbox on Configuration → Appearance
(off by default). Toggling it clears the cached undecorated names and refreshes
the view. It composes with the existing "Undecorate C++ Functions" option.

Implementation

  • Symbols/CStlNameSimplifier.cs — the standalone, WinForms-free transformer.
  • CSymbolResolver.SimplifyTemplateDefaults applies it at the end of
    UndecorateFunctionName.
  • CConfiguration.SimplifyStlNames (persisted, default false), wired through
    MainForm and the configuration form.

Tests

A decoupled xUnit project (WinDepends.StlSimplifier.Tests) links only the
simplifier source — no WinForms / windows-specific TFM — and covers folding,
bottom-up nesting, the function-signature case, operator</<< guards, user
templates, and malformed-input fallbacks. 23/23 passing.

Incidental

The repository had no .gitignore; one for .NET/C++ build artifacts is included
as a separate commit. Happy to drop it from this PR if you'd prefer it separate.

🤖 Generated with Claude Code

@hfiref0x hfiref0x added the ai-code Something created with AI label Jun 2, 2026
Comment thread src/WinDepends.StlSimplifier.Tests/CStlNameSimplifierTests.cs Outdated
Comment thread .gitignore Outdated
@@ -0,0 +1,376 @@
/*******************************************************************************

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent remains unclear. What are the benefits of this approach? The original Dependency Walker does not simplify the data (even as an option); its sole purpose is to present information exactly as it is from symbols.

@chen3feng chen3feng Jun 3, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the thoughtful pushback — I fully agree that faithfully presenting symbols as-is should remain the tool's default, and this change preserves that: the option is off by default, so nothing changes for users who want raw symbols, and the original name is always one tooltip (or one toggle) away. Nothing is hidden or lost.

The motivation is purely readability for C++ developers. With modern STL, a single std::string parameter expands to ~80 characters of char_traits/allocator boilerplate, and a std::unordered_map line can run off the screen — almost all of it being the default template arguments the compiler synthesized, which by definition carry no information. The feature only collapses those canonical default forms (and only for the std library); user templates and any non-default argument are left exactly as-is, and any unexpected input falls back to the raw string unchanged.

In that sense it's less "altering the data" and more in the same spirit as the demangler already dropping calling-convention/MS keywords for legibility — a display-layer convenience, opt-in, deterministic, and with zero new dependencies.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, will take your PR into consideration, thank you for feedback and interest in this project!

@hfiref0x hfiref0x Jun 4, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chen3feng
Can you provide a sample to test your code with? It can be Windows dll or specially built test dll.

Have you tested this code with for example msvcp140.dll?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, let me show some examples later.

Collapses the canonical default-argument forms produced by the MSVC
demangler into their conventional STL spellings, purely for display:

  std::basic_string<char,std::char_traits<char>,std::allocator<char> >
     -> std::string
  std::vector<T,std::allocator<T> >               -> std::vector<T>
  std::map<K,V,std::less<K>,std::allocator<...> >  -> std::map<K,V>

Only the default-value template forms of the standard library are
matched (basic_string/_view, vector/list/deque/forward_list, set/multiset,
map/multimap, unordered_*, unique_ptr); user templates and non-default
arguments are left untouched. The transform is bracket-aware (walks
balanced angle brackets, folds bottom-up) so nested defaults collapse
correctly, and any unexpected input is returned unchanged so a displayed
name can never be corrupted.

Exposed as a new "Simplify STL Template Names" option on the
Configuration > Appearance page (off by default). Toggling it clears the
cached undecorated names and refreshes the view. The original names remain
available via the existing tooltip.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@chen3feng
chen3feng force-pushed the feature/stl-name-simplify branch from 52ba5c8 to 9a4e51b Compare June 3, 2026 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-code Something created with AI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants