From 58773bafafdf223b0894253e9456ca1d4db3a4a2 Mon Sep 17 00:00:00 2001 From: Thorsten de Buhr Date: Tue, 24 Jan 2023 16:18:46 +0100 Subject: [PATCH] Fix CodeQL warnings in SVDConv and PackChk --- tools/packchk/include/GatherCompilers.h | 2 +- tools/packchk/src/PackOptions.cpp | 22 ++++---- tools/svdconv/SVDConv/src/SvdOptions.cpp | 22 ++++---- tools/svdconv/SVDModel/include/SvdItem.h | 4 +- tools/svdconv/SVDModel/include/SvdTypes.h | 22 ++++---- tools/svdconv/SVDModel/src/SvdCExpression.cpp | 20 ++++---- tools/svdconv/SVDModel/src/SvdDerivedFrom.cpp | 11 ++-- tools/svdconv/SVDModel/src/SvdDevice.cpp | 12 ++--- tools/svdconv/SVDModel/src/SvdDimension.cpp | 50 ++++++++++++------- tools/svdconv/SVDModel/src/SvdEnum.cpp | 22 ++++---- tools/svdconv/SVDModel/src/SvdField.cpp | 22 +++++--- tools/svdconv/SVDModel/src/SvdItem.cpp | 43 ++++++++-------- tools/svdconv/SVDModel/src/SvdPeripheral.cpp | 16 +++--- tools/svdconv/SVDModel/src/SvdTypes.cpp | 22 ++++---- tools/svdconv/SVDModel/src/SvdUtils.cpp | 40 +++++++-------- 15 files changed, 179 insertions(+), 151 deletions(-) diff --git a/tools/packchk/include/GatherCompilers.h b/tools/packchk/include/GatherCompilers.h index bd5180df5..82baf72d2 100644 --- a/tools/packchk/include/GatherCompilers.h +++ b/tools/packchk/include/GatherCompilers.h @@ -30,8 +30,8 @@ class GatherCompilersVisitor : public RteVisitor std::map EMPTY_MAP; std::map m_compilerMap; - RteTarget m_target; // for expression evaluation RteModel m_filteredModel; // needed to test conditions + RteTarget m_target; // for expression evaluation }; #endif //GATHERCOMPILERS_H diff --git a/tools/packchk/src/PackOptions.cpp b/tools/packchk/src/PackOptions.cpp index 92cb0d046..b359b1306 100644 --- a/tools/packchk/src/PackOptions.cpp +++ b/tools/packchk/src/PackOptions.cpp @@ -283,20 +283,18 @@ const string CPackOptions::GetHeader() */ string CPackOptions::GetCurrentDateTime() { - string text; - - char buffer[128] = { "0000-00-00" }; - - time_t rawtime; - time(&rawtime); - struct tm* timeinfo = localtime(&rawtime); - if(timeinfo) { - strftime(buffer, sizeof(buffer), "%A %Y-%m-%d %H:%M:%S (%z)", timeinfo); // https://de.wikipedia.org/wiki/ISO_8601 + time_t result = time(nullptr); + const char* timeAsc = asctime(std::localtime(&result)); + string timeText { "" }; + if(timeAsc) { + timeText = timeAsc; + + if(*timeText.rbegin() == '\n') { + timeText.pop_back(); // erase '\n' + } } - text = buffer; - - return text; + return timeText; } /** diff --git a/tools/svdconv/SVDConv/src/SvdOptions.cpp b/tools/svdconv/SVDConv/src/SvdOptions.cpp index d1a2db0f2..28af12012 100644 --- a/tools/svdconv/SVDConv/src/SvdOptions.cpp +++ b/tools/svdconv/SVDConv/src/SvdOptions.cpp @@ -187,20 +187,18 @@ string SvdOptions::GetHeader() */ string SvdOptions::GetCurrentDateTime() { - string text; - - char buffer[128] = { "0000-00-00" }; - - time_t rawtime; - time(&rawtime); - struct tm* timeinfo = localtime(&rawtime); - if(timeinfo) { - strftime(buffer, sizeof(buffer), "%A %Y-%m-%d %H:%M:%S (%z)", timeinfo); // https://de.wikipedia.org/wiki/ISO_8601 + time_t result = time(nullptr); + const char* timeAsc = asctime(std::localtime(&result)); + string timeText { "" }; + if(timeAsc) { + timeText = timeAsc; + + if(*timeText.rbegin() == '\n') { + timeText.pop_back(); // erase '\n' + } } - text = buffer; - - return text; + return timeText; } /** diff --git a/tools/svdconv/SVDModel/include/SvdItem.h b/tools/svdconv/SVDModel/include/SvdItem.h index 1ef972b0a..ea960886c 100644 --- a/tools/svdconv/SVDModel/include/SvdItem.h +++ b/tools/svdconv/SVDModel/include/SvdItem.h @@ -287,7 +287,7 @@ bool SvdItem::GetDeriveItem(T *&item, const std::list& searchName, } if(parent && parent->FindChild(child, name)) { - bool found = false; + found = false; // go down the levels for(const auto& searchN : searchName) { const auto& childs = parent->GetChildren(); @@ -307,7 +307,7 @@ bool SvdItem::GetDeriveItem(T *&item, const std::list& searchName, if(parent && parent->FindChild(parent->GetChildren(), child, searchN)) { parent = child; found = true; - } + } else { found = false; break; diff --git a/tools/svdconv/SVDModel/include/SvdTypes.h b/tools/svdconv/SVDModel/include/SvdTypes.h index cd47d9eb8..b02402898 100644 --- a/tools/svdconv/SVDModel/include/SvdTypes.h +++ b/tools/svdconv/SVDModel/include/SvdTypes.h @@ -32,9 +32,9 @@ struct CpuFeature { const uint16_t NUMEXTIRQ; public: CpuFeature(const bool vtor, const bool mpu, const bool fpu, const bool fpudp, - const bool icache, const bool dcache, const bool itcm, const bool dtcm, + const bool icache, const bool dcache, const bool itcm, const bool dtcm, const bool sau, const bool dsp, const bool pmu, const bool mve, const bool mvefp, - const uint16_t numExtIrq) + const uint16_t numExtIrq) : VTOR(vtor), MPU(mpu), FPU(fpu), FPUDP(fpudp), ICACHE(icache), DCACHE(dcache), ITCM(itcm), DTCM(dtcm), SAU(sau), DSP(dsp), PMU(pmu), MVE(mve), MVEFP(mvefp), NUMEXTIRQ(numExtIrq) @@ -53,19 +53,19 @@ struct CpuTypeFeature { const CpuFeature cpuFeature; public: - CpuTypeFeature(const char *t, const char *n, + CpuTypeFeature(const char *t, const char *n, const bool irqVals0, const bool irqVals1, const bool irqVals2, const bool irqVals3, const bool irqVals4, const bool irqVals5, const bool irqVals6, const bool irqVals7, const bool irqVals8, const bool irqVals9, const bool irqVals10, const bool irqVals11, const bool irqVals12, const bool irqVals13, const bool irqVals14, const bool irqVals15, const bool cpuF0, const bool cpuF1, const bool cpuF2, const bool cpuF3, - const bool cpuF4, const bool cpuF5, const bool cpuF6, const bool cpuF7, - const bool cpuF8, const bool cpuF9, const bool cpuF10, const bool cpuF11, + const bool cpuF4, const bool cpuF5, const bool cpuF6, const bool cpuF7, + const bool cpuF8, const bool cpuF9, const bool cpuF10, const bool cpuF11, const bool cpuF12, const uint16_t numExtIrq ) : type(t), name(n), - cpuFeature(cpuF0,cpuF1,cpuF2,cpuF3,cpuF4,cpuF5,cpuF6,cpuF7,cpuF8,cpuF9,cpuF10,cpuF11,cpuF12, numExtIrq) + cpuFeature(cpuF0,cpuF1,cpuF2,cpuF3,cpuF4,cpuF5,cpuF6,cpuF7,cpuF8,cpuF9,cpuF10,cpuF11,cpuF12, numExtIrq) { uint32_t i = 0; irq[i++] = irqVals0; @@ -103,7 +103,7 @@ class SvdTypes { enum class EnumUsage { UNDEF = 0, READ, WRITE, READWRITE }; enum class SvdConvV2accType { EMPTY = 0, READ, READONLY, WRITE, WRITEONLY, READWRITE, UNDEF }; enum class CpuIrqNum { IRQ0 = 0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7, IRQ8, IRQ9, IRQ10, IRQ11, IRQ12, IRQ13, IRQ14, IRQ15, IRQ_END, IRQ_RESERVED, IRQ_UNDEF }; - + #define CPUTYPE(enumType, name) enumType, enum class CpuType { #include "EnumStringTables.h" @@ -115,7 +115,7 @@ class SvdTypes { #include "EnumStringTables.h" }; #undef MODIFWRV - + struct CmsisCfgForce { uint32_t bMpuPresent : 1; uint32_t bFpuPresent : 1; @@ -131,7 +131,7 @@ class SvdTypes { uint32_t bMvePresent : 1; uint32_t bMveFP : 1; }; - + static const std::string& GetExpressionType (Expression exprType); static const std::string& GetAccessType (Access accType); static const std::string& GetAccessTypeSfd (Access accType); @@ -145,8 +145,8 @@ class SvdTypes { static const std::string& GetCortexMInterruptName (SvdTypes::CpuIrqNum num); static const std::string& GetCortexMInterruptDescription (SvdTypes::CpuIrqNum num); static const std::string& GetEnumUsage (EnumUsage enumUsage); - static const bool GetCortexMInterruptAvailable (CpuType cpuType, SvdTypes::CpuIrqNum num); - static const bool GetCortexMInterrupt (CpuType cpuType, SvdTypes::CpuIrqNum num, std::string &name, std::string &descr); + static bool GetCortexMInterruptAvailable (CpuType cpuType, SvdTypes::CpuIrqNum num); + static bool GetCortexMInterrupt (CpuType cpuType, SvdTypes::CpuIrqNum num, std::string &name, std::string &descr); static const CpuFeature& GetCpuFeatures (CpuType cpuType); private: diff --git a/tools/svdconv/SVDModel/src/SvdCExpression.cpp b/tools/svdconv/SVDModel/src/SvdCExpression.cpp index f9886f837..c292e482b 100644 --- a/tools/svdconv/SVDModel/src/SvdCExpression.cpp +++ b/tools/svdconv/SVDModel/src/SvdCExpression.cpp @@ -77,27 +77,27 @@ bool SvdCExpression::LinkSymbols(SvdItem* item, const SvdCExpressionParser::Toke auto& regList = device->GetExpressionRegistersList(); - for(auto& symbol : m_symbolsList) { - switch(symbol.token.type) { + for(auto& foundSymbol : m_symbolsList) { + switch(foundSymbol.token.type) { case SvdCExpressionParser::xme_identi: { SvdItem* from = 0; string lastSearchName; - item->GetDeriveItem(from, symbol.searchname, L_UNDEF, lastSearchName); + item->GetDeriveItem(from, foundSymbol.searchname, L_UNDEF, lastSearchName); if(!from) { LogMsg("M244", NAME(lastSearchName), MSG(errText), lineNo); return false; } - symbol.svdItem = from; + foundSymbol.svdItem = from; - string name = symbol.svdItem->GetHierarchicalNameResulting(); + string name = foundSymbol.svdItem->GetHierarchicalNameResulting(); if(!name.empty()) { - if(symbol.svdItem->GetSvdLevel() == L_Register) { - regList[name] = symbol.svdItem; + if(foundSymbol.svdItem->GetSvdLevel() == L_Register) { + regList[name] = foundSymbol.svdItem; } - else if(symbol.svdItem->GetSvdLevel() == L_Field) { - SvdItem* item = symbol.svdItem->GetParent()->GetParent(); + else if(foundSymbol.svdItem->GetSvdLevel() == L_Field) { + SvdItem* symbolItem = foundSymbol.svdItem->GetParent()->GetParent(); if(item) { - regList[name] = item; + regList[name] = symbolItem; } } else { diff --git a/tools/svdconv/SVDModel/src/SvdDerivedFrom.cpp b/tools/svdconv/SVDModel/src/SvdDerivedFrom.cpp index 428e47f25..d02e73b2d 100644 --- a/tools/svdconv/SVDModel/src/SvdDerivedFrom.cpp +++ b/tools/svdconv/SVDModel/src/SvdDerivedFrom.cpp @@ -83,7 +83,7 @@ bool SvdDerivedFrom::CalculateDerivedFrom() do { auto it = name.find("%"); if(it == string::npos) { - break; + break; } name.erase(it, 1); } while(1); @@ -91,9 +91,9 @@ bool SvdDerivedFrom::CalculateDerivedFrom() const auto lineNo = GetLineNumber(); LogMsg("M206", NAME(name), lineNo); Invalidate(); - auto parent = GetParent(); - if(parent) { - parent->Invalidate(); + auto invalidParent = GetParent(); + if(invalidParent) { + invalidParent->Invalidate(); } } @@ -103,6 +103,9 @@ bool SvdDerivedFrom::CalculateDerivedFrom() bool SvdDerivedFrom::DeriveItem(SvdItem *from) { const auto parent = GetParent(); + if(!parent) { + return true; + } // If there are already any childs, the item is changed from it's derivedFrom item if(parent->GetChildCount()) { diff --git a/tools/svdconv/SVDModel/src/SvdDevice.cpp b/tools/svdconv/SVDModel/src/SvdDevice.cpp index 52f991f4d..072da49dd 100644 --- a/tools/svdconv/SVDModel/src/SvdDevice.cpp +++ b/tools/svdconv/SVDModel/src/SvdDevice.cpp @@ -428,7 +428,7 @@ bool SvdDevice::AddToMap(SvdCluster *clust) if(enumCont) { AddToMap(enumCont); } - + return true; } @@ -622,8 +622,8 @@ bool SvdDevice::CheckPeripherals(const list& childs) // ClusterNames must be unique to peripherals const auto regs = peri->GetRegisterContainer(); if(regs) { - const auto& childs = regs->GetChildren(); - AddClusterNames(childs); + const auto& children = regs->GetChildren(); + AddClusterNames(children); } } } @@ -787,12 +787,12 @@ bool SvdDevice::CheckForItemsRegister(SvdRegister* reg) if(dim) { const auto& dimChilds = dim->GetChildren(); for(const auto dimChild : dimChilds) { - const auto reg = dynamic_cast(dimChild); - if(!reg || !reg->IsValid()) { + const auto dimReg = dynamic_cast(dimChild); + if(!dimReg || !dimReg->IsValid()) { continue; } - itemCnt += CheckForItemsRegister(reg); + itemCnt += CheckForItemsRegister(dimReg); } return true; } diff --git a/tools/svdconv/SVDModel/src/SvdDimension.cpp b/tools/svdconv/SVDModel/src/SvdDimension.cpp index 7fb36e9ca..684d51e71 100644 --- a/tools/svdconv/SVDModel/src/SvdDimension.cpp +++ b/tools/svdconv/SVDModel/src/SvdDimension.cpp @@ -125,23 +125,26 @@ bool SvdDimension::Construct(XMLTreeElement* xmlElement) SetLineNumber(xmlElement->GetLineNumber()); if(GetTag().empty()) { - string tag { "Dim data: " }; + string thisTag { "Dim data: " }; auto parent = GetParent(); if(parent) { - tag += parent->GetTag(); + thisTag += parent->GetTag(); } else { - tag += "???"; + thisTag += "???"; } - SetTag(tag); + SetTag(thisTag); } if(!IsTagAllowed(tag)) { const auto parent = GetParent(); - const auto lineNo = xmlElement->GetLineNumber(); - const auto svdLevel = parent->GetSvdLevel(); - LogMsg("M240", TAG(tag), THISLEVEL(), LEVEL2(GetSvdLevelStr(svdLevel)), lineNo); - parent->Invalidate(); + if(parent) { + const auto lineNo = xmlElement->GetLineNumber(); + const auto svdLevel = parent->GetSvdLevel(); + LogMsg("M240", TAG(tag), THISLEVEL(), LEVEL2(GetSvdLevelStr(svdLevel)), lineNo); + parent->Invalidate(); + } + return true; } @@ -343,7 +346,7 @@ bool SvdDimension::CalculateNameFromExpression() if(!item) { return true; } - + const auto& itemName = item->GetName(); string name; uint32_t insertPos = 0; @@ -361,9 +364,11 @@ bool SvdDimension::CalculateNameFromExpression() } const auto expr = GetExpression(); - expr->SetName(name); - expr->SetType(exprType); - expr->SetNameInsertPos(insertPos); + if(expr) { + expr->SetName(name); + expr->SetType(exprType); + expr->SetNameInsertPos(insertPos); + } return true; } @@ -392,8 +397,10 @@ bool SvdDimension::CalculateDisplayNameFromExpression() } const auto expr = GetExpression(); - expr->SetDisplayName (name); - expr->SetDisplayNameInsertPos (insertPos); + if(expr) { + expr->SetDisplayName (name); + expr->SetDisplayNameInsertPos (insertPos); + } return true; } @@ -422,8 +429,10 @@ bool SvdDimension::CalculateDescriptionFromExpression() } const auto expr = GetExpression(); - expr->SetDescription (descr); - expr->SetDescriptionInsertPos (insertPos); + if(expr) { + expr->SetDescription (descr); + expr->SetDescriptionInsertPos (insertPos); + } return true; } @@ -521,8 +530,11 @@ bool SvdDimension::CopyItem(SvdItem *from) bool SvdDimension::AddToMap(const string& dimIndex) { const auto parent = GetParent(); - const auto lineNo = parent->GetLineNumber(); + if(!parent) { + return true; + } + const auto lineNo = parent->GetLineNumber(); auto found = m_dimIndexSet.find(dimIndex); if(found != m_dimIndexSet.end()) { LogMsg("M336", LEVEL(""), NAME(dimIndex), LINE2(lineNo), lineNo); @@ -541,6 +553,10 @@ bool SvdDimension::CheckItem() } const auto parent = GetParent(); + if(!parent) { + return true; + } + const auto name = parent->GetNameCalculated(); const auto lineNo = parent->GetLineNumber(); diff --git a/tools/svdconv/SVDModel/src/SvdEnum.cpp b/tools/svdconv/SVDModel/src/SvdEnum.cpp index 1e3871b44..d8eba86f4 100644 --- a/tools/svdconv/SVDModel/src/SvdEnum.cpp +++ b/tools/svdconv/SVDModel/src/SvdEnum.cpp @@ -197,16 +197,18 @@ bool SvdEnum::Calculate() SetName(n); it++; - for(; it != numbers.end(); it++) { - const auto enu = new SvdEnum(parent); - parent->AddItem(enu); - enu->CopyItem(this); - enu->SetValue(*it); - - string n = name; - n += "_"; - n += SvdUtils::CreateDecNum(*it); - enu->SetName(n); + if(parent) { + for(; it != numbers.end(); it++) { + const auto enu = new SvdEnum(parent); + parent->AddItem(enu); + enu->CopyItem(this); + enu->SetValue(*it); + + string n2 = name; + n2 += "_"; + n2 += SvdUtils::CreateDecNum(*it); + enu->SetName(n2); + } } } diff --git a/tools/svdconv/SVDModel/src/SvdField.cpp b/tools/svdconv/SVDModel/src/SvdField.cpp index bcb40d642..3e32d4bce 100644 --- a/tools/svdconv/SVDModel/src/SvdField.cpp +++ b/tools/svdconv/SVDModel/src/SvdField.cpp @@ -196,7 +196,13 @@ bool SvdField::CalculateDim() dim->CalculateDim(); - if(dim->GetExpression()->GetType() == SvdTypes::Expression::ARRAY) { + const auto dimExpression = dim->GetExpression(); + SvdTypes::Expression exprType = SvdTypes::Expression::NONE; + if(dimExpression) { + exprType = dimExpression->GetType(); + } + + if(exprType == SvdTypes::Expression::ARRAY) { const auto lineNo = GetLineNumber(); const auto& svdLevelStr = GetSvdLevelStr(GetSvdLevel()); const auto name = GetNameCalculated(); @@ -233,13 +239,15 @@ bool SvdField::CalculateDim() } } - if(dimIndexList.size() >= 1) { - auto dimIndexText = *dimIndexList.begin(); + if(dimIndexText.empty()) { + if(dimIndexList.size() >= 1) { + dimIndexText = *dimIndexList.begin(); - if(dimIndexList.size() > 1) { - const auto& dimIndexTextEnd = *dimIndexList.rbegin(); - dimIndexText += ".."; - dimIndexText += dimIndexTextEnd; + if(dimIndexList.size() > 1) { + const auto& dimIndexTextEnd = *dimIndexList.rbegin(); + dimIndexText += ".."; + dimIndexText += dimIndexTextEnd; + } } } diff --git a/tools/svdconv/SVDModel/src/SvdItem.cpp b/tools/svdconv/SVDModel/src/SvdItem.cpp index 3b9f243f9..90f7fa6f8 100644 --- a/tools/svdconv/SVDModel/src/SvdItem.cpp +++ b/tools/svdconv/SVDModel/src/SvdItem.cpp @@ -60,18 +60,18 @@ SvdElement::~SvdElement() { } -bool SvdElement::SetName(const string &name) +bool SvdElement::SetName(const string &name) { m_name = name; return true; } -const string &SvdElement::GetName() +const string &SvdElement::GetName() { return m_name; } -bool SvdElement::SetTag(const string &tag) +bool SvdElement::SetTag(const string &tag) { m_tag = tag; return true; @@ -126,13 +126,13 @@ SvdItem::~SvdItem() ClearChildren(); } -bool SvdItem::SetDescription(const string &descr) +bool SvdItem::SetDescription(const string &descr) { m_description = descr; return true; } -const string &SvdItem::GetDescription() +const string &SvdItem::GetDescription() { return m_description; } @@ -336,7 +336,7 @@ bool SvdItem::Validate() return IsValid(); } -void SvdItem::AddItem(SvdItem* item) +void SvdItem::AddItem(SvdItem* item) { if(!item) { return; @@ -409,7 +409,7 @@ string SvdItem::GetDisplayNameCalculated(bool bDataCheck /*= false*/) if(!dispName.empty()) { return dispName; } - } + } else { const auto& dispName = GetDisplayName(); if(!dispName.empty()) { @@ -462,34 +462,34 @@ string SvdItem::GetDeriveName() return deriveName; } -bool SvdItem::SetDisplayName(const string &name) +bool SvdItem::SetDisplayName(const string &name) { m_displayName = name; return true; } -const string &SvdItem::GetDisplayName() +const string &SvdItem::GetDisplayName() { return m_displayName; } -const string& SvdItem::GetAlternate() +const string& SvdItem::GetAlternate() { return GetParent()->GetAlternate(); } -const string& SvdItem::GetPrependToName() +const string& SvdItem::GetPrependToName() { return GetParent()->GetPrependToName(); } -const string& SvdItem::GetAppendToName() +const string& SvdItem::GetAppendToName() { return GetParent()->GetAppendToName(); } -const string& SvdItem::GetHeaderDefinitionsPrefix() +const string& SvdItem::GetHeaderDefinitionsPrefix() { return GetParent()->GetHeaderDefinitionsPrefix(); } @@ -612,26 +612,26 @@ const string& SvdItem::GetPeripheralName() return SvdUtils::EMPTY_STRING; } -bool SvdItem::SetDerivedFrom(SvdDerivedFrom *derivedFrom) +bool SvdItem::SetDerivedFrom(SvdDerivedFrom *derivedFrom) { m_derivedFrom = derivedFrom; return true; } -SvdDerivedFrom* SvdItem::GetDerivedFrom() +SvdDerivedFrom* SvdItem::GetDerivedFrom() { return m_derivedFrom; } -bool SvdItem::SetDimension(SvdDimension *dimension) +bool SvdItem::SetDimension(SvdDimension *dimension) { m_dimension = dimension; return true; } -SvdDimension* SvdItem::GetDimension() +SvdDimension* SvdItem::GetDimension() { return m_dimension; } @@ -947,7 +947,7 @@ bool SvdItem::CopyChilds(SvdItem *from, SvdItem *hook) nItem = new SvdFieldContainer(hook); hook->AddItem(nItem); nItem->CopyItem(copy); - } + } else { nItem = (SvdFieldContainer *)*(hook->GetChildren().begin()); } @@ -959,7 +959,7 @@ bool SvdItem::CopyChilds(SvdItem *from, SvdItem *hook) nItem = new SvdRegisterContainer(hook); hook->AddItem(nItem); nItem->CopyItem(copy); - } + } else { nItem = (SvdRegisterContainer *)*(hook->GetChildren().begin()); } @@ -1150,12 +1150,12 @@ SvdTypes::ProtectionType SvdItem::GetEffectiveProtection() return SvdTypes::ProtectionType::UNDEF; // default, if UNDEF, then do not generate information (SFD, ...); } -const string& SvdItem::GetSvdLevelStr(SVD_LEVEL level) +const string& SvdItem::GetSvdLevelStr(SVD_LEVEL level) { return m_svdLevelStr[level]; } -const string& SvdItem::GetSvdLevelStr() +const string& SvdItem::GetSvdLevelStr() { return m_svdLevelStr[GetSvdLevel()]; } @@ -1185,6 +1185,7 @@ bool SvdItem::CheckItem() if(IsNameRequired()) { const auto dim = GetDimension(); if(svdLevel != L_Peripheral && dim && dim->GetExpression()->GetType() == SvdTypes::Expression::EXTEND) { + ; } else { LogMsg("M316", LEVEL(svdLevelStr), lineNo); diff --git a/tools/svdconv/SVDModel/src/SvdPeripheral.cpp b/tools/svdconv/SVDModel/src/SvdPeripheral.cpp index 6a4147c33..455703d68 100644 --- a/tools/svdconv/SVDModel/src/SvdPeripheral.cpp +++ b/tools/svdconv/SVDModel/src/SvdPeripheral.cpp @@ -103,6 +103,8 @@ SvdPeripheral::~SvdPeripheral() for(const auto interrupt : m_interrupt) { delete interrupt; } + + delete m_disableCondition; } bool SvdPeripheral::Construct(XMLTreeElement* xmlElement) @@ -232,7 +234,7 @@ bool SvdPeripheral::ProcessXmlElement(XMLTreeElement* xmlElement) return SvdItem::ProcessXmlElement(xmlElement); } -bool SvdPeripheral::ProcessXmlAttributes(XMLTreeElement* xmlElement) +bool SvdPeripheral::ProcessXmlAttributes(XMLTreeElement* xmlElement) { return SvdItem::ProcessXmlAttributes(xmlElement); } @@ -248,22 +250,22 @@ SvdRegisterContainer* SvdPeripheral::GetRegisterContainer() const return cont; } -list& SvdPeripheral::GetAddressBlock() +list& SvdPeripheral::GetAddressBlock() { return m_addressBlock; } -list& SvdPeripheral::GetInterrupt() +list& SvdPeripheral::GetInterrupt() { return m_interrupt; } -void SvdPeripheral::AddAddressBlock (SvdAddressBlock* addrBlock) +void SvdPeripheral::AddAddressBlock (SvdAddressBlock* addrBlock) { m_addressBlock.push_back(addrBlock); } -void SvdPeripheral::AddInterrupt (SvdInterrupt* interrupt) +void SvdPeripheral::AddInterrupt (SvdInterrupt* interrupt) { m_interrupt.push_back(interrupt); } @@ -886,7 +888,7 @@ bool SvdPeripheral::CheckRegisterAddress(SvdRegister* reg, const list SvdTypes::cpuTypeName = { }; -const string& SvdTypes::GetExpressionType(Expression expr) +const string& SvdTypes::GetExpressionType(Expression expr) { return expression_str[(uint32_t)expr]; } -const string& SvdTypes::GetAccessType(Access acc) +const string& SvdTypes::GetAccessType(Access acc) { return access_str[(uint32_t)acc]; } -const string& SvdTypes::GetAccessTypeSfd(Access acc) +const string& SvdTypes::GetAccessTypeSfd(Access acc) { return accessSfd_str[(uint32_t)acc]; } -const string& SvdTypes::GetAccessTypeIo(Access acc) +const string& SvdTypes::GetAccessTypeIo(Access acc) { return access_ioTypes_str[(uint32_t)acc]; } -const string& SvdTypes::GetUsage(AddrBlockUsage usage) +const string& SvdTypes::GetUsage(AddrBlockUsage usage) { return addrBlockUsage_str[(uint32_t)usage]; } -const string& SvdTypes::GetCpuType(CpuType cpuType) +const string& SvdTypes::GetCpuType(CpuType cpuType) { auto it = cpuTypeName.find(cpuType); if(it != cpuTypeName.end()) { @@ -180,7 +180,7 @@ const string& SvdTypes::GetCpuType(CpuType cpuType) return SvdUtils::EMPTY_STRING; } -const string& SvdTypes::GetCpuName(CpuType cpuType) +const string& SvdTypes::GetCpuName(CpuType cpuType) { auto it = cpuTypeName.find(cpuType); if(it != cpuTypeName.end()) { @@ -190,7 +190,7 @@ const string& SvdTypes::GetCpuName(CpuType cpuType) return SvdUtils::EMPTY_STRING; } -const string& SvdTypes::GetCpuEndian(Endian endian) +const string& SvdTypes::GetCpuEndian(Endian endian) { return endian_str[(uint32_t)endian]; } @@ -225,7 +225,7 @@ const string& SvdTypes::GetCortexMInterruptDescription(SvdTypes::CpuIrqNum num) return SvdUtils::EMPTY_STRING; } -const bool SvdTypes::GetCortexMInterruptAvailable(CpuType cpuType, SvdTypes::CpuIrqNum num) +bool SvdTypes::GetCortexMInterruptAvailable(CpuType cpuType, SvdTypes::CpuIrqNum num) { auto it = cpuTypeName.find(cpuType); if(it != cpuTypeName.end()) { @@ -235,7 +235,7 @@ const bool SvdTypes::GetCortexMInterruptAvailable(CpuType cpuType, SvdTypes::Cpu return false; } -const bool SvdTypes::GetCortexMInterrupt(CpuType cpuType, SvdTypes::CpuIrqNum num, string &name, string &descr) +bool SvdTypes::GetCortexMInterrupt(CpuType cpuType, SvdTypes::CpuIrqNum num, string &name, string &descr) { if(!GetCortexMInterruptAvailable(cpuType, num)) { name = GetCortexMInterruptName(SvdTypes::CpuIrqNum::IRQ_RESERVED); @@ -255,7 +255,7 @@ const string& SvdTypes::GetEnumUsage(EnumUsage enumUsage) return enumUsage_str[(uint32_t)enumUsage]; } -const CpuFeature& SvdTypes::GetCpuFeatures(CpuType cpuType) +const CpuFeature& SvdTypes::GetCpuFeatures(CpuType cpuType) { auto it = cpuTypeName.find(cpuType); if(it != cpuTypeName.end()) { diff --git a/tools/svdconv/SVDModel/src/SvdUtils.cpp b/tools/svdconv/SVDModel/src/SvdUtils.cpp index 809aa662a..d3a56f70b 100644 --- a/tools/svdconv/SVDModel/src/SvdUtils.cpp +++ b/tools/svdconv/SVDModel/src/SvdUtils.cpp @@ -133,7 +133,7 @@ SvdTypes::Expression SvdUtils::ParseExpression(const string &expr, string &name, string::size_type pos = expr.find("%"); if(pos != string::npos) { - string::size_type pos = expr.find("[%s]"); + pos = expr.find("[%s]"); if(pos != string::npos) { exp = SvdTypes::Expression::ARRAY; if(pos != expr.length() - 4) { @@ -440,7 +440,7 @@ bool SvdUtils::ConvertNumber(const string &text, set &numbers) if(!ConvertNumber(text, num)) { return false; } - + numbers.insert(num); return true; @@ -497,7 +497,7 @@ bool SvdUtils::ConvertNumber (const string &text, uint64_t &number) if(t.find_first_of("x", 2) != string::npos) { // XBin Number return false; } - + // Bin Number if(!ConvertNumber(&t[2], num, 2)) { return false; @@ -689,7 +689,7 @@ bool SvdUtils::ConvertAccess (const string &text, SvdTypes::Access &acc, uint32_ LogMsg("M225", NAME(text), NAME2("read-only"), lineNo); } return true; - } + } else if(t == "write-only") { acc = SvdTypes::Access::WRITEONLY; if(text != "write-only") { @@ -788,14 +788,14 @@ bool SvdUtils::ConvertEnumUsage (const string &text, SvdTypes::EnumUsage &usage, LogMsg("M225", NAME(text), NAME2("read"), lineNo); } return true; - } + } else if(t == "write") { usage = SvdTypes::EnumUsage::WRITE; if(text != "write") { LogMsg("M225", NAME(text), NAME2("write"), lineNo); } return true; - } + } else if(t == "read-write") { usage = SvdTypes::EnumUsage::READWRITE; if(text != "read-write") { @@ -847,21 +847,21 @@ bool SvdUtils::ConvertCpuEndian (const string &text, SvdTypes::Endian &endian, u LogMsg("M225", NAME(text), NAME2("little"), lineNo); } return true; - } + } else if(t == "big") { endian = SvdTypes::Endian::BIG; if(text != "big") { LogMsg("M225", NAME(text), NAME2("big"), lineNo); } return true; - } + } else if(t == "selectable") { endian = SvdTypes::Endian::SELECTABLE; if(text != "selectable") { LogMsg("M225", NAME(text), NAME2("selectable"), lineNo); } return true; - } + } else if(t == "other") { endian = SvdTypes::Endian::OTHER; if(text != "other") { @@ -935,56 +935,56 @@ bool SvdUtils::ConvertModifiedWriteValues(const string &text, SvdTypes::Modified LogMsg("M225", NAME(text), NAME2("oneToClear"), lineNo); } return true; - } + } else if(t == "onetoset") { val = SvdTypes::ModifiedWriteValue::ONETOSET; if(text != "oneToSet") { LogMsg("M225", NAME(text), NAME2("oneToSet"), lineNo); } return true; - } + } else if(t == "onetotoggle") { val = SvdTypes::ModifiedWriteValue::ONETOTOGGLE; if(text != "oneToToggle") { LogMsg("M225", NAME(text), NAME2("oneToToggle"), lineNo); } return true; - } + } else if(t == "zerotoclear") { val = SvdTypes::ModifiedWriteValue::ZEROTOCLEAR; if(text != "zeroToClear") { LogMsg("M225", NAME(text), NAME2("zeroToClear"), lineNo); } return true; - } + } else if(t == "zerotoset") { val = SvdTypes::ModifiedWriteValue::ZEROTOSET; if(text != "zeroToSet") { LogMsg("M225", NAME(text), NAME2("zeroToSet"), lineNo); } return true; - } + } else if(t == "zerototoggle") { val = SvdTypes::ModifiedWriteValue::ZEROTOTOGGLE; if(text != "zeroToToggle") { LogMsg("M225", NAME(text), NAME2("zeroToToggle"), lineNo); } return true; - } + } else if(t == "clear") { val = SvdTypes::ModifiedWriteValue::CLEAR; if(text != "clear") { LogMsg("M225", NAME(text), NAME2("clear"), lineNo); } return true; - } + } else if(t == "set") { val = SvdTypes::ModifiedWriteValue::SET; if(text != "set") { LogMsg("M225", NAME(text), NAME2("set"), lineNo); } return true; - } + } else if(t == "selectable") { val = SvdTypes::ModifiedWriteValue::SET; if(text != "selectable") { @@ -1027,14 +1027,14 @@ bool SvdUtils::ConvertReadAction (const string &text, SvdTypes::ReadAction &act LogMsg("M225", NAME(text), NAME2("set"), lineNo); } return true; - } + } else if(t == "modify") { act = SvdTypes::ReadAction::MODIFY; if(text != "modify") { LogMsg("M225", NAME(text), NAME2("modify"), lineNo); } return true; - } + } else if(t == "modifyexternal") { act = SvdTypes::ReadAction::MODIFEXT; if(text != "modifyExternal") { @@ -1070,7 +1070,7 @@ bool SvdUtils::ConvertDerivedNameHirachy(const string &name, list& searc string text = name.substr(prevPos, pos - prevPos); if(!text.empty()) { searchName.push_back(text); - } + } else { searchName.push_back("!ERROR!"); }