2
2
3
3
use std:: fmt:: Write ;
4
4
5
- type BoxStr = Box < str > ;
6
-
5
+ /// The constness of a C type.
7
6
#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
8
7
pub ( crate ) enum Constness {
9
8
Const ,
@@ -13,6 +12,8 @@ pub(crate) enum Constness {
13
12
#[ cfg_attr( not( test) , expect( unused_imports) ) ]
14
13
use Constness :: { Const , Mut } ;
15
14
15
+ use crate :: BoxStr ;
16
+
16
17
/// A basic representation of C's types.
17
18
#[ derive( Clone , Debug ) ]
18
19
pub ( crate ) enum CTy {
@@ -175,6 +176,7 @@ fn space_if(yes: bool, s: &mut String) {
175
176
}
176
177
}
177
178
179
+ /// Create a named type with a certain constness.
178
180
pub ( crate ) fn named ( name : & str , constness : Constness ) -> CTy {
179
181
CTy :: Named {
180
182
name : name. into ( ) ,
@@ -186,6 +188,7 @@ pub(crate) fn named(name: &str, constness: Constness) -> CTy {
186
188
}
187
189
}
188
190
191
+ /// Create a named type with certain qualifiers.
189
192
#[ cfg_attr( not( test) , expect( unused) ) ]
190
193
pub ( crate ) fn named_qual ( name : & str , qual : Qual ) -> CTy {
191
194
CTy :: Named {
@@ -194,6 +197,7 @@ pub(crate) fn named_qual(name: &str, qual: Qual) -> CTy {
194
197
}
195
198
}
196
199
200
+ /// Create a pointer to a type, specifying constness of the pointer.
197
201
pub ( crate ) fn ptr ( inner : CTy , constness : Constness ) -> CTy {
198
202
ptr_qual (
199
203
inner,
@@ -205,21 +209,23 @@ pub(crate) fn ptr(inner: CTy, constness: Constness) -> CTy {
205
209
)
206
210
}
207
211
212
+ /// Create a pointer to a type, specifying the qualifiers of the pointer.
208
213
pub ( crate ) fn ptr_qual ( inner : CTy , qual : Qual ) -> CTy {
209
214
CTy :: Ptr {
210
215
ty : Box :: new ( inner) ,
211
216
qual,
212
217
}
213
218
}
214
219
220
+ /// Create an array of some type and optional length.
215
221
pub ( crate ) fn array ( inner : CTy , len : Option < & str > ) -> CTy {
216
222
CTy :: Array {
217
223
ty : Box :: new ( inner) ,
218
224
len : len. map ( Into :: into) ,
219
225
}
220
226
}
221
227
222
- /// Function type (not a pointer)
228
+ /// Create a function type (not a pointer) with the given arguments and return type.
223
229
#[ cfg_attr( not( test) , expect( unused) ) ]
224
230
pub ( crate ) fn func ( args : Vec < CTy > , ret : CTy ) -> CTy {
225
231
CTy :: Fn {
@@ -228,7 +234,9 @@ pub(crate) fn func(args: Vec<CTy>, ret: CTy) -> CTy {
228
234
}
229
235
}
230
236
231
- /// Function pointer
237
+ /// Create a function pointer with the given arguments and return type.
238
+ ///
239
+ /// By default the function pointer is mutable, with `volatile` and `restrict` keywords not applied.
232
240
pub ( crate ) fn func_ptr ( args : Vec < CTy > , ret : CTy ) -> CTy {
233
241
CTy :: Ptr {
234
242
ty : Box :: new ( CTy :: Fn {
0 commit comments