[Lldb-commits] [lldb] [lldb][Fortran] Added support for basic types in TypeSystemFortran (PR #223380)
Tarun Prabhu via lldb-commits
lldb-commits at lists.llvm.org
Mon Oct 19 07:52:34 PDT 2026
================
@@ -58,6 +61,253 @@ LanguageSet TypeSystemFortran::GetSupportedLanguagesForExpressions() {
return GetSupportedLanguagesForTypes();
}
+#ifndef NDEBUG
+bool TypeSystemFortran::Verify(lldb::opaque_compiler_type_t type) {
+ return !type || llvm::isa<FortranType>(static_cast<FortranType *>(type));
+}
+#endif
+
+bool TypeSystemFortran::IsFloatingPointType(opaque_compiler_type_t type) {
+ if (!type)
+ return false;
+ int kind = static_cast<FortranType *>(type)->GetKind();
+
+ if (kind == FortranType::KIND_REAL || kind == FortranType::KIND_COMPLEX)
+ return true;
+
+ return false;
+}
+
+bool TypeSystemFortran::IsIntegerType(opaque_compiler_type_t type,
+ bool &is_signed) {
+ if (!type)
+ return false;
+ int kind = static_cast<FortranType *>(type)->GetKind();
+ if (kind == FortranType::KIND_INTEGER || kind == FortranType::KIND_UNSIGNED) {
+ is_signed = (kind == FortranType::KIND_INTEGER);
+ return true;
+ }
+
+ return false;
+}
+
bool TypeSystemFortran::SupportsLanguage(lldb::LanguageType language) {
return Language::LanguageIsFortran(language);
}
+
+/// Returns the type name upper-cased to follow Fortran's general style.
+ConstString TypeSystemFortran::GetTypeName(opaque_compiler_type_t type,
+ bool base_only) {
+ if (!type)
+ return ConstString();
+
+ FortranType *fortran_type = static_cast<FortranType *>(type);
+ switch (fortran_type->GetKind()) {
+ case FortranType::KIND_INTEGER:
+ case FortranType::KIND_LOGICAL:
+ case FortranType::KIND_REAL:
+ case FortranType::KIND_COMPLEX:
+ case FortranType::KIND_UNSIGNED:
+ return fortran_type->GetName();
+ case FortranType::KIND_UNKNOWN:
+ return ConstString("Unsupported");
+ }
+ return ConstString("Unsupported");
+}
+
+CompilerType
+TypeSystemFortran::CreateBaseType(llvm::dwarf::TypeKind dwarf_encoding,
+ uint64_t bitsize, ConstString name) {
+ int underlying_kind = FortranType::KIND_UNKNOWN;
+ const char *default_name = nullptr;
+
+ switch (dwarf_encoding) {
+ case dwarf::DW_ATE_boolean:
+ underlying_kind = FortranType::KIND_LOGICAL;
+ default_name = "LOGICAL";
+ break;
+ case dwarf::DW_ATE_float:
+ underlying_kind = FortranType::KIND_REAL;
+ default_name = "REAL";
+ break;
+ case dwarf::DW_ATE_signed:
+ case dwarf::DW_ATE_signed_char:
+ underlying_kind = FortranType::KIND_INTEGER;
+ default_name = "INTEGER";
+ break;
+ // Flang allows for unsigned types if the program is compiled with -funsigned.
+ case dwarf::DW_ATE_unsigned:
+ underlying_kind = FortranType::KIND_UNSIGNED;
+ default_name = "UNSIGNED";
+ break;
+ case dwarf::DW_ATE_complex_float:
+ underlying_kind = FortranType::KIND_COMPLEX;
+ default_name = "COMPLEX";
+ break;
+ default:
+ return CompilerType();
+ }
+ /// DWARFASTParserFortran provides the names it gets from DWARF, but in case
+ /// it doesn't we fallback to the default name.
+ if (name.IsEmpty() && default_name)
+ name.SetCString(default_name);
+
+ return GetOrCreateFortranBaseType(underlying_kind, bitsize, name);
+}
+
+/// Creates the type if it has not been created before, otherwise it gets it
+/// from the type map.
+CompilerType TypeSystemFortran::GetOrCreateFortranBaseType(int kind,
+ uint64_t bitsize,
+ ConstString name) {
+ FoldingSetNodeID id;
+ FortranType::Profile(id, kind, bitsize);
+ FoldingSetInsertToken token;
+ FortranType *candidate_type = m_basic_types.lookup(id, token);
+ if (candidate_type)
+ return CompilerType(weak_from_this(), (void *)candidate_type);
+
+ auto new_type_up = std::make_unique<FortranType>(kind, bitsize, name);
+ candidate_type = new_type_up.get();
+ m_basic_types.insert(candidate_type, token);
+ m_types.push_back(std::move(new_type_up));
+ return CompilerType(weak_from_this(), (void *)candidate_type);
+}
+
+lldb::TypeClass
+TypeSystemFortran::GetTypeClass(lldb::opaque_compiler_type_t type) {
+ return type ? lldb::eTypeClassBuiltin : lldb::eTypeClassInvalid;
+}
+
+CompilerType
+TypeSystemFortran::GetCanonicalType(lldb::opaque_compiler_type_t type) {
+ if (!type)
+ return CompilerType();
+
+ return CompilerType(weak_from_this(), type);
+}
+
+Expected<uint64_t>
+TypeSystemFortran::GetBitSize(opaque_compiler_type_t type,
+ ExecutionContextScope *exe_scope) {
+ if (!type)
+ return 0;
+
----------------
tarunprabhu wrote:
nit: Since there is just a single line after the sanity check, we can get away with not leaving an empty line here.
```suggestion
```
https://github.com/llvm/llvm-project/pull/223380
More information about the lldb-commits
mailing list