Skip to content

Commit

Permalink
Ensure that correct item order is maintained in the serialized output
Browse files Browse the repository at this point in the history
 - Top level items are always orderes (ASAP2_VERSION, A2ML_VERSION, PROJECT)
 - axis info under RECORD_LAYOUT is ordered by the position number in the data

fixes issue #29
  • Loading branch information
DanielT committed Dec 24, 2023
1 parent e9667ad commit 7f2dbb5
Show file tree
Hide file tree
Showing 4 changed files with 342 additions and 73 deletions.
36 changes: 33 additions & 3 deletions a2lmacros/src/codegenerator/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,49 @@ fn generate_block_item_writers(structitems: &[DataItem]) -> Vec<TokenStream> {
tgwriters.push(quote! {
for #tgname in &self.#tgname {
let #tgname_out = #tgname.stringify(indent + 1);
tgroup.push(writer::TaggedItemInfo::build(#tag, #tgname_out, #is_block, &#tgname.__block_info));
tgroup.push(writer::TaggedItemInfo {
tag: #tag,
item_text: #tgname_out,
is_block: #is_block,
incfile: &#tgname.__block_info.incfile,
uid: #tgname.__block_info.uid,
line: #tgname.__block_info.line,
start_offset: #tgname.__block_info.start_offset,
end_offset: #tgname.__block_info.end_offset,
position_restriction: #tgname.pos_restrict(),
});
}
});
} else if tgitem.required {
tgwriters.push(quote! {
let #tgname_out = self.#tgname.stringify(indent + 1);
tgroup.push(writer::TaggedItemInfo::build(#tag, #tgname_out, #is_block, &self.#tgname.__block_info));
tgroup.push(writer::TaggedItemInfo {
tag: #tag,
item_text: #tgname_out,
is_block: #is_block,
incfile: &self.#tgname.__block_info.incfile,
uid: self.#tgname.__block_info.uid,
line: self.#tgname.__block_info.line,
start_offset: self.#tgname.__block_info.start_offset,
end_offset: self.#tgname.__block_info.end_offset,
position_restriction: self.#tgname.pos_restrict(),
});
});
} else {
tgwriters.push(quote! {
if let Some(#tgname) = &self.#tgname {
let #tgname_out = #tgname.stringify(indent + 1);
tgroup.push(writer::TaggedItemInfo::build(#tag, #tgname_out, #is_block, &#tgname.__block_info));
tgroup.push(writer::TaggedItemInfo {
tag: #tag,
item_text: #tgname_out,
is_block: #is_block,
incfile: &#tgname.__block_info.incfile,
uid: #tgname.__block_info.uid,
line: #tgname.__block_info.line,
start_offset: #tgname.__block_info.start_offset,
end_offset: #tgname.__block_info.end_offset,
position_restriction: #tgname.pos_restrict(),
});
}
});
}
Expand Down
15 changes: 11 additions & 4 deletions src/a2ml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1087,10 +1087,17 @@ impl GenericIfData {
let mut tgroup = Vec::new();
for tgitemlist in taggeditems.values() {
for tgitem in tgitemlist {
tgroup.push(TaggedItemInfo::build_generic(
tgitem.data.write(indent + 1),
tgitem,
));
tgroup.push(TaggedItemInfo {
tag: &tgitem.tag,
incfile: &tgitem.incfile,
uid: tgitem.uid,
line: tgitem.line,
start_offset: tgitem.start_offset,
end_offset: tgitem.end_offset,
is_block: tgitem.is_block,
item_text: tgitem.data.write(indent + 1),
position_restriction: None,
});
}
}
writer.add_group(tgroup);
Expand Down
Loading

0 comments on commit 7f2dbb5

Please sign in to comment.