Skip to content

Commit 7d6e290

Browse files
committed
literals
1 parent 56f2890 commit 7d6e290

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/generate/peripheral.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ fn array_proxy(
10021002
let ap_path = parse_str::<syn::TypePath>(&format!(
10031003
"crate::ArrayProxy<{tys}, {}, {}>",
10041004
array_info.dim,
1005-
util::hex(array_info.dim_increment as u64)
1005+
util::hex(array_info.dim_increment as u64).into_token_stream(),
10061006
))?;
10071007

10081008
Ok(RegisterBlockField {

src/generate/register.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ pub fn render(
281281
});
282282
}
283283
if let Some(rv) = properties.reset_value.map(util::hex) {
284+
let rv = rv.into_token_stream();
284285
let doc = format!("`reset()` method sets {} to value {rv}", register.name);
285286
mod_items.extend(quote! {
286287
#[doc = #doc]

src/util.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use std::borrow::Cow;
22

33
use crate::svd::{Access, Cluster, Device, Field, Register, RegisterInfo, RegisterProperties};
44
use inflections::Inflect;
5-
use proc_macro2::{Ident, Literal, Span, TokenStream};
6-
use quote::{quote, ToTokens};
5+
use proc_macro2::{Ident, Span, TokenStream};
6+
use quote::quote;
77
use std::collections::HashSet;
88
use std::path::{Path, PathBuf};
99
use svd_rs::{MaybeArray, PeripheralInfo};
@@ -282,7 +282,7 @@ pub fn access_of(properties: &RegisterProperties, fields: Option<&[Field]>) -> A
282282
})
283283
}
284284

285-
pub fn digit_or_hex(n: u64) -> TokenStream {
285+
pub fn digit_or_hex(n: u64) -> syn::LitInt {
286286
if n < 10 {
287287
unsuffixed(n)
288288
} else {
@@ -291,14 +291,14 @@ pub fn digit_or_hex(n: u64) -> TokenStream {
291291
}
292292

293293
/// Turns `n` into an unsuffixed separated hex token
294-
pub fn hex(n: u64) -> TokenStream {
294+
pub fn hex(n: u64) -> syn::LitInt {
295295
let (h4, h3, h2, h1) = (
296296
(n >> 48) & 0xffff,
297297
(n >> 32) & 0xffff,
298298
(n >> 16) & 0xffff,
299299
n & 0xffff,
300300
);
301-
syn::parse_str::<syn::Lit>(
301+
syn::LitInt::new(
302302
&(if h4 != 0 {
303303
format!("0x{h4:04x}_{h3:04x}_{h2:04x}_{h1:04x}")
304304
} else if h3 != 0 {
@@ -312,21 +312,20 @@ pub fn hex(n: u64) -> TokenStream {
312312
} else {
313313
"0".to_string()
314314
}),
315+
Span::call_site(),
315316
)
316-
.unwrap()
317-
.into_token_stream()
318317
}
319318

320319
/// Turns `n` into an unsuffixed token
321-
pub fn unsuffixed(n: u64) -> TokenStream {
322-
Literal::u64_unsuffixed(n).into_token_stream()
320+
pub fn unsuffixed(n: u64) -> syn::LitInt {
321+
syn::LitInt::new(&n.to_string(), Span::call_site())
323322
}
324323

325-
pub fn unsuffixed_or_bool(n: u64, width: u32) -> TokenStream {
324+
pub fn unsuffixed_or_bool(n: u64, width: u32) -> syn::Lit {
326325
if width == 1 {
327-
Ident::new(if n == 0 { "false" } else { "true" }, Span::call_site()).into_token_stream()
326+
syn::Lit::Bool(syn::LitBool::new(n != 0, Span::call_site()))
328327
} else {
329-
unsuffixed(n)
328+
syn::Lit::Int(unsuffixed(n))
330329
}
331330
}
332331

0 commit comments

Comments
 (0)