2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:58:39 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
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;
|
2011-04-19 15:42:14 +02:00
|
|
|
foreach (const QByteArray &formal, _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
|
|
|
}
|