Skip to content

Commit 00ddb0e

Browse files
author
bors-servo
authored
Auto merge of #3 - metajack:add-elab, r=emilio
Add support for elaborated types. Things like JS::Latin1Char now show up as elaborated types and we need to use clang_Type_getNamedType to resolve them. This should fix #1.
2 parents 08e7fe4 + 1c4ca74 commit 00ddb0e

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

src/clang.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,12 @@ impl Type {
455455
clang_getFunctionTypeCallingConv(self.x)
456456
}
457457
}
458+
459+
pub fn named(&self) -> Type {
460+
unsafe {
461+
Type { x: clang_Type_getNamedType(self.x) }
462+
}
463+
}
458464
}
459465

460466
// SourceLocation
@@ -955,6 +961,9 @@ pub fn type_to_str(x: Enum_CXTypeKind) -> &'static str {
955961
CXType_IncompleteArray => "IncompleteArray",
956962
CXType_VariableArray => "VariableArray",
957963
CXType_DependentSizedArray => "DependentSizedArray",
964+
CXType_MemberPointer => "MemberPointer",
965+
CXType_Auto => "Auto",
966+
CXType_Elaborated => "Elaborated",
958967
_ => "?"
959968
}
960969
}

src/clangll.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ pub const CXType_IncompleteArray: c_uint = 114;
408408
pub const CXType_VariableArray: c_uint = 115;
409409
pub const CXType_DependentSizedArray: c_uint = 116;
410410
pub const CXType_MemberPointer: c_uint = 117;
411+
pub const CXType_Auto: c_uint = 118;
412+
pub const CXType_Elaborated: c_uint = 119;
411413
pub type Enum_CXCallingConv = c_uint;
412414
pub const CXCallingConv_Default: c_uint = 0;
413415
pub const CXCallingConv_C: c_uint = 1;
@@ -1108,6 +1110,7 @@ extern "C" {
11081110
pub fn clang_Type_getNumTemplateArguments(T: CXType) -> c_int;
11091111
pub fn clang_Type_getTemplateArgumentAsType(T: CXType, i: c_int) ->
11101112
CXType;
1113+
pub fn clang_Type_getNamedType(CT: CXType) -> CXType;
11111114
pub fn clang_Cursor_isBitField(C: CXCursor) -> c_uint;
11121115
#[cfg(not(feature="llvm_stable"))]
11131116
pub fn clang_Cursor_isFunctionInlined(C: CXCursor) -> c_uint;

src/parser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ fn conv_ty_resolving_typedefs(ctx: &mut ClangParserCtx,
489489
CXType_Unexposed |
490490
CXType_Enum => conv_decl_ty_resolving_typedefs(ctx, ty, cursor, resolve_typedefs),
491491
CXType_ConstantArray => TArray(Box::new(conv_ty_resolving_typedefs(ctx, &ty.elem_type(), cursor, resolve_typedefs)), ty.array_size(), layout),
492+
CXType_Elaborated => conv_ty_resolving_typedefs(ctx, &ty.named(), cursor, resolve_typedefs),
492493
_ => {
493494
let fail = ctx.options.fail_on_unknown_type;
494495
log_err_warn(ctx,

tests/expectations/elaborated.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
pub type whatever_t = ::std::os::raw::c_int;
4+
extern "C" {
5+
#[link_name = "_Z9somethingPKi"]
6+
pub fn something(wat: *const whatever_t);
7+
}

tests/headers/elaborated.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace whatever {
2+
typedef int whatever_t;
3+
}
4+
5+
void something(const whatever::whatever_t *wat);

0 commit comments

Comments
 (0)