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