21#include "llvm/Support/FormatAdapters.h"
29 return type_system.get()->GetBasicTypeFromAST(basic_type);
36 llvm::StringRef name) {
46static llvm::Expected<lldb::TypeSystemSP>
49 ctx->GetSymbolContext(lldb::eSymbolContextCompUnit);
52 symbol_context = ctx->GetSymbolContext(lldb::eSymbolContextModule);
53 return symbol_context.
module_sp->GetTypeSystemForLanguage(language);
56llvm::Expected<lldb::ValueObjectSP>
59 return llvm::make_error<DILDiagnosticError>(
m_expr,
"invalid value object",
61 llvm::Expected<lldb::TypeSystemSP> type_system =
64 return type_system.takeError();
67 if (valobj->IsBitfield()) {
72 uint32_t bitfield_size = valobj->GetBitfieldBitSize();
75 if (bitfield_size > 0 && in_type.
IsInteger()) {
79 llvm::Expected<uint64_t> int_bit_size =
82 return int_bit_size.takeError();
83 llvm::Expected<uint64_t> uint_bit_size =
86 return uint_bit_size.takeError();
87 if (bitfield_size < *int_bit_size ||
88 (in_type.
IsSigned() && bitfield_size == *int_bit_size))
89 return valobj->CastToBasicType(int_type);
90 if (bitfield_size <= *uint_bit_size)
91 return valobj->CastToBasicType(uint_type);
94 bool resolved = valobj->ResolveValue(scalar);
96 return llvm::createStringError(
"invalid scalar value");
106 valobj->GetCompilerType().GetPromotedIntegerType();
108 return valobj->CastToBasicType(promoted_type);
153 switch (basic_type) {
172llvm::Expected<CompilerType>
177 llvm::Expected<uint64_t> lhs_size =
180 return lhs_size.takeError();
181 llvm::Expected<uint64_t> rhs_size =
184 return rhs_size.takeError();
186 if (*rhs_size == *lhs_size) {
187 llvm::Expected<lldb::TypeSystemSP> type_system =
190 return type_system.takeError();
195 return r_type_unsigned;
201llvm::Expected<CompilerType>
207 return lhs_or_err.takeError();
211 return rhs_or_err.takeError();
227 if (l_rank == 0 || r_rank == 0)
228 return llvm::make_error<DILDiagnosticError>(
229 m_expr,
"unexpected basic type in arithmetic operation", location);
234 using Rank = std::tuple<size_t, bool>;
235 Rank int_l_rank = {l_rank, !lhs_type.
IsSigned()};
236 Rank int_r_rank = {r_rank, !rhs_type.
IsSigned()};
237 if (int_l_rank < int_r_rank) {
240 return type_or_err.takeError();
243 if (int_l_rank > int_r_rank) {
246 return type_or_err.takeError();
261 std::vector<lldb::VariableSP> possible_matches;
264 llvm::StringRef str_ref_name = var_sp->GetName().GetStringRef();
266 str_ref_name.consume_front(
"::");
272 if (var_sp->NameMatches(name))
273 possible_matches.push_back(var_sp);
277 if (possible_matches.size() > 0)
278 return possible_matches[0];
284 llvm::StringRef name_ref, std::shared_ptr<StackFrame> stack_frame,
288 stack_frame->GetSymbolContext(lldb::eSymbolContextCompUnit);
293 name_ref.consume_front(
"::");
300 stack_frame->GetValueObjectForFrameVariable(var_sp, use_dynamic);
308 target_sp->GetImages().FindGlobalVariables(
309 ConstString(name_ref), std::numeric_limits<uint32_t>::max(),
312 if (!modules_var_list.
Empty()) {
325 std::shared_ptr<StackFrame> stack_frame,
329 if (name_ref.consume_front(
"$")) {
334 if (
const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName(name_ref))
340 if (!name_ref.contains(
"::")) {
344 stack_frame->GetInScopeVariableList(
false));
349 variable_list->FindVariable(
ConstString(name_ref));
352 stack_frame->GetValueObjectForFrameVariable(var_sp, use_dynamic);
360 lldb::eSymbolContextFunction | lldb::eSymbolContextBlock);
362 value_sp = stack_frame->FindVariable(
ConstString(instance_name));
364 value_sp = value_sp->GetChildMemberWithName(name_ref);
373 std::shared_ptr<StackFrame> frame_sp,
378 const bool check_ptr_vs_member =
380 const bool no_synth_child =
382 const bool allow_var_updates =
384 const bool disallow_globals =
395 auto value_or_error = node.
Accept(
this);
397 if (value_or_error && !*value_or_error)
398 return llvm::make_error<DILDiagnosticError>(
m_expr,
"invalid value object",
402 return value_or_error;
405llvm::Expected<lldb::ValueObjectSP>
407 auto valobj_or_err =
Evaluate(node);
409 return valobj_or_err;
413 if (valobj->GetCompilerType().IsReferenceType()) {
414 valobj = valobj->Dereference(
error);
416 return error.ToError();
421llvm::Expected<lldb::ValueObjectSP>
433 llvm::formatv(
"use of undeclared identifier '{0}'", node.
GetName());
434 return llvm::make_error<DILDiagnosticError>(
441llvm::Expected<lldb::ValueObjectSP>
454 operand = dynamic_op;
460 child_sp = synth_obj_sp->Dereference(
error);
464 return llvm::make_error<DILDiagnosticError>(
m_expr,
error.AsCString(),
473 return llvm::make_error<DILDiagnosticError>(
m_expr,
error.AsCString(),
479 if (operand->GetCompilerType().IsReferenceType()) {
480 operand = operand->Dereference(
error);
482 return error.ToError();
484 llvm::Expected<lldb::ValueObjectSP> conv_op =
492 llvm::formatv(
"invalid argument type '{0}' to unary expression",
494 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg,
498 bool resolved = operand->ResolveValue(scalar);
509 if (operand->GetCompilerType().IsReferenceType()) {
510 operand = operand->Dereference(
error);
512 return error.ToError();
514 llvm::Expected<lldb::ValueObjectSP> conv_op =
524 llvm::formatv(
"invalid argument type '{0}' to unary expression",
526 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg,
532 return llvm::make_error<DILDiagnosticError>(
m_expr,
"invalid unary operation",
536llvm::Expected<lldb::ValueObjectSP>
540 if (ptr->GetCompilerType().IsPointerToVoid())
541 return llvm::make_error<DILDiagnosticError>(
542 m_expr,
"arithmetic on a pointer to void", location);
543 if (ptr->GetValueAsUnsigned(0) == 0 && offset != 0)
544 return llvm::make_error<DILDiagnosticError>(
545 m_expr,
"arithmetic on a nullptr is undefined", location);
548 int64_t offset_int = offset->GetValueAsSigned(0, &success);
550 std::string errMsg = llvm::formatv(
"could not get the offset: {0}",
551 offset->GetError().AsCString());
552 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
556 llvm::Expected<uint64_t> byte_size =
557 ptr->GetCompilerType().GetPointeeType().GetByteSize(
560 return byte_size.takeError();
561 uint64_t ptr_addr = ptr->GetValueAsUnsigned(0);
563 ptr_addr -= offset_int * (*byte_size);
565 ptr_addr += offset_int * (*byte_size);
573llvm::Expected<lldb::ValueObjectSP>
578 bool l_resolved = lhs->ResolveValue(
l);
581 llvm::formatv(
"invalid lhs value: {0}", lhs->GetError().AsCString());
582 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg, location);
584 bool r_resolved = rhs->ResolveValue(r);
587 llvm::formatv(
"invalid rhs value: {0}", rhs->GetError().AsCString());
588 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg, location);
591 auto value_object = [
this, result_type](
Scalar scalar) {
593 result_type,
"result");
598 return value_object(
l + r);
600 return value_object(
l - r);
602 return value_object(
l * r);
604 return value_object(
l / r);
606 return value_object(
l % r);
608 return llvm::make_error<DILDiagnosticError>(
609 m_expr,
"invalid arithmetic operation", location);
618 auto orig_lhs_type = lhs->GetCompilerType();
619 auto orig_rhs_type = rhs->GetCompilerType();
622 return type_or_err.takeError();
631 if (lhs->GetCompilerType().IsPointerType()) {
634 }
else if (rhs->GetCompilerType().IsPointerType()) {
639 if (!ptr || !offset->GetCompilerType().IsInteger()) {
641 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
642 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
643 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
656 auto orig_lhs_type = lhs->GetCompilerType();
657 auto orig_rhs_type = rhs->GetCompilerType();
660 return type_or_err.takeError();
666 auto lhs_type = lhs->GetCompilerType();
667 auto rhs_type = rhs->GetCompilerType();
670 if (lhs_type.IsPointerType() && rhs_type.IsInteger())
674 if (lhs_type.IsPointerType() && rhs_type.IsPointerType()) {
675 if (lhs_type.IsPointerToVoid() && rhs_type.IsPointerToVoid()) {
676 return llvm::make_error<DILDiagnosticError>(
677 m_expr,
"arithmetic on pointers to void", location);
682 if (!lhs_unqualified_type.
CompareTypes(rhs_unqualified_type)) {
683 std::string errMsg = llvm::formatv(
684 "'{0}' and '{1}' are not pointers to compatible types",
685 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
686 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg, location);
689 llvm::Expected<uint64_t> lhs_byte_size =
692 return lhs_byte_size.takeError();
694 int64_t item_size = *lhs_byte_size;
695 int64_t diff =
static_cast<int64_t
>(lhs->GetValueAsUnsigned(0) -
696 rhs->GetValueAsUnsigned(0));
697 assert(item_size > 0 &&
"Pointee size cannot be 0");
698 if (diff % item_size != 0) {
701 return llvm::make_error<DILDiagnosticError>(
702 m_expr,
"undefined pointer arithmetic", location);
706 llvm::Expected<lldb::TypeSystemSP> type_system =
709 return type_system.takeError();
710 CompilerType ptrdiff_type = type_system.get()->GetPointerDiffType(
true);
712 return llvm::make_error<DILDiagnosticError>(
713 m_expr,
"unable to determine pointer diff type", location);
717 ptrdiff_type,
"result");
721 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
722 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
723 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
731 auto orig_lhs_type = lhs->GetCompilerType();
732 auto orig_rhs_type = rhs->GetCompilerType();
735 return type_or_err.takeError();
740 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
741 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
742 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
753 auto orig_lhs_type = lhs->GetCompilerType();
754 auto orig_rhs_type = rhs->GetCompilerType();
757 return type_or_err.takeError();
762 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
763 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
764 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
769 if (result_type.
IsInteger() && rhs->GetValueAsSigned(-1) == 0) {
770 return llvm::make_error<DILDiagnosticError>(
771 m_expr,
"division by zero is undefined", location);
781 auto orig_lhs_type = lhs->GetCompilerType();
782 auto orig_rhs_type = rhs->GetCompilerType();
785 return type_or_err.takeError();
790 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
791 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
792 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
796 if (rhs->GetValueAsSigned(-1) == 0) {
797 return llvm::make_error<DILDiagnosticError>(
798 m_expr,
"division by zero is undefined", location);
804llvm::Expected<lldb::ValueObjectSP>
816 lhs->GetCompilerType().GetTypeSystem().GetSharedPointer();
818 rhs->GetCompilerType().GetTypeSystem().GetSharedPointer();
819 if (lhs_system->GetPluginName() != rhs_system->GetPluginName()) {
821 return llvm::make_error<DILDiagnosticError>(
838 return llvm::make_error<DILDiagnosticError>(
842llvm::Expected<lldb::ValueObjectSP>
854 if (!base->IsPointerType() && base->HasSyntheticValue()) {
857 base->GetSyntheticValue()->Dereference(deref_error);
858 synth_deref_sp && deref_error.
Success()) {
859 base = std::move(synth_deref_sp);
861 if (!base || deref_error.
Fail()) {
862 std::string errMsg = llvm::formatv(
863 "Failed to dereference synthetic value: {0}", deref_error);
864 return llvm::make_error<DILDiagnosticError>(
870 std::string errMsg =
"Failed to dereference synthetic value";
871 return llvm::make_error<DILDiagnosticError>(
879 bool base_is_ptr = base->IsPointerType();
881 if (expr_is_ptr != base_is_ptr) {
884 llvm::formatv(
"member reference type {0} is a pointer; "
885 "did you mean to use '->'?",
886 base->GetCompilerType().TypeDescription());
887 return llvm::make_error<DILDiagnosticError>(
891 llvm::formatv(
"member reference type {0} is not a pointer; "
892 "did you mean to use '.'?",
893 base->GetCompilerType().TypeDescription());
894 return llvm::make_error<DILDiagnosticError>(
904 field_obj = base->GetSyntheticValue();
906 field_obj = field_obj->GetChildMemberWithName(node.
GetFieldName());
910 std::string errMsg = llvm::formatv(
911 "\"{0}\" is not a member of \"({1}) {2}\"", node.
GetFieldName(),
912 base->GetTypeName().AsCString(
"<invalid type>"), base->GetName());
913 return llvm::make_error<DILDiagnosticError>(
923 field_obj = dynamic_val_sp;
929 if (node.
GetIsArrow() && base->IsPointerType())
931 std::string errMsg = llvm::formatv(
932 "\"{0}\" is not a member of \"({1}) {2}\"", node.
GetFieldName(),
933 base->GetTypeName().AsCString(
"<invalid type>"), base->GetName());
934 return llvm::make_error<DILDiagnosticError>(
938llvm::Expected<lldb::ValueObjectSP>
945 if (!idx->GetCompilerType().IsIntegerOrUnscopedEnumerationType()) {
946 return llvm::make_error<DILDiagnosticError>(
951 uint64_t child_idx = idx->GetValueAsUnsigned(0);
959 CompilerType base_type = base->GetCompilerType().GetNonReferenceType();
960 base->GetExpressionPath(var_expr_path_strm);
961 bool is_incomplete_array =
false;
963 bool is_objc_pointer =
true;
966 is_objc_pointer =
false;
967 else if (!base->GetCompilerType().IsPointerType())
968 is_objc_pointer =
false;
971 std::string err_msg = llvm::formatv(
972 "\"({0}) {1}\" is an Objective-C pointer, and cannot be subscripted",
973 base->GetTypeName().AsCString(
"<invalid type>"),
975 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
978 if (is_objc_pointer) {
980 if (!synthetic || synthetic == base) {
981 std::string err_msg =
982 llvm::formatv(
"\"({0}) {1}\" is not an array type",
983 base->GetTypeName().AsCString(
"<invalid type>"),
985 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
988 if (
static_cast<uint32_t
>(child_idx) >=
989 synthetic->GetNumChildrenIgnoringErrors()) {
990 std::string err_msg = llvm::formatv(
991 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
992 base->GetTypeName().AsCString(
"<invalid type>"),
994 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
997 child_valobj_sp = synthetic->GetChildAtIndex(child_idx);
998 if (!child_valobj_sp) {
999 std::string err_msg = llvm::formatv(
1000 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1001 base->GetTypeName().AsCString(
"<invalid type>"),
1002 var_expr_path_strm.
GetData());
1003 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1007 if (
auto dynamic_sp = child_valobj_sp->GetDynamicValue(
m_use_dynamic))
1008 child_valobj_sp = std::move(dynamic_sp);
1010 return child_valobj_sp;
1013 child_valobj_sp = base->GetSyntheticArrayMember(child_idx,
true);
1014 if (!child_valobj_sp) {
1015 std::string err_msg = llvm::formatv(
1016 "failed to use pointer as array for index {0} for "
1018 child_idx, base->GetTypeName().AsCString(
"<invalid type>"),
1019 var_expr_path_strm.
GetData());
1021 err_msg =
"subscript of pointer to incomplete type 'void'";
1022 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1025 }
else if (base_type.
IsArrayType(
nullptr,
nullptr, &is_incomplete_array)) {
1026 child_valobj_sp = base->GetChildAtIndex(child_idx);
1028 child_valobj_sp = base->GetSyntheticArrayMember(child_idx,
true);
1029 if (!child_valobj_sp) {
1030 std::string err_msg = llvm::formatv(
1031 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1032 base->GetTypeName().AsCString(
"<invalid type>"),
1033 var_expr_path_strm.
GetData());
1034 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1039 base->GetSyntheticBitFieldChild(child_idx, child_idx,
true);
1040 if (!child_valobj_sp) {
1041 std::string err_msg = llvm::formatv(
1042 "bitfield range {0}:{1} is not valid for \"({2}) {3}\"", child_idx,
1043 child_idx, base->GetTypeName().AsCString(
"<invalid type>"),
1044 var_expr_path_strm.
GetData());
1045 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1051 std::string err_msg =
1052 llvm::formatv(
"\"{0}\" is not an array type",
1053 base->GetTypeName().AsCString(
"<invalid type>"));
1054 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1057 if (
static_cast<uint32_t
>(child_idx) >=
1058 synthetic->GetNumChildrenIgnoringErrors(child_idx + 1)) {
1059 std::string err_msg = llvm::formatv(
1060 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1061 base->GetTypeName().AsCString(
"<invalid type>"),
1062 var_expr_path_strm.
GetData());
1063 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1066 child_valobj_sp = synthetic->GetChildAtIndex(child_idx);
1067 if (!child_valobj_sp) {
1068 std::string err_msg = llvm::formatv(
1069 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1070 base->GetTypeName().AsCString(
"<invalid type>"),
1071 var_expr_path_strm.
GetData());
1072 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1077 if (child_valobj_sp) {
1079 if (
auto dynamic_sp = child_valobj_sp->GetDynamicValue(
m_use_dynamic))
1080 child_valobj_sp = std::move(dynamic_sp);
1082 return child_valobj_sp;
1086 int64_t signed_child_idx = idx->GetValueAsSigned(0, &success);
1088 return llvm::make_error<DILDiagnosticError>(
1089 m_expr,
"could not get the index as an integer",
1091 return base->GetSyntheticArrayMember(signed_child_idx,
true);
1094llvm::Expected<lldb::ValueObjectSP>
1097 if (!first_idx_or_err)
1098 return first_idx_or_err;
1101 if (!last_idx_or_err)
1102 return last_idx_or_err;
1105 if (!first_idx->GetCompilerType().IsIntegerOrUnscopedEnumerationType() ||
1106 !last_idx->GetCompilerType().IsIntegerOrUnscopedEnumerationType()) {
1107 return llvm::make_error<DILDiagnosticError>(
1111 bool success_first, success_last;
1112 int64_t first_index = first_idx->GetValueAsSigned(0, &success_first);
1113 int64_t last_index = last_idx->GetValueAsSigned(0, &success_last);
1114 if (!success_first || !success_last)
1115 return llvm::make_error<DILDiagnosticError>(
1119 if (first_index > last_index)
1120 std::swap(first_index, last_index);
1127 base->GetSyntheticBitFieldChild(first_index, last_index,
true);
1128 if (!child_valobj_sp) {
1129 std::string message = llvm::formatv(
1130 "bitfield range {0}:{1} is not valid for \"({2}) {3}\"", first_index,
1131 last_index, base->GetTypeName().AsCString(
"<invalid type>"),
1132 base->GetName().GetStringRef());
1133 return llvm::make_error<DILDiagnosticError>(
m_expr, message,
1136 return child_valobj_sp;
1139llvm::Expected<CompilerType>
1141 std::shared_ptr<ExecutionContextScope> ctx,
1146 llvm::APInt apint = literal.
GetValue();
1148 llvm::SmallVector<std::pair<lldb::BasicType, lldb::BasicType>, 3> candidates;
1159 for (
auto [signed_, unsigned_] : candidates) {
1160 CompilerType signed_type = type_system->GetBasicTypeFromAST(signed_);
1163 llvm::Expected<uint64_t> size = signed_type.
GetBitSize(ctx.get());
1165 return size.takeError();
1166 if (!literal.
IsUnsigned() && apint.isIntN(*size - 1))
1169 return type_system->GetBasicTypeFromAST(unsigned_);
1172 return llvm::make_error<DILDiagnosticError>(
1174 "integer literal is too large to be represented in any integer type",
1178llvm::Expected<lldb::ValueObjectSP>
1180 llvm::Expected<lldb::TypeSystemSP> type_system =
1183 return type_system.takeError();
1185 llvm::Expected<CompilerType> type =
1188 return type.takeError();
1193 llvm::Expected<uint64_t> type_bitsize =
1196 return type_bitsize.takeError();
1202llvm::Expected<lldb::ValueObjectSP>
1204 llvm::Expected<lldb::TypeSystemSP> type_system =
1207 return type_system.takeError();
1210 &node.
GetValue().getSemantics() == &llvm::APFloat::IEEEsingle();
1216 return llvm::make_error<DILDiagnosticError>(
1224llvm::Expected<lldb::ValueObjectSP>
1227 llvm::Expected<lldb::TypeSystemSP> type_system =
1230 return type_system.takeError();
1235llvm::Expected<CastKind>
1240 if (target_type.
GetTypeInfo() & lldb::eTypeIsFloat) {
1241 std::string errMsg = llvm::formatv(
"Cast from {0} to {1} is not allowed",
1244 return llvm::make_error<DILDiagnosticError>(
1245 m_expr, std::move(errMsg), location,
1255 uint64_t type_byte_size = 0;
1256 uint64_t rhs_type_byte_size = 0;
1258 type_byte_size = *temp;
1260 std::string errMsg = llvm::formatv(
"unable to get byte size for type {0}",
1263 "GetByteSize failed: {0}");
1264 return llvm::make_error<DILDiagnosticError>(
1265 m_expr, std::move(errMsg), location,
1270 rhs_type_byte_size = *temp;
1272 std::string errMsg = llvm::formatv(
"unable to get byte size for type {0}",
1275 "GetByteSize failed: {0}");
1276 return llvm::make_error<DILDiagnosticError>(
1277 m_expr, std::move(errMsg), location,
1281 if (type_byte_size < rhs_type_byte_size) {
1282 std::string errMsg = llvm::formatv(
1283 "cast from pointer to smaller type {0} loses information",
1285 return llvm::make_error<DILDiagnosticError>(
1286 m_expr, std::move(errMsg), location,
1291 std::string errMsg = llvm::formatv(
"cannot convert {0} to {1}",
1295 return llvm::make_error<DILDiagnosticError>(
1296 m_expr, std::move(errMsg), location,
1302llvm::Expected<CastKind>
1313 std::string errMsg = llvm::formatv(
"Cast from {0} to {1} is not allowed",
1317 return llvm::make_error<DILDiagnosticError>(
1318 m_expr, std::move(errMsg), location,
1328 std::string errMsg = llvm::formatv(
1329 "cannot cast from type {0} to pointer type {1}",
1332 return llvm::make_error<DILDiagnosticError>(
1333 m_expr, std::move(errMsg), location,
1340 std::string errMsg = llvm::formatv(
1341 "casting of {0} to {1} is not implemented yet",
1343 return llvm::make_error<DILDiagnosticError>(
1344 m_expr, std::move(errMsg), location,
1351 if (!operand_or_err)
1352 return operand_or_err;
1362 operand->GetName().GetStringRef());
1363 op_type = operand->GetCompilerType();
1368 return type_or_err.takeError();
1371 if (operand->GetCompilerType().IsReferenceType()) {
1373 operand = operand->Dereference(
error);
1375 return llvm::make_error<DILDiagnosticError>(
m_expr,
error.AsCString(),
1379 switch (cast_kind) {
1384 return operand->CastToEnumType(target_type);
1390 return operand->CastToBasicType(target_type);
1395 ? operand->GetLoadAddress()
1396 : (op_type.
IsSigned() ? operand->GetValueAsSigned(0)
1397 : operand->GetValueAsUnsigned(0));
1398 llvm::StringRef name =
"result";
1409 std::string errMsg =
1410 llvm::formatv(
"unable to cast from '{0}' to '{1}'",
1412 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG_ERROR(log, error,...)
lldb::VariableListSP GetVariableList(bool can_create)
Get the variable list for a compile unit.
lldb::LanguageType GetLanguage()
Generic representation of a type in a programming language.
bool IsEnumerationType(bool &is_signed) const
lldb::BasicType GetBasicTypeEnumeration() const
bool IsArrayType(CompilerType *element_type=nullptr, uint64_t *size=nullptr, bool *is_incomplete=nullptr) const
CompilerType GetPointerType() const
Return a new CompilerType that is a pointer to this type.
llvm::Expected< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
bool IsPointerToVoid() const
CompilerType GetNonReferenceType() const
If this type is a reference to a type (L value or R value reference), return a new type with the refe...
ConstString GetTypeName(bool BaseOnly=false) const
bool IsReferenceType(CompilerType *pointee_type=nullptr, bool *is_rvalue=nullptr) const
std::string TypeDescription()
CompilerType GetArrayElementType(ExecutionContextScope *exe_scope) const
Creating related types.
bool IsInteger() const
This is used when you don't care about the signedness of the integer.
CompilerType GetPointeeType() const
If this type is a pointer type, return the type that the pointer points to, else return an invalid ty...
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr) const
bool CompareTypes(CompilerType rhs) const
llvm::Expected< uint64_t > GetBitSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bits.
bool IsScalarType() const
bool IsNullPtrType() const
CompilerType GetCanonicalType() const
bool IsPointerType(CompilerType *pointee_type=nullptr) const
A uniqued constant string class.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
virtual void CalculateExecutionContext(ExecutionContext &exe_ctx)=0
Reconstruct the object's execution context into sc.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
void TruncOrExtendTo(uint16_t bits, bool sign)
Convert to an integer with bits and the given signedness.
@ eExpressionPathOptionCheckPtrVsMember
@ eExpressionPathOptionsDisallowGlobals
@ eExpressionPathOptionsAllowVarUpdates
@ eExpressionPathOptionsNoSyntheticChildren
bool Fail() const
Test for error condition.
bool Success() const
Test for success condition.
const char * GetData() const
Defines a symbol context baton that can be handed other debug core functions.
llvm::StringRef GetInstanceName()
Determines the name of the instance for this decl context.
lldb::ModuleSP module_sp
The Module for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, lldb::RegisterContextSP ®_ctx_sp, const RegisterInfo *reg_info)
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, const lldb::VariableSP &var_sp)
static lldb::ValueObjectSP CreateValueObjectFromScalar(const ExecutionContext &exe_ctx, Scalar &s, CompilerType type, llvm::StringRef name, ValueObject *parent=nullptr)
Create a value object containing the given Scalar value.
static lldb::ValueObjectSP CreateValueObjectFromBool(const ExecutionContext &exe_ctx, lldb::TypeSystemSP typesystem, bool value, llvm::StringRef name, ValueObject *parent=nullptr)
Create a value object containing the given boolean value.
lldb::addr_t GetLoadAddress()
Return the target load address associated with this value object.
CompilerType GetCompilerType()
static lldb::ValueObjectSP CreateValueObjectFromAddress(llvm::StringRef name, uint64_t address, const ExecutionContext &exe_ctx, CompilerType type, bool do_deref=true, ValueObject *parent=nullptr)
Given an address either create a value object containing the value at that address,...
The rest of the classes in this file, except for the Visitor class at the very end,...
uint32_t GetLocation() const
virtual llvm::Expected< lldb::ValueObjectSP > Accept(Visitor *v) const =0
ASTNode & GetBase() const
ASTNode & GetIndex() const
BinaryOpKind GetKind() const
ASTNode & GetOperand() const
CompilerType GetType() const
const llvm::APFloat & GetValue() const
std::string GetName() const
uint32_t GetRadix() const
IntegerTypeSuffix GetTypeSuffix() const
const llvm::APInt & GetValue() const
std::shared_ptr< StackFrame > m_exe_ctx_scope
llvm::Expected< lldb::ValueObjectSP > EvaluateBinaryRemainder(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
llvm::Expected< lldb::ValueObjectSP > Evaluate(const ASTNode &node)
Evaluate an ASTNode.
llvm::Expected< lldb::ValueObjectSP > EvaluateBinaryAddition(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
llvm::Expected< lldb::ValueObjectSP > EvaluateAndDereference(const ASTNode &node)
Evaluate an ASTNode.
llvm::Expected< lldb::ValueObjectSP > PointerOffset(lldb::ValueObjectSP ptr, lldb::ValueObjectSP offset, BinaryOpKind operation, uint32_t location)
Add or subtract the offset to the pointer according to the pointee type byte size.
llvm::Expected< lldb::ValueObjectSP > EvaluateScalarOp(BinaryOpKind kind, lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, CompilerType result_type, uint32_t location)
llvm::Expected< CompilerType > PromoteSignedInteger(CompilerType &lhs_type, CompilerType &rhs_type)
If lhs_type is unsigned and rhs_type is signed, check whether it can represent all of the values of l...
llvm::Expected< lldb::ValueObjectSP > EvaluateBinarySubtraction(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
llvm::Expected< lldb::ValueObjectSP > UnaryConversion(lldb::ValueObjectSP valobj, uint32_t location)
Perform usual unary conversions on a value.
llvm::Expected< lldb::ValueObjectSP > Visit(const IdentifierNode &node) override
bool m_check_ptr_vs_member
llvm::Expected< CompilerType > PickIntegerType(lldb::TypeSystemSP type_system, std::shared_ptr< ExecutionContextScope > ctx, const IntegerLiteralNode &literal)
llvm::Expected< lldb::ValueObjectSP > EvaluateBinaryDivision(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
Interpreter(lldb::TargetSP target, llvm::StringRef expr, std::shared_ptr< StackFrame > frame_sp, lldb::DynamicValueType use_dynamic, uint32_t options)
lldb::DynamicValueType m_use_dynamic
llvm::Expected< CompilerType > ArithmeticConversion(lldb::ValueObjectSP &lhs, lldb::ValueObjectSP &rhs, uint32_t location)
Perform an arithmetic conversion on two values from an arithmetic operation.
llvm::Expected< lldb::ValueObjectSP > EvaluateBinaryMultiplication(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
llvm::Expected< CastKind > VerifyCastType(lldb::ValueObjectSP operand, CompilerType source_type, CompilerType target_type, int location)
As a preparation for type casting, compare the requested 'target' type of the cast with the type of t...
llvm::Expected< CastKind > VerifyArithmeticCast(CompilerType source_type, CompilerType target_type, int location)
A helper function for VerifyCastType (below).
llvm::StringRef GetFieldName() const
ASTNode & GetBase() const
UnaryOpKind GetKind() const
ASTNode & GetOperand() const
CastKind
The type casts allowed by DIL.
@ eEnumeration
Casting from a scalar to an enumeration type.
@ ePointer
Casting to a pointer type.
@ eNone
Invalid promotion type (results in error).
@ eArithmetic
Casting to a scalar.
static lldb::BasicType BasicTypeToUnsigned(lldb::BasicType basic_type)
static llvm::Expected< lldb::TypeSystemSP > GetTypeSystemFromCU(std::shared_ptr< StackFrame > ctx)
static CompilerType GetBasicType(lldb::TypeSystemSP type_system, lldb::BasicType basic_type)
static lldb::ValueObjectSP ArrayToPointerConversion(ValueObject &valobj, ExecutionContextScope &ctx, llvm::StringRef name)
BinaryOpKind
The binary operators recognized by DIL.
static size_t ConversionRank(CompilerType type)
Basic types with a lower rank are converted to the basic type with a higher rank.
static lldb::VariableSP DILFindVariable(ConstString name, VariableList &variable_list)
lldb::ValueObjectSP LookupGlobalIdentifier(llvm::StringRef name_ref, std::shared_ptr< StackFrame > frame_sp, lldb::TargetSP target_sp, lldb::DynamicValueType use_dynamic)
Given the name of an identifier, check to see if it matches the name of a global variable.
lldb::ValueObjectSP LookupIdentifier(llvm::StringRef name_ref, std::shared_ptr< StackFrame > frame_sp, lldb::DynamicValueType use_dynamic)
Given the name of an identifier (variable name, member name, type name, etc.), find the ValueObject f...
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
std::shared_ptr< lldb_private::TypeSystem > TypeSystemSP
BasicType
Basic types enumeration for the public API SBType::GetBasicType().
@ eBasicTypeUnsignedShort
@ eBasicTypeUnsignedInt128
@ eBasicTypeUnsignedLongLong
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
LanguageType
Programming language type.
@ eLanguageTypeObjC
Objective-C.
std::shared_ptr< lldb_private::VariableList > VariableListSP
std::shared_ptr< lldb_private::Variable > VariableSP
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
Every register is described in detail including its name, alternate name (optional),...