20#include "llvm/Support/FormatAdapters.h"
28 return type_system.get()->GetBasicTypeFromAST(basic_type);
35 llvm::StringRef name) {
45static llvm::Expected<lldb::TypeSystemSP>
48 ctx->GetSymbolContext(lldb::eSymbolContextCompUnit);
51 symbol_context = ctx->GetSymbolContext(lldb::eSymbolContextModule);
52 return symbol_context.
module_sp->GetTypeSystemForLanguage(language);
55llvm::Expected<lldb::ValueObjectSP>
58 return llvm::make_error<DILDiagnosticError>(
m_expr,
"invalid value object",
60 llvm::Expected<lldb::TypeSystemSP> type_system =
63 return type_system.takeError();
66 if (valobj->IsBitfield()) {
71 uint32_t bitfield_size = valobj->GetBitfieldBitSize();
74 if (bitfield_size > 0 && in_type.
IsInteger()) {
78 llvm::Expected<uint64_t> int_bit_size =
81 return int_bit_size.takeError();
82 llvm::Expected<uint64_t> uint_bit_size =
85 return int_bit_size.takeError();
86 if (bitfield_size < *int_bit_size ||
87 (in_type.
IsSigned() && bitfield_size == *int_bit_size))
88 return valobj->CastToBasicType(int_type);
89 if (bitfield_size <= *uint_bit_size)
90 return valobj->CastToBasicType(uint_type);
93 bool resolved = valobj->ResolveValue(scalar);
95 return llvm::createStringError(
"invalid scalar value");
105 valobj->GetCompilerType().GetPromotedIntegerType();
107 return valobj->CastToBasicType(promoted_type);
152 switch (basic_type) {
171llvm::Expected<CompilerType>
176 llvm::Expected<uint64_t> lhs_size =
179 return lhs_size.takeError();
180 llvm::Expected<uint64_t> rhs_size =
183 return rhs_size.takeError();
185 if (*rhs_size == *lhs_size) {
186 llvm::Expected<lldb::TypeSystemSP> type_system =
189 return type_system.takeError();
194 return r_type_unsigned;
200llvm::Expected<CompilerType>
206 return lhs_or_err.takeError();
210 return rhs_or_err.takeError();
226 if (l_rank == 0 || r_rank == 0)
227 return llvm::make_error<DILDiagnosticError>(
228 m_expr,
"unexpected basic type in arithmetic operation", location);
233 using Rank = std::tuple<size_t, bool>;
234 Rank int_l_rank = {l_rank, !lhs_type.
IsSigned()};
235 Rank int_r_rank = {r_rank, !rhs_type.
IsSigned()};
236 if (int_l_rank < int_r_rank) {
239 return type_or_err.takeError();
242 if (int_l_rank > int_r_rank) {
245 return type_or_err.takeError();
260 std::vector<lldb::VariableSP> possible_matches;
263 llvm::StringRef str_ref_name = var_sp->GetName().GetStringRef();
265 str_ref_name.consume_front(
"::");
271 if (var_sp->NameMatches(name))
272 possible_matches.push_back(var_sp);
276 if (possible_matches.size() > 0)
277 return possible_matches[0];
283 llvm::StringRef name_ref, std::shared_ptr<StackFrame> stack_frame,
287 stack_frame->GetSymbolContext(lldb::eSymbolContextCompUnit);
292 name_ref.consume_front(
"::");
299 stack_frame->GetValueObjectForFrameVariable(var_sp, use_dynamic);
307 target_sp->GetImages().FindGlobalVariables(
308 ConstString(name_ref), std::numeric_limits<uint32_t>::max(),
311 if (!modules_var_list.
Empty()) {
324 std::shared_ptr<StackFrame> stack_frame,
328 if (name_ref.consume_front(
"$")) {
333 if (
const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName(name_ref))
339 if (!name_ref.contains(
"::")) {
343 stack_frame->GetInScopeVariableList(
false));
348 variable_list->FindVariable(
ConstString(name_ref));
351 stack_frame->GetValueObjectForFrameVariable(var_sp, use_dynamic);
359 lldb::eSymbolContextFunction | lldb::eSymbolContextBlock);
361 value_sp = stack_frame->FindVariable(
ConstString(ivar_name));
363 value_sp = value_sp->GetChildMemberWithName(name_ref);
372 std::shared_ptr<StackFrame> frame_sp,
377 const bool check_ptr_vs_member =
379 const bool no_fragile_ivar =
381 const bool no_synth_child =
383 const bool allow_var_updates =
385 const bool disallow_globals =
397 auto value_or_error = node.
Accept(
this);
399 if (value_or_error && !*value_or_error)
400 return llvm::make_error<DILDiagnosticError>(
m_expr,
"invalid value object",
404 return value_or_error;
407llvm::Expected<lldb::ValueObjectSP>
409 auto valobj_or_err =
Evaluate(node);
411 return valobj_or_err;
415 if (valobj->GetCompilerType().IsReferenceType()) {
416 valobj = valobj->Dereference(
error);
418 return error.ToError();
423llvm::Expected<lldb::ValueObjectSP>
435 llvm::formatv(
"use of undeclared identifier '{0}'", node.
GetName());
436 return llvm::make_error<DILDiagnosticError>(
443llvm::Expected<lldb::ValueObjectSP>
456 operand = dynamic_op;
462 child_sp = synth_obj_sp->Dereference(
error);
466 return llvm::make_error<DILDiagnosticError>(
m_expr,
error.AsCString(),
475 return llvm::make_error<DILDiagnosticError>(
m_expr,
error.AsCString(),
481 if (operand->GetCompilerType().IsReferenceType()) {
482 operand = operand->Dereference(
error);
484 return error.ToError();
486 llvm::Expected<lldb::ValueObjectSP> conv_op =
494 llvm::formatv(
"invalid argument type '{0}' to unary expression",
496 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg,
500 bool resolved = operand->ResolveValue(scalar);
511 if (operand->GetCompilerType().IsReferenceType()) {
512 operand = operand->Dereference(
error);
514 return error.ToError();
516 llvm::Expected<lldb::ValueObjectSP> conv_op =
526 llvm::formatv(
"invalid argument type '{0}' to unary expression",
528 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg,
534 return llvm::make_error<DILDiagnosticError>(
m_expr,
"invalid unary operation",
538llvm::Expected<lldb::ValueObjectSP>
542 if (ptr->GetCompilerType().IsPointerToVoid())
543 return llvm::make_error<DILDiagnosticError>(
544 m_expr,
"arithmetic on a pointer to void", location);
545 if (ptr->GetValueAsUnsigned(0) == 0 && offset != 0)
546 return llvm::make_error<DILDiagnosticError>(
547 m_expr,
"arithmetic on a nullptr is undefined", location);
550 int64_t offset_int = offset->GetValueAsSigned(0, &success);
552 std::string errMsg = llvm::formatv(
"could not get the offset: {0}",
553 offset->GetError().AsCString());
554 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
558 llvm::Expected<uint64_t> byte_size =
559 ptr->GetCompilerType().GetPointeeType().GetByteSize(
562 return byte_size.takeError();
563 uint64_t ptr_addr = ptr->GetValueAsUnsigned(0);
565 ptr_addr -= offset_int * (*byte_size);
567 ptr_addr += offset_int * (*byte_size);
575llvm::Expected<lldb::ValueObjectSP>
580 bool l_resolved = lhs->ResolveValue(
l);
583 llvm::formatv(
"invalid lhs value: {0}", lhs->GetError().AsCString());
584 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg, location);
586 bool r_resolved = rhs->ResolveValue(r);
589 llvm::formatv(
"invalid rhs value: {0}", rhs->GetError().AsCString());
590 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg, location);
593 auto value_object = [
this, result_type](
Scalar scalar) {
595 result_type,
"result");
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 value_object(
l % r);
610 return llvm::make_error<DILDiagnosticError>(
611 m_expr,
"invalid arithmetic operation", location);
620 auto orig_lhs_type = lhs->GetCompilerType();
621 auto orig_rhs_type = rhs->GetCompilerType();
624 return type_or_err.takeError();
633 if (lhs->GetCompilerType().IsPointerType()) {
636 }
else if (rhs->GetCompilerType().IsPointerType()) {
641 if (!ptr || !offset->GetCompilerType().IsInteger()) {
643 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
644 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
645 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
658 auto orig_lhs_type = lhs->GetCompilerType();
659 auto orig_rhs_type = rhs->GetCompilerType();
662 return type_or_err.takeError();
668 auto lhs_type = lhs->GetCompilerType();
669 auto rhs_type = rhs->GetCompilerType();
672 if (lhs_type.IsPointerType() && rhs_type.IsInteger())
676 if (lhs_type.IsPointerType() && rhs_type.IsPointerType()) {
677 if (lhs_type.IsPointerToVoid() && rhs_type.IsPointerToVoid()) {
678 return llvm::make_error<DILDiagnosticError>(
679 m_expr,
"arithmetic on pointers to void", location);
684 if (!lhs_unqualified_type.
CompareTypes(rhs_unqualified_type)) {
685 std::string errMsg = llvm::formatv(
686 "'{0}' and '{1}' are not pointers to compatible types",
687 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
688 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg, location);
691 llvm::Expected<uint64_t> lhs_byte_size =
694 return lhs_byte_size.takeError();
696 int64_t item_size = *lhs_byte_size;
697 int64_t diff =
static_cast<int64_t
>(lhs->GetValueAsUnsigned(0) -
698 rhs->GetValueAsUnsigned(0));
699 assert(item_size > 0 &&
"Pointee size cannot be 0");
700 if (diff % item_size != 0) {
703 return llvm::make_error<DILDiagnosticError>(
704 m_expr,
"undefined pointer arithmetic", location);
708 llvm::Expected<lldb::TypeSystemSP> type_system =
711 return type_system.takeError();
712 CompilerType ptrdiff_type = type_system.get()->GetPointerDiffType(
true);
714 return llvm::make_error<DILDiagnosticError>(
715 m_expr,
"unable to determine pointer diff type", location);
719 ptrdiff_type,
"result");
723 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
724 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
725 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
733 auto orig_lhs_type = lhs->GetCompilerType();
734 auto orig_rhs_type = rhs->GetCompilerType();
737 return type_or_err.takeError();
742 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
743 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
744 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
755 auto orig_lhs_type = lhs->GetCompilerType();
756 auto orig_rhs_type = rhs->GetCompilerType();
759 return type_or_err.takeError();
764 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
765 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
766 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
771 if (result_type.
IsInteger() && rhs->GetValueAsSigned(-1) == 0) {
772 return llvm::make_error<DILDiagnosticError>(
773 m_expr,
"division by zero is undefined", location);
783 auto orig_lhs_type = lhs->GetCompilerType();
784 auto orig_rhs_type = rhs->GetCompilerType();
787 return type_or_err.takeError();
792 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
793 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
794 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
798 if (rhs->GetValueAsSigned(-1) == 0) {
799 return llvm::make_error<DILDiagnosticError>(
800 m_expr,
"division by zero is undefined", location);
806llvm::Expected<lldb::ValueObjectSP>
818 lhs->GetCompilerType().GetTypeSystem().GetSharedPointer();
820 rhs->GetCompilerType().GetTypeSystem().GetSharedPointer();
821 if (lhs_system->GetPluginName() != rhs_system->GetPluginName()) {
823 return llvm::make_error<DILDiagnosticError>(
840 return llvm::make_error<DILDiagnosticError>(
844llvm::Expected<lldb::ValueObjectSP>
857 const uint32_t pointer_type_flags =
858 base->GetCompilerType().GetTypeInfo(
nullptr);
859 if ((pointer_type_flags & lldb::eTypeIsObjC) &&
860 (pointer_type_flags & lldb::eTypeIsPointer)) {
869 if (!base->IsPointerType() && base->HasSyntheticValue()) {
872 base->GetSyntheticValue()->Dereference(deref_error);
873 synth_deref_sp && deref_error.
Success()) {
874 base = std::move(synth_deref_sp);
876 if (!base || deref_error.
Fail()) {
877 std::string errMsg = llvm::formatv(
878 "Failed to dereference synthetic value: {0}", deref_error);
879 return llvm::make_error<DILDiagnosticError>(
885 std::string errMsg =
"Failed to dereference synthetic value";
886 return llvm::make_error<DILDiagnosticError>(
894 bool base_is_ptr = base->IsPointerType();
896 if (expr_is_ptr != base_is_ptr) {
899 llvm::formatv(
"member reference type {0} is a pointer; "
900 "did you mean to use '->'?",
901 base->GetCompilerType().TypeDescription());
902 return llvm::make_error<DILDiagnosticError>(
906 llvm::formatv(
"member reference type {0} is not a pointer; "
907 "did you mean to use '.'?",
908 base->GetCompilerType().TypeDescription());
909 return llvm::make_error<DILDiagnosticError>(
919 field_obj = base->GetSyntheticValue();
921 field_obj = field_obj->GetChildMemberWithName(node.
GetFieldName());
925 std::string errMsg = llvm::formatv(
926 "\"{0}\" is not a member of \"({1}) {2}\"", node.
GetFieldName(),
927 base->GetTypeName().AsCString(
"<invalid type>"), base->GetName());
928 return llvm::make_error<DILDiagnosticError>(
938 field_obj = dynamic_val_sp;
944 if (node.
GetIsArrow() && base->IsPointerType())
946 std::string errMsg = llvm::formatv(
947 "\"{0}\" is not a member of \"({1}) {2}\"", node.
GetFieldName(),
948 base->GetTypeName().AsCString(
"<invalid type>"), base->GetName());
949 return llvm::make_error<DILDiagnosticError>(
953llvm::Expected<lldb::ValueObjectSP>
960 if (!idx->GetCompilerType().IsIntegerOrUnscopedEnumerationType()) {
961 return llvm::make_error<DILDiagnosticError>(
966 uint64_t child_idx = idx->GetValueAsUnsigned(0);
974 CompilerType base_type = base->GetCompilerType().GetNonReferenceType();
975 base->GetExpressionPath(var_expr_path_strm);
976 bool is_incomplete_array =
false;
978 bool is_objc_pointer =
true;
981 is_objc_pointer =
false;
982 else if (!base->GetCompilerType().IsPointerType())
983 is_objc_pointer =
false;
986 std::string err_msg = llvm::formatv(
987 "\"({0}) {1}\" is an Objective-C pointer, and cannot be subscripted",
988 base->GetTypeName().AsCString(
"<invalid type>"),
990 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
993 if (is_objc_pointer) {
995 if (!synthetic || synthetic == base) {
996 std::string err_msg =
997 llvm::formatv(
"\"({0}) {1}\" is not an array type",
998 base->GetTypeName().AsCString(
"<invalid type>"),
1000 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1003 if (
static_cast<uint32_t
>(child_idx) >=
1004 synthetic->GetNumChildrenIgnoringErrors()) {
1005 std::string err_msg = llvm::formatv(
1006 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1007 base->GetTypeName().AsCString(
"<invalid type>"),
1008 var_expr_path_strm.
GetData());
1009 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1012 child_valobj_sp = synthetic->GetChildAtIndex(child_idx);
1013 if (!child_valobj_sp) {
1014 std::string err_msg = llvm::formatv(
1015 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1016 base->GetTypeName().AsCString(
"<invalid type>"),
1017 var_expr_path_strm.
GetData());
1018 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1022 if (
auto dynamic_sp = child_valobj_sp->GetDynamicValue(
m_use_dynamic))
1023 child_valobj_sp = std::move(dynamic_sp);
1025 return child_valobj_sp;
1028 child_valobj_sp = base->GetSyntheticArrayMember(child_idx,
true);
1029 if (!child_valobj_sp) {
1030 std::string err_msg = llvm::formatv(
1031 "failed to use pointer as array for index {0} for "
1033 child_idx, base->GetTypeName().AsCString(
"<invalid type>"),
1034 var_expr_path_strm.
GetData());
1036 err_msg =
"subscript of pointer to incomplete type 'void'";
1037 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1040 }
else if (base_type.
IsArrayType(
nullptr,
nullptr, &is_incomplete_array)) {
1041 child_valobj_sp = base->GetChildAtIndex(child_idx);
1043 child_valobj_sp = base->GetSyntheticArrayMember(child_idx,
true);
1044 if (!child_valobj_sp) {
1045 std::string err_msg = llvm::formatv(
1046 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1047 base->GetTypeName().AsCString(
"<invalid type>"),
1048 var_expr_path_strm.
GetData());
1049 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1054 base->GetSyntheticBitFieldChild(child_idx, child_idx,
true);
1055 if (!child_valobj_sp) {
1056 std::string err_msg = llvm::formatv(
1057 "bitfield range {0}:{1} is not valid for \"({2}) {3}\"", child_idx,
1058 child_idx, base->GetTypeName().AsCString(
"<invalid type>"),
1059 var_expr_path_strm.
GetData());
1060 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1066 std::string err_msg =
1067 llvm::formatv(
"\"{0}\" is not an array type",
1068 base->GetTypeName().AsCString(
"<invalid type>"));
1069 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1072 if (
static_cast<uint32_t
>(child_idx) >=
1073 synthetic->GetNumChildrenIgnoringErrors(child_idx + 1)) {
1074 std::string err_msg = llvm::formatv(
1075 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1076 base->GetTypeName().AsCString(
"<invalid type>"),
1077 var_expr_path_strm.
GetData());
1078 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1081 child_valobj_sp = synthetic->GetChildAtIndex(child_idx);
1082 if (!child_valobj_sp) {
1083 std::string err_msg = llvm::formatv(
1084 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1085 base->GetTypeName().AsCString(
"<invalid type>"),
1086 var_expr_path_strm.
GetData());
1087 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1092 if (child_valobj_sp) {
1094 if (
auto dynamic_sp = child_valobj_sp->GetDynamicValue(
m_use_dynamic))
1095 child_valobj_sp = std::move(dynamic_sp);
1097 return child_valobj_sp;
1101 int64_t signed_child_idx = idx->GetValueAsSigned(0, &success);
1103 return llvm::make_error<DILDiagnosticError>(
1104 m_expr,
"could not get the index as an integer",
1106 return base->GetSyntheticArrayMember(signed_child_idx,
true);
1109llvm::Expected<lldb::ValueObjectSP>
1112 if (!first_idx_or_err)
1113 return first_idx_or_err;
1116 if (!last_idx_or_err)
1117 return last_idx_or_err;
1120 if (!first_idx->GetCompilerType().IsIntegerOrUnscopedEnumerationType() ||
1121 !last_idx->GetCompilerType().IsIntegerOrUnscopedEnumerationType()) {
1122 return llvm::make_error<DILDiagnosticError>(
1126 bool success_first, success_last;
1127 int64_t first_index = first_idx->GetValueAsSigned(0, &success_first);
1128 int64_t last_index = last_idx->GetValueAsSigned(0, &success_last);
1129 if (!success_first || !success_last)
1130 return llvm::make_error<DILDiagnosticError>(
1134 if (first_index > last_index)
1135 std::swap(first_index, last_index);
1142 base->GetSyntheticBitFieldChild(first_index, last_index,
true);
1143 if (!child_valobj_sp) {
1144 std::string message = llvm::formatv(
1145 "bitfield range {0}:{1} is not valid for \"({2}) {3}\"", first_index,
1146 last_index, base->GetTypeName().AsCString(
"<invalid type>"),
1147 base->GetName().GetStringRef());
1148 return llvm::make_error<DILDiagnosticError>(
m_expr, message,
1151 return child_valobj_sp;
1154llvm::Expected<CompilerType>
1156 std::shared_ptr<ExecutionContextScope> ctx,
1161 llvm::APInt apint = literal.
GetValue();
1163 llvm::SmallVector<std::pair<lldb::BasicType, lldb::BasicType>, 3> candidates;
1174 for (
auto [signed_, unsigned_] : candidates) {
1175 CompilerType signed_type = type_system->GetBasicTypeFromAST(signed_);
1178 llvm::Expected<uint64_t> size = signed_type.
GetBitSize(ctx.get());
1180 return size.takeError();
1181 if (!literal.
IsUnsigned() && apint.isIntN(*size - 1))
1184 return type_system->GetBasicTypeFromAST(unsigned_);
1187 return llvm::make_error<DILDiagnosticError>(
1189 "integer literal is too large to be represented in any integer type",
1193llvm::Expected<lldb::ValueObjectSP>
1195 llvm::Expected<lldb::TypeSystemSP> type_system =
1198 return type_system.takeError();
1200 llvm::Expected<CompilerType> type =
1203 return type.takeError();
1208 llvm::Expected<uint64_t> type_bitsize =
1211 return type_bitsize.takeError();
1217llvm::Expected<lldb::ValueObjectSP>
1219 llvm::Expected<lldb::TypeSystemSP> type_system =
1222 return type_system.takeError();
1225 &node.
GetValue().getSemantics() == &llvm::APFloat::IEEEsingle();
1231 return llvm::make_error<DILDiagnosticError>(
1239llvm::Expected<lldb::ValueObjectSP>
1242 llvm::Expected<lldb::TypeSystemSP> type_system =
1245 return type_system.takeError();
1250llvm::Expected<CastKind>
1255 if (target_type.
GetTypeInfo() & lldb::eTypeIsFloat) {
1256 std::string errMsg = llvm::formatv(
"Cast from {0} to {1} is not allowed",
1259 return llvm::make_error<DILDiagnosticError>(
1260 m_expr, std::move(errMsg), location,
1270 uint64_t type_byte_size = 0;
1271 uint64_t rhs_type_byte_size = 0;
1273 type_byte_size = *temp;
1275 std::string errMsg = llvm::formatv(
"unable to get byte size for type {0}",
1277 return llvm::make_error<DILDiagnosticError>(
1278 m_expr, std::move(errMsg), location,
1283 rhs_type_byte_size = *temp;
1285 std::string errMsg = llvm::formatv(
"unable to get byte size for type {0}",
1287 return llvm::make_error<DILDiagnosticError>(
1288 m_expr, std::move(errMsg), location,
1292 if (type_byte_size < rhs_type_byte_size) {
1293 std::string errMsg = llvm::formatv(
1294 "cast from pointer to smaller type {0} loses information",
1296 return llvm::make_error<DILDiagnosticError>(
1297 m_expr, std::move(errMsg), location,
1302 std::string errMsg = llvm::formatv(
"cannot convert {0} to {1}",
1306 return llvm::make_error<DILDiagnosticError>(
1307 m_expr, std::move(errMsg), location,
1313llvm::Expected<CastKind>
1324 std::string errMsg = llvm::formatv(
"Cast from {0} to {1} is not allowed",
1328 return llvm::make_error<DILDiagnosticError>(
1329 m_expr, std::move(errMsg), location,
1339 std::string errMsg = llvm::formatv(
1340 "cannot cast from type {0} to pointer type {1}",
1343 return llvm::make_error<DILDiagnosticError>(
1344 m_expr, std::move(errMsg), location,
1351 std::string errMsg = llvm::formatv(
1352 "casting of {0} to {1} is not implemented yet",
1354 return llvm::make_error<DILDiagnosticError>(
1355 m_expr, std::move(errMsg), location,
1362 if (!operand_or_err)
1363 return operand_or_err;
1373 operand->GetName().GetStringRef());
1374 op_type = operand->GetCompilerType();
1379 return type_or_err.takeError();
1382 if (operand->GetCompilerType().IsReferenceType()) {
1384 operand = operand->Dereference(
error);
1386 return llvm::make_error<DILDiagnosticError>(
m_expr,
error.AsCString(),
1390 switch (cast_kind) {
1395 return operand->CastToEnumType(target_type);
1401 return operand->CastToBasicType(target_type);
1406 ? operand->GetLoadAddress()
1407 : (op_type.
IsSigned() ? operand->GetValueAsSigned(0)
1408 : operand->GetValueAsUnsigned(0));
1409 llvm::StringRef name =
"result";
1420 std::string errMsg =
1421 llvm::formatv(
"unable to cast from '{0}' to '{1}'",
1423 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
static llvm::raw_ostream & error(Stream &strm)
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.
@ eExpressionPathOptionsNoFragileObjcIvar
@ 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 GetInstanceVariableName()
Determines the name of the instance variable for the 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 CreateValueObjectFromAddress(llvm::StringRef name, uint64_t address, const ExecutionContext &exe_ctx, CompilerType type, bool do_deref=true)
Given an address either create a value object containing the value at that address,...
static lldb::ValueObjectSP CreateValueObjectFromScalar(const ExecutionContext &exe_ctx, Scalar &s, CompilerType type, llvm::StringRef name)
Create a value object containing the given Scalar value.
lldb::addr_t GetLoadAddress()
Return the target load address associated with this value object.
CompilerType GetCompilerType()
static lldb::ValueObjectSP CreateValueObjectFromBool(const ExecutionContext &exe_ctx, lldb::TypeSystemSP typesystem, bool value, llvm::StringRef name)
Create a value object containing the given boolean value.
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...
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),...