// try to limit the voluminous output a little static std::set<MyFieldInfo> excludedSet; static std::set<MyFieldInfo> definitionSet; static std::set<MyFieldInfo> deletedInDestructorSet; static std::set<MyFieldInfo> newedInConstructorSet;
class InlineFields: public RecursiveASTVisitor<InlineFields>, public loplugin::Plugin
{ public: explicit InlineFields(loplugin::InstantiationData const & data):
Plugin(data) {}
bool InlineFields::VisitFieldDecl( const FieldDecl* fieldDecl )
{
fieldDecl = fieldDecl->getCanonicalDecl(); if (ignoreLocation( fieldDecl )) { returntrue;
} // ignore stuff that forms part of the stable URE interface if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc(fieldDecl->getLocation()))) { returntrue;
}
QualType type = fieldDecl->getType(); if (!type->isPointerType()) returntrue;
definitionSet.insert(niceName(fieldDecl)); returntrue;
}
bool InlineFields::VisitCXXConstructorDecl( const CXXConstructorDecl* decl )
{ if( ignoreLocation( decl ) ) returntrue; if (decl->isCopyOrMoveConstructor()) returntrue; for(auto it = decl->init_begin(); it != decl->init_end(); ++it)
{ const CXXCtorInitializer* init = *it; const FieldDecl* fieldDecl = init->getMember(); if( !fieldDecl || !fieldDecl->getType()->isPointerType() ) continue; auto e = init->getInit(); if (auto parentListExpr = dyn_cast<ParenListExpr>(e))
e = parentListExpr->getExpr(0);
e = e->IgnoreParenImpCasts(); if( isa<CXXNewExpr>(e) )
newedInConstructorSet.insert(niceName(fieldDecl)); elseif( isa<CXXNullPtrLiteralExpr>(e) || isa<GNUNullExpr>(e))
; // ignore else
excludedSet.insert(niceName(fieldDecl));
} returntrue;
}
bool InlineFields::VisitBinaryOperator(const BinaryOperator * binaryOp)
{ if (binaryOp->getOpcode() != BO_Assign) { returntrue;
} if( ignoreLocation( binaryOp ) ) returntrue; auto memberExpr = dyn_cast<MemberExpr>(binaryOp->getLHS()); if (!memberExpr) returntrue; auto fieldDecl = dyn_cast<FieldDecl>(memberExpr->getMemberDecl()); if (!fieldDecl || !fieldDecl->getType()->isPointerType()) { returntrue;
} const FunctionDecl* parentFunction = getParentFunctionDecl(binaryOp); if (!parentFunction) { returntrue;
} // if the field is being assigned from outside its own constructor or destructor, exclude auto constructorDecl = dyn_cast<CXXConstructorDecl>(parentFunction); if (constructorDecl && isSameParent(constructorDecl, fieldDecl)) { if( isa<CXXNewExpr>(binaryOp->getRHS()) )
newedInConstructorSet.insert(niceName(fieldDecl)); else {
excludedSet.insert(niceName(fieldDecl));
std::cout << "assign in constructor:" << std::endl;
binaryOp->getRHS()->dump();
} returntrue;
} auto destructorDecl = dyn_cast<CXXDestructorDecl>(parentFunction); if (destructorDecl && isSameParent(destructorDecl, fieldDecl)) { auto e = binaryOp->getRHS()->IgnoreParenImpCasts(); if( !isa<CXXNullPtrLiteralExpr>(e) && !isa<GNUNullExpr>(e)) {
excludedSet.insert(niceName(fieldDecl));
std::cout << "assign in destructor:" << std::endl;
e->dump();
} returntrue;
}
excludedSet.insert(niceName(fieldDecl)); returntrue;
}
bool InlineFields::VisitCXXDeleteExpr(const CXXDeleteExpr * deleteExpr)
{ if( ignoreLocation( deleteExpr ) ) returntrue; auto memberExpr = dyn_cast<MemberExpr>(deleteExpr->getArgument()->IgnoreParenImpCasts()); if (!memberExpr) returntrue; auto fieldDecl = dyn_cast<FieldDecl>(memberExpr->getMemberDecl()); if (!fieldDecl || !fieldDecl->getType()->isPointerType()) { returntrue;
} // TODO for some reason, this part is not working properly, it doesn't find the parent // function for delete statements properly const FunctionDecl* parentFunction = getParentFunctionDecl(deleteExpr); if (!parentFunction) { returntrue;
} auto destructorDecl = dyn_cast<CXXDestructorDecl>(parentFunction); if (destructorDecl && isSameParent(destructorDecl, fieldDecl)) {
deletedInDestructorSet.insert(niceName(fieldDecl)); returntrue;
}
excludedSet.insert(niceName(fieldDecl)); 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.