From 32b42188005c82b6659a3e6516c6e3071ccda587 Mon Sep 17 00:00:00 2001 From: yuanbo Date: Mon, 14 Feb 2022 20:50:33 +0800 Subject: [PATCH] fix: clean code scan issue Signed-off-by: yuanbo --- core/host/include/hdf_device.h | 6 +++--- core/manager/src/devmgr_service.c | 5 +++-- tools/hc-gen/src/bytecode_gen.cpp | 4 ++-- tools/hc-gen/src/decompile.cpp | 8 ++++---- tools/hc-gen/src/lexer.cpp | 2 +- tools/hc-gen/src/macro_gen.cpp | 14 +++++++------- tools/hc-gen/src/macro_gen.h | 8 ++++---- tools/hc-gen/src/text_gen.cpp | 24 ++++++++++++------------ tools/hc-gen/src/text_gen.h | 14 +++++++------- 9 files changed, 43 insertions(+), 42 deletions(-) diff --git a/core/host/include/hdf_device.h b/core/host/include/hdf_device.h index a61d784b..18cd8068 100644 --- a/core/host/include/hdf_device.h +++ b/core/host/include/hdf_device.h @@ -28,9 +28,9 @@ typedef uint32_t devid_t; #define DEVNODEID_MASK ((1 << DEVNODEID_BITS) - 1) #define DEVICEID_MASK ((1 << DEVICEID_BITS) - 1) -#define HOSTID(devid) (devid >> (DEVICEID_BITS + DEVNODEID_BITS)) -#define DEVICEID(devid) ((devid >> DEVNODEID_BITS) & DEVICEID_MASK) -#define DEVNODEID(devid) (devid & DEVNODEID_MASK) +#define HOSTID(devid) ((uint32_t)devid >> (DEVICEID_BITS + DEVNODEID_BITS)) +#define DEVICEID(devid) (((uint32_t)devid >> DEVNODEID_BITS) & DEVICEID_MASK) +#define DEVNODEID(devid) ((uint32_t)devid & DEVNODEID_MASK) #define MK_DEVID(hostId, deviceId, devnodeId) \ (hostId << (DEVICEID_BITS + DEVNODEID_BITS) | deviceId << DEVNODEID_BITS | devnodeId) diff --git a/core/manager/src/devmgr_service.c b/core/manager/src/devmgr_service.c index 86fb5cfd..8f70c527 100644 --- a/core/manager/src/devmgr_service.c +++ b/core/manager/src/devmgr_service.c @@ -66,8 +66,9 @@ static int DevmgrServiceStartHostProcess(struct DevHostServiceClnt *hostClnt, bo return HDF_SUCCESS; } - while (hostClnt->hostService == NULL && waitCount-- > 0) { + while (hostClnt->hostService == NULL && waitCount > 0) { OsalMSleep(WAIT_HOST_SLEEP_TIME); + waitCount--; } if (waitCount <= 0) { @@ -268,7 +269,7 @@ static int DevmgrServiceStartDeviceHost(struct DevmgrService *devmgr, struct Hdf static int DevmgrServiceStartDeviceHosts(struct DevmgrService *inst) { - uint32_t ret; + int ret; struct HdfSList hostList; struct HdfSListIterator it; struct HdfHostInfo *hostAttr = NULL; diff --git a/tools/hc-gen/src/bytecode_gen.cpp b/tools/hc-gen/src/bytecode_gen.cpp index 7ff30a66..bc7d5232 100644 --- a/tools/hc-gen/src/bytecode_gen.cpp +++ b/tools/hc-gen/src/bytecode_gen.cpp @@ -70,7 +70,7 @@ bool ByteCodeGen::Initialize() bool ByteCodeGen::ByteCodeConvert() { - return ast_->WalkBackward([this](std::shared_ptr &object, uint32_t depth) { + return ast_->WalkBackward([this](std::shared_ptr &object, int32_t depth) { if (object->IsNode() && ConfigNode::CastFrom(object)->GetNodeType() == NODE_TEMPLATE) { object->Separate(); return NOERR; @@ -186,7 +186,7 @@ bool ByteCodeGen::ByteCodeWrite(bool dummy) bool ByteCodeGen::ByteCodeWriteWalk() { - return ast_->WalkForward([this](std::shared_ptr ¤t, uint32_t depth) { + return ast_->WalkForward([this](std::shared_ptr ¤t, int32_t depth) { current->SetHash(writeSize_); auto opcode = current->OpCode(); Write(opcode); diff --git a/tools/hc-gen/src/decompile.cpp b/tools/hc-gen/src/decompile.cpp index e31089ec..916e4cc4 100644 --- a/tools/hc-gen/src/decompile.cpp +++ b/tools/hc-gen/src/decompile.cpp @@ -49,7 +49,7 @@ bool Decompile::VerifyDecompileFile() Logger().Error() << "read header failed"; return false; } - Logger().Debug() << "read Header: magic is: " << header.magicNumber << " version major: " << header.versionMajor << + Logger().Debug() << "read Header: magic is: " << header.magicNumber << " version major: " << header.versionMajor << " version minor: " << header.versionMinor << " checksum: " << header.checkSum << " totalSize: " << header.totalSize; if (header.magicNumber != HCB_MAGIC_NUM) { Logger().Error() << "magic number is: " << header.magicNumber << ", check failed!"; @@ -149,8 +149,8 @@ std::shared_ptr Decompile::RebuildNode() node->SetSize(nodeSize); node->SetHash(nodeHash); Logger().Debug() << "node name is: " << node->Name() << ", size is: " << nodeSize << ", hash is: " << nodeHash; - uint32_t pos = file_.tellg(); - uint32_t nodeEnd = pos + nodeSize; + int32_t pos = file_.tellg(); + int32_t nodeEnd = pos + nodeSize; while (pos < nodeEnd) { uint32_t childOpCode; if (!GetNextByteCode(childOpCode)) { @@ -312,7 +312,7 @@ bool Decompile::DoDecompile() if(!InitDecompileFile()) { return false; } - + if (!VerifyDecompileFile()) { Logger().Error() << "Verify decompile file failed!"; return false; diff --git a/tools/hc-gen/src/lexer.cpp b/tools/hc-gen/src/lexer.cpp index 38444f64..25a8e395 100644 --- a/tools/hc-gen/src/lexer.cpp +++ b/tools/hc-gen/src/lexer.cpp @@ -270,7 +270,7 @@ bool Lexer::LexFromNumber(Token &token) ConsumeChar(); value.push_back(c); } - v = strtoll(value.data(), nullptr, 8); + v = (uint64_t)strtoll(value.data(), nullptr, 8); break; } switch (c) { diff --git a/tools/hc-gen/src/macro_gen.cpp b/tools/hc-gen/src/macro_gen.cpp index 4858a0a2..f77eaba8 100755 --- a/tools/hc-gen/src/macro_gen.cpp +++ b/tools/hc-gen/src/macro_gen.cpp @@ -96,7 +96,7 @@ bool MacroGen::Initialize() bool MacroGen::TemplateNodeSeparate() { - return ast_->WalkBackward([this](std::shared_ptr &object, uint32_t depth) { + return ast_->WalkBackward([this](std::shared_ptr &object, int32_t depth) { if (object->IsNode() && ConfigNode::CastFrom(object)->GetNodeType() == NODE_TEMPLATE) { object->Separate(); return NOERR; @@ -105,7 +105,7 @@ bool MacroGen::TemplateNodeSeparate() }); } -std::string MacroGen::GenFullName(uint32_t depth, const std::shared_ptr &node, const std::string &sep) +std::string MacroGen::GenFullName(int32_t depth, const std::shared_ptr &node, const std::string &sep) { std::string name; for (int i = 0; i < depth; i++) { @@ -151,7 +151,7 @@ bool MacroGen::GenArray(const std::string &arrName, uint32_t &arrSize, uint32_t return true; } -bool MacroGen::GenNodeForeach(uint32_t depth, const std::shared_ptr &node) +bool MacroGen::GenNodeForeach(int32_t depth, const std::shared_ptr &node) { std::list subList; auto child = node->Child(); @@ -200,7 +200,7 @@ bool MacroGen::GenNodeForeach(uint32_t depth, const std::shared_ptr & return true; } -std::string MacroGen::GenRefObjName(uint32_t depth, const std::shared_ptr &object) +std::string MacroGen::GenRefObjName(int32_t depth, const std::shared_ptr &object) { std::string name(object->StringValue()); if (name.find(".") == std::string::npos) { @@ -217,7 +217,7 @@ std::string MacroGen::GenRefObjName(uint32_t depth, const std::shared_ptrWalkForward([this](std::shared_ptr ¤t, uint32_t depth) { + return ast_->WalkForward([this](std::shared_ptr ¤t, int32_t depth) { auto type = current->Type(); static uint32_t arraySize = 0; @@ -225,13 +225,13 @@ bool MacroGen::NodeWalk() << "] depth:" << depth \ << " arraySize:" << std::dec << arraySize << '\n'; SetTypeData(type, current, arraySize, depth); - + return NOERR; }); } void MacroGen::SetTypeData(uint32_t type, const std::shared_ptr ¤t, - uint32_t &arraySize, uint32_t depth) + uint32_t &arraySize, int32_t depth) { static std::string nodeName; static std::string arrayName; diff --git a/tools/hc-gen/src/macro_gen.h b/tools/hc-gen/src/macro_gen.h index 9325d3e1..527f52fc 100755 --- a/tools/hc-gen/src/macro_gen.h +++ b/tools/hc-gen/src/macro_gen.h @@ -28,13 +28,13 @@ private: bool TemplateNodeSeparate(); - std::string GenFullName(uint32_t depth, const std::shared_ptr &node, const std::string &sep); + std::string GenFullName(int32_t depth, const std::shared_ptr &node, const std::string &sep); - bool GenNodeForeach(uint32_t depth, const std::shared_ptr &node); + bool GenNodeForeach(int32_t depth, const std::shared_ptr &node); bool NodeWalk(); - void SetTypeData(uint32_t type, const std::shared_ptr ¤t, uint32_t &arraySize, uint32_t depth); + void SetTypeData(uint32_t type, const std::shared_ptr ¤t, uint32_t &arraySize, int32_t depth); void SetTypeDataUinit64(const std::string &arrayName, uint32_t &arraySize, uint32_t arrayType, const std::shared_ptr ¤t); @@ -47,7 +47,7 @@ private: bool GenArray(const std::string &name, uint32_t &arrSize, uint32_t type, const std::shared_ptr &node); - std::string GenRefObjName(uint32_t depth, const std::shared_ptr &object); + std::string GenRefObjName(int32_t depth, const std::shared_ptr &object); std::ofstream ofs_; std::string outFileName_; diff --git a/tools/hc-gen/src/text_gen.cpp b/tools/hc-gen/src/text_gen.cpp index 0c7d72e6..cc39e4b8 100644 --- a/tools/hc-gen/src/text_gen.cpp +++ b/tools/hc-gen/src/text_gen.cpp @@ -83,7 +83,7 @@ bool TextGen::HeaderOutput() bool TextGen::HeaderOutputTraversal() { - auto ret = ast_->WalkBackward([this](const std::shared_ptr ¤t, uint32_t) -> uint32_t { + auto ret = ast_->WalkBackward([this](const std::shared_ptr ¤t, int32_t) -> uint32_t { if (!current->IsNode()) { return NOERR; } @@ -339,11 +339,11 @@ const std::string &TextGen::TypeToStr(uint32_t type) bool TextGen::OutputImplGlobalVariables() { - auto forwardWalkFunc = [this](const std::shared_ptr& current, uint32_t depth) -> uint32_t { + auto forwardWalkFunc = [this](const std::shared_ptr& current, int32_t depth) -> uint32_t { return ImplementGenTraversal(current, depth); }; - auto backwardWalkFunc = [this](const std::shared_ptr& current, uint32_t depth) -> uint32_t { + auto backwardWalkFunc = [this](const std::shared_ptr& current, int32_t depth) -> uint32_t { return ImplementCloseBraceGen(current, depth); }; @@ -365,7 +365,7 @@ const std::string &TextGen::Indent(uint32_t times) return indentMap.at(times); } -uint32_t TextGen::ImplementCloseBraceGen(const std::shared_ptr &object, uint32_t depth) +uint32_t TextGen::ImplementCloseBraceGen(const std::shared_ptr &object, int32_t depth) { if (!object->IsNode() || ConfigNode::CastFrom(object)->GetNodeType() == NODE_INHERIT) { return NOERR; @@ -378,7 +378,7 @@ uint32_t TextGen::ImplementCloseBraceGen(const std::shared_ptr &objec return ofs_.good() ? NOERR : EOUTPUT; } -uint32_t TextGen::ImplementGenTraversal(const std::shared_ptr &object, uint32_t depth) +uint32_t TextGen::ImplementGenTraversal(const std::shared_ptr &object, int32_t depth) { if (!object->IsNode() && !object->IsTerm()) { return NOERR; @@ -411,7 +411,7 @@ bool TextGen::IsInSubClassNode(const std::shared_ptr &object) return false; } -uint32_t TextGen::ObjectImplementGen(const std::shared_ptr &object, uint32_t depth) +uint32_t TextGen::ObjectImplementGen(const std::shared_ptr &object, int32_t depth) { switch (object->Type()) { case PARSEROP_CONFNODE: { @@ -434,7 +434,7 @@ uint32_t TextGen::ObjectImplementGen(const std::shared_ptr &object, u return ofs_.good() ? NOERR : EOUTPUT; } -bool TextGen::TemplateObjectImplGen(const std::shared_ptr &object, uint32_t depth) +bool TextGen::TemplateObjectImplGen(const std::shared_ptr &object, int32_t depth) { auto node = ConfigNode::CastFrom(object); if (node->GetNodeType() != NODE_TEMPLATE) { @@ -487,7 +487,7 @@ void TextGen::SymbolAdd(const std::string &name, const std::shared_ptr(object, 1))); } -uint32_t TextGen::PrintTermImplement(const std::shared_ptr &object, uint32_t depth) +uint32_t TextGen::PrintTermImplement(const std::shared_ptr &object, int32_t depth) { auto term = ConfigTerm::CastFrom(object); auto value = object->Child(); @@ -536,7 +536,7 @@ bool TextGen::PrintBaseTypeValue(const std::shared_ptr &object) return ofs_.good(); } -uint32_t TextGen::PrintArrayImplement(const std::shared_ptr &object, uint32_t depth) +uint32_t TextGen::PrintArrayImplement(const std::shared_ptr &object, int32_t depth) { if (IsInSubClassNode(object)) { return PrintArrayImplInSubClass(object, depth) ? NOERR : EOUTPUT; @@ -554,7 +554,7 @@ uint32_t TextGen::PrintArrayImplement(const std::shared_ptr &object, return ofs_.good() ? NOERR : EOUTPUT; } -bool TextGen::PrintArrayImplInSubClass(const std::shared_ptr &object, uint32_t depth) +bool TextGen::PrintArrayImplInSubClass(const std::shared_ptr &object, int32_t depth) { auto array = ConfigArray::CastFrom(object->Child()); auto arrayName = GenArrayName(object); @@ -611,7 +611,7 @@ bool TextGen::OutputTemplateImpl() return false; } - return ast_->WalkBackward([this](const std::shared_ptr &object, uint32_t) -> uint32_t { + return ast_->WalkBackward([this](const std::shared_ptr &object, int32_t) -> uint32_t { if (!object->IsNode() || (object->IsNode() && ConfigNode::CastFrom(object)->GetNodeType() != NODE_TEMPLATE)) { return NOERR; @@ -640,7 +640,7 @@ bool TextGen::OutputTemplateImpl() bool TextGen::OutputTemplateVariablesDeclare() { - return ast_->WalkBackward([this](const std::shared_ptr &object, uint32_t) -> uint32_t { + return ast_->WalkBackward([this](const std::shared_ptr &object, int32_t) -> uint32_t { if (object->IsTerm() && object->Child()->IsArray()) { return ArrayVariablesDeclareGen(object); } else if (!object->IsNode() || diff --git a/tools/hc-gen/src/text_gen.h b/tools/hc-gen/src/text_gen.h index e165c10a..f0ed649d 100644 --- a/tools/hc-gen/src/text_gen.h +++ b/tools/hc-gen/src/text_gen.h @@ -61,17 +61,17 @@ private: bool OutputImplGlobalVariables(); - uint32_t ImplementGenTraversal(const std::shared_ptr &object, uint32_t depth); + uint32_t ImplementGenTraversal(const std::shared_ptr &object, int32_t depth); - uint32_t ImplementCloseBraceGen(const std::shared_ptr &object, uint32_t depth); + uint32_t ImplementCloseBraceGen(const std::shared_ptr &object, int32_t depth); static const std::string & Indent(uint32_t times = 1); static bool IsInSubClassNode(const std::shared_ptr &object); - uint32_t ObjectImplementGen(const std::shared_ptr &object, uint32_t depth); + uint32_t ObjectImplementGen(const std::shared_ptr &object, int32_t depth); - bool TemplateObjectImplGen(const std::shared_ptr &object, uint32_t depth); + bool TemplateObjectImplGen(const std::shared_ptr &object, int32_t depth); std::string GenTemplateVariableName(const std::shared_ptr &object); @@ -94,13 +94,13 @@ private: std::string rootVariableName_; std::map> symMap; - uint32_t PrintTermImplement(const std::shared_ptr &object, uint32_t depth); + uint32_t PrintTermImplement(const std::shared_ptr &object, int32_t depth); bool PrintBaseTypeValue(const std::shared_ptr& object); - uint32_t PrintArrayImplement(const std::shared_ptr &object, uint32_t depth); + uint32_t PrintArrayImplement(const std::shared_ptr &object, int32_t depth); - bool PrintArrayImplInSubClass(const std::shared_ptr &object, uint32_t depth); + bool PrintArrayImplInSubClass(const std::shared_ptr &object, int32_t depth); bool HcsPrintArrayContent(const std::shared_ptr& object, uint32_t indent);