tosomethingmoreprecise.
*/ namespace
{ class ConvertLong : public loplugin::FilteringPlugin<ConvertLong>
{ public: explicit ConvertLong(loplugin::InstantiationData const& data)
: FilteringPlugin(data)
{
}
virtualvoid run() override
{
std::string fn(handler.getMainFileName());
loplugin::normalizeDotDotInFilePath(fn); // using sal_uIntPtr as in-between type when converting void* to rtl_TextEncoding if (fn == SRCDIR "/sal/osl/unx/thread.cxx") return; // too much magic if (fn == SRCDIR "/sal/rtl/alloc_arena.cxx") return; if (fn == SRCDIR "/sal/rtl/alloc_cache.cxx") return; // TODO not sure what is going on here if (fn == SRCDIR "/tools/source/generic/bigint.cxx") return;
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
}
bool ConvertLong::VisitVarDecl(VarDecl const* varDecl)
{ if (ignoreLocation(varDecl)) returntrue;
StringRef fileName{ getFilenameOfLocation(varDecl->getLocation()) }; if (loplugin::isSamePathname(fileName, SRCDIR "/include/tools/bigint.hxx")) returntrue; if (loplugin::isSamePathname(fileName, SRCDIR "/include/tools/solar.h")) returntrue; if (!varDecl->hasInit()) returntrue; if (isa<IntegerLiteral>(varDecl->getInit()->IgnoreParenImpCasts())) returntrue; // ignore int x = -1; if (isa<UnaryOperator>(varDecl->getInit()->IgnoreParenImpCasts())) returntrue; auto lhsType = varDecl->getType(); auto rhsType = varDecl->getInit()->IgnoreParenImpCasts()->getType(); if (lhsType.getLocalUnqualifiedType() == rhsType) returntrue; if (!rhsType.getTypePtrOrNull()) returntrue; if (isInterestingType(rhsType)) returntrue; if (!isInterestingType(lhsType)) returntrue; if (rhsType->isFloatingType()) // TODO returntrue;
report(DiagnosticsEngine::Warning, "rather replace type of decl %0 with %1",
varDecl->getLocation())
<< lhsType << rhsType << varDecl->getSourceRange(); //lhsType->dump(); //varDecl->dump(); returntrue;
}
bool ConvertLong::isInterestingType(QualType qt)
{ auto tc = loplugin::TypeCheck(qt); if (tc.Typedef())
{
TypedefType const* typedefType = qt->getAs<TypedefType>(); auto name = typedefType->getDecl()->getName(); if (name == "sal_uLong") returntrue; // because this is a typedef to long on 64-bit Linux if (name == "sal_Int64" || name == "sal_uInt64" || name.find("size_t") != StringRef::npos) returnfalse;
} if (isa<AutoType>(qt.getTypePtr())) returnfalse; auto unqual = qt.getUnqualifiedType(); if (unqual->isSpecificBuiltinType(BuiltinType::Kind::Long)
|| unqual->isSpecificBuiltinType(BuiltinType::Kind::ULong))
{ returntrue;
} if (!tc.Typedef()) returnfalse;
TypedefType const* typedefType = qt->getAs<TypedefType>(); auto name = typedefType->getDecl()->getName(); return name == "sal_uIntPtr" || name == "sal_IntPtr";
}
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.