forked from OSchip/llvm-project
Refactor ClangUserExpression::GetLanguageForExpr
Summary: The `ClangUserExpression::GetLanguageForExpr` method is currently a big source of sadness, as it's name implies that it's an accessor method, but it actually is also initializing some variables that we need for parsing. This caused that we currently call this getter just for it's side effects while ignoring it's return value, which is confusing for the reader. This patch renames it to `UpdateLanguageForExpr` and merges all calls to the method into a single call in `ClangUserExpression::PrepareForParsing` (as calling this method is anyway mandatory for parsing to succeed) While looking at the code, I also found that we actually have two language variables in this class hierarchy. The normal `Language` from the UserExpression class and the `LanguageForExpr` that we implemented in this subclass. Both don't seem to actually contain the same value, so we probably should look at this next. Reviewers: xbolva00 Reviewed By: xbolva00 Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D52561 llvm-svn: 343191
This commit is contained in:
parent
436c012702
commit
dababf70e2
|
@ -376,9 +376,9 @@ static void SetupDeclVendor(ExecutionContext &exe_ctx, Target *target) {
|
|||
}
|
||||
}
|
||||
|
||||
llvm::Optional<lldb::LanguageType> ClangUserExpression::GetLanguageForExpr(
|
||||
void ClangUserExpression::UpdateLanguageForExpr(
|
||||
DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx) {
|
||||
lldb::LanguageType lang_type = lldb::LanguageType::eLanguageTypeUnknown;
|
||||
m_expr_lang = lldb::LanguageType::eLanguageTypeUnknown;
|
||||
|
||||
std::string prefix = m_expr_prefix;
|
||||
|
||||
|
@ -390,17 +390,17 @@ llvm::Optional<lldb::LanguageType> ClangUserExpression::GetLanguageForExpr(
|
|||
m_expr_text.c_str()));
|
||||
|
||||
if (m_in_cplusplus_method)
|
||||
lang_type = lldb::eLanguageTypeC_plus_plus;
|
||||
m_expr_lang = lldb::eLanguageTypeC_plus_plus;
|
||||
else if (m_in_objectivec_method)
|
||||
lang_type = lldb::eLanguageTypeObjC;
|
||||
m_expr_lang = lldb::eLanguageTypeObjC;
|
||||
else
|
||||
lang_type = lldb::eLanguageTypeC;
|
||||
m_expr_lang = lldb::eLanguageTypeC;
|
||||
|
||||
if (!source_code->GetText(m_transformed_text, lang_type, m_in_static_method,
|
||||
exe_ctx)) {
|
||||
if (!source_code->GetText(m_transformed_text, m_expr_lang,
|
||||
m_in_static_method, exe_ctx)) {
|
||||
diagnostic_manager.PutString(eDiagnosticSeverityError,
|
||||
"couldn't construct expression body");
|
||||
return llvm::Optional<lldb::LanguageType>();
|
||||
return;
|
||||
}
|
||||
|
||||
// Find and store the start position of the original code inside the
|
||||
|
@ -408,12 +408,11 @@ llvm::Optional<lldb::LanguageType> ClangUserExpression::GetLanguageForExpr(
|
|||
std::size_t original_start;
|
||||
std::size_t original_end;
|
||||
bool found_bounds = source_code->GetOriginalBodyBounds(
|
||||
m_transformed_text, lang_type, original_start, original_end);
|
||||
m_transformed_text, m_expr_lang, original_start, original_end);
|
||||
if (found_bounds) {
|
||||
m_user_expression_start_pos = original_start;
|
||||
}
|
||||
}
|
||||
return lang_type;
|
||||
}
|
||||
|
||||
bool ClangUserExpression::PrepareForParsing(
|
||||
|
@ -437,6 +436,8 @@ bool ClangUserExpression::PrepareForParsing(
|
|||
ApplyObjcCastHack(m_expr_text);
|
||||
|
||||
SetupDeclVendor(exe_ctx, m_target);
|
||||
|
||||
UpdateLanguageForExpr(diagnostic_manager, exe_ctx);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -450,11 +451,6 @@ bool ClangUserExpression::Parse(DiagnosticManager &diagnostic_manager,
|
|||
if (!PrepareForParsing(diagnostic_manager, exe_ctx))
|
||||
return false;
|
||||
|
||||
lldb::LanguageType lang_type = lldb::LanguageType::eLanguageTypeUnknown;
|
||||
if (auto new_lang = GetLanguageForExpr(diagnostic_manager, exe_ctx)) {
|
||||
lang_type = new_lang.getValue();
|
||||
}
|
||||
|
||||
if (log)
|
||||
log->Printf("Parsing the following code:\n%s", m_transformed_text.c_str());
|
||||
|
||||
|
@ -514,7 +510,7 @@ bool ClangUserExpression::Parse(DiagnosticManager &diagnostic_manager,
|
|||
const std::string &fixed_expression =
|
||||
diagnostic_manager.GetFixedExpression();
|
||||
if (ExpressionSourceCode::GetOriginalBodyBounds(
|
||||
fixed_expression, lang_type, fixed_start, fixed_end))
|
||||
fixed_expression, m_expr_lang, fixed_start, fixed_end))
|
||||
m_fixed_text =
|
||||
fixed_expression.substr(fixed_start, fixed_end - fixed_start);
|
||||
}
|
||||
|
@ -655,8 +651,6 @@ bool ClangUserExpression::Complete(ExecutionContext &exe_ctx,
|
|||
if (!PrepareForParsing(diagnostic_manager, exe_ctx))
|
||||
return false;
|
||||
|
||||
GetLanguageForExpr(diagnostic_manager, exe_ctx);
|
||||
|
||||
if (log)
|
||||
log->Printf("Parsing the following code:\n%s", m_transformed_text.c_str());
|
||||
|
||||
|
|
|
@ -177,8 +177,8 @@ private:
|
|||
lldb::addr_t struct_address,
|
||||
DiagnosticManager &diagnostic_manager) override;
|
||||
|
||||
llvm::Optional<lldb::LanguageType> GetLanguageForExpr(
|
||||
DiagnosticManager &diagnostic_manager, ExecutionContext &exe_ctx);
|
||||
void UpdateLanguageForExpr(DiagnosticManager &diagnostic_manager,
|
||||
ExecutionContext &exe_ctx);
|
||||
bool SetupPersistentState(DiagnosticManager &diagnostic_manager,
|
||||
ExecutionContext &exe_ctx);
|
||||
bool PrepareForParsing(DiagnosticManager &diagnostic_manager,
|
||||
|
@ -201,6 +201,9 @@ private:
|
|||
lldb::TargetSP m_target_sp;
|
||||
};
|
||||
|
||||
/// The language type of the current expression.
|
||||
lldb::LanguageType m_expr_lang = lldb::eLanguageTypeUnknown;
|
||||
|
||||
/// 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.
|
||||
|
|
Loading…
Reference in New Issue