and fix bug in ScriptDocument::getTitle
which has been there since
commit e304ba66f4
Date: Thu Mar 15 14:59:30 2007 +0000
INTEGRATION: CWS basmgr02 (1.1.2); FILE ADDED
plugin is off by default since it uses expensive parentStmt() calls
Change-Id: Id0f16baec48e0381e0083594d7e59b58b023da2f
Reviewed-on: https://gerrit.libreoffice.org/43750
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
78 lines
2.1 KiB
C++
78 lines
2.1 KiB
C++
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
/*
|
|
* This file is part of the LibreOffice project.
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#include <cassert>
|
|
#include <string>
|
|
#include <iostream>
|
|
#include <fstream>
|
|
#include <set>
|
|
#include "plugin.hxx"
|
|
|
|
namespace {
|
|
|
|
class DodgySwitch:
|
|
public RecursiveASTVisitor<DodgySwitch>, public loplugin::Plugin
|
|
{
|
|
public:
|
|
explicit DodgySwitch(InstantiationData const & data): Plugin(data) {}
|
|
|
|
virtual void run() override
|
|
{
|
|
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
|
|
}
|
|
|
|
bool VisitDefaultStmt(DefaultStmt const * );
|
|
bool VisitCaseStmt(CaseStmt const * );
|
|
private:
|
|
bool IsParentSwitch(Stmt const * );
|
|
};
|
|
|
|
bool DodgySwitch::VisitDefaultStmt(DefaultStmt const * defaultStmt)
|
|
{
|
|
if (ignoreLocation(defaultStmt))
|
|
return true;
|
|
if (!IsParentSwitch(defaultStmt))
|
|
report(
|
|
DiagnosticsEngine::Warning, "default statement not directly under switch",
|
|
defaultStmt->getLocStart())
|
|
<< defaultStmt->getSourceRange();
|
|
return true;
|
|
}
|
|
|
|
bool DodgySwitch::VisitCaseStmt(CaseStmt const * caseStmt)
|
|
{
|
|
if (ignoreLocation(caseStmt))
|
|
return true;
|
|
if (!IsParentSwitch(caseStmt))
|
|
{
|
|
//parentStmt(parentStmt(caseStmt))->dump();
|
|
report(
|
|
DiagnosticsEngine::Warning, "case statement not directly under switch",
|
|
caseStmt->getLocStart())
|
|
<< caseStmt->getSourceRange();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool DodgySwitch::IsParentSwitch(Stmt const * stmt)
|
|
{
|
|
auto parent = parentStmt(stmt);
|
|
if (isa<CaseStmt>(parent) || isa<DefaultStmt>(parent)) // daisy chain
|
|
return true;
|
|
auto compoundStmt = dyn_cast<CompoundStmt>(parent);
|
|
if (!compoundStmt)
|
|
return false;
|
|
return isa<SwitchStmt>(parentStmt(compoundStmt));
|
|
}
|
|
|
|
loplugin::Plugin::Registration< DodgySwitch > X("dodgyswitch", false);
|
|
|
|
}
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|