Use an artifical namespace so that member vars do not hide local vars.
authorSiva Chandra <sivachandra@google.com>
Thu, 4 Feb 2016 18:38:35 +0000 (18:38 +0000)
committerSiva Chandra <sivachandra@google.com>
Thu, 4 Feb 2016 18:38:35 +0000 (18:38 +0000)
commit375882dddb92b4cf9fac72b3388b9c4af35d8ba6
treeef1bee8ec19899ee4edb351549bffc40a1f62135
parent76c48e0e704ef72f37766ef12b3fa1a924c33ad8
Use an artifical namespace so that member vars do not hide local vars.

Summary:
While evaluating expressions when stopped in a class method, there was a
problem of member variables hiding local variables. This was happening
because, in the context of a method, clang already knew about member
variables with their name and assumed that they were the only variables
with those names in scope. Consequently, clang never checks with LLDB
about the possibility of local variables with the same name and goes
wrong. This change addresses the problem by using an artificial
namespace "$__lldb_local_vars". All local variables in scope are
declared in the "$__lldb_expr" method as follows:

    using $__lldb_local_vars::<local var 1>;
    using $__lldb_local_vars::<local var 2>;
    ...

This hides the member variables with the same name and forces clang to
enquire about the variables which it thinks are declared in
$__lldb_local_vars. When LLDB notices that clang is enquiring about
variables in $__lldb_local_vars, it looks up local vars and conveys
their information if found. This way, member variables do not hide local
variables, leading to correct evaluation of expressions.

A point to keep in mind is that the above solution does not solve the
problem for one specific case:

    namespace N
    {
        int a;
    }

    class A
    {
    public:
        void Method();
        int a;
    };

    void
    A::Method()
    {
        using N::a;
        ...

        // Since the above solution only touches locals, it does not
        // force clang to enquire about "a" coming from namespace N.
    }

Reviewers: clayborg, spyffe

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D16746

llvm-svn: 259810
12 files changed:
lldb/include/lldb/Symbol/ClangASTContext.h
lldb/include/lldb/Symbol/CompilerDeclContext.h
lldb/include/lldb/Symbol/TypeSystem.h
lldb/packages/Python/lldbsuite/test/lang/cpp/member-and-local-vars-with-same-name/Makefile [new file with mode: 0644]
lldb/packages/Python/lldbsuite/test/lang/cpp/member-and-local-vars-with-same-name/TestMembersAndLocalsWithSameName.py [new file with mode: 0644]
lldb/packages/Python/lldbsuite/test/lang/cpp/member-and-local-vars-with-same-name/main.cpp [new file with mode: 0644]
lldb/source/Expression/ExpressionSourceCode.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
lldb/source/Symbol/ClangASTContext.cpp
lldb/source/Symbol/CompilerDeclContext.cpp
lldb/source/Symbol/TypeSystem.cpp