summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaroline Tice <cmtice@google.com>2024-12-23 07:52:38 -0800
committerCaroline Tice <cmtice@google.com>2024-12-23 07:52:38 -0800
commit34b2abd3d38d0411211af505796cfa2e82c3a7fb (patch)
treec30b04cf2bedeb4fb8fac90d79074b5dad57e2c4
parentb5f75e9c20ec993090ad3d14d4d4fe75c88ad8cb (diff)
Fix DIL FormatDiagnostics issues.users/cmtice/DIL-collaboration-work
Fix the bug, so we can now use the full formatting again. Also, move FormatDiagnostics out of the DILParser class, so both the parser and the intepreter can call it, and remove the static redundant copy of the function from DILEval.
-rw-r--r--lldb/include/lldb/ValueObject/DILParser.h7
-rw-r--r--lldb/source/ValueObject/DILEval.cpp43
-rw-r--r--lldb/source/ValueObject/DILParser.cpp63
3 files changed, 34 insertions, 79 deletions
diff --git a/lldb/include/lldb/ValueObject/DILParser.h b/lldb/include/lldb/ValueObject/DILParser.h
index 8fc9ad812808..587959f228db 100644
--- a/lldb/include/lldb/ValueObject/DILParser.h
+++ b/lldb/include/lldb/ValueObject/DILParser.h
@@ -59,6 +59,9 @@ enum class ErrorCode : unsigned char {
kUnknown,
};
+std::string FormatDiagnostics(DILSourceManager& sm, const std::string& message,
+ uint32_t loc);
+
void SetUbStatus(Status& error, ErrorCode code);
/// TypeDeclaration builds information about the literal type definition as
@@ -220,10 +223,6 @@ class DILParser {
std::string TokenDescription(const DILToken& token);
- std::string FormatDiagnostics(DILSourceManager& sm,
- const std::string& message,
- uint32_t loc);
-
template <typename... Ts>
void ExpectOneOf(dil::TokenKind k, Ts... ks);
diff --git a/lldb/source/ValueObject/DILEval.cpp b/lldb/source/ValueObject/DILEval.cpp
index 396a3795cff5..a0ac3b52fd7a 100644
--- a/lldb/source/ValueObject/DILEval.cpp
+++ b/lldb/source/ValueObject/DILEval.cpp
@@ -237,46 +237,6 @@ lldb::ValueObjectSP DILInterpreter::EvaluateMemberOf(lldb::ValueObjectSP value,
return member_val_sp;
}
-static std::string FormatDiagnostics(std::shared_ptr<DILSourceManager> sm,
- const std::string& message,
- uint32_t loc,
- ErrorCode code)
-{
- const char *ecode_names[7] = {
- "kOK", "kInvalidExpressionSyntax", "kInvalidNumericLiteral",
- "kInvalidOperandType", "kUndeclaredIdentifier", "kNotImplemented",
- "kUnknown"};
-
- // Translate ErrorCode
- llvm::StringRef error_code = ecode_names[(int)code];
-
- // Get the source buffer and the location of the current token.
- llvm::StringRef text(sm->GetSource());
- size_t loc_offset = (size_t) loc;
-
- // Look for the start of the line.
- size_t line_start = text.rfind('\n', loc_offset);
- line_start = line_start == llvm::StringRef::npos ? 0 : line_start + 1;
-
- // Look for the end of the line.
- size_t line_end = text.find('\n', loc_offset);
- line_end = line_end == llvm::StringRef::npos ? text.size() : line_end;
-
- // Get a view of the current line in the source code and the position of the
- // diagnostics pointer.
- llvm::StringRef line = text.slice(line_start, line_end);
- int32_t arrow = loc;
-
- // Calculate the padding in case we point outside of the expression (this can
- // happen if the parser expected something, but got EOF).
- size_t expr_rpad = std::max(0, arrow - static_cast<int32_t>(line.size()));
- size_t arrow_rpad = std::max(0, static_cast<int32_t>(line.size()) - arrow);
-
- return llvm::formatv("{0}: {1}\n{2}\n{3}", error_code, message,
- llvm::fmt_pad(line, 0, expr_rpad),
- llvm::fmt_pad("^", arrow - 1, arrow_rpad));
-}
-
void SetUbStatus(Status& error, ErrorCode code) {
llvm::StringRef err_str;
switch ((int) code) {
@@ -372,7 +332,8 @@ lldb::ValueObjectSP DILInterpreter::DILEvalNode(const DILASTNode* node,
void DILInterpreter::SetError(ErrorCode code, std::string error,
uint32_t loc) {
assert(m_error.Success() && "interpreter can error only once");
- m_error = Status(FormatDiagnostics(m_sm, error, loc, code));
+ m_error = Status((uint32_t) code, lldb::eErrorTypeGeneric,
+ FormatDiagnostics(*m_sm, error, loc));
}
void DILInterpreter::Visit(const ErrorNode* node) {
diff --git a/lldb/source/ValueObject/DILParser.cpp b/lldb/source/ValueObject/DILParser.cpp
index 2d828238ee26..147af6c02e6a 100644
--- a/lldb/source/ValueObject/DILParser.cpp
+++ b/lldb/source/ValueObject/DILParser.cpp
@@ -679,6 +679,35 @@ lldb::BasicType PickCharType(const dil::StringLiteralParser& literal) {
return lldb::eBasicTypeChar;
}
+std::string FormatDiagnostics(DILSourceManager& sm, const std::string& message,
+ uint32_t loc) {
+ // Get the source buffer and the location of the current token.
+ llvm::StringRef text = sm.GetSource();
+ size_t loc_offset = (size_t) loc;
+
+ // Look for the start of the line.
+ size_t line_start = text.rfind('\n', loc_offset);
+ line_start = line_start == llvm::StringRef::npos ? 0 : line_start + 1;
+
+ // Look for the end of the line.
+ size_t line_end = text.find('\n', loc_offset);
+ line_end = line_end == llvm::StringRef::npos ? text.size() : line_end;
+
+ // Get a view of the current line in the source code and the position of the
+ // diagnostics pointer.
+ llvm::StringRef line = text.slice(line_start, line_end);
+ int32_t arrow = loc + 1; // Column offset starts at 1, not 0.
+
+ // Calculate the padding in case we point outside of the expression (this can
+ // happen if the parser expected something, but got EOF).˚
+ size_t expr_rpad = std::max(0, arrow - static_cast<int32_t>(line.size()));
+ size_t arrow_rpad = std::max(0, static_cast<int32_t>(line.size()) - arrow);
+
+ return llvm::formatv("<expr:1:{0}>: {1}\n{2}\n{3}", loc,
+ message, llvm::fmt_pad(line, 0, expr_rpad),
+ llvm::fmt_pad("^", arrow - 1, arrow_rpad));
+}
+
DILParser::DILParser(std::shared_ptr<DILSourceManager> dil_sm,
std::shared_ptr<ExecutionContextScope> exe_ctx_scope,
lldb::DynamicValueType use_dynamic, bool use_synthetic,
@@ -4046,40 +4075,6 @@ std::string DILParser::TokenDescription(const DILToken& token) {
return llvm::formatv("<'{0}' ({1})>", spelling, kind_name);
}
-std::string DILParser::FormatDiagnostics(
- DILSourceManager& sm,
- const std::string& message,
- uint32_t loc) {
- return message; // CAROLINE!! TODO: Fix this?
-
- // Get the source buffer and the location of the current token.
- llvm::StringRef text = sm.GetSource();
- size_t loc_offset = (size_t) loc;
-
- // Look for the start of the line.
- size_t line_start = text.rfind('\n', loc_offset);
- line_start = line_start == llvm::StringRef::npos ? 0 : line_start + 1;
-
- // Look for the end of the line.
- size_t line_end = text.find('\n', loc_offset);
- line_end = line_end == llvm::StringRef::npos ? text.size() : line_end;
-
- // Get a view of the current line in the source code and the position of the
- // diagnostics pointer.
- llvm::StringRef line = text.slice(line_start, line_end);
- int32_t arrow = loc;
-
- // Calculate the padding in case we point outside of the expression (this can
- // happen if the parser expected something, but got EOF).˚
- size_t expr_rpad = std::max(0, arrow - static_cast<int32_t>(line.size()));
- size_t arrow_rpad = std::max(0, static_cast<int32_t>(line.size()) - arrow);
-
- //return llvm::formatv("<expr:1:{0}>: {1}\n{2}\n{3}", loc,
- return llvm::formatv("{0}: {1}\n{2}\n{3}", loc,
- message, llvm::fmt_pad(line, 0, expr_rpad),
- llvm::fmt_pad("^", arrow - 1, arrow_rpad));
-}
-
bool DILParser::ImplicitConversionIsAllowed(CompilerType src, CompilerType dst,
bool is_src_literal_zero) {
if (dst.IsInteger() || dst.IsFloat()) {