[Lldb-commits] [lldb] [LLDB] Add `ScalarLiteralNode` and literal parsing in DIL (PR #152308)
Ilia Kuklin via lldb-commits
lldb-commits at lists.llvm.org
Sun Aug 17 07:33:02 PDT 2025
================
@@ -402,4 +404,125 @@ Interpreter::Visit(const BitFieldExtractionNode *node) {
return child_valobj_sp;
}
+static llvm::Expected<lldb::TypeSystemSP>
+GetTypeSystemFromCU(std::shared_ptr<StackFrame> ctx) {
+ SymbolContext symbol_context =
+ ctx->GetSymbolContext(lldb::eSymbolContextCompUnit);
+ lldb::LanguageType language = symbol_context.comp_unit->GetLanguage();
+
+ symbol_context = ctx->GetSymbolContext(lldb::eSymbolContextModule);
+ return symbol_context.module_sp->GetTypeSystemForLanguage(language);
+}
+
+static CompilerType GetBasicType(lldb::TypeSystemSP type_system,
+ lldb::BasicType basic_type) {
+ if (type_system)
+ if (auto compiler_type = type_system.get()->GetBasicTypeFromAST(basic_type))
+ return compiler_type;
+
+ CompilerType empty_type;
+ return empty_type;
+}
+
+llvm::Expected<CompilerType>
+Interpreter::PickIntegerType(lldb::TypeSystemSP type_system,
+ std::shared_ptr<ExecutionContextScope> ctx,
+ const IntegerLiteralNode *literal) {
+ // Binary, Octal, Hexadecimal and literals with a U suffix are allowed to be
+ // an unsigned integer.
+ bool unsigned_is_allowed = literal->IsUnsigned() || literal->GetRadix() != 10;
+ llvm::APInt apint = literal->GetValue();
+
+ // Try int/unsigned int.
+ llvm::Expected<uint64_t> int_size =
+ GetBasicType(type_system, lldb::eBasicTypeInt).GetBitSize(ctx.get());
+ if (!int_size)
+ return int_size.takeError();
+ if (literal->GetTypeSuffix() == IntegerTypeSuffix::None &&
+ apint.isIntN(*int_size)) {
+ if (!literal->IsUnsigned() && apint.isIntN(*int_size - 1))
----------------
kuilpd wrote:
Only positive numbers from bare literals are handled by this function, a minus will make it a unary node and negate the number afterwards.
https://github.com/llvm/llvm-project/pull/152308
More information about the lldb-commits
mailing list