================
@@ -393,6 +474,82 @@ Interpreter::Visit(const UnaryOpNode &node) {
node.GetLocation());
}
+llvm::Expected<lldb::ValueObjectSP>
+Interpreter::EvaluateScalarOp(BinaryOpKind kind, lldb::ValueObjectSP lhs,
+ lldb::ValueObjectSP rhs, CompilerType
result_type,
+ uint32_t location) {
+ Scalar l, r;
+ bool l_resolved = lhs->ResolveValue(l);
+ bool r_resolved = rhs->ResolveValue(r);
+
+ if (!l_resolved || !r_resolved)
+ return llvm::make_error<DILDiagnosticError>(m_expr, "invalid scalar value",
+ location);
+
+ auto value_object = [this, result_type](Scalar scalar) {
+ return ValueObject::CreateValueObjectFromScalar(m_target, scalar,
+ result_type, "result");
+ };
+
+ switch (kind) {
+ case BinaryOpKind::Add:
+ return value_object(l + r);
+ }
+ return llvm::make_error<DILDiagnosticError>(
+ m_expr, "invalid arithmetic operation", location);
+}
+
+llvm::Expected<lldb::ValueObjectSP> Interpreter::EvaluateBinaryAddition(
+ lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location) {
+ // Operation '+' works for:
+ // {scalar,unscoped_enum} <-> {scalar,unscoped_enum}
+ // TODO: Pointer arithmetics
+ auto orig_lhs_type = lhs->GetCompilerType();
+ auto orig_rhs_type = rhs->GetCompilerType();
+ auto type_or_err = ArithmeticConversion(lhs, rhs, location);
+ if (!type_or_err)
+ return type_or_err.takeError();
+ CompilerType result_type = *type_or_err;
+
+ if (result_type.IsScalarType())
+ return EvaluateScalarOp(BinaryOpKind::Add, lhs, rhs, result_type,
location);
+
+ std::string errMsg =
+ llvm::formatv("invalid operands to binary expression ('{0}' and '{1}')",
+ orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
+ return llvm::make_error<DILDiagnosticError>(m_expr, errMsg, location);
----------------
Michael137 wrote:
```suggestion
return llvm::make_error<DILDiagnosticError>(m_expr, std::move(errMsg),
location);
```
or possibly inline it into the call?
https://github.com/llvm/llvm-project/pull/177208
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits