[Lldb-commits] [lldb] [lldb] Better matching of types in anonymous namespaces (PR #102111)

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Thu Aug 8 04:51:19 PDT 2024


labath wrote:

> This patch relies on "(anonymous namespace)" being removed from the compiler contexts to work. What is the user types any of:
> 
> ```
> (lldb) type lookup "(anonymous namespace)::A"
> (lldb) script lldb.target.FindFirstType("(anonymous namespace)::A");
> (lldb) script lldb.target.FindTypes("(anonymous namespace)::A");
> ```
> 
> Do we correctly set this "(anonymous namespace)" to empty? Or are we expecting these type lookups will always use the looser matching strategy?

These lookups use the looser matching strategy which means they can to the lookup both with and without the namespace prefix. Matching the exact string in the matching algorighm is not necessary because it gets canonicalized in the parser. I've now added a test for this.

> If not we need to check for both.
> 
> We might want to stop passing around `std::vector<CompilerContext>` and pass around a class that contains the language:
> 
> ```
> struct CompilerContexts {
>   lldb::LanguageType language;
>   std::vector<CompilerContext>;
> };
> ```
> 
> Then we could add a method to check for anonymous namespaces where C++ can check for "(anonymous namespace)".

For something like this, I think the bigger question is whether we want our type name syntax to be language specific. If we don't (which is the current state), and we say that we use the same syntax for all language (and the syntax happens to mostly match the c++ language), then I don't think we need this, as we can just canonicalize the type context during parsing (like I did here).

OTOH, if we want to have language-specific syntax, then we may need to do something completely different, because it's not even possible to parse the string into the context vector without knowing the language (the type queries don't usually specify a specific language, so we may have to delay the parsing until we know which language we are matching against).

https://github.com/llvm/llvm-project/pull/102111


More information about the lldb-commits mailing list