From ad50df273cf32ffdac7010dca11ee468ca94dd58 Mon Sep 17 00:00:00 2001 From: Henner Zeller Date: Sat, 9 Nov 2024 10:01:46 -0800 Subject: [PATCH] Remove redundant casts. Essentially an auto-repair by clang-tidy .github/bin/run-clang-tidy-cached.cc --checks="-*,readability-redundant-casting" --fix --- .clang-tidy | 7 +++-- src/API/SLAPI.cpp | 28 +++++++++---------- src/DesignCompile/CompileExpression.cpp | 34 +++++++++++------------- src/DesignCompile/CompileHelper.cpp | 16 +++++------ src/DesignCompile/CompileStmt.cpp | 22 +++++++-------- src/DesignCompile/ElaborationStep.cpp | 6 ++--- src/DesignCompile/NetlistElaboration.cpp | 6 ++--- src/DesignCompile/UhdmWriter.cpp | 9 +++---- src/Utils/NumUtils.cpp | 6 ++--- 9 files changed, 63 insertions(+), 71 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 61436dcb64..782b6c63c2 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -12,8 +12,8 @@ Checks: > bugprone-*, -bugprone-branch-clone, - -bugprone-narrowing-conversions, -bugprone-easily-swappable-parameters, + -bugprone-narrowing-conversions, clang-diagnostic-*, clang-analyzer-*, -clang-analyzer-core.CallAndMessage, @@ -32,10 +32,13 @@ Checks: > -misc-unused-parameters, -misc-use-anonymous-namespace, modernize-*, - -modernize-use-trailing-return-type, + -modernize-type-traits, -modernize-use-auto, + -modernize-use-nodiscard, + -modernize-use-trailing-return-type, performance-*, -performance-avoid-endl, + -performance-enum-size, readability-*, -readability-braces-around-statements, -readability-convert-member-functions-to-static, diff --git a/src/API/SLAPI.cpp b/src/API/SLAPI.cpp index 7c013ddefd..ae272cbd9e 100644 --- a/src/API/SLAPI.cpp +++ b/src/API/SLAPI.cpp @@ -135,8 +135,8 @@ void SLaddErrorContext(SV3_1aPythonListener* prog, const char* messageId, const char* objectName, bool printColumn) { #ifdef SURELOG_WITH_PYTHON - SV3_1aPythonListener* listener = (SV3_1aPythonListener*)prog; - antlr4::ParserRuleContext* ctx = (antlr4::ParserRuleContext*)context; + SV3_1aPythonListener* listener = prog; + antlr4::ParserRuleContext* ctx = context; ErrorContainer* errors = listener->getPythonListen()->getCompileSourceFile()->getErrorContainer(); ParseUtils::LineColumn lineCol = @@ -164,9 +164,9 @@ void SLaddMLErrorContext(SV3_1aPythonListener* prog, const char* messageId, const char* objectName1, const char* objectName2, bool printColumn) { #ifdef SURELOG_WITH_PYTHON - SV3_1aPythonListener* listener = (SV3_1aPythonListener*)prog; - antlr4::ParserRuleContext* ctx1 = (antlr4::ParserRuleContext*)context1; - antlr4::ParserRuleContext* ctx2 = (antlr4::ParserRuleContext*)context2; + SV3_1aPythonListener* listener = prog; + antlr4::ParserRuleContext* ctx1 = context1; + antlr4::ParserRuleContext* ctx2 = context2; ErrorContainer* errors = listener->getPythonListen()->getCompileSourceFile()->getErrorContainer(); ParseUtils::LineColumn lineCol1 = @@ -203,7 +203,7 @@ std::string SLgetFile(SV3_1aPythonListener* prog, antlr4::ParserRuleContext* context) { #ifdef SURELOG_WITH_PYTHON FileSystem* const fileSystem = FileSystem::getInstance(); - SV3_1aPythonListener* listener = (SV3_1aPythonListener*)prog; + SV3_1aPythonListener* listener = prog; ParseFile* parseFile = listener->getPythonListen()->getParseFile(); return std::string(fileSystem->toPath(parseFile->getFileId(0))); #else @@ -215,8 +215,8 @@ std::string SLgetFile(SV3_1aPythonListener* prog, int32_t SLgetLine(SV3_1aPythonListener* prog, antlr4::ParserRuleContext* context) { #ifdef SURELOG_WITH_PYTHON - SV3_1aPythonListener* listener = (SV3_1aPythonListener*)prog; - antlr4::ParserRuleContext* ctx = (antlr4::ParserRuleContext*)context; + SV3_1aPythonListener* listener = prog; + antlr4::ParserRuleContext* ctx = context; ParseUtils::LineColumn lineCol = ParseUtils::getLineColumn(listener->getTokenStream(), ctx); return lineCol.first; @@ -229,8 +229,8 @@ int32_t SLgetLine(SV3_1aPythonListener* prog, int32_t SLgetColumn(SV3_1aPythonListener* prog, antlr4::ParserRuleContext* context) { #ifdef SURELOG_WITH_PYTHON - SV3_1aPythonListener* listener = (SV3_1aPythonListener*)prog; - antlr4::ParserRuleContext* ctx = (antlr4::ParserRuleContext*)context; + SV3_1aPythonListener* listener = prog; + antlr4::ParserRuleContext* ctx = context; ParseUtils::LineColumn lineCol = ParseUtils::getLineColumn(listener->getTokenStream(), ctx); return lineCol.second; @@ -242,7 +242,7 @@ int32_t SLgetColumn(SV3_1aPythonListener* prog, std::string SLgetText(SV3_1aPythonListener* /*prog*/, antlr4::ParserRuleContext* context) { - antlr4::ParserRuleContext* ctx = (antlr4::ParserRuleContext*)context; + antlr4::ParserRuleContext* ctx = context; std::vector tokens = ParseUtils::getFlatTokenList(ctx); std::string text; for (auto token : tokens) { @@ -253,7 +253,7 @@ std::string SLgetText(SV3_1aPythonListener* /*prog*/, std::vector SLgetTokens(SV3_1aPythonListener* /*prog*/, antlr4::ParserRuleContext* context) { - antlr4::ParserRuleContext* ctx = (antlr4::ParserRuleContext*)context; + antlr4::ParserRuleContext* ctx = context; std::vector tokens = ParseUtils::getFlatTokenList(ctx); std::vector body_tokens; body_tokens.reserve(tokens.size()); @@ -265,13 +265,13 @@ std::vector SLgetTokens(SV3_1aPythonListener* /*prog*/, antlr4::ParserRuleContext* SLgetParentContext( SV3_1aPythonListener* /*prog*/, antlr4::ParserRuleContext* context) { - antlr4::ParserRuleContext* ctx = (antlr4::ParserRuleContext*)context; + antlr4::ParserRuleContext* ctx = context; return (antlr4::ParserRuleContext*)ctx->parent; } std::vector SLgetChildrenContext( SV3_1aPythonListener* /*prog*/, antlr4::ParserRuleContext* context) { - antlr4::ParserRuleContext* ctx = (antlr4::ParserRuleContext*)context; + antlr4::ParserRuleContext* ctx = context; std::vector children; for (antlr4::tree::ParseTree* child : ctx->children) { diff --git a/src/DesignCompile/CompileExpression.cpp b/src/DesignCompile/CompileExpression.cpp index 4362489dec..27ba8e13d3 100644 --- a/src/DesignCompile/CompileExpression.cpp +++ b/src/DesignCompile/CompileExpression.cpp @@ -207,7 +207,7 @@ any *CompileHelper::getObject(std::string_view name, DesignComponent *component, const std::string_view pname = p->Lhs()->VpiName(); if (pname == name) { if (substituteAssignedValue(p->Rhs(), compileDesign)) { - result = (any *)p->Rhs(); + result = p->Rhs(); break; } } @@ -253,7 +253,7 @@ any *CompileHelper::getObject(std::string_view name, DesignComponent *component, const std::string_view pname = p->Lhs()->VpiName(); if (pname == name) { if (substituteAssignedValue(p->Rhs(), compileDesign)) { - result = (any *)p->Rhs(); + result = p->Rhs(); break; } } @@ -276,7 +276,7 @@ any *CompileHelper::getObject(std::string_view name, DesignComponent *component, result = getObject(refname, component, compileDesign, instance, pexpr); if (result) { if (UHDM::param_assign *passign = any_cast(result)) { - result = (any *)passign->Rhs(); + result = passign->Rhs(); } } } @@ -932,8 +932,7 @@ any *CompileHelper::getValue(std::string_view name, DesignComponent *component, } ElaboratorContext elaboratorContext(&s, false, true); - result = - UHDM::clone_tree((any *)param->Rhs(), &elaboratorContext); + result = UHDM::clone_tree(param->Rhs(), &elaboratorContext); break; } } @@ -1035,8 +1034,7 @@ any *CompileHelper::getValue(std::string_view name, DesignComponent *component, } ElaboratorContext elaboratorContext(&s, false, true); - result = - UHDM::clone_tree((any *)param->Rhs(), &elaboratorContext); + result = UHDM::clone_tree(param->Rhs(), &elaboratorContext); if (result != nullptr) result->VpiParent(param); break; } @@ -2432,7 +2430,7 @@ UHDM::any *CompileHelper::compileExpression( if (substituteAssignedValue(param->Rhs(), compileDesign)) { ElaboratorContext elaboratorContext(&s, false, true); - result = UHDM::clone_tree((any *)param->Rhs(), + result = UHDM::clone_tree(param->Rhs(), &elaboratorContext); result->VpiParent(pexpr); fC->populateCoreMembers(child, child, result); @@ -2480,7 +2478,7 @@ UHDM::any *CompileHelper::compileExpression( if (substituteAssignedValue(param->Rhs(), compileDesign)) { ElaboratorContext elaboratorContext(&s, false, true); - result = UHDM::clone_tree((any *)param->Rhs(), + result = UHDM::clone_tree(param->Rhs(), &elaboratorContext); fC->populateCoreMembers(child, child, result); } @@ -2590,10 +2588,9 @@ UHDM::any *CompileHelper::compileExpression( compileDesign)) { ElaboratorContext elaboratorContext(&s, false, true); - result = UHDM::clone_tree((any *)param_ass->Rhs(), + result = UHDM::clone_tree(param_ass->Rhs(), &elaboratorContext); - result->VpiParent( - const_cast(param_ass)); + result->VpiParent(param_ass); fC->populateCoreMembers(child, child, result); typespec *tps = nullptr; const any *lhs = param_ass->Lhs(); @@ -2659,10 +2656,9 @@ UHDM::any *CompileHelper::compileExpression( } else { ElaboratorContext elaboratorContext(&s, false, true); - result = UHDM::clone_tree((any *)param_ass->Rhs(), + result = UHDM::clone_tree(param_ass->Rhs(), &elaboratorContext); - result->VpiParent( - const_cast(param_ass)); + result->VpiParent(param_ass); fC->populateCoreMembers(child, child, result); } typespec *tps = nullptr; @@ -3622,7 +3618,7 @@ bool CompileHelper::errorOnNegativeConstant(DesignComponent *component, for (auto ps : *inst->getNetlist()->param_assigns()) { std::cout << ps->Lhs()->VpiName() << " = " << "\n"; - decompile((any *)ps->Rhs()); + decompile(ps->Rhs()); } } inst = inst->getParent(); @@ -5146,7 +5142,7 @@ UHDM::any *CompileHelper::compileComplexFuncCall( path->Root_value(expval->Low_conn()); } else if (UHDM::param_assign *passign = any_cast(rootValue)) { - path->Root_value((any *)passign->Rhs()); + path->Root_value(passign->Rhs()); const any *param = passign->Lhs(); typespec *tps = nullptr; if (param->UhdmType() == uhdmparameter) { @@ -5607,8 +5603,8 @@ void CompileHelper::reorderAssignmentPattern( if (ranges) { if (level < ranges->size()) { range *r = ranges->at(level); - expr *lr = (expr *)r->Left_expr(); - expr *rr = (expr *)r->Right_expr(); + expr *lr = r->Left_expr(); + expr *rr = r->Right_expr(); bool invalidValue = false; UHDM::ExprEval eval; lr = reduceExpr(lr, invalidValue, mod, compileDesign, instance, diff --git a/src/DesignCompile/CompileHelper.cpp b/src/DesignCompile/CompileHelper.cpp index e7a4042454..d7e5fb0ce6 100644 --- a/src/DesignCompile/CompileHelper.cpp +++ b/src/DesignCompile/CompileHelper.cpp @@ -3324,15 +3324,15 @@ UHDM::any* CompileHelper::defaultPatternAssignment(const UHDM::typespec* tps, bool invalidValue = false; UHDM::ExprEval eval; expr* lexp = reduceExpr( - (expr*)r->Left_expr(), invalidValue, component, compileDesign, + r->Left_expr(), invalidValue, component, compileDesign, instance, fileSystem->toPathId( r->VpiFile(), compileDesign->getCompiler()->getSymbolTable()), r->VpiLineNo(), nullptr); expr* rexp = reduceExpr( - (expr*)r->Right_expr(), invalidValue, component, - compileDesign, instance, + r->Right_expr(), invalidValue, component, compileDesign, + instance, fileSystem->toPathId( r->VpiFile(), compileDesign->getCompiler()->getSymbolTable()), @@ -4983,7 +4983,7 @@ UHDM::expr* CompileHelper::expandPatternAssignment(const typespec* tps, uint64_t patternSize = 0; UHDM::ExprEval eval(true); - rhs = eval.flattenPatternAssignments(s, tps, (UHDM::expr*)rhs); + rhs = eval.flattenPatternAssignments(s, tps, rhs); std::vector values(size, 0); if (rhs->UhdmType() == uhdmoperation) { @@ -5014,8 +5014,8 @@ UHDM::expr* CompileHelper::expandPatternAssignment(const typespec* tps, defaultval = eval.get_value( invalidValue, reduceExpr( - (any*)tp->Pattern(), invalidValue, component, - compileDesign, instance, + tp->Pattern(), invalidValue, component, compileDesign, + instance, fileSystem->toPathId( tp->Pattern()->VpiFile(), compileDesign->getCompiler()->getSymbolTable()), @@ -5089,8 +5089,8 @@ UHDM::expr* CompileHelper::expandPatternAssignment(const typespec* tps, UHDM::ExprEval eval; val = eval.get_value( invalidValue, - reduceExpr((any*)tp->Pattern(), invalidValue, - component, compileDesign, instance, + reduceExpr(tp->Pattern(), invalidValue, component, + compileDesign, instance, fileSystem->toPathId( tp->Pattern()->VpiFile(), compileDesign->getCompiler() diff --git a/src/DesignCompile/CompileStmt.cpp b/src/DesignCompile/CompileStmt.cpp index 318cd10c06..7caf277791 100644 --- a/src/DesignCompile/CompileStmt.cpp +++ b/src/DesignCompile/CompileStmt.cpp @@ -2077,8 +2077,7 @@ bool CompileHelper::compileTask(DesignComponent* component, } if (stmt_type == uhdmassignment) { assignment* stmt = (assignment*)st; - if (stmt->Rhs() == nullptr || - any_cast((expr*)stmt->Lhs())) { + if (stmt->Rhs() == nullptr || any_cast(stmt->Lhs())) { // Declaration VectorOfvariables* vars = task->Variables(); if (vars == nullptr) { @@ -2089,7 +2088,7 @@ bool CompileHelper::compileTask(DesignComponent* component, if (stmt->Rhs() != nullptr) { stmts->push_back(st); } else { - if (variables* var = any_cast((expr*)stmt->Lhs())) + if (variables* var = any_cast(stmt->Lhs())) var->VpiParent(begin); // s.Erase(stmt); } @@ -2124,8 +2123,7 @@ bool CompileHelper::compileTask(DesignComponent* component, param_assigns->push_back(pst); } else if (stmt_type == uhdmassignment) { assignment* stmt = (assignment*)st; - if (stmt->Rhs() == nullptr || - any_cast((expr*)stmt->Lhs())) { + if (stmt->Rhs() == nullptr || any_cast(stmt->Lhs())) { // Declaration VectorOfvariables* vars = task->Variables(); if (vars == nullptr) { @@ -2136,7 +2134,7 @@ bool CompileHelper::compileTask(DesignComponent* component, if (stmt->Rhs() != nullptr) { task->Stmt(st); } else { - if (variables* var = any_cast((expr*)stmt->Lhs())) + if (variables* var = any_cast(stmt->Lhs())) var->VpiParent(task); // s.Erase(stmt); } @@ -2496,8 +2494,7 @@ bool CompileHelper::compileFunction(DesignComponent* component, param_assigns->push_back(pst); } else if (stmt_type == uhdmassignment) { assignment* stmt = (assignment*)st; - if (stmt->Rhs() == nullptr || - any_cast((expr*)stmt->Lhs())) { + if (stmt->Rhs() == nullptr || any_cast(stmt->Lhs())) { // Declaration VectorOfvariables* vars = func->Variables(); if (vars == nullptr) { @@ -2508,7 +2505,7 @@ bool CompileHelper::compileFunction(DesignComponent* component, if (stmt->Rhs() != nullptr) { stmts->push_back(st); } else { - if (variables* var = any_cast((expr*)stmt->Lhs())) + if (variables* var = any_cast(stmt->Lhs())) var->VpiParent(begin); // s.Erase(stmt); } @@ -2543,8 +2540,7 @@ bool CompileHelper::compileFunction(DesignComponent* component, param_assigns->push_back(pst); } else if (stmt_type == uhdmassignment) { assignment* stmt = (assignment*)st; - if (stmt->Rhs() == nullptr || - any_cast((expr*)stmt->Lhs())) { + if (stmt->Rhs() == nullptr || any_cast(stmt->Lhs())) { // Declaration VectorOfvariables* vars = func->Variables(); if (vars == nullptr) { @@ -2555,7 +2551,7 @@ bool CompileHelper::compileFunction(DesignComponent* component, if (stmt->Rhs() != nullptr) { func->Stmt(st); } else { - if (variables* var = any_cast((expr*)stmt->Lhs())) + if (variables* var = any_cast(stmt->Lhs())) var->VpiParent(func); // s.Erase(stmt); } @@ -3038,7 +3034,7 @@ UHDM::any* CompileHelper::bindParameter(DesignComponent* component, if (netlist->param_assigns()) { for (param_assign* pass : *netlist->param_assigns()) { if (pass->Lhs()->VpiName() == name) { - return (any*)pass->Lhs(); + return pass->Lhs(); } } } diff --git a/src/DesignCompile/ElaborationStep.cpp b/src/DesignCompile/ElaborationStep.cpp index 123491c5f0..e0be516431 100644 --- a/src/DesignCompile/ElaborationStep.cpp +++ b/src/DesignCompile/ElaborationStep.cpp @@ -2239,8 +2239,8 @@ any* ElaborationStep::makeVar_(DesignComponent* component, Signal* sig, obj->VpiParent(array_var); if ((array_var->Typespec() == nullptr) || associative) { VectorOfvariables* array_vars = array_var->Variables(); - array_vars->push_back((variables*)obj); - ((variables*)obj)->VpiName(""); + array_vars->push_back(obj); + (obj)->VpiName(""); } if (array_var->Typespec() == nullptr) { ref_typespec* tsRef = s.MakeRef_typespec(); @@ -2263,7 +2263,7 @@ any* ElaborationStep::makeVar_(DesignComponent* component, Signal* sig, } else if (obj->UhdmType() == uhdmlogic_var) { ((logic_var*)obj)->VpiName(signame); } - vars->push_back((variables*)obj); + vars->push_back(obj); } if (assignExp) { diff --git a/src/DesignCompile/NetlistElaboration.cpp b/src/DesignCompile/NetlistElaboration.cpp index cab04719ba..7bc18ccc46 100644 --- a/src/DesignCompile/NetlistElaboration.cpp +++ b/src/DesignCompile/NetlistElaboration.cpp @@ -222,7 +222,7 @@ bool NetlistElaboration::elab_parameters_(ModuleInstance* instance, pclone->VpiParent((any*)mod_assign->VpiParent()); pclone->VpiOverriden(instance->isOverridenParam(paramName)); const any* lhs = pclone->Lhs(); - any* rhs = (any*)pclone->Rhs(); + any* rhs = pclone->Rhs(); if (complexVal) { rhs = UHDM::clone_tree(complexVal, &elaboratorContext); rhs->VpiParent(pclone); @@ -287,7 +287,7 @@ bool NetlistElaboration::elab_parameters_(ModuleInstance* instance, inst_assign->VpiColumnNo(mod_assign->VpiColumnNo()); inst_assign->VpiEndLineNo(mod_assign->VpiEndLineNo()); inst_assign->VpiEndColumnNo(mod_assign->VpiEndColumnNo()); - inst_assign->Lhs((any*)mod_assign->Lhs()); + inst_assign->Lhs(mod_assign->Lhs()); bool overriden = false; for (Parameter* tpm : @@ -2926,7 +2926,7 @@ any* NetlistElaboration::bind_net_(ModuleInstance* instance, if (ios) { for (io_decl* decl : *ios) { if (decl->VpiName() == subname) { - return (any*)decl->Expr(); + return decl->Expr(); } } } diff --git a/src/DesignCompile/UhdmWriter.cpp b/src/DesignCompile/UhdmWriter.cpp index 056ffe04e8..d2bfb5e942 100644 --- a/src/DesignCompile/UhdmWriter.cpp +++ b/src/DesignCompile/UhdmWriter.cpp @@ -1029,11 +1029,11 @@ class ReInstanceTypespec : public VpiListener { any* object = (any*)cobject; const instance* inst = nullptr; if (typespec* tps = any_cast(object)) { - inst = (instance*)tps->Instance(); + inst = tps->Instance(); } else if (function* tps = any_cast(object)) { - inst = (instance*)tps->Instance(); + inst = tps->Instance(); } else if (task* tps = any_cast(object)) { - inst = (instance*)tps->Instance(); + inst = tps->Instance(); } if (inst) { const std::string_view name = inst->VpiName(); @@ -3698,8 +3698,7 @@ void UhdmWriter::lateBinding(Serializer& s, DesignComponent* mod, scope* m) { if (lhs->VpiName() == name) { // Do not bind blindly here, let the uhdmelab do this correctly // Unless we are in a package - if (m && m->UhdmType() == uhdmpackage) - ref->Actual_group((any*)p->Rhs()); + if (m && m->UhdmType() == uhdmpackage) ref->Actual_group(p->Rhs()); isParam = true; break; } diff --git a/src/Utils/NumUtils.cpp b/src/Utils/NumUtils.cpp index 81dae38cc2..9c7d4eff7b 100644 --- a/src/Utils/NumUtils.cpp +++ b/src/Utils/NumUtils.cpp @@ -88,10 +88,8 @@ std::string NumUtils::toBinary(int32_t size, uint64_t val) { uint64_t NumUtils::getMask(uint64_t wide) { uint64_t mask = 0; uint64_t sizeInBits = sizeof(mask) * 8; - mask = (wide >= sizeInBits) - ? ((uint64_t)-1) - : ((uint64_t)((uint64_t)(((uint64_t)1) << ((uint64_t)wide))) - - (uint64_t)1); + mask = (wide >= sizeInBits) ? ((uint64_t)-1) + : (((((uint64_t)1) << (wide))) - (uint64_t)1); return mask; }