aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-12-01 11:10:59 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-12-01 15:25:42 +0000
commitf379fe417a31981cf923930cae8799dc775a9b5f (patch)
treeee9b03aba796a7e9d5b44c0df2f1738ae1ec3e67 /sources/shiboken6
parent7cc341813c2c34520e8af610d34de0dfded8a67c (diff)
shiboken6: Use initializer lists for the converter replacement regexps
Complements 28aa3c4f6605a6331b12f47e03a9aba4aaefe201. Change-Id: I2814ce4832a6cf7623abb9e6e290773377795565 Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken6')
-rw-r--r--sources/shiboken6/generator/shiboken/shibokengenerator.cpp35
-rw-r--r--sources/shiboken6/generator/shiboken/shibokengenerator.h10
2 files changed, 28 insertions, 17 deletions
diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
index eac7f87f7..8d8483c6b 100644
--- a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp
@@ -124,21 +124,28 @@ using GeneratorClassInfoCache = QHash<const AbstractMetaClass *, GeneratorClassI
Q_GLOBAL_STATIC(GeneratorClassInfoCache, generatorClassInfoCache)
-ShibokenGenerator::ShibokenGenerator()
-{
- const char CHECKTYPE_REGEX[] = R"(%CHECKTYPE\[([^\[]*)\]\()";
- const char ISCONVERTIBLE_REGEX[] = R"(%ISCONVERTIBLE\[([^\[]*)\]\()";
- const char CONVERTTOPYTHON_REGEX[] = R"(%CONVERTTOPYTHON\[([^\[]*)\]\()";
- // Capture a '*' leading the variable name into the target
- // so that "*valuePtr = %CONVERTTOCPP..." works as expected.
- const char CONVERTTOCPP_REGEX[] =
- R"((\*?%?[a-zA-Z_][\w\.]*(?:\[[^\[^<^>]+\])*)(?:\s+)=(?:\s+)%CONVERTTOCPP\[([^\[]*)\]\()";
- m_typeSystemConvRegEx[TypeSystemCheckFunction] = QRegularExpression(QLatin1String(CHECKTYPE_REGEX));
- m_typeSystemConvRegEx[TypeSystemIsConvertibleFunction] = QRegularExpression(QLatin1String(ISCONVERTIBLE_REGEX));
- m_typeSystemConvRegEx[TypeSystemToPythonFunction] = QRegularExpression(QLatin1String(CONVERTTOPYTHON_REGEX));
- m_typeSystemConvRegEx[TypeSystemToCppFunction] = QRegularExpression(QLatin1String(CONVERTTOCPP_REGEX));
+static const char CHECKTYPE_REGEX[] = R"(%CHECKTYPE\[([^\[]*)\]\()";
+static const char ISCONVERTIBLE_REGEX[] = R"(%ISCONVERTIBLE\[([^\[]*)\]\()";
+static const char CONVERTTOPYTHON_REGEX[] = R"(%CONVERTTOPYTHON\[([^\[]*)\]\()";
+// Capture a '*' leading the variable name into the target
+// so that "*valuePtr = %CONVERTTOCPP..." works as expected.
+static const char CONVERTTOCPP_REGEX[] =
+ R"((\*?%?[a-zA-Z_][\w\.]*(?:\[[^\[^<^>]+\])*)(?:\s+)=(?:\s+)%CONVERTTOCPP\[([^\[]*)\]\()";
+
+const ShibokenGenerator::TypeSystemConverterRegExps &
+ ShibokenGenerator::typeSystemConvRegExps()
+{
+ static const TypeSystemConverterRegExps result = {
+ QRegularExpression(QLatin1String(CHECKTYPE_REGEX)),
+ QRegularExpression(QLatin1String(ISCONVERTIBLE_REGEX)),
+ QRegularExpression(QLatin1String(CONVERTTOCPP_REGEX)),
+ QRegularExpression(QLatin1String(CONVERTTOPYTHON_REGEX))
+ };
+ return result;
}
+ShibokenGenerator::ShibokenGenerator() = default;
+
ShibokenGenerator::~ShibokenGenerator() = default;
// Correspondences between primitive and Python types.
@@ -1934,7 +1941,7 @@ void ShibokenGenerator::replaceConverterTypeSystemVariable(TypeSystemConverterVa
QString &code) const
{
QList<StringPair> replacements;
- QRegularExpressionMatchIterator rit = m_typeSystemConvRegEx[converterVariable].globalMatch(code);
+ QRegularExpressionMatchIterator rit = typeSystemConvRegExps()[converterVariable].globalMatch(code);
while (rit.hasNext()) {
const QRegularExpressionMatch match = rit.next();
const QStringList list = match.capturedTexts();
diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.h b/sources/shiboken6/generator/shiboken/shibokengenerator.h
index b20a64515..4a73e0c6d 100644
--- a/sources/shiboken6/generator/shiboken/shibokengenerator.h
+++ b/sources/shiboken6/generator/shiboken/shibokengenerator.h
@@ -51,6 +51,8 @@ extern const char *END_ALLOW_THREADS;
#include <QtCore/QRegularExpression>
+#include <array>
+
class DocParser;
class CodeSnip;
class QPropertySpec;
@@ -366,8 +368,8 @@ protected:
/// Returns true if the Python wrapper for the received OverloadData must accept a list of arguments.
static bool pythonFunctionWrapperUsesListOfArguments(const OverloadData &overloadData);
- const QRegularExpression &convertToCppRegEx() const
- { return m_typeSystemConvRegEx[TypeSystemToCppFunction]; }
+ static const QRegularExpression &convertToCppRegEx()
+ { return typeSystemConvRegExps()[TypeSystemToCppFunction]; }
static QString pythonArgsAt(int i);
@@ -502,7 +504,9 @@ private:
/// Type system converter variable replacement names and regular expressions.
static const QHash<int, QString> &typeSystemConvName();
- QRegularExpression m_typeSystemConvRegEx[TypeSystemConverterVariables];
+
+ using TypeSystemConverterRegExps = std::array<QRegularExpression, TypeSystemConverterVariables>;
+ static const TypeSystemConverterRegExps &typeSystemConvRegExps();
};
Q_DECLARE_OPERATORS_FOR_FLAGS(ShibokenGenerator::AttroCheck);