@@ -10,6 +10,20 @@ use std::marker::PhantomData;
10
10
use std:: iter:: Iterator ;
11
11
use std:: ops:: Deref ;
12
12
13
+ macro_rules! sub {
14
+ ( $ty: ty, $kind: ident) => (
15
+ unsafe impl Sub <:: Type > for $ty {
16
+ fn is( ty: & Type ) -> bool {
17
+ unsafe {
18
+ let kind = core:: LLVMGetTypeKind ( ty. into( ) ) ;
19
+ kind as c_uint == LLVMTypeKind :: $kind as c_uint
20
+ }
21
+ }
22
+ }
23
+ deref!{ $ty, Type }
24
+ )
25
+ }
26
+
13
27
/// Defines how a value should be laid out in memory.
14
28
pub struct Type ( PhantomData < [ u8 ] > ) ;
15
29
native_ref ! ( & Type = LLVMTypeRef ) ;
@@ -35,10 +49,6 @@ impl Type {
35
49
pub fn new_pointer < ' a > ( elem : & ' a Type ) -> & ' a Type {
36
50
unsafe { core:: LLVMPointerType ( elem. into ( ) , 0 as c_uint ) } . into ( )
37
51
}
38
- /// Make a new structure type with the given types.
39
- pub fn new_struct < ' a > ( context : & ' a Context , elems : & [ & ' a Type ] , packed : bool ) -> & ' a Type {
40
- unsafe { core:: LLVMStructTypeInContext ( context. into ( ) , elems. as_ptr ( ) as * mut LLVMTypeRef , elems. len ( ) as c_uint , packed as c_int ) } . into ( )
41
- }
42
52
/// Returns true if the size of the type is known at compile-time.
43
53
///
44
54
/// This is equivalent to the type implementing `Sized` in Rust
@@ -92,6 +102,7 @@ to_str!(Type, LLVMPrintTypeToString);
92
102
/// A structure type, such as a tuple or struct.
93
103
pub struct StructType ;
94
104
native_ref ! ( & StructType = LLVMTypeRef ) ;
105
+ sub ! { StructType , LLVMStructTypeKind }
95
106
impl StructType {
96
107
/// Make a new struct with the given fields and packed representation.
97
108
pub fn new < ' a > ( context : & ' a Context , fields : & [ & ' a Type ] , packed : bool ) -> & ' a StructType {
@@ -115,15 +126,6 @@ impl StructType {
115
126
}
116
127
}
117
128
}
118
- unsafe impl Sub < Type > for StructType {
119
- fn is ( ty : & Type ) -> bool {
120
- unsafe {
121
- let kind = core:: LLVMGetTypeKind ( ty. into ( ) ) ;
122
- kind as c_uint == LLVMTypeKind :: LLVMStructTypeKind as c_uint
123
- }
124
- }
125
- }
126
- deref ! ( StructType , Type ) ;
127
129
get_context ! ( StructType , LLVMGetTypeContext ) ;
128
130
to_str ! ( StructType , LLVMPrintTypeToString ) ;
129
131
0 commit comments