bump product version to 6.3.0.0.beta1
[LibreOffice.git] / compilerplugins / clang / blockblock.cxx
blob8405609af3df089120e9bf6983da486a3b2b6ecc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #ifndef LO_CLANG_SHARED_PLUGINS
12 #include <cassert>
13 #include <string>
14 #include <iostream>
15 #include <fstream>
16 #include <set>
17 #include "plugin.hxx"
19 /**
20 Check for places where we declare a block directly inside a block
22 namespace {
24 class BlockBlock:
25 public loplugin::FilteringPlugin<BlockBlock>
27 public:
28 explicit BlockBlock(loplugin::InstantiationData const & data):
29 FilteringPlugin(data) {}
31 virtual bool preRun() override
33 StringRef fn(handler.getMainFileName());
34 if (loplugin::isSamePathname(fn, SRCDIR "/sal/osl/unx/file_misc.cxx"))
35 return false;
36 return true;
39 void run() override {
40 if (preRun()) {
41 TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
45 bool VisitCompoundStmt(CompoundStmt const * );
48 bool BlockBlock::VisitCompoundStmt(CompoundStmt const * compound)
50 if (ignoreLocation(compound))
51 return true;
52 if (compound->size() != 1)
53 return true;
54 auto inner = *compound->body_begin();
55 if (!isa<CompoundStmt>(inner))
56 return true;
57 if (compiler.getSourceManager().isMacroBodyExpansion(compat::getBeginLoc(compound)))
58 return true;
59 if (compiler.getSourceManager().isMacroBodyExpansion(compat::getBeginLoc(inner)))
60 return true;
61 if (containsPreprocessingConditionalInclusion(compound->getSourceRange())) {
62 return true;
64 report(
65 DiagnosticsEngine::Warning,
66 "block directly inside block",
67 compat::getBeginLoc(compound))
68 << compound->getSourceRange();
69 report(
70 DiagnosticsEngine::Note,
71 "inner block here",
72 compat::getBeginLoc(inner))
73 << inner->getSourceRange();
74 return true;
77 loplugin::Plugin::Registration< BlockBlock > blockblock("blockblock", true);
81 #endif // LO_CLANG_SHARED_PLUGINS
83 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */