@@ -33,10 +33,6 @@ impl Type {
33
33
pub fn get < ' a , T > ( context : & ' a Context ) -> & ' a Type where T : Compile < ' a > {
34
34
T :: get_type ( context)
35
35
}
36
- /// Make a new function signature with the return type and arguments given.
37
- pub fn new_function < ' a > ( ret : & ' a Type , args : & [ & ' a Type ] ) -> & ' a FunctionType {
38
- unsafe { core:: LLVMFunctionType ( ret. into ( ) , args. as_ptr ( ) as * mut LLVMTypeRef , args. len ( ) as c_uint , 0 ) } . into ( )
39
- }
40
36
/// Make a new array with the length given.
41
37
pub fn new_array < ' a > ( element : & ' a Type , length : usize ) -> & ' a Type {
42
38
unsafe { core:: LLVMArrayType ( element. into ( ) , length as c_uint ) } . into ( )
@@ -45,10 +41,6 @@ impl Type {
45
41
pub fn new_vector < ' a > ( element : & ' a Type , length : usize ) -> & ' a Type {
46
42
unsafe { core:: LLVMVectorType ( element. into ( ) , length as c_uint ) } . into ( )
47
43
}
48
- /// Make a new pointer with the given element type.
49
- pub fn new_pointer < ' a > ( elem : & ' a Type ) -> & ' a Type {
50
- unsafe { core:: LLVMPointerType ( elem. into ( ) , 0 as c_uint ) } . into ( )
51
- }
52
44
/// Returns true if the size of the type is known at compile-time.
53
45
///
54
46
/// This is equivalent to the type implementing `Sized` in Rust
@@ -91,10 +83,6 @@ impl Type {
91
83
pub fn get_size ( & self , target : & TargetData ) -> usize {
92
84
unsafe { target:: LLVMABISizeOfType ( target. into ( ) , self . into ( ) ) as usize }
93
85
}
94
- /// Returns the element of this pointer type.
95
- pub fn get_element ( & self ) -> Option < & Type > {
96
- unsafe { mem:: transmute ( core:: LLVMGetElementType ( self . into ( ) ) ) }
97
- }
98
86
}
99
87
get_context ! ( Type , LLVMGetTypeContext ) ;
100
88
to_str ! ( Type , LLVMPrintTypeToString ) ;
@@ -136,15 +124,19 @@ deref!(FunctionType, Type);
136
124
unsafe impl Sub < Type > for FunctionType {
137
125
fn is ( mut ty : & Type ) -> bool {
138
126
unsafe {
139
- while let Some ( elem ) = ty . get_element ( ) {
140
- ty = elem ;
127
+ while let Some ( ptr ) = PointerType :: from_super ( ty ) {
128
+ ty = ptr . get_element ( ) ;
141
129
}
142
130
let kind = core:: LLVMGetTypeKind ( ty. into ( ) ) ;
143
131
kind as c_uint == LLVMTypeKind :: LLVMFunctionTypeKind as c_uint
144
132
}
145
133
}
146
134
}
147
135
impl FunctionType {
136
+ /// Make a new function signature with the return type and arguments given.
137
+ pub fn new < ' a > ( ret : & ' a Type , args : & [ & ' a Type ] ) -> & ' a FunctionType {
138
+ unsafe { core:: LLVMFunctionType ( ret. into ( ) , args. as_ptr ( ) as * mut LLVMTypeRef , args. len ( ) as c_uint , 0 ) } . into ( )
139
+ }
148
140
/// Returns the number of parameters this signature takes.
149
141
pub fn num_params ( & self ) -> usize {
150
142
unsafe { core:: LLVMCountParamTypes ( self . into ( ) ) as usize }
@@ -165,3 +157,20 @@ impl FunctionType {
165
157
}
166
158
get_context ! ( FunctionType , LLVMGetTypeContext ) ;
167
159
to_str ! ( FunctionType , LLVMPrintTypeToString ) ;
160
+
161
+ /// A pointer type.
162
+ pub struct PointerType ;
163
+ sub ! { PointerType , LLVMPointerTypeKind }
164
+ native_ref ! ( & PointerType = LLVMTypeRef ) ;
165
+ impl PointerType {
166
+ /// Make a new pointer type with the given element type.
167
+ pub fn new ( elem : & Type ) -> & Type {
168
+ unsafe { core:: LLVMPointerType ( elem. into ( ) , 0 as c_uint ) } . into ( )
169
+ }
170
+ /// Returns the element of this pointer type.
171
+ pub fn get_element ( & self ) -> & Type {
172
+ unsafe { mem:: transmute ( core:: LLVMGetElementType ( self . into ( ) ) ) }
173
+ }
174
+ }
175
+ get_context ! ( PointerType , LLVMGetTypeContext ) ;
176
+ to_str ! ( PointerType , LLVMPrintTypeToString ) ;
0 commit comments