This patch adds a hook into the TypePrinter to allow clients
decide whether a template argument corresponds to the default
parameter.
Motivation
DWARF encodes information about template instantiations, but
not about the generic definition of a template. If an argument
in a template instantiation corresponds to the default parameter
of the generic template then DWARF will attach a DW_AT_default_value
to that argument. LLDB uses the Clang TypePrinter for
displaying/formatting C++ types but currently can't give Clang the ClassTemplateDecl
that it expects. Since LLDB does know whether a particular instantiation has
default arguments, this patch allows LLDB (and other clients with external AST sources)
to help Clang in identifying those default arguments.
Alternatives
- Encode information about generic template definitions in DWARF. It's unclear how long it would take to get this proposed and implemented and whether something like this would work in the first place. If we could construct ClassTemplateDecls with the correct generic parameters this patch wouldn't be required.
- Add something like a bool IsDefaulted somewhere in Clang, e.g., in TemplateArgument and consult it from the TypePrinter. This would be much simpler but requires adding a field on one of the Clang types
The TrisState is needed because LLDB has two AST sources:
When we import a type from a clang module we would never have consulted DWARF about whether a parameter was defaulted. So instead of more complex bookkeeping it seemed simpler to say "if we've never seen this decl when parsing DWARF, I can't say anything about the default-ness of the arguments"