22
33use std:: fmt:: Write ;
44
5- type BoxStr = Box < str > ;
6-
5+ /// The constness of a C type.
76#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
87pub ( crate ) enum Constness {
98 Const ,
@@ -13,6 +12,8 @@ pub(crate) enum Constness {
1312#[ cfg_attr( not( test) , expect( unused_imports) ) ]
1413use Constness :: { Const , Mut } ;
1514
15+ use crate :: BoxStr ;
16+
1617/// A basic representation of C's types.
1718#[ derive( Clone , Debug ) ]
1819pub ( crate ) enum CTy {
@@ -175,6 +176,7 @@ fn space_if(yes: bool, s: &mut String) {
175176 }
176177}
177178
179+ /// Create a named type with a certain constness.
178180pub ( crate ) fn named ( name : & str , constness : Constness ) -> CTy {
179181 CTy :: Named {
180182 name : name. into ( ) ,
@@ -186,6 +188,7 @@ pub(crate) fn named(name: &str, constness: Constness) -> CTy {
186188 }
187189}
188190
191+ /// Create a named type with certain qualifiers.
189192#[ cfg_attr( not( test) , expect( unused) ) ]
190193pub ( crate ) fn named_qual ( name : & str , qual : Qual ) -> CTy {
191194 CTy :: Named {
@@ -194,6 +197,7 @@ pub(crate) fn named_qual(name: &str, qual: Qual) -> CTy {
194197 }
195198}
196199
200+ /// Create a pointer to a type, specifying constness of the pointer.
197201pub ( crate ) fn ptr ( inner : CTy , constness : Constness ) -> CTy {
198202 ptr_qual (
199203 inner,
@@ -205,21 +209,23 @@ pub(crate) fn ptr(inner: CTy, constness: Constness) -> CTy {
205209 )
206210}
207211
212+ /// Create a pointer to a type, specifying the qualifiers of the pointer.
208213pub ( crate ) fn ptr_qual ( inner : CTy , qual : Qual ) -> CTy {
209214 CTy :: Ptr {
210215 ty : Box :: new ( inner) ,
211216 qual,
212217 }
213218}
214219
220+ /// Create an array of some type and optional length.
215221pub ( crate ) fn array ( inner : CTy , len : Option < & str > ) -> CTy {
216222 CTy :: Array {
217223 ty : Box :: new ( inner) ,
218224 len : len. map ( Into :: into) ,
219225 }
220226}
221227
222- /// Function type (not a pointer)
228+ /// Create a function type (not a pointer) with the given arguments and return type.
223229#[ cfg_attr( not( test) , expect( unused) ) ]
224230pub ( crate ) fn func ( args : Vec < CTy > , ret : CTy ) -> CTy {
225231 CTy :: Fn {
@@ -228,7 +234,9 @@ pub(crate) fn func(args: Vec<CTy>, ret: CTy) -> CTy {
228234 }
229235}
230236
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.
232240pub ( crate ) fn func_ptr ( args : Vec < CTy > , ret : CTy ) -> CTy {
233241 CTy :: Ptr {
234242 ty : Box :: new ( CTy :: Fn {
0 commit comments