2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2023-01-04 08:52:22 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2016-01-15 14:58:39 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
/*
|
|
|
|
|
Copyright 2005 Roberto Raggi <roberto@kdevelop.org>
|
|
|
|
|
|
|
|
|
|
Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
|
documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
|
the above copyright notice appear in all copies and that both that
|
|
|
|
|
copyright notice and this permission notice appear in supporting
|
|
|
|
|
documentation.
|
|
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
KDEVELOP TEAM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
|
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
2008-12-22 14:10:47 +01:00
|
|
|
#include "Macro.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2008-12-22 14:10:47 +01:00
|
|
|
using namespace CPlusPlus;
|
2008-12-08 12:59:33 +01:00
|
|
|
|
2008-12-22 14:10:47 +01:00
|
|
|
Macro::Macro()
|
2019-07-31 17:21:41 +02:00
|
|
|
: _next(nullptr),
|
2008-12-22 14:10:47 +01:00
|
|
|
_hashcode(0),
|
2012-10-11 16:16:01 +02:00
|
|
|
_fileRevision(0),
|
2008-12-22 14:10:47 +01:00
|
|
|
_line(0),
|
2014-05-09 10:04:13 -04:00
|
|
|
_bytesOffset(0),
|
|
|
|
|
_utf16charsOffset(0),
|
2009-12-21 14:47:22 +01:00
|
|
|
_length(0),
|
2008-12-22 14:10:47 +01:00
|
|
|
_state(0)
|
|
|
|
|
{ }
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-09-06 11:50:58 +02:00
|
|
|
QString Macro::decoratedName() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2008-12-22 14:10:47 +01:00
|
|
|
QString text;
|
2009-07-27 21:47:03 +02:00
|
|
|
if (f._hidden)
|
2008-12-22 14:10:47 +01:00
|
|
|
text += QLatin1String("#undef ");
|
|
|
|
|
else
|
|
|
|
|
text += QLatin1String("#define ");
|
|
|
|
|
text += QString::fromUtf8(_name.constData(), _name.size());
|
2009-07-27 21:47:03 +02:00
|
|
|
if (f._functionLike) {
|
2008-12-22 14:10:47 +01:00
|
|
|
text += QLatin1Char('(');
|
|
|
|
|
bool first = true;
|
2022-10-07 14:46:06 +02:00
|
|
|
for (const QByteArray &formal : std::as_const(_formals)) {
|
2008-12-22 14:10:47 +01:00
|
|
|
if (! first)
|
|
|
|
|
text += QLatin1String(", ");
|
|
|
|
|
else
|
|
|
|
|
first = false;
|
2012-03-16 14:06:09 +01:00
|
|
|
if (formal != "__VA_ARGS__")
|
|
|
|
|
text += QString::fromUtf8(formal.constData(), formal.size());
|
2008-12-22 14:10:47 +01:00
|
|
|
}
|
2009-07-27 21:47:03 +02:00
|
|
|
if (f._variadic)
|
2008-12-22 14:10:47 +01:00
|
|
|
text += QLatin1String("...");
|
|
|
|
|
text += QLatin1Char(')');
|
|
|
|
|
}
|
|
|
|
|
text += QLatin1Char(' ');
|
2011-09-06 11:50:58 +02:00
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString Macro::toString() const
|
|
|
|
|
{
|
|
|
|
|
QString text = decoratedName();
|
2012-03-26 15:18:01 +02:00
|
|
|
text.append(QString::fromUtf8(_definitionText.constData(), _definitionText.size()));
|
2011-09-06 11:50:58 +02:00
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString Macro::toStringWithLineBreaks() const
|
|
|
|
|
{
|
2012-03-26 15:18:01 +02:00
|
|
|
return toString();
|
2008-12-22 14:10:47 +01:00
|
|
|
}
|