From 83c81c0a469482888482983c302c09c02680ae7c Mon Sep 17 00:00:00 2001 From: Raphael Isemann Date: Mon, 30 Mar 2020 11:50:55 +0200 Subject: [PATCH] [lldb] Make Fix-Its also apply to top-level expressions Summary: Currently top-level expressions won't automatically get Fix-Its applied. The reason for that is that we only set the `m_fixed_text` member if we have a wrapping source code (I.e. `m_source_code` is not zero and is wrapping some expressions). This patch just always sets `m_fixed_text` to get this working. Reviewers: labath, jingham Reviewed By: labath Subscribers: JDevlieghere Differential Revision: https://reviews.llvm.org/D77042 --- .../Plugins/ExpressionParser/Clang/ClangUserExpression.cpp | 7 +++---- lldb/test/API/commands/expression/fixits/TestFixIts.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp index b246fc3..2b75c4f 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp @@ -616,15 +616,14 @@ bool ClangUserExpression::Parse(DiagnosticManager &diagnostic_manager, if (parser.RewriteExpression(diagnostic_manager)) { size_t fixed_start; size_t fixed_end; - const std::string &fixed_expression = - diagnostic_manager.GetFixedExpression(); + m_fixed_text = diagnostic_manager.GetFixedExpression(); // Retrieve the original expression in case we don't have a top level // expression (which has no surrounding source code). if (m_source_code && - m_source_code->GetOriginalBodyBounds(fixed_expression, m_expr_lang, + m_source_code->GetOriginalBodyBounds(m_fixed_text, m_expr_lang, fixed_start, fixed_end)) m_fixed_text = - fixed_expression.substr(fixed_start, fixed_end - fixed_start); + m_fixed_text.substr(fixed_start, fixed_end - fixed_start); } } return false; diff --git a/lldb/test/API/commands/expression/fixits/TestFixIts.py b/lldb/test/API/commands/expression/fixits/TestFixIts.py index 273982c..eb1dd97aa 100644 --- a/lldb/test/API/commands/expression/fixits/TestFixIts.py +++ b/lldb/test/API/commands/expression/fixits/TestFixIts.py @@ -33,6 +33,10 @@ class ExprCommandWithFixits(TestBase): options = lldb.SBExpressionOptions() options.SetAutoApplyFixIts(True) + top_level_options = lldb.SBExpressionOptions() + top_level_options.SetAutoApplyFixIts(True) + top_level_options.SetTopLevel(True) + frame = self.thread.GetFrameAtIndex(0) # Try with one error: @@ -41,6 +45,15 @@ class ExprCommandWithFixits(TestBase): self.assertTrue(value.GetError().Success()) self.assertEquals(value.GetValueAsUnsigned(), 10) + # Try with one error in a top-level expression. + # The Fix-It changes "ptr.m" to "ptr->m". + expr = "struct X { int m; }; X x; X *ptr = &x; int m = ptr.m;" + value = frame.EvaluateExpression(expr, top_level_options) + # A successfully parsed top-level expression will yield an error + # that there is 'no value'. If a parsing error would have happened we + # would get a different error kind, so let's check the error kind here. + self.assertEquals(value.GetError().GetCString(), "error: No value") + # Try with two errors: two_error_expression = "my_pointer.second->a" value = frame.EvaluateExpression(two_error_expression, options) -- 2.7.4