Skip to content

Commit cc45313

Browse files
bors[bot]theli-ua
andauthored
Merge #489
489: Fix type path for cluster fields. Allows nested clusters r=Emilgardis a=theli-ua Fixes #249 Tested on following test svd: https://gist.github.com/theli-ua/a1b9c17e94442fbd56c774bb504795a0 Co-authored-by: Anton Romanov <theli.ua@gmail.com>
2 parents 6457c30 + 6594018 commit cc45313

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/generate/peripheral.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ fn expand_cluster(
633633

634634
match cluster {
635635
Cluster::Single(info) => cluster_expanded.push(RegisterBlockField {
636-
field: convert_svd_cluster(cluster)?,
636+
field: convert_svd_cluster(cluster, name)?,
637637
description: info.description.as_ref().unwrap_or(&info.name).into(),
638638
offset: info.address_offset,
639639
size: cluster_size,
@@ -653,7 +653,7 @@ fn expand_cluster(
653653

654654
if array_convertible {
655655
cluster_expanded.push(RegisterBlockField {
656-
field: convert_svd_cluster(&cluster)?,
656+
field: convert_svd_cluster(&cluster, name)?,
657657
description: info.description.as_ref().unwrap_or(&info.name).into(),
658658
offset: info.address_offset,
659659
size: cluster_size * array_info.dim,
@@ -855,7 +855,7 @@ fn expand_svd_cluster(
855855
let mut out = vec![];
856856

857857
match &cluster {
858-
Cluster::Single(_info) => out.push(convert_svd_cluster(cluster)?),
858+
Cluster::Single(_info) => out.push(convert_svd_cluster(cluster, name)?),
859859
Cluster::Array(info, array_info) => {
860860
let indices = array_info
861861
.dim_index
@@ -884,14 +884,13 @@ fn expand_svd_cluster(
884884
}
885885

886886
/// Convert a parsed `Cluster` into its `Field` equivalent
887-
fn convert_svd_cluster(cluster: &Cluster) -> Result<syn::Field, syn::Error> {
887+
fn convert_svd_cluster(cluster: &Cluster, name: Option<&str>) -> Result<syn::Field, syn::Error> {
888888
Ok(match cluster {
889-
Cluster::Single(info) => new_syn_field(
890-
&info.name.to_sanitized_snake_case(),
891-
syn::Type::Path(parse_str::<syn::TypePath>(
892-
&info.name.to_sanitized_upper_case(),
893-
)?),
894-
),
889+
Cluster::Single(info) => {
890+
let ty_name = util::replace_suffix(&info.name, "");
891+
let ty = name_to_ty(&ty_name, name)?;
892+
new_syn_field(&info.name.to_sanitized_snake_case(), ty)
893+
}
895894
Cluster::Array(info, array_info) => {
896895
let name = util::replace_suffix(&info.name, "");
897896

0 commit comments

Comments
 (0)