From e503476a96636df41532b988f8f8f0c318fff24a Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 1 Sep 2022 12:36:11 -0500 Subject: bring back optional cursor kind --- src/clang.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/clang.rs b/src/clang.rs index 0fcccaa4..fddb261c 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -18,7 +18,7 @@ use std::{mem, ptr, slice}; /// function. pub struct Attribute { name: &'static [u8], - kind: CXCursorKind, + kind: Option, token_kind: CXTokenKind, } @@ -27,14 +27,14 @@ impl Attribute { pub const MUST_USE: Self = Self { name: b"warn_unused_result", // FIXME(emilio): clang-sys doesn't expose `CXCursor_WarnUnusedResultAttr` (from clang 9). - kind: 440, + kind: Some(440), token_kind: CXToken_Identifier, }; /// A `_Noreturn` attribute. pub const NO_RETURN: Self = Self { name: b"_Noreturn", - kind: CXCursor_UnexposedAttr, + kind: None, token_kind: CXToken_Keyword, }; } @@ -678,11 +678,13 @@ impl Cursor { for (idx, attr) in attrs.iter().enumerate() { let found_attr = &mut found_attrs[idx]; if !*found_attr { - if kind == attr.kind && - cur.tokens().iter().any(|t| { - t.kind == attr.token_kind && - t.spelling() == attr.name - }) + // `attr.name` and` attr.token_kind` are checked against unexposed attributes only. + if attr.kind.map_or(false, |k| k == kind) || + (kind == CXCursor_UnexposedAttr && + cur.tokens().iter().any(|t| { + t.kind == attr.token_kind && + t.spelling() == attr.name + })) { *found_attr = true; found_count += 1; -- cgit v1.2.3