/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * Based on LLVM/Clang. * * This file is distributed under the University of Illinois Open Source * License. See LICENSE.TXT for details. * */ #include "sallogareas.hxx" #include "check.hxx" #include "compat.hxx" #include #include namespace loplugin { /* This is a compile check. Check area used in SAL_INFO/SAL_WARN macros against the list in include/sal/log-areas.dox and report if the area is not listed there. The fix is either use a proper area or add it to the list if appropriate. */ SalLogAreas::SalLogAreas( const InstantiationData& data ) : FilteringPlugin(data), inFunction(nullptr) { } void SalLogAreas::run() { inFunction = NULL; lastSalDetailLogStreamMacro = SourceLocation(); TraverseDecl( compiler.getASTContext().getTranslationUnitDecl()); } bool SalLogAreas::VisitFunctionDecl( const FunctionDecl* function ) { inFunction = function; return true; } bool SalLogAreas::VisitCallExpr( const CallExpr* call ) { if( ignoreLocation( call )) return true; const FunctionDecl* func = call->getDirectCallee(); if( !func ) return true; if( !( func->getNumParams() == 5 && func->getIdentifier() != NULL && ( func->getName() == "sal_detail_log" || func->getName() == "log" || func->getName() == "DbgUnhandledException")) ) return true; auto tc = loplugin::DeclCheck(func); enum class LogCallKind { Sal, DbgUnhandledException}; LogCallKind kind; int areaArgIndex; if( tc.Function("sal_detail_log") || tc.Function("log").Namespace("detail").Namespace("sal").GlobalNamespace() ) { kind = LogCallKind::Sal; // fine areaArgIndex = 1; } else if( tc.Function("DbgUnhandledException").GlobalNamespace() ) { kind = LogCallKind::DbgUnhandledException; // ok areaArgIndex = 3; } else return true; // The SAL_DETAIL_LOG_STREAM macro expands to two calls to sal::detail::log(), // so do not warn repeatedly about the same macro (the area->getLocStart() of all the calls // from the same macro should be the same). if( kind == LogCallKind::Sal ) { SourceLocation expansionLocation = compiler.getSourceManager().getExpansionLoc( compat::getBeginLoc(call)); if( expansionLocation == lastSalDetailLogStreamMacro ) return true; lastSalDetailLogStreamMacro = expansionLocation; }; if( const clang::StringLiteral* area = dyn_cast< clang::StringLiteral >( call->getArg( areaArgIndex )->IgnoreParenImpCasts())) { if( area->getKind() == clang::StringLiteral::Ascii ) checkArea( area->getBytes(), area->getExprLoc()); else report( DiagnosticsEngine::Warning, "unsupported string literal kind (plugin needs fixing?)", compat::getBeginLoc(area)); return true; } if( loplugin::DeclCheck(inFunction).Function("log").Namespace("detail").Namespace("sal").GlobalNamespace() || loplugin::DeclCheck(inFunction).Function("sal_detail_logFormat").GlobalNamespace() ) return true; // These functions only forward to sal_detail_log, so ok. if( call->getArg( areaArgIndex )->isNullPointerConstant( compiler.getASTContext(), Expr::NPC_ValueDependentIsNotNull ) != Expr::NPCK_NotNull ) { // If the area argument is a null pointer, that is allowed only for SAL_DEBUG. const SourceManager& source = compiler.getSourceManager(); for( SourceLocation loc = compat::getBeginLoc(call); loc.isMacroID(); loc = compat::getImmediateExpansionRange(source, loc ).first ) { StringRef inMacro = Lexer::getImmediateMacroName( loc, source, compiler.getLangOpts()); if( inMacro == "SAL_DEBUG" || inMacro == "SAL_DEBUG_BACKTRACE" ) return true; // ok } report( DiagnosticsEngine::Warning, "missing log area", compat::getBeginLoc(call->getArg( 1 )->IgnoreParenImpCasts())); return true; } report( DiagnosticsEngine::Warning, "cannot analyse log area argument (plugin needs fixing?)", compat::getBeginLoc(call)); return true; } void SalLogAreas::checkArea( StringRef area, SourceLocation location ) { if( logAreas.empty()) readLogAreas(); if( !logAreas.count( area )) { report( DiagnosticsEngine::Warning, "unknown log area '%0' (check or extend include/sal/log-areas.dox)", location ) << area; checkAreaSyntax(area, location); return; } // don't leave this alive by default, generates too many false+ #if 0 if (compiler.getSourceManager().isInMainFile(location)) { auto matchpair = [this,area](StringRef p1, StringRef p2) { return (area == p1 && firstSeenLogArea == p2) || (area == p2 && firstSeenLogArea == p1); }; // these are "cross-module" log areas if (area == "i18n" || area == "lok" || area == "lok.tiledrendering") ; // these appear to be cross-file log areas else if ( area == "chart2" || area == "oox.cscode" || area == "oox.csdata" || area == "slideshow.verbose" || area == "sc.opencl" || area == "sc.core.formulagroup" || area == "sw.pageframe" || area == "sw.idle" || area == "sw.level2" || area == "sw.docappend" || area == "sw.mailmerge" || area == "sw.uno" || area == "vcl.layout" || area == "vcl.a11y" || area == "vcl.gdi.fontmetric" || area == "vcl.opengl" || area == "vcl.harfbuzz" || area == "vcl.eventtesting" || area == "vcl.schedule" || area == "vcl.unity" || area == "xmlsecurity.comp" ) ; else if (firstSeenLogArea == "") { firstSeenLogArea = area; firstSeenLocation = location; } // some modules do this deliberately else if (firstSeenLogArea.compare(0, 3, "jfw") == 0 || firstSeenLogArea.compare(0, 6, "opencl") == 0) ; // mixing these in the same file seems legitimate else if ( matchpair("chart2.pie.label.bestfit", "chart2.pie.label.bestfit.inside") || matchpair("editeng", "editeng.chaining") || matchpair("oox.drawingml", "oox.cscode") || matchpair("oox.drawingml", "oox.drawingml.gradient") || matchpair("sc.core", "sc.core.grouparealistener") || matchpair("sc.orcus", "sc.orcus.condformat") || matchpair("sc.orcus", "sc.orcus.style") || matchpair("sc.orcus", "sc.orcus.autofilter") || matchpair("svx", "svx.chaining") || matchpair("sw.ww8", "sw.ww8.level2") || matchpair("writerfilter", "writerfilter.profile") ) ; else if (firstSeenLogArea != area) { report( DiagnosticsEngine::Warning, "two different log areas '%0' and '%1' in the same file?", location ) << firstSeenLogArea << area; report( DiagnosticsEngine::Note, "first area was seen here", firstSeenLocation ); } } #endif } void SalLogAreas::checkAreaSyntax(StringRef area, SourceLocation location) { for (std::size_t i = 0;;) { std::size_t j = area.find('.', i); if (j == StringRef::npos) { j = area.size(); } if (j == i) { goto bad; } for (; i != j; ++i) { auto c = area[i]; if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z'))) { goto bad; } } if (j == area.size()) { return; } i = j + 1; } bad: report( DiagnosticsEngine::Warning, "invalid log area syntax '%0'%1 (see include/sal/log.hxx for details)", location) << area << (location.isValid() ? "" : " in include/sal/log-areas.dox"); } void SalLogAreas::readLogAreas() { std::ifstream is( SRCDIR "/include/sal/log-areas.dox" ); while( is.good()) { std::string line; getline( is, line ); size_t pos = line.find( "@li @c " ); if( pos != std::string::npos ) { pos += strlen( "@li @c " ); size_t end = line.find( ' ', pos ); std::string area; if( end == std::string::npos ) area = line.substr( pos ); else if( pos != end ) area = line.substr( pos, end - pos ); checkAreaSyntax(area, SourceLocation()); logAreas.insert(area); } } // If you get this error message, you possibly have too old icecream (ICECC_EXTRAFILES is needed). if( logAreas.empty()) report( DiagnosticsEngine::Warning, "error reading log areas" ); } static Plugin::Registration< SalLogAreas > X( "sallogareas" ); } // namespace /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ release'>distro/vector/vector-24.2-release LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2016-04-18clean-up: unused using declarations and includesJochen Nitschke
Searched source for using declarations. Checked if those symbols reappear in the source file, even in comments or dead code but not in #include statements. If they don't reappear, remove the declaration. Remove includes whose symbol got removed. Change-Id: Ibb77163f63c1120070e9518e3dc0a78c6c59fab0 Reviewed-on: https://gerrit.libreoffice.org/24148 Reviewed-by: Jochen Nitschke <j.nitschke+logerrit@ok.de> Reviewed-by: Noel Grandin <noelgrandin@gmail.com> Tested-by: Noel Grandin <noelgrandin@gmail.com>
2016-02-09Remove excess newlinesChris Sherlock
A ridiculously fast way of doing this is: for i in $(pcregrep -l -M -r --include='.*[hc]xx$' \ --exclude-dir=workdir --exclude-dir=instdir '^ {3,}' .) do perl -0777 -i -pe 's/^ {3,}/ /gm' $i done Change-Id: Iebb93eccbee9e4fc5c4380474ba595858a27ac2c Reviewed-on: https://gerrit.libreoffice.org/22224 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Chris Sherlock <chris.sherlock79@gmail.com>
2015-10-02Fix typosAndrea Gelmini
Change-Id: Ib30f4e5f16518cbbe71cf03998513ebd8c2a4d1a Reviewed-on: https://gerrit.libreoffice.org/18949 Reviewed-by: Oliver Specht <oliver.specht@cib.de> Tested-by: Oliver Specht <oliver.specht@cib.de>
2015-10-02com::sun::star->css in forms/Noel Grandin
Change-Id: I1c09e88f839bdf11c6ff809ec95769e8f729c7cd
2015-08-19Remove two silly typedefsStephan Bergmann
Change-Id: Ia7de1cebf6009e770ca1b96bab6d5e121573ccc1
2015-03-17Fix various XServiceInfo implementationsStephan Bergmann
...to match what is recorded in the .component files Change-Id: Ie548cd37872d3b8540222201afaac73040e65c8f
2015-02-17forms: use constructor feature for form modulesChris Sherlock
Change-Id: I8f1588cbd338e2f8b5bc6047d84b17c697a7d2d3
2014-05-25Remove ASCII art, useless comments and whitespace from forms moduleChris Laplante
Change-Id: Ib6157a493092a137a6b0bf5b96d0e760d307f9da Reviewed-on: https://gerrit.libreoffice.org/9472 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
2014-05-06forms: sal_Bool->boolNoel Grandin
Change-Id: Ifa15f4ed3107b1075b504f09d2cae69ee38d347a
2014-02-26Remove visual noise from formsAlexander Wilms
Conflicts: forms/source/component/DatabaseForm.cxx Change-Id: I4005fe65e89794bd92191c37221c252a3e964917 Reviewed-on: https://gerrit.libreoffice.org/8262 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
2014-02-26cppuhelper: retrofit std::exception into overriding exception specsStephan Bergmann
Change-Id: I56e32131b7991ee9948ce46765632eb823d463b3
2014-02-23Remove unneccessary commentsAlexander Wilms
Change-Id: I939160ae72fecbe3d4a60ce755730bd4c38497fb Reviewed-on: https://gerrit.libreoffice.org/8182 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
2014-01-21FORMS : Remove usage of DBG_CTOR and DBG_DTOR.Arnaud Versini
Valgrind is capable of detecting such bugs. No need for extra macros. Change-Id: Ida618d6ac383c65f1c09212a7b6aa5ee228677db Reviewed-on: https://gerrit.libreoffice.org/7534 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
2013-06-03fdo#46808, Convert comphelper::ComponentContext in forms moduleNoel Grandin
Change-Id: I8a9913d964633381f00c0a4885cc655805fa1974
2013-06-03fdo#46808, Convert ComponentContext in connectivity,extension..Noel Grandin
...modules. Change-Id: Ie61976dc12b514bb85ca42496c0d9173a1c56264