[Lldb-commits] [PATCH] D77042: [lldb] Make Fix-Its also apply to top-level expressions

Raphael Isemann via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Mar 30 03:13:11 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG83c81c0a4694: [lldb] Make Fix-Its also apply to top-level expressions (authored by teemperor).
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77042/new/

https://reviews.llvm.org/D77042

Files:
  lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
  lldb/test/API/commands/expression/fixits/TestFixIts.py


Index: lldb/test/API/commands/expression/fixits/TestFixIts.py
===================================================================
--- lldb/test/API/commands/expression/fixits/TestFixIts.py
+++ lldb/test/API/commands/expression/fixits/TestFixIts.py
@@ -33,6 +33,10 @@
         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 @@
         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)
Index: lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
===================================================================
--- lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
@@ -616,15 +616,14 @@
       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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77042.253538.patch
Type: text/x-patch
Size: 2651 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200330/aeb2a4a7/attachment-0001.bin>


More information about the lldb-commits mailing list