diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-11-05 16:41:23 +0100 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-11-06 08:11:57 +0000 |
| commit | 562edc619787d83b2d4418fa7a69c597a7b6945c (patch) | |
| tree | 959812de4b3fc30b24a0e7637c5d917c53f1c676 /sources/shiboken6/ApiExtractor/abstractmetaenum.cpp | |
| parent | e21b3c5f6201c97a89b736cec17a1855870409e8 (diff) | |
shiboken6: Split the abstractmetalang headers and sources
Split out enums, fields and functions. Only
AbstractMetaClass remains in abstractmetalang.h.
Change-Id: I49846f92fafc5969d83aa4a1767eb4ac23f39d1c
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken6/ApiExtractor/abstractmetaenum.cpp')
| -rw-r--r-- | sources/shiboken6/ApiExtractor/abstractmetaenum.cpp | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetaenum.cpp b/sources/shiboken6/ApiExtractor/abstractmetaenum.cpp new file mode 100644 index 000000000..21fa13a29 --- /dev/null +++ b/sources/shiboken6/ApiExtractor/abstractmetaenum.cpp @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt for Python. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** 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 +** 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. +** +** 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. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "abstractmetaenum.h" +#include "typesystem.h" + +AbstractMetaEnum::AbstractMetaEnum() : + m_hasQenumsDeclaration(false), m_signed(true) +{ +} + +AbstractMetaEnum::~AbstractMetaEnum() +{ + qDeleteAll(m_enumValues); +} + +template <class String> +AbstractMetaEnumValue *findMatchingEnumValue(const AbstractMetaEnumValueList &list, const String &value) +{ + for (AbstractMetaEnumValue *enumValue : list) { + if (enumValue->name() == value) + return enumValue; + } + return nullptr; +} + +// Find enum values for "enum Enum { e1 }" either for "e1" or "Enum::e1" +AbstractMetaEnumValue *AbstractMetaEnum::findEnumValue(const QString &value) const +{ + if (isAnonymous()) + return findMatchingEnumValue(m_enumValues, value); + const int sepPos = value.indexOf(QLatin1String("::")); + if (sepPos == -1) + return findMatchingEnumValue(m_enumValues, value); + return name() == QStringView{value}.left(sepPos) + ? findMatchingEnumValue(m_enumValues, QStringView{value}.right(value.size() - sepPos - 2)) + : nullptr; +} + +QString AbstractMetaEnum::name() const +{ + return m_typeEntry->targetLangEntryName(); +} + +QString AbstractMetaEnum::qualifier() const +{ + return m_typeEntry->targetLangQualifier(); +} + +QString AbstractMetaEnum::package() const +{ + return m_typeEntry->targetLangPackage(); +} + +#ifndef QT_NO_DEBUG_STREAM + +static void formatMetaEnumValue(QDebug &d, const AbstractMetaEnumValue *v) +{ + const QString &name = v->stringValue(); + if (!name.isEmpty()) + d << name << '='; + d << v->value(); +} + +QDebug operator<<(QDebug d, const AbstractMetaEnumValue *v) +{ + QDebugStateSaver saver(d); + d.noquote(); + d.nospace(); + d << "AbstractMetaEnumValue("; + if (v) + formatMetaEnumValue(d, v); + else + d << '0'; + d << ')'; + return d; +} + +QDebug operator<<(QDebug d, const AbstractMetaEnum *ae) +{ + QDebugStateSaver saver(d); + d.noquote(); + d.nospace(); + d << "AbstractMetaEnum("; + if (ae) { + d << ae->fullName(); + if (!ae->isSigned()) + d << " (unsigned) "; + d << '['; + const AbstractMetaEnumValueList &values = ae->values(); + for (int i = 0, count = values.size(); i < count; ++i) { + if (i) + d << ' '; + formatMetaEnumValue(d, values.at(i)); + } + d << ']'; + } else { + d << '0'; + } + d << ')'; + return d; +} +#endif // !QT_NO_DEBUG_STREAM |
