[Lldb-commits] [PATCH] D54843: [Expr] Check the language before ignoring Objective C keywords

Aleksandr Urakov via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Nov 23 01:46:04 PST 2018


aleksandr.urakov created this revision.
aleksandr.urakov added reviewers: jingham, zturner.
aleksandr.urakov added a project: LLDB.
Herald added a subscriber: lldb-commits.

This patch adds the check of the language before ignoring names like `id` or `Class`, which are reserved in Objective C, but allowed in C++. It is needed to make it possible to evaluate expressions in a C++ program containing names like `id` or `Class`.

There was a discussion of this at the end of October 2018 in `lldb-dev`.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D54843

Files:
  packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py
  packages/Python/lldbsuite/test/expression_command/options/main.cpp
  source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
  source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp


Index: source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
===================================================================
--- source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -398,10 +398,6 @@
     LLVM_FALLTHROUGH;
   case lldb::eLanguageTypeC_plus_plus_03:
     m_compiler->getLangOpts().CPlusPlus = true;
-    // FIXME: the following language option is a temporary workaround,
-    // to "ask for C++, get ObjC++".  Apple hopes to remove this requirement on
-    // non-Apple platforms, but for now it is needed.
-    m_compiler->getLangOpts().ObjC = true;
     break;
   case lldb::eLanguageTypeObjC_plus_plus:
   case lldb::eLanguageTypeUnknown:
Index: source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
===================================================================
--- source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -771,8 +771,9 @@
   static const ConstString id_name("id");
   static const ConstString Class_name("Class");
 
-  if (name == id_name || name == Class_name)
-    return true;
+  if (m_ast_context->getLangOpts().ObjC)
+    if (name == id_name || name == Class_name)
+      return true;
 
   StringRef name_string_ref = name.GetStringRef();
 
Index: packages/Python/lldbsuite/test/expression_command/options/main.cpp
===================================================================
--- packages/Python/lldbsuite/test/expression_command/options/main.cpp
+++ packages/Python/lldbsuite/test/expression_command/options/main.cpp
@@ -1,5 +1,6 @@
 extern "C" int foo(void);
 static int static_value = 0;
+static int id = 1234;
 
 int
 bar()
Index: packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py
===================================================================
--- packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py
+++ packages/Python/lldbsuite/test/expression_command/options/TestExprOptions.py
@@ -63,3 +63,16 @@
         val = frame.EvaluateExpression('foo != nullptr', options)
         self.assertTrue(val.IsValid())
         self.assertFalse(val.GetError().Success())
+
+        # Make sure we can retrieve `id` variable if language is set to C++11:
+        options.SetLanguage(lldb.eLanguageTypeC_plus_plus_11)
+        val = frame.EvaluateExpression('id == 1234', options)
+        self.assertTrue(val.IsValid())
+        self.assertTrue(val.GetError().Success())
+        self.DebugSBValue(val)
+
+        # Make sure we can't retrieve `id` variable if language is set to ObjC:
+        options.SetLanguage(lldb.eLanguageTypeObjC)
+        val = frame.EvaluateExpression('id == 1234', options)
+        self.assertTrue(val.IsValid())
+        self.assertFalse(val.GetError().Success())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54843.175090.patch
Type: text/x-patch
Size: 2860 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20181123/baa80e98/attachment.bin>


More information about the lldb-commits mailing list