Skip to content

Commit 4d190c6

Browse files
[svdconv] changed casts to dynamic_cast (#1336) (#2240)
changed casts Co-authored-by: Thorsten de Buhr <[email protected]>
1 parent 27a0951 commit 4d190c6

File tree

2 files changed

+44
-40
lines changed

2 files changed

+44
-40
lines changed

tools/svdconv/SVDModel/src/SvdCpu.cpp

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -238,38 +238,40 @@ bool SvdCpu::ProcessXmlAttributes(XMLTreeElement* xmlElement)
238238

239239
bool SvdCpu::CopyItem(SvdItem *from)
240240
{
241-
const auto pFrom = (SvdCpu*) from;
242-
243-
const auto& revisionStr = GetRevisionStr ();
244-
const auto revision = GetRevision ();
245-
const auto nvicPrioBits = GetNvicPrioBits ();
246-
const auto mpuPresent = GetMpuPresent ();
247-
const auto fpuPresent = GetFpuPresent ();
248-
const auto vendorSystickConfig = GetVendorSystickConfig ();
249-
const auto fpuDP = GetFpuDP ();
250-
const auto icachePresent = GetIcachePresent ();
251-
const auto dcachePresent = GetDcachePresent ();
252-
const auto itcmPresent = GetItcmPresent ();
253-
const auto dtcmPresent = GetDtcmPresent ();
254-
const auto vtorPresent = GetVtorPresent ();
255-
const auto endian = GetEndian ();
256-
const auto type = GetType ();
257-
258-
if(revisionStr == "") { SetRevisionStr (pFrom->GetRevisionStr ()); }
259-
if(revision == 0 ) { SetRevision (pFrom->GetRevision ()); }
260-
if(nvicPrioBits == 0 ) { SetNvicPrioBits (pFrom->GetNvicPrioBits ()); }
261-
if(mpuPresent == 0 ) { SetMpuPresent (pFrom->GetMpuPresent ()); }
262-
if(fpuPresent == 0 ) { SetFpuPresent (pFrom->GetFpuPresent ()); }
263-
if(vendorSystickConfig == 0 ) { SetVendorSystickConfig (pFrom->GetVendorSystickConfig ()); }
264-
if(fpuDP == 0 ) { SetFpuDP (pFrom->GetFpuDP ()); }
265-
if(icachePresent == 0 ) { SetIcachePresent (pFrom->GetIcachePresent ()); }
266-
if(dcachePresent == 0 ) { SetDcachePresent (pFrom->GetDcachePresent ()); }
267-
if(itcmPresent == 0 ) { SetItcmPresent (pFrom->GetItcmPresent ()); }
268-
if(dtcmPresent == 0 ) { SetDtcmPresent (pFrom->GetDtcmPresent ()); }
269-
if(vtorPresent == 0 ) { SetVtorPresent (pFrom->GetVtorPresent ()); }
270-
if(endian == SvdTypes::Endian::UNDEF) { SetEndian (pFrom->GetEndian ()); }
271-
if(type == SvdTypes::CpuType::UNDEF) { SetType (pFrom->GetType ()); }
272-
241+
const auto pFrom = dynamic_cast<SvdCpu*>(from);
242+
243+
if(pFrom) {
244+
const auto& revisionStr = GetRevisionStr ();
245+
const auto revision = GetRevision ();
246+
const auto nvicPrioBits = GetNvicPrioBits ();
247+
const auto mpuPresent = GetMpuPresent ();
248+
const auto fpuPresent = GetFpuPresent ();
249+
const auto vendorSystickConfig = GetVendorSystickConfig ();
250+
const auto fpuDP = GetFpuDP ();
251+
const auto icachePresent = GetIcachePresent ();
252+
const auto dcachePresent = GetDcachePresent ();
253+
const auto itcmPresent = GetItcmPresent ();
254+
const auto dtcmPresent = GetDtcmPresent ();
255+
const auto vtorPresent = GetVtorPresent ();
256+
const auto endian = GetEndian ();
257+
const auto type = GetType ();
258+
259+
if(revisionStr == "") { SetRevisionStr (pFrom->GetRevisionStr ()); }
260+
if(revision == 0 ) { SetRevision (pFrom->GetRevision ()); }
261+
if(nvicPrioBits == 0 ) { SetNvicPrioBits (pFrom->GetNvicPrioBits ()); }
262+
if(mpuPresent == 0 ) { SetMpuPresent (pFrom->GetMpuPresent ()); }
263+
if(fpuPresent == 0 ) { SetFpuPresent (pFrom->GetFpuPresent ()); }
264+
if(vendorSystickConfig == 0 ) { SetVendorSystickConfig (pFrom->GetVendorSystickConfig ()); }
265+
if(fpuDP == 0 ) { SetFpuDP (pFrom->GetFpuDP ()); }
266+
if(icachePresent == 0 ) { SetIcachePresent (pFrom->GetIcachePresent ()); }
267+
if(dcachePresent == 0 ) { SetDcachePresent (pFrom->GetDcachePresent ()); }
268+
if(itcmPresent == 0 ) { SetItcmPresent (pFrom->GetItcmPresent ()); }
269+
if(dtcmPresent == 0 ) { SetDtcmPresent (pFrom->GetDtcmPresent ()); }
270+
if(vtorPresent == 0 ) { SetVtorPresent (pFrom->GetVtorPresent ()); }
271+
if(endian == SvdTypes::Endian::UNDEF) { SetEndian (pFrom->GetEndian ()); }
272+
if(type == SvdTypes::CpuType::UNDEF) { SetType (pFrom->GetType ()); }
273+
}
274+
273275
SvdItem::CopyItem(from);
274276

275277
return false;

tools/svdconv/SVDModel/src/SvdEnum.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,21 +225,23 @@ bool SvdEnum::SetValue(uint64_t value)
225225

226226
bool SvdEnum::CopyItem(SvdItem *from)
227227
{
228-
const auto pFrom = (SvdEnum*) from;
228+
const auto pFrom = dynamic_cast<SvdEnum*>(from);
229229

230230
bool valValid = GetValue ().bValid;
231231
bool isDefault = IsDefault();
232232

233-
if(!valValid) {
234-
if(pFrom->GetValue().bValid) {
235-
SetValue(pFrom->GetValue().u32);
233+
if(pFrom) {
234+
if(!valValid) {
235+
if(pFrom->GetValue().bValid) {
236+
SetValue(pFrom->GetValue().u32);
237+
}
236238
}
237-
}
238239

239-
if(isDefault == 0 ) {
240-
SetIsDefault(pFrom->IsDefault());
240+
if(isDefault == 0 ) {
241+
SetIsDefault(pFrom->IsDefault());
242+
}
241243
}
242-
244+
243245
return SvdItem::CopyItem(from);
244246
}
245247

0 commit comments

Comments
 (0)