if (auto operatorCall = dyn_cast<CXXOperatorCallExpr>(stmt))
{ if (operatorCall->getOperator() == OO_Equal)
{ if (auto declRefExprLHS = dyn_cast<DeclRefExpr>(ignore(operatorCall->getArg(0)))) if (declRefExprLHS->getDecl() == varDecl)
{
report(DiagnosticsEngine::Warning, "simplify by merging with the preceding assignment", stmt->getBeginLoc())
<< stmt->getSourceRange();
}
} return;
}
if (auto binaryOp = dyn_cast<BinaryOperator>(stmt))
{ if (binaryOp->getOpcode() == BO_Assign)
{ if (auto declRefExpr = dyn_cast<DeclRefExpr>(ignore(binaryOp->getLHS()))) if (declRefExpr->getDecl() == varDecl)
{
report(DiagnosticsEngine::Warning, "simplify by merging with the preceding assignment", stmt->getBeginLoc())
<< stmt->getSourceRange();
}
}
}
}
const VarDecl* SequentialAssign::findSimpleAssign(Stmt const* stmt)
{ if (auto declStmt = dyn_cast<DeclStmt>(stmt)) if (declStmt->isSingleDecl()) if (auto varDeclLHS = dyn_cast_or_null<VarDecl>(declStmt->getSingleDecl()))
{ if (varDeclLHS->getStorageDuration() == SD_Static) return nullptr; // if it's call-style init (e.g. OUString s("xxx")), we only treat // it as simple if it only contains a variable in the call // (e.g. OUString s(x)) if (varDeclLHS->getInitStyle() == VarDecl::InitializationStyle::CallInit)
{ auto cxxConstructExpr
= dyn_cast<CXXConstructExpr>(ignore(varDeclLHS->getInit())); if (cxxConstructExpr)
{ if (cxxConstructExpr->getNumArgs() == 0) return varDeclLHS; if (cxxConstructExpr->getNumArgs() > 1) return nullptr; if (!isa<DeclRefExpr>(ignore(cxxConstructExpr->getArg(0)))) return nullptr;
}
} if (auto init = varDeclLHS->getInit()) if (isSimpleRHS(init)) return varDeclLHS;
} if (auto operatorCall = dyn_cast<CXXOperatorCallExpr>(stmt)) if (operatorCall->getOperator() == OO_Equal) if (auto declRefExprLHS = dyn_cast<DeclRefExpr>(ignore(operatorCall->getArg(0)))) if (auto varDeclLHS = dyn_cast<VarDecl>(declRefExprLHS->getDecl())) if (isSimpleRHS(operatorCall->getArg(1))) return varDeclLHS; if (auto binaryOp = dyn_cast<BinaryOperator>(stmt)) if (binaryOp->getOpcode() == BO_Assign) if (auto declRefExprLHS = dyn_cast<DeclRefExpr>(ignore(binaryOp->getLHS()))) if (auto varDeclLHS = dyn_cast<VarDecl>(declRefExprLHS->getDecl())) if (isSimpleRHS(binaryOp->getRHS())) return varDeclLHS; return nullptr;
}
// code like // Point aCurPos = rGlyphs // always has a CXXConstructExpr wrapping the RHS if (auto cxxConstructExpr = dyn_cast<CXXConstructExpr>(expr)) if (cxxConstructExpr->getNumArgs() == 1)
expr = ignore(cxxConstructExpr->getArg(0));
if (!expr->isValueDependent()
&& expr->isConstantInitializer(compiler.getASTContext(), false/*ForRef*/)) returntrue; if (isa<CXXMemberCallExpr>(expr)) returnfalse; if (isa<CXXOperatorCallExpr>(expr)) returnfalse; if (isa<UserDefinedLiteral>(expr)) returntrue; if (isa<CallExpr>(expr)) returnfalse; if (isa<CastExpr>(expr)) returnfalse; if (isa<ArraySubscriptExpr>(expr)) returnfalse; if (isa<BinaryOperator>(expr)) returnfalse; if (isa<ConditionalOperator>(expr)) returnfalse; if (isa<UnaryOperator>(expr)) returnfalse; if (isa<CXXNewExpr>(expr)) returnfalse; if (auto memberExpr = dyn_cast<MemberExpr>(expr)) return isSimpleRHS(memberExpr->getBase());
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.