summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poveda <christian.poveda@ferrous-systems.com>2022-09-01 10:54:48 -0500
committerEmilio Cobos Álvarez <emilio@crisal.io>2022-09-22 20:25:33 -1000
commitb8f3920ad11b82673d06f2d25bb663e2b7efe491 (patch)
tree93bdbd440e8ad2a08d841e7a1c1394387a890b4b
parent1704775d9183ae757cc67c16af267a517dac5a7c (diff)
add `CxTokenKind` argument to `has_attr`
-rw-r--r--src/clang.rs33
1 files changed, 14 insertions, 19 deletions
diff --git a/src/clang.rs b/src/clang.rs
index 5579c42b..4779e0b7 100644
--- a/src/clang.rs
+++ b/src/clang.rs
@@ -642,39 +642,34 @@ impl Cursor {
pub fn has_warn_unused_result_attr(&self) -> bool {
// FIXME(emilio): clang-sys doesn't expose this (from clang 9).
const CXCursor_WarnUnusedResultAttr: CXCursorKind = 440;
- self.has_attr("warn_unused_result", Some(CXCursor_WarnUnusedResultAttr))
+ self.has_attr(
+ "warn_unused_result",
+ Some(CXCursor_WarnUnusedResultAttr),
+ CXToken_Identifier,
+ )
}
+ /// Check wether this cursor has the `_Noreturn` attribute.
pub fn has_no_return_attr(&self) -> bool {
- let mut found_attr = false;
- self.visit(|cur| {
- found_attr = cur.kind() == CXCursor_UnexposedAttr &&
- cur.tokens().iter().any(|t| {
- t.kind == CXToken_Keyword && t.spelling() == b"_Noreturn"
- });
-
- if found_attr {
- CXChildVisit_Break
- } else {
- CXChildVisit_Continue
- }
- });
-
- found_attr
+ self.has_attr("_Noreturn", None, CXToken_Keyword)
}
/// Does this cursor have the given attribute?
///
/// `name` is checked against unexposed attributes.
- fn has_attr(&self, name: &str, clang_kind: Option<CXCursorKind>) -> bool {
+ fn has_attr(
+ &self,
+ name: &str,
+ clang_kind: Option<CXCursorKind>,
+ token_kind: CXTokenKind,
+ ) -> bool {
let mut found_attr = false;
self.visit(|cur| {
let kind = cur.kind();
found_attr = clang_kind.map_or(false, |k| k == kind) ||
(kind == CXCursor_UnexposedAttr &&
cur.tokens().iter().any(|t| {
- t.kind == CXToken_Identifier &&
- t.spelling() == name.as_bytes()
+ t.kind == token_kind && t.spelling() == name.as_bytes()
}));
if found_attr {