1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
17 class OslEndian
: public loplugin::Plugin
, public PPCallbacks
{
19 explicit OslEndian(loplugin::InstantiationData
const & data
): Plugin(data
) {
20 compiler
.getPreprocessor().addPPCallbacks(std::unique_ptr
<PPCallbacks
>(this));
23 enum { isPPCallback
= true };
26 void run() override
{}
28 void MacroDefined(Token
const & MacroNameTok
, MacroDirective
const *)
31 auto id
= MacroNameTok
.getIdentifierInfo()->getName();
32 if (id
== "OSL_BIGENDIAN") {
33 if (definedLit_
.isValid()) {
35 DiagnosticsEngine::Warning
,
36 "macro %0 defined in addition to 'OSL_LITENDIAN'",
37 MacroNameTok
.getLocation())
38 << MacroNameTok
.getIdentifierInfo();
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()) {
48 DiagnosticsEngine::Warning
,
49 "macro %0 defined in addition to 'OSL_BIGENDIAN'",
50 MacroNameTok
.getLocation())
51 << MacroNameTok
.getIdentifierInfo();
53 DiagnosticsEngine::Note
,
54 "conflicting macro definition is here", definedBig_
);
56 definedLit_
= MacroNameTok
.getLocation();
57 assert(definedLit_
.isValid());
62 Token
const & MacroNameTok
, MacroDefinition
const &
63 #if CLANG_VERSION >= 50000
64 , MacroDirective
const *
68 auto id
= MacroNameTok
.getIdentifierInfo()->getName();
69 if (id
== "OSL_BIGENDIAN" || id
== "OSL_LITENDIAN") {
71 DiagnosticsEngine::Warning
, "macro %0 undefinition",
72 MacroNameTok
.getLocation())
73 << MacroNameTok
.getIdentifierInfo();
78 Token
const & MacroNameTok
, MacroDefinition
const &, SourceRange
)
85 SourceLocation
, Token
const & MacroNameTok
,
86 MacroDefinition
const &) override
92 SourceLocation
, Token
const & MacroNameTok
,
93 MacroDefinition
const &) override
98 void check(Token
const & macro
) const {
99 auto id
= macro
.getIdentifierInfo()->getName();
100 if ((id
== "OSL_BIGENDIAN" || id
== "OSL_LITENDIAN")
101 && definedBig_
.isInvalid() && definedLit_
.isInvalid())
104 DiagnosticsEngine::Warning
,
105 "definition of macro %0 checked but 'osl/endian.h' is not"
108 << macro
.getIdentifierInfo();
112 SourceLocation definedBig_
;
113 SourceLocation definedLit_
;
116 loplugin::Plugin::Registration
<OslEndian
> X("oslendian");
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */