bool OptMove::VisitVarDecl(const VarDecl* varDecl)
{ if (ignoreLocation(varDecl)) returntrue; if (varDecl->hasGlobalStorage()) returntrue; if (varDecl->getLinkageAndVisibility().getLinkage() == ExternalLinkage) returntrue; if (!varDecl->getType()->isRecordType()) returntrue;
auto cxxRecord = dyn_cast<CXXRecordDecl>(varDecl->getType()->getAsRecordDecl()); if (!cxxRecord || !cxxRecord->hasDefinition() || !cxxRecord->hasMoveAssignment()) returntrue; // ignore our simpler types for now, I'm after bigger game autotypeName = cxxRecord->getName(); if (typeName.contains("Reference") || typeName.contains("Color") || typeName.contains("VclPtr")
|| typeName.contains("OString") || typeName.contains("OUString")
|| typeName.contains("Rectangle") || typeName.contains("Size")
|| typeName.contains("Selection") || typeName.contains("Point")
|| typeName.contains("strong_int")) returntrue;
m_Candidates.emplace(varDecl, Candidate());
if (!varDecl->hasInit()) returntrue; auto cons = dyn_cast<CXXConstructExpr>(varDecl->getInit()); if (!cons || !cons->getConstructor()->isCopyConstructor()) returntrue; auto arg1 = dyn_cast<DeclRefExpr>(cons->getArg(0)->IgnoreImplicit()); if (!arg1) returntrue; auto varDecl1 = dyn_cast<VarDecl>(arg1->getDecl()); if (!varDecl1) returntrue; auto it = m_Candidates.find(varDecl1); if (it == m_Candidates.end()) returntrue;
it->second.operatorArg1 = arg1;
it->second.canUseExpr = cons; returntrue;
}
bool OptMove::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const* cxxOperatorCallExpr)
{ if (ignoreLocation(cxxOperatorCallExpr)) returntrue; auto op = cxxOperatorCallExpr->getOperator(); if (op != OO_Equal) returntrue; auto arg0 = dyn_cast<DeclRefExpr>(cxxOperatorCallExpr->getArg(0)->IgnoreImplicit()); auto arg1 = dyn_cast<DeclRefExpr>(cxxOperatorCallExpr->getArg(1)->IgnoreImplicit()); if (!arg0 || !arg1) returntrue; auto varDecl0 = dyn_cast<VarDecl>(arg0->getDecl()); auto varDecl1 = dyn_cast<VarDecl>(arg1->getDecl()); if (!varDecl0 || !varDecl1) returntrue; auto cxxMethodDecl = dyn_cast_or_null<CXXMethodDecl>(cxxOperatorCallExpr->getDirectCallee()); if (!cxxMethodDecl || !cxxMethodDecl->isCopyAssignmentOperator()) returntrue; auto it = m_Candidates.find(varDecl1); if (it == m_Candidates.end()) returntrue;
it->second.operatorArg1 = arg1;
it->second.canUseExpr = cxxOperatorCallExpr; returntrue;
}
bool OptMove::VisitDeclRefExpr(const DeclRefExpr* declRefExpr)
{ if (ignoreLocation(declRefExpr)) returntrue; auto varDecl = dyn_cast<VarDecl>(declRefExpr->getDecl()); if (!varDecl) returntrue; auto it = m_Candidates.find(varDecl); if (it == m_Candidates.end()) returntrue; if (it->second.operatorArg1 == declRefExpr) returntrue;
m_Candidates.erase(it); returntrue;
}
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.