@@ -8,13 +8,14 @@ use parse::{Invocation, StructuredInput};
8
8
use proc_macro as pm;
9
9
use proc_macro2:: { self as pm2, Span } ;
10
10
use quote:: { ToTokens , quote} ;
11
+ use shared:: OpScope ;
11
12
pub ( crate ) use shared:: { ALL_OPERATIONS , FloatTy , MathOpInfo , Ty } ;
12
13
use syn:: spanned:: Spanned ;
13
14
use syn:: visit_mut:: VisitMut ;
14
- use syn:: { Ident , ItemEnum } ;
15
+ use syn:: { Ident , ItemEnum , PathArguments , PathSegment } ;
15
16
16
17
const KNOWN_TYPES : & [ & str ] = & [
17
- "FTy" , "CFn" , "CArgs" , "CRet" , "RustFn" , "RustArgs" , "RustRet" , "public " ,
18
+ "FTy" , "CFn" , "CArgs" , "CRet" , "RustFn" , "RustArgs" , "RustRet" , "path " ,
18
19
] ;
19
20
20
21
/// Populate an enum with a variant representing function. Names are in upper camel case.
@@ -82,8 +83,8 @@ pub fn base_name_enum(attributes: pm::TokenStream, tokens: pm::TokenStream) -> p
82
83
/// RustArgs: $RustArgs:ty,
83
84
/// // The Rust version's return type (e.g. `(f32, f32)`)
84
85
/// RustRet: $RustRet:ty,
85
- /// // True if this is part of `libm`'s public API
86
- /// public : $public:expr ,
86
+ /// // True if this is part of `libm`'s path API
87
+ /// path : $path:path ,
87
88
/// // Attributes for the current function, if any
88
89
/// attrs: [$($attr:meta),*],
89
90
/// // Extra tokens passed directly (if any)
@@ -162,6 +163,18 @@ fn validate(input: &mut StructuredInput) -> syn::Result<Vec<&'static MathOpInfo>
162
163
map. insert ( Ident :: new ( op. name , key. span ( ) ) , val. clone ( ) ) ;
163
164
}
164
165
}
166
+
167
+ if let Some ( k) = map. keys ( ) . find ( |key| * key == "ALL_BUILTINS" ) {
168
+ let key = k. clone ( ) ;
169
+ let val = map. remove ( & key) . unwrap ( ) ;
170
+
171
+ for op in ALL_OPERATIONS
172
+ . iter ( )
173
+ . filter ( |op| op. scope == OpScope :: BuiltinsPublic )
174
+ {
175
+ map. insert ( Ident :: new ( op. name , key. span ( ) ) , val. clone ( ) ) ;
176
+ }
177
+ }
165
178
}
166
179
167
180
// Collect lists of all functions that are provied as macro inputs in various fields (only,
@@ -227,6 +240,10 @@ fn validate(input: &mut StructuredInput) -> syn::Result<Vec<&'static MathOpInfo>
227
240
continue ;
228
241
}
229
242
243
+ if input. skip_builtins && func. scope == OpScope :: BuiltinsPublic {
244
+ continue ;
245
+ }
246
+
230
247
// Run everything else
231
248
fn_list. push ( func) ;
232
249
}
@@ -363,7 +380,17 @@ fn expand(input: StructuredInput, fn_list: &[&MathOpInfo]) -> syn::Result<pm2::T
363
380
let c_ret = & func. c_sig . returns ;
364
381
let rust_args = & func. rust_sig . args ;
365
382
let rust_ret = & func. rust_sig . returns ;
366
- let public = func. public ;
383
+ let path = syn:: Path {
384
+ leading_colon : None ,
385
+ segments : func
386
+ . path
387
+ . split ( "::" )
388
+ . map ( |pseg| PathSegment {
389
+ ident : Ident :: new ( pseg, Span :: call_site ( ) ) ,
390
+ arguments : PathArguments :: None ,
391
+ } )
392
+ . collect ( ) ,
393
+ } ;
367
394
368
395
let mut ty_fields = Vec :: new ( ) ;
369
396
for ty in & input. emit_types {
@@ -375,8 +402,8 @@ fn expand(input: StructuredInput, fn_list: &[&MathOpInfo]) -> syn::Result<pm2::T
375
402
"RustFn" => quote ! { RustFn : fn ( #( #rust_args) , * , ) -> ( #( #rust_ret) , * ) , } ,
376
403
"RustArgs" => quote ! { RustArgs : ( #( #rust_args) , * , ) , } ,
377
404
"RustRet" => quote ! { RustRet : ( #( #rust_ret) , * ) , } ,
378
- "public " => quote ! { public : #public , } ,
379
- _ => unreachable ! ( "checked in validation" ) ,
405
+ "path " => quote ! { path : #path , } ,
406
+ _ => unreachable ! ( "fields should be checked in validation" ) ,
380
407
} ;
381
408
ty_fields. push ( field) ;
382
409
}
@@ -465,6 +492,8 @@ fn base_name(name: &str) -> &str {
465
492
None => name
466
493
. strip_suffix ( "f" )
467
494
. or_else ( || name. strip_suffix ( "f16" ) )
495
+ . or_else ( || name. strip_suffix ( "f32" ) )
496
+ . or_else ( || name. strip_suffix ( "f64" ) )
468
497
. or_else ( || name. strip_suffix ( "f128" ) )
469
498
. unwrap_or ( name) ,
470
499
}
0 commit comments