Skip to content

Commit

Permalink
Remove redundant casts.
Browse files Browse the repository at this point in the history
Essentially an auto-repair by clang-tidy
.github/bin/run-clang-tidy-cached.cc --checks="-*,readability-redundant-casting" --fix
  • Loading branch information
hzeller committed Nov 9, 2024
1 parent cf0a5c6 commit ad50df2
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 71 deletions.
7 changes: 5 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
28 changes: 14 additions & 14 deletions src/API/SLAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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<antlr4::Token*> tokens = ParseUtils::getFlatTokenList(ctx);
std::string text;
for (auto token : tokens) {
Expand All @@ -253,7 +253,7 @@ std::string SLgetText(SV3_1aPythonListener* /*prog*/,

std::vector<std::string> SLgetTokens(SV3_1aPythonListener* /*prog*/,
antlr4::ParserRuleContext* context) {
antlr4::ParserRuleContext* ctx = (antlr4::ParserRuleContext*)context;
antlr4::ParserRuleContext* ctx = context;
std::vector<antlr4::Token*> tokens = ParseUtils::getFlatTokenList(ctx);
std::vector<std::string> body_tokens;
body_tokens.reserve(tokens.size());
Expand All @@ -265,13 +265,13 @@ std::vector<std::string> 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<antlr4::ParserRuleContext*> SLgetChildrenContext(
SV3_1aPythonListener* /*prog*/, antlr4::ParserRuleContext* context) {
antlr4::ParserRuleContext* ctx = (antlr4::ParserRuleContext*)context;
antlr4::ParserRuleContext* ctx = context;
std::vector<antlr4::ParserRuleContext*> children;

for (antlr4::tree::ParseTree* child : ctx->children) {
Expand Down
34 changes: 15 additions & 19 deletions src/DesignCompile/CompileExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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<param_assign *>(result)) {
result = (any *)passign->Rhs();
result = passign->Rhs();
}
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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_assign *>(param_ass));
result->VpiParent(param_ass);
fC->populateCoreMembers(child, child, result);
typespec *tps = nullptr;
const any *lhs = param_ass->Lhs();
Expand Down Expand Up @@ -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_assign *>(param_ass));
result->VpiParent(param_ass);
fC->populateCoreMembers(child, child, result);
}
typespec *tps = nullptr;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -5146,7 +5142,7 @@ UHDM::any *CompileHelper::compileComplexFuncCall(
path->Root_value(expval->Low_conn());
} else if (UHDM::param_assign *passign =
any_cast<param_assign *>(rootValue)) {
path->Root_value((any *)passign->Rhs());
path->Root_value(passign->Rhs());
const any *param = passign->Lhs();
typespec *tps = nullptr;
if (param->UhdmType() == uhdmparameter) {
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions src/DesignCompile/CompileHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down Expand Up @@ -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<int32_t> values(size, 0);
if (rhs->UhdmType() == uhdmoperation) {
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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()
Expand Down
22 changes: 9 additions & 13 deletions src/DesignCompile/CompileStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2077,8 +2077,7 @@ bool CompileHelper::compileTask(DesignComponent* component,
}
if (stmt_type == uhdmassignment) {
assignment* stmt = (assignment*)st;
if (stmt->Rhs() == nullptr ||
any_cast<variables*>((expr*)stmt->Lhs())) {
if (stmt->Rhs() == nullptr || any_cast<variables*>(stmt->Lhs())) {
// Declaration
VectorOfvariables* vars = task->Variables();
if (vars == nullptr) {
Expand All @@ -2089,7 +2088,7 @@ bool CompileHelper::compileTask(DesignComponent* component,
if (stmt->Rhs() != nullptr) {
stmts->push_back(st);
} else {
if (variables* var = any_cast<variables*>((expr*)stmt->Lhs()))
if (variables* var = any_cast<variables*>(stmt->Lhs()))
var->VpiParent(begin);
// s.Erase(stmt);
}
Expand Down Expand Up @@ -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<variables*>((expr*)stmt->Lhs())) {
if (stmt->Rhs() == nullptr || any_cast<variables*>(stmt->Lhs())) {
// Declaration
VectorOfvariables* vars = task->Variables();
if (vars == nullptr) {
Expand All @@ -2136,7 +2134,7 @@ bool CompileHelper::compileTask(DesignComponent* component,
if (stmt->Rhs() != nullptr) {
task->Stmt(st);
} else {
if (variables* var = any_cast<variables*>((expr*)stmt->Lhs()))
if (variables* var = any_cast<variables*>(stmt->Lhs()))
var->VpiParent(task);
// s.Erase(stmt);
}
Expand Down Expand Up @@ -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<variables*>((expr*)stmt->Lhs())) {
if (stmt->Rhs() == nullptr || any_cast<variables*>(stmt->Lhs())) {
// Declaration
VectorOfvariables* vars = func->Variables();
if (vars == nullptr) {
Expand All @@ -2508,7 +2505,7 @@ bool CompileHelper::compileFunction(DesignComponent* component,
if (stmt->Rhs() != nullptr) {
stmts->push_back(st);
} else {
if (variables* var = any_cast<variables*>((expr*)stmt->Lhs()))
if (variables* var = any_cast<variables*>(stmt->Lhs()))
var->VpiParent(begin);
// s.Erase(stmt);
}
Expand Down Expand Up @@ -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<variables*>((expr*)stmt->Lhs())) {
if (stmt->Rhs() == nullptr || any_cast<variables*>(stmt->Lhs())) {
// Declaration
VectorOfvariables* vars = func->Variables();
if (vars == nullptr) {
Expand All @@ -2555,7 +2551,7 @@ bool CompileHelper::compileFunction(DesignComponent* component,
if (stmt->Rhs() != nullptr) {
func->Stmt(st);
} else {
if (variables* var = any_cast<variables*>((expr*)stmt->Lhs()))
if (variables* var = any_cast<variables*>(stmt->Lhs()))
var->VpiParent(func);
// s.Erase(stmt);
}
Expand Down Expand Up @@ -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();
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/DesignCompile/ElaborationStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand Down
Loading

0 comments on commit ad50df2

Please sign in to comment.