summaryrefslogtreecommitdiff
path: root/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/Plugins/ExpressionParser/Clang/ClangUserExpression.h')
-rw-r--r--source/Plugins/ExpressionParser/Clang/ClangUserExpression.h78
1 files changed, 46 insertions, 32 deletions
diff --git a/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h b/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
index 7e4cba6618507..24c152bdb45d3 100644
--- a/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
+++ b/source/Plugins/ExpressionParser/Clang/ClangUserExpression.h
@@ -1,9 +1,8 @@
//===-- ClangUserExpression.h -----------------------------------*- C++ -*-===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// 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
//
//===----------------------------------------------------------------------===//
@@ -29,8 +28,7 @@
namespace lldb_private {
-//----------------------------------------------------------------------
-/// @class ClangUserExpression ClangUserExpression.h
+/// \class ClangUserExpression ClangUserExpression.h
/// "lldb/Expression/ClangUserExpression.h" Encapsulates a single expression
/// for use with Clang
///
@@ -38,9 +36,13 @@ namespace lldb_private {
/// and as a backend for the expr command. ClangUserExpression encapsulates
/// the objects needed to parse and interpret or JIT an expression. It uses
/// the Clang parser to produce LLVM IR from the expression.
-//----------------------------------------------------------------------
class ClangUserExpression : public LLVMUserExpression {
public:
+ /// LLVM-style RTTI support.
+ static bool classof(const Expression *E) {
+ return E->getKind() == eKindClangUserExpression;
+ }
+
enum { kDefaultTimeout = 500000u };
class ClangUserExpressionHelper : public ClangExpressionHelper {
@@ -50,10 +52,8 @@ public:
~ClangUserExpressionHelper() override = default;
- //------------------------------------------------------------------
/// Return the object that the parser should use when resolving external
/// values. May be NULL if everything should be self-contained.
- //------------------------------------------------------------------
ClangExpressionDeclMap *DeclMap() override {
return m_expr_decl_map_up.get();
}
@@ -62,16 +62,15 @@ public:
void ResetDeclMap(ExecutionContext &exe_ctx,
Materializer::PersistentVariableDelegate &result_delegate,
- bool keep_result_in_memory);
+ bool keep_result_in_memory,
+ ValueObject *ctx_obj);
- //------------------------------------------------------------------
/// Return the object that the parser should allow to access ASTs. May be
/// NULL if the ASTs do not need to be transformed.
///
- /// @param[in] passthrough
+ /// \param[in] passthrough
/// The ASTConsumer that the returned transformer should send
/// the ASTs to after transformation.
- //------------------------------------------------------------------
clang::ASTConsumer *
ASTTransformer(clang::ASTConsumer *passthrough) override;
@@ -88,53 +87,55 @@ public:
bool m_top_level;
};
- //------------------------------------------------------------------
/// Constructor
///
- /// @param[in] expr
+ /// \param[in] expr
/// The expression to parse.
///
- /// @param[in] expr_prefix
+ /// \param[in] expr_prefix
/// If non-NULL, a C string containing translation-unit level
/// definitions to be included when the expression is parsed.
///
- /// @param[in] language
+ /// \param[in] language
/// If not eLanguageTypeUnknown, a language to use when parsing
/// the expression. Currently restricted to those languages
/// supported by Clang.
///
- /// @param[in] desired_type
+ /// \param[in] desired_type
/// If not eResultTypeAny, the type to use for the expression
/// result.
- //------------------------------------------------------------------
+ ///
+ /// \param[in] ctx_obj
+ /// The object (if any) in which context the expression
+ /// must be evaluated. For details see the comment to
+ /// `UserExpression::Evaluate`.
ClangUserExpression(ExecutionContextScope &exe_scope, llvm::StringRef expr,
llvm::StringRef prefix, lldb::LanguageType language,
ResultType desired_type,
- const EvaluateExpressionOptions &options);
+ const EvaluateExpressionOptions &options,
+ ValueObject *ctx_obj);
~ClangUserExpression() override;
- //------------------------------------------------------------------
/// Parse the expression
///
- /// @param[in] diagnostic_manager
+ /// \param[in] diagnostic_manager
/// A diagnostic manager to report parse errors and warnings to.
///
- /// @param[in] exe_ctx
+ /// \param[in] exe_ctx
/// The execution context to use when looking up entities that
/// are needed for parsing (locations of functions, types of
/// variables, persistent variables, etc.)
///
- /// @param[in] execution_policy
+ /// \param[in] execution_policy
/// Determines whether interpretation is possible or mandatory.
///
- /// @param[in] keep_result_in_memory
+ /// \param[in] keep_result_in_memory
/// True if the resulting persistent variable should reside in
/// target memory, if applicable.
///
- /// @return
+ /// \return
/// True on success (no errors); false otherwise.
- //------------------------------------------------------------------
bool Parse(DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx,
lldb_private::ExecutionPolicy execution_policy,
bool keep_result_in_memory, bool generate_debug_info) override;
@@ -154,17 +155,18 @@ public:
Materializer::PersistentVariableDelegate &result_delegate,
bool keep_result_in_memory) {
m_type_system_helper.ResetDeclMap(exe_ctx, result_delegate,
- keep_result_in_memory);
+ keep_result_in_memory,
+ m_ctx_obj);
}
lldb::ExpressionVariableSP
GetResultAfterDematerialization(ExecutionContextScope *exe_scope) override;
+ bool DidImportCxxModules() const { return m_imported_cpp_modules; }
+
private:
- //------------------------------------------------------------------
/// Populate m_in_cplusplus_method and m_in_objectivec_method based on the
/// environment.
- //------------------------------------------------------------------
void ScanContext(ExecutionContext &exe_ctx,
lldb_private::Status &err) override;
@@ -173,12 +175,15 @@ private:
lldb::addr_t struct_address,
DiagnosticManager &diagnostic_manager) override;
+ std::vector<std::string> GetModulesToImport(ExecutionContext &exe_ctx);
void UpdateLanguageForExpr(DiagnosticManager &diagnostic_manager,
- ExecutionContext &exe_ctx);
+ ExecutionContext &exe_ctx,
+ std::vector<std::string> modules_to_import,
+ bool for_completion);
bool SetupPersistentState(DiagnosticManager &diagnostic_manager,
ExecutionContext &exe_ctx);
bool PrepareForParsing(DiagnosticManager &diagnostic_manager,
- ExecutionContext &exe_ctx);
+ ExecutionContext &exe_ctx, bool for_completion);
ClangUserExpressionHelper m_type_system_helper;
@@ -199,12 +204,21 @@ private:
/// The language type of the current expression.
lldb::LanguageType m_expr_lang = lldb::eLanguageTypeUnknown;
+ /// The include directories that should be used when parsing the expression.
+ std::vector<ConstString> m_include_directories;
/// The absolute character position in the transformed source code where the
/// user code (as typed by the user) starts. If the variable is empty, then we
/// were not able to calculate this position.
llvm::Optional<size_t> m_user_expression_start_pos;
ResultDelegate m_result_delegate;
+
+ /// The object (if any) in which context the expression is evaluated.
+ /// See the comment to `UserExpression::Evaluate` for details.
+ ValueObject *m_ctx_obj;
+
+ /// True iff this expression explicitly imported C++ modules.
+ bool m_imported_cpp_modules = false;
};
} // namespace lldb_private