Factor the clang specific parts of ExpressionSourceCode.{h,cpp} into the clang plugin.
authorJim Ingham <jingham@apple.com>
Wed, 6 Mar 2019 22:43:25 +0000 (22:43 +0000)
committerJim Ingham <jingham@apple.com>
Wed, 6 Mar 2019 22:43:25 +0000 (22:43 +0000)
NFC

Differential Revision: https://reviews.llvm.org/D59040

llvm-svn: 355560

lldb/include/lldb/Expression/ExpressionSourceCode.h
lldb/lldb.xcodeproj/project.pbxproj
lldb/source/Expression/LLVMUserExpression.cpp
lldb/source/Expression/UserExpression.cpp
lldb/source/Expression/UtilityFunction.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.cpp [moved from lldb/source/Expression/ExpressionSourceCode.cpp with 97% similarity]
lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h [new file with mode: 0644]
lldb/source/Plugins/ExpressionParser/Clang/ClangUserExpression.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangUtilityFunction.cpp

index f8785ba..1226ead 100644 (file)
 
 namespace lldb_private {
 
-class ExecutionContext;
-
 class ExpressionSourceCode {
 public:
-  static const char *g_expression_prefix;
-
-  static ExpressionSourceCode *CreateWrapped(const char *prefix,
-                                             const char *body) {
-    return new ExpressionSourceCode("$__lldb_expr", prefix, body, true);
-  }
-
-  static ExpressionSourceCode *CreateUnwrapped(const char *name,
-                                               const char *body) {
-    return new ExpressionSourceCode(name, "", body, false);
-  }
-
   bool NeedsWrapping() const { return m_wrap; }
 
   const char *GetName() const { return m_name.c_str(); }
 
-  bool GetText(std::string &text, lldb::LanguageType wrapping_language,
-               bool static_method, ExecutionContext &exe_ctx,
-               bool add_locals) const;
-
-  // Given a string returned by GetText, find the beginning and end of the body
-  // passed to CreateWrapped. Return true if the bounds could be found.  This
-  // will also work on text with FixItHints applied.
-  static bool GetOriginalBodyBounds(std::string transformed_text,
-                                    lldb::LanguageType wrapping_language,
-                                    size_t &start_loc, size_t &end_loc);
-
-private:
+protected:
   ExpressionSourceCode(const char *name, const char *prefix, const char *body,
                        bool wrap)
       : m_name(name), m_prefix(prefix), m_body(body), m_wrap(wrap) {}
index 7261528..b71bc28 100644 (file)
                2689005E13353E0E00698AC0 /* ClangASTSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49D7072811B5AD11001AD875 /* ClangASTSource.cpp */; };
                2689006013353E0E00698AC0 /* ClangExpressionDeclMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49F1A74511B3388F003ED505 /* ClangExpressionDeclMap.cpp */; };
                2689006113353E0E00698AC0 /* ClangExpressionParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49445C2512245E3600C11A81 /* ClangExpressionParser.cpp */; };
+               4C61465E223059B000D686F9 /* ClangExpressionSourceCode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C61465C223059B000D686F9 /* ClangExpressionSourceCode.cpp */; };
                4984BA131B978C55008658D4 /* ClangExpressionVariable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4984BA0E1B978C3E008658D4 /* ClangExpressionVariable.cpp */; };
                268900D313353E6F00698AC0 /* ClangExternalASTSourceCallbacks.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26E69030129C6BEF00DDECD9 /* ClangExternalASTSourceCallbacks.cpp */; };
                4966DCC4148978A10028481B /* ClangExternalASTSourceCommon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4966DCC3148978A10028481B /* ClangExternalASTSourceCommon.cpp */; };
                2660387A211CA90F00329572 /* ExceptionBreakpoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26603874211CA90E00329572 /* ExceptionBreakpoint.cpp */; };
                268900EB13353E6F00698AC0 /* ExecutionContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26BC7F3510F1B90C00F91463 /* ExecutionContext.cpp */; };
                4C88BC2A1BA3722B00AA0964 /* Expression.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C88BC291BA3722B00AA0964 /* Expression.cpp */; };
-               49A1CAC51430E8DE00306AC9 /* ExpressionSourceCode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49A1CAC31430E8BD00306AC9 /* ExpressionSourceCode.cpp */; };
                4984BA161B979973008658D4 /* ExpressionVariable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4984BA151B979973008658D4 /* ExpressionVariable.cpp */; };
                4984BA181B979C08008658D4 /* ExpressionVariable.h in Headers */ = {isa = PBXBuildFile; fileRef = 4984BA171B979C08008658D4 /* ExpressionVariable.h */; };
                2689006E13353E1A00698AC0 /* File.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 260C6EA213011581005E16B0 /* File.cpp */; };
                26BC7DC010F1B79500F91463 /* ClangExpressionHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ClangExpressionHelper.h; path = ExpressionParser/Clang/ClangExpressionHelper.h; sourceTree = "<group>"; };
                49445C2512245E3600C11A81 /* ClangExpressionParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ClangExpressionParser.cpp; path = ExpressionParser/Clang/ClangExpressionParser.cpp; sourceTree = "<group>"; };
                49445C2912245E5500C11A81 /* ClangExpressionParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ClangExpressionParser.h; path = ExpressionParser/Clang/ClangExpressionParser.h; sourceTree = "<group>"; };
+               4C61465C223059B000D686F9 /* ClangExpressionSourceCode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ClangExpressionSourceCode.cpp; path = ExpressionParser/Clang/ClangExpressionSourceCode.cpp; sourceTree = "<group>"; };
+               4C61465D223059B000D686F9 /* ClangExpressionSourceCode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ClangExpressionSourceCode.h; path = ExpressionParser/Clang/ClangExpressionSourceCode.h; sourceTree = "<group>"; };
                4984BA0E1B978C3E008658D4 /* ClangExpressionVariable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ClangExpressionVariable.cpp; path = ExpressionParser/Clang/ClangExpressionVariable.cpp; sourceTree = "<group>"; };
                4984BA0F1B978C3E008658D4 /* ClangExpressionVariable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ClangExpressionVariable.h; path = ExpressionParser/Clang/ClangExpressionVariable.h; sourceTree = "<group>"; };
                26E69030129C6BEF00DDECD9 /* ClangExternalASTSourceCallbacks.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ClangExternalASTSourceCallbacks.cpp; path = source/Symbol/ClangExternalASTSourceCallbacks.cpp; sourceTree = "<group>"; };
                4C88BC291BA3722B00AA0964 /* Expression.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Expression.cpp; path = source/Expression/Expression.cpp; sourceTree = "<group>"; };
                4C00832C1B9A58A700D5CF24 /* Expression.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Expression.h; path = include/lldb/Expression/Expression.h; sourceTree = "<group>"; };
                4C2479BE1BA39843009C9A7B /* ExpressionParser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ExpressionParser.h; path = include/lldb/Expression/ExpressionParser.h; sourceTree = "<group>"; };
-               49A1CAC31430E8BD00306AC9 /* ExpressionSourceCode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ExpressionSourceCode.cpp; path = source/Expression/ExpressionSourceCode.cpp; sourceTree = "<group>"; };
                49A1CAC11430E21D00306AC9 /* ExpressionSourceCode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ExpressionSourceCode.h; path = include/lldb/Expression/ExpressionSourceCode.h; sourceTree = "<group>"; };
                4C29E77D1BA2403F00DFF855 /* ExpressionTypeSystemHelper.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; name = ExpressionTypeSystemHelper.h; path = include/lldb/Expression/ExpressionTypeSystemHelper.h; sourceTree = "<group>"; };
                4984BA151B979973008658D4 /* ExpressionVariable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ExpressionVariable.cpp; path = source/Expression/ExpressionVariable.cpp; sourceTree = "<group>"; };
                                4C00833D1B9F9B8400D5CF24 /* UtilityFunction.h */,
                                4C00833F1B9F9BA900D5CF24 /* UtilityFunction.cpp */,
                                49A1CAC11430E21D00306AC9 /* ExpressionSourceCode.h */,
-                               49A1CAC31430E8BD00306AC9 /* ExpressionSourceCode.cpp */,
                                4984BA171B979C08008658D4 /* ExpressionVariable.h */,
                                4984BA151B979973008658D4 /* ExpressionVariable.cpp */,
                                4C2479BE1BA39843009C9A7B /* ExpressionParser.h */,
                                49F1A74511B3388F003ED505 /* ClangExpressionDeclMap.cpp */,
                                49445C2912245E5500C11A81 /* ClangExpressionParser.h */,
                                49445C2512245E3600C11A81 /* ClangExpressionParser.cpp */,
+                               4C61465D223059B000D686F9 /* ClangExpressionSourceCode.h */,
+                               4C61465C223059B000D686F9 /* ClangExpressionSourceCode.cpp */,
                                4959511B1A1BC48100F6F8FC /* ClangModulesDeclVendor.h */,
                                4959511E1A1BC4BC00F6F8FC /* ClangModulesDeclVendor.cpp */,
                                49D4FE821210B5FB00CDB854 /* ClangPersistentVariables.h */,
                                8C3BD9961EF45DA50016C343 /* MainThreadCheckerRuntime.cpp in Sources */,
                                23042D121976CA1D00621B2C /* PlatformKalimba.cpp in Sources */,
                                2689001413353DDE00698AC0 /* CommandObjectBreakpoint.cpp in Sources */,
+                               4C61465E223059B000D686F9 /* ClangExpressionSourceCode.cpp in Sources */,
                                2689001513353DDE00698AC0 /* CommandObjectBreakpointCommand.cpp in Sources */,
                                2689001613353DDE00698AC0 /* CommandObjectCommands.cpp in Sources */,
                                AFEC3362194A8ABA00FF05C6 /* StructuredData.cpp in Sources */,
                                23DDF226196C3EE600BB8417 /* CommandOptionValidators.cpp in Sources */,
                                B207C4931429607D00F36E4E /* CommandObjectWatchpoint.cpp in Sources */,
                                26EFC4CD18CFAF0D00865D87 /* ObjectFileJIT.cpp in Sources */,
-                               49A1CAC51430E8DE00306AC9 /* ExpressionSourceCode.cpp in Sources */,
                                494260DA14579144003C1C78 /* VerifyDecl.cpp in Sources */,
                                2657AFB71B86910100958979 /* CompilerDeclContext.cpp in Sources */,
                                49DA65031485C92A005FF180 /* AppleObjCDeclVendor.cpp in Sources */,
index 8afde07..6a9fd9e 100644 (file)
@@ -12,7 +12,6 @@
 #include "lldb/Core/StreamFile.h"
 #include "lldb/Core/ValueObjectConstResult.h"
 #include "lldb/Expression/DiagnosticManager.h"
-#include "lldb/Expression/ExpressionSourceCode.h"
 #include "lldb/Expression/IRExecutionUnit.h"
 #include "lldb/Expression/IRInterpreter.h"
 #include "lldb/Expression/Materializer.h"
index 997ac9e..2d9820e 100644 (file)
@@ -20,7 +20,6 @@
 #include "lldb/Core/StreamFile.h"
 #include "lldb/Core/ValueObjectConstResult.h"
 #include "lldb/Expression/DiagnosticManager.h"
-#include "lldb/Expression/ExpressionSourceCode.h"
 #include "lldb/Expression/IRExecutionUnit.h"
 #include "lldb/Expression/IRInterpreter.h"
 #include "lldb/Expression/Materializer.h"
index 30c33d2..8cf9de9 100644 (file)
@@ -15,7 +15,6 @@
 #include "lldb/Core/Module.h"
 #include "lldb/Core/StreamFile.h"
 #include "lldb/Expression/DiagnosticManager.h"
-#include "lldb/Expression/ExpressionSourceCode.h"
 #include "lldb/Expression/FunctionCaller.h"
 #include "lldb/Expression/IRExecutionUnit.h"
 #include "lldb/Expression/UtilityFunction.h"
@@ -42,11 +41,8 @@ using namespace lldb;
 UtilityFunction::UtilityFunction(ExecutionContextScope &exe_scope,
                                  const char *text, const char *name)
     : Expression(exe_scope), m_execution_unit_sp(), m_jit_module_wp(),
-      m_function_text(ExpressionSourceCode::g_expression_prefix),
-      m_function_name(name) {
-  if (text && text[0])
-    m_function_text.append(text);
-}
+      m_function_text(),
+      m_function_name(name) {}
 
 UtilityFunction::~UtilityFunction() {
   lldb::ProcessSP process_sp(m_jit_process_wp.lock());
@@ -1,4 +1,4 @@
-//===-- ExpressionSourceCode.cpp --------------------------------*- C++ -*-===//
+//===-- ClangExpressionSourceCode.cpp ---------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "lldb/Expression/ExpressionSourceCode.h"
+#include "ClangExpressionSourceCode.h"
 
 #include "Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h"
 #include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h"
@@ -24,7 +24,7 @@
 
 using namespace lldb_private;
 
-const char *ExpressionSourceCode::g_expression_prefix = R"(
+const char *ClangExpressionSourceCode::g_expression_prefix = R"(
 #ifndef NULL
 #define NULL (__null)
 #endif
@@ -175,7 +175,7 @@ static void AddLocalVariableDecls(const lldb::VariableListSP &var_list_sp,
   }
 }
 
-bool ExpressionSourceCode::GetText(std::string &text,
+bool ClangExpressionSourceCode::GetText(std::string &text,
                                    lldb::LanguageType wrapping_language,
                                    bool static_method,
                                    ExecutionContext &exe_ctx,
@@ -354,7 +354,7 @@ bool ExpressionSourceCode::GetText(std::string &text,
   return true;
 }
 
-bool ExpressionSourceCode::GetOriginalBodyBounds(
+bool ClangExpressionSourceCode::GetOriginalBodyBounds(
     std::string transformed_text, lldb::LanguageType wrapping_language,
     size_t &start_loc, size_t &end_loc) {
   const char *start_marker;
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionSourceCode.h
new file mode 100644 (file)
index 0000000..28ec090
--- /dev/null
@@ -0,0 +1,55 @@
+//===-- ClangExpressionSourceCode.h -----------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_ClangExpressionSourceCode_h
+#define liblldb_ClangExpressionSourceCode_h
+
+#include "lldb/Expression/Expression.h"
+#include "lldb/Expression/ExpressionSourceCode.h"
+#include "lldb/lldb-enumerations.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringRef.h"
+
+#include <string>
+
+namespace lldb_private {
+
+class ExecutionContext;
+
+class ClangExpressionSourceCode : public ExpressionSourceCode {
+public:
+  static const char *g_expression_prefix;
+
+  static ClangExpressionSourceCode *CreateWrapped(const char *prefix,
+                                             const char *body) {
+    return new ClangExpressionSourceCode("$__lldb_expr", prefix, body, true);
+  }
+
+  uint32_t GetNumBodyLines();
+
+  bool GetText(std::string &text, lldb::LanguageType wrapping_language,
+               bool static_method,
+               ExecutionContext &exe_ctx,
+               bool add_locals) const;
+
+  // Given a string returned by GetText, find the beginning and end of the body
+  // passed to CreateWrapped. Return true if the bounds could be found.  This
+  // will also work on text with FixItHints applied.
+  static bool GetOriginalBodyBounds(std::string transformed_text,
+                                    lldb::LanguageType wrapping_language,
+                                    size_t &start_loc, size_t &end_loc);
+
+protected:
+  ClangExpressionSourceCode(const char *name, const char *prefix, const char *body,
+                       bool wrap) :
+      ExpressionSourceCode(name, prefix, body, wrap) {}
+};
+
+} // namespace lldb_private
+
+#endif
index bc725c9..10d76d5 100644 (file)
@@ -21,6 +21,7 @@
 #include "ClangDiagnostic.h"
 #include "ClangExpressionDeclMap.h"
 #include "ClangExpressionParser.h"
+#include "ClangExpressionSourceCode.h"
 #include "ClangModulesDeclVendor.h"
 #include "ClangPersistentVariables.h"
 
@@ -404,8 +405,8 @@ void ClangUserExpression::UpdateLanguageForExpr(
   if (m_options.GetExecutionPolicy() == eExecutionPolicyTopLevel) {
     m_transformed_text = m_expr_text;
   } else {
-    std::unique_ptr<ExpressionSourceCode> source_code(
-        ExpressionSourceCode::CreateWrapped(prefix.c_str(),
+    std::unique_ptr<ClangExpressionSourceCode> source_code(
+        ClangExpressionSourceCode::CreateWrapped(prefix.c_str(),
                                             m_expr_text.c_str()));
 
     if (m_in_cplusplus_method)
@@ -529,7 +530,7 @@ bool ClangUserExpression::Parse(DiagnosticManager &diagnostic_manager,
         size_t fixed_end;
         const std::string &fixed_expression =
             diagnostic_manager.GetFixedExpression();
-        if (ExpressionSourceCode::GetOriginalBodyBounds(
+        if (ClangExpressionSourceCode::GetOriginalBodyBounds(
                 fixed_expression, m_expr_lang, fixed_start, fixed_end))
           m_fixed_text =
               fixed_expression.substr(fixed_start, fixed_end - fixed_start);
index c15bfa5..e1d1fdd 100644 (file)
@@ -9,6 +9,7 @@
 #include "ClangUtilityFunction.h"
 #include "ClangExpressionDeclMap.h"
 #include "ClangExpressionParser.h"
+#include "ClangExpressionSourceCode.h"
 
 #include <stdio.h>
 #if HAVE_SYS_TYPES_H
@@ -18,7 +19,6 @@
 
 #include "lldb/Core/Module.h"
 #include "lldb/Core/StreamFile.h"
-#include "lldb/Expression/ExpressionSourceCode.h"
 #include "lldb/Expression/IRExecutionUnit.h"
 #include "lldb/Host/Host.h"
 #include "lldb/Target/ExecutionContext.h"
@@ -40,7 +40,11 @@ using namespace lldb_private;
 //------------------------------------------------------------------
 ClangUtilityFunction::ClangUtilityFunction(ExecutionContextScope &exe_scope,
                                            const char *text, const char *name)
-    : UtilityFunction(exe_scope, text, name) {}
+    : UtilityFunction(exe_scope, text, name) {
+  m_function_text.assign(ClangExpressionSourceCode::g_expression_prefix);
+  if (text && text[0])
+    m_function_text.append(text);
+}
 
 ClangUtilityFunction::~ClangUtilityFunction() {}