[Lldb-commits] [lldb] 337151f - [lldb][NFC] Move searching for the local variable namespace into own function

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Thu Nov 21 02:03:59 PST 2019


Author: Raphael Isemann
Date: 2019-11-21T11:03:24+01:00
New Revision: 337151f41e78f42df1eedbb86479888a2c5d0a04

URL: https://github.com/llvm/llvm-project/commit/337151f41e78f42df1eedbb86479888a2c5d0a04
DIFF: https://github.com/llvm/llvm-project/commit/337151f41e78f42df1eedbb86479888a2c5d0a04.diff

LOG: [lldb][NFC] Move searching for the local variable namespace into own function

Added: 
    

Modified: 
    lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
    lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
index 31bf55ca4af4..f2d5ded7d98f 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -1073,6 +1073,32 @@ void ClangExpressionDeclMap::LookUpLldbObjCClass(NameSearchContext &context,
   }
 }
 
+void ClangExpressionDeclMap::LookupLocalVarNamespace(
+    SymbolContext &sym_ctx, NameSearchContext &context) {
+  CompilerDeclContext frame_decl_context = sym_ctx.block != nullptr
+                                               ? sym_ctx.block->GetDeclContext()
+                                               : CompilerDeclContext();
+
+  if (frame_decl_context) {
+    ClangASTContext *frame_ast = llvm::dyn_cast_or_null<ClangASTContext>(
+        frame_decl_context.GetTypeSystem());
+
+    ClangASTContext *map_ast = ClangASTContext::GetASTContext(m_ast_context);
+    if (frame_ast && map_ast) {
+      clang::NamespaceDecl *namespace_decl =
+          map_ast->GetUniqueNamespaceDeclaration(
+              g_lldb_local_vars_namespace_cstr, nullptr);
+      if (namespace_decl) {
+        context.AddNamedDecl(namespace_decl);
+        clang::DeclContext *clang_decl_ctx =
+            clang::Decl::castToDeclContext(namespace_decl);
+        clang_decl_ctx->setHasExternalVisibleStorage(true);
+        context.m_found.local_vars_nsp = true;
+      }
+    }
+  }
+}
+
 void ClangExpressionDeclMap::FindExternalVisibleDecls(
     NameSearchContext &context, lldb::ModuleSP module_sp,
     CompilerDeclContext &namespace_decl, unsigned int current_id) {
@@ -1113,30 +1139,7 @@ void ClangExpressionDeclMap::FindExternalVisibleDecls(
       return;
     }
     if (name == ConstString(g_lldb_local_vars_namespace_cstr)) {
-      CompilerDeclContext frame_decl_context =
-          sym_ctx.block != nullptr ? sym_ctx.block->GetDeclContext()
-                                   : CompilerDeclContext();
-
-      if (frame_decl_context) {
-        ClangASTContext *frame_ast = llvm::dyn_cast_or_null<ClangASTContext>(
-            frame_decl_context.GetTypeSystem());
-
-        ClangASTContext *map_ast =
-            ClangASTContext::GetASTContext(m_ast_context);
-        if (frame_ast && map_ast) {
-          clang::NamespaceDecl *namespace_decl =
-              map_ast->GetUniqueNamespaceDeclaration(name.GetCString(),
-                                                     nullptr);
-          if (namespace_decl) {
-            context.AddNamedDecl(namespace_decl);
-            clang::DeclContext *clang_decl_ctx =
-                clang::Decl::castToDeclContext(namespace_decl);
-            clang_decl_ctx->setHasExternalVisibleStorage(true);
-            context.m_found.local_vars_nsp = true;
-          }
-        }
-      }
-
+      LookupLocalVarNamespace(sym_ctx, context);
       return;
     }
 

diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
index 93342dace77e..b599e2802d14 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.h
@@ -410,6 +410,17 @@ class ClangExpressionDeclMap : public ClangASTSource {
   ///     for logging purposes.
   void LookUpLldbObjCClass(NameSearchContext &context, unsigned int current_id);
 
+  /// Handles looking up the synthetic namespace that contains our local
+  /// variables for the current frame.
+  ///
+  /// \param[in] sym_ctx
+  ///     The current SymbolContext of this frame.
+  ///
+  /// \param[in] context
+  ///     The NameSearchContext that can construct Decls for this name.
+  void LookupLocalVarNamespace(SymbolContext &sym_ctx,
+                               NameSearchContext &context);
+
   /// Given a target, find a variable that matches the given name and type.
   ///
   /// \param[in] target


        


More information about the lldb-commits mailing list