Skip to content

[lldb] add has methods to all DemangledNameInfo attributes #144549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

charles-zablit
Copy link
Contributor

Add hasX methods to all the attributes of DemangledNameInfo.

@llvmbot
Copy link
Member

llvmbot commented Jun 17, 2025

@llvm/pr-subscribers-lldb

Author: Charles Zablit (charles-zablit)

Changes

Add hasX methods to all the attributes of DemangledNameInfo.


Full diff: https://github.com/llvm/llvm-project/pull/144549.diff

1 Files Affected:

  • (modified) lldb/include/lldb/Core/DemangledNameInfo.h (+19)
diff --git a/lldb/include/lldb/Core/DemangledNameInfo.h b/lldb/include/lldb/Core/DemangledNameInfo.h
index 4b5ba5e42b3b1..a2f3fde90c611 100644
--- a/lldb/include/lldb/Core/DemangledNameInfo.h
+++ b/lldb/include/lldb/Core/DemangledNameInfo.h
@@ -73,6 +73,25 @@ struct DemangledNameInfo {
   bool hasBasename() const {
     return BasenameRange.second > BasenameRange.first;
   }
+
+  /// Returns \c true if this object holds a valid scope range.
+  bool hasScope() const { return ScopeRange.second > ScopeRange.first; }
+
+  /// Returns \c true if this object holds a valid arguments range.
+  bool hasArguments() const {
+    return ArgumentsRange.second > ArgumentsRange.first;
+  }
+
+  /// Returns \c true if this object holds a valid qualifiers range.
+  bool hasQualifiers() const {
+    return QualifiersRange.second > QualifiersRange.first;
+  }
+
+  /// Returns \c true if this object holds a valid prefix range.
+  bool hasPrefix() const { return PrefixRange.second > PrefixRange.first; }
+
+  /// Returns \c true if this object holds a valid suffix range.
+  bool hasSuffix() const { return SuffixRange.second > SuffixRange.first; }
 };
 
 /// An OutputBuffer which keeps a record of where certain parts of a

@charles-zablit
Copy link
Contributor Author

Rationale: I am working on a patch (swiftlang#10710) which adds the hasArguments method and I think it would be a good fit for upstream llvm as well.

Copy link
Collaborator

@adrian-prantl adrian-prantl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if these were at least unit-tested on llvm.org, but given how trivial the implementation is, make not strictly necessary.

@Michael137
Copy link
Member

Michael137 commented Jun 19, 2025

Agreed, if we can somehow call these in MangledTest.cpp, that'd be great

Possibly just adding another unit-test case that demangles a simple mangled name and confirms that these getters return true/false appropriately

@charles-zablit
Copy link
Contributor Author

I ended up creating a new test suite, to isolate the checks as much as possible. This way, if someone accidentally refactors one of the has methods and replaces basenameRange with scopeRange in hasBasename, we are sure to catch it.


INSTANTIATE_TEST_SUITE_P(DemangledNameInfoRangesTests,
DemangledNameInfoTestFixture,
::testing::ValuesIn(g_demangled_name_info_test_cases));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, that's what i had in mind. Thanks!

@Michael137 Michael137 merged commit c079040 into llvm:main Jun 19, 2025
7 checks passed
charles-zablit added a commit to charles-zablit/llvm-project that referenced this pull request Jun 23, 2025
Add `hasX` methods to all the attributes of `DemangledNameInfo`.
charles-zablit added a commit to charles-zablit/llvm-project that referenced this pull request Jun 23, 2025
Add `hasX` methods to all the attributes of `DemangledNameInfo`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants