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(InstantiationData
const & data
): Plugin(data
) {
20 compat::addPPCallbacks(compiler
.getPreprocessor(), 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());
61 void MacroUndefined(Token
const & MacroNameTok
, MacroDefinition
const &)
64 auto id
= MacroNameTok
.getIdentifierInfo()->getName();
65 if (id
== "OSL_BIGENDIAN" || id
== "OSL_LITENDIAN") {
67 DiagnosticsEngine::Warning
, "macro %0 undefinition",
68 MacroNameTok
.getLocation())
69 << MacroNameTok
.getIdentifierInfo();
74 Token
const & MacroNameTok
, MacroDefinition
const &, SourceRange
)
81 SourceLocation
, Token
const & MacroNameTok
, MacroDefinition
const &)
88 SourceLocation
, Token
const & MacroNameTok
, MacroDefinition
const &)
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())
100 DiagnosticsEngine::Warning
,
101 "definition of macro %0 checked but 'osl/endian.h' is not"
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: */