Skip to content

Commit a57c59b

Browse files
committed
Implement isFunctionMacroLike in new paradigm
1 parent 3538599 commit a57c59b

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

src/clang.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,14 @@ impl Cursor {
417417

418418
/// Is this Cursor pointing to a function-like macro definition?
419419
pub fn is_macro_function_like(&self) -> bool {
420-
unsafe { clang_Cursor_isMacroFunctionLike(self.x) != 0 }
420+
match self.node {
421+
ASTNode::PreprocessedEntity(p) => unsafe {
422+
clang_interface::PreprocessedEntity_isFunctionMacroLike(
423+
self.unit, p,
424+
)
425+
},
426+
_ => false,
427+
}
421428
}
422429

423430
/// Get the kind of referent this cursor is pointing to.

src/clang/clang_interface.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ CX_CXXAccessSpecifier CXXBaseSpecifier_getAccess(const CXXBaseSpecifier *);
264264
BindgenSourceRange Attr_getSourceRange(const Attr *);
265265
BindgenSourceRange PreprocessedEntity_getSourceRange(const PreprocessedEntity *);
266266

267+
bool PreprocessedEntity_isFunctionMacroLike(ASTUnit *TU, const PreprocessedEntity *ppe);
268+
267269
} // extern "C"
268270

269271
#endif // BINDGEN_CLANG_AST_H

src/clang/clang_interface.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8453,6 +8453,12 @@ extern "C" {
84538453
arg1: *const clang_PreprocessedEntity,
84548454
) -> BindgenSourceRange;
84558455
}
8456+
extern "C" {
8457+
pub fn PreprocessedEntity_isFunctionMacroLike(
8458+
TU: *mut clang_ASTUnit,
8459+
ppe: *const clang_PreprocessedEntity,
8460+
) -> bool;
8461+
}
84568462
#[repr(C)]
84578463
#[derive(Debug, Copy, Clone)]
84588464
pub struct __locale_data {

src/clang/libclang_compat.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,6 +1714,15 @@ void tokenize(ASTUnit *TU, BindgenSourceRange Range, CXToken **Tokens,
17141714
*NumTokens = CXTokens.size();
17151715
}
17161716

1717+
// Adapted from CursorVisitor:visitPreprocessedEntities in CIndex.cpp
1718+
bool PreprocessedEntity_isFunctionMacroLike(ASTUnit *TU,
1719+
const PreprocessedEntity *ppe) {
1720+
return isa<MacroDefinitionRecord>(ppe) &&
1721+
TU->getPreprocessor()
1722+
.getMacroInfo(cast<MacroDefinitionRecord>(ppe)->getName())
1723+
->isFunctionLike();
1724+
}
1725+
17171726
// Originally clang_getTokenKind in CIndex.cpp
17181727
CXTokenKind getTokenKind(CXToken token) {
17191728
return static_cast<CXTokenKind>(token.int_data[0]);

0 commit comments

Comments
 (0)