Supports the parsing of the "using namespace XXX" and "using XXX::XXX" directives. Added ambiguity errors when it two decls with the same name are encountered (see comments in TestCppNsImport). Fixes using directives being duplicated for anonymous namespaces. Fixes GetDeclForUID for specification DIEs.
Details
- Reviewers
chaoren sivachandra clayborg - Commits
- rGea188fc318a0: Add using directives to the clang::DeclContext and fix decls for variables…
rLLDB247836: Add using directives to the clang::DeclContext and fix decls for variables…
rL247836: Add using directives to the clang::DeclContext and fix decls for variables…
Diff Detail
Event Timeline
If you can explain the need for ParseDeclsForContext() as mentioned in the inlined comment that would help me understand this change better.
Also, Sean suggested that we might be able to fix all of this in another way that might make it easier on everyone: don't do any of the decl context searches manually like we are, but just add the using directives to the expression source code. When we make an expression we make a $_lldb_expr function and we put our expression inside of it. So if I run to "main" and run:
(lldb) expr argc
We generate the code:
void $__lldb_expr(void *$__lldb_arg) { argc; }
Now, if we grabbed the using directives, we could translate them into source and place them inside the function lexical block:
void $__lldb_expr(void *$__lldb_arg) { using namespace foo; using namespace bar; argc; }
Then we might not need to make as any modifications to the name lookups to do this manually. Thoughts?
source/Symbol/ClangASTContext.cpp | ||
---|---|---|
8877 | Can you explain why you need to call ParseDeclsForContext() here? I would like to always avoid parsing everything within a decl context if possible only allow targeted searches (find "b" in namespace "a", not parse everything in namespace "a"). |
The need for ParseDeclsInContext is to get a list of namespaces that are contained within a using-directive. This does not actually parse anything but DW_TAG_imported_namespace and DW_TAG_imported_decl. The actual contents of the namespace are parsed only when the search reaches it.
About having the using-directives in the source that is passed to clang, I don't think that will work since there is a comment in ClangASTSource::FindExternalDeclsByName:
// Using directives found in this context. // Tell Sema we didn't find any or we'll end up getting asked a *lot*. case DeclarationName::CXXUsingDirective: SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); return false;
Add using directives to the clang::DeclContext and fix decls for variables inside namespaces
Rebased the patch.
Can you explain why you need to call ParseDeclsForContext() here? I would like to always avoid parsing everything within a decl context if possible only allow targeted searches (find "b" in namespace "a", not parse everything in namespace "a").