cURL: follow redirects
[LibreOffice.git] / compilerplugins / clang / oslendian.cxx
blob99b2851614be30eaa88a09988a7b3629df35dbd5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 #include <cassert>
12 #include "compat.hxx"
13 #include "plugin.hxx"
15 namespace {
17 class OslEndian: public loplugin::Plugin, public PPCallbacks {
18 public:
19 explicit OslEndian(InstantiationData const & data): Plugin(data) {
20 compat::addPPCallbacks(compiler.getPreprocessor(), this);
23 enum { isPPCallback = true };
25 private:
26 void run() override {}
28 void MacroDefined(Token const & MacroNameTok, MacroDirective const *)
29 override
31 auto id = MacroNameTok.getIdentifierInfo()->getName();
32 if (id == "OSL_BIGENDIAN") {
33 if (definedLit_.isValid()) {
34 report(
35 DiagnosticsEngine::Warning,
36 "macro %0 defined in addition to 'OSL_LITENDIAN'",
37 MacroNameTok.getLocation())
38 << MacroNameTok.getIdentifierInfo();
39 report(
40 DiagnosticsEngine::Note,
41 "conflicting macro definition is here", definedLit_);
43 definedBig_ = MacroNameTok.getLocation();
44 assert(definedBig_.isValid());
45 } else if (id == "OSL_LITENDIAN") {
46 if (definedBig_.isValid()) {
47 report(
48 DiagnosticsEngine::Warning,
49 "macro %0 defined in addition to 'OSL_BIGENDIAN'",
50 MacroNameTok.getLocation())
51 << MacroNameTok.getIdentifierInfo();
52 report(
53 DiagnosticsEngine::Note,
54 "conflicting macro definition is here", definedBig_);
56 definedLit_ = MacroNameTok.getLocation();
57 assert(definedLit_.isValid());
61 void MacroUndefined(Token const & MacroNameTok, MacroDefinition const &)
62 override
64 auto id = MacroNameTok.getIdentifierInfo()->getName();
65 if (id == "OSL_BIGENDIAN" || id == "OSL_LITENDIAN") {
66 report(
67 DiagnosticsEngine::Warning, "macro %0 undefinition",
68 MacroNameTok.getLocation())
69 << MacroNameTok.getIdentifierInfo();
73 void Defined(
74 Token const & MacroNameTok, MacroDefinition const &, SourceRange)
75 override
77 check(MacroNameTok);
80 void Ifdef(
81 SourceLocation, Token const & MacroNameTok, MacroDefinition const &)
82 override
84 check(MacroNameTok);
87 void Ifndef(
88 SourceLocation, Token const & MacroNameTok, MacroDefinition const &)
89 override
91 check(MacroNameTok);
94 void check(Token const & macro) const {
95 auto id = macro.getIdentifierInfo()->getName();
96 if ((id == "OSL_BIGENDIAN" || id == "OSL_LITENDIAN")
97 && definedBig_.isInvalid() && definedLit_.isInvalid())
99 report(
100 DiagnosticsEngine::Warning,
101 "definition of macro %0 checked but 'osl/endian.h' is not"
102 " included",
103 macro.getLocation())
104 << macro.getIdentifierInfo();
108 SourceLocation definedBig_;
109 SourceLocation definedLit_;
112 loplugin::Plugin::Registration<OslEndian> X("oslendian");
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */