aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2017-02-24 16:46:22 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2017-02-28 07:10:18 +0000
commit80fef1705ca23be01edbb12ece1b8bd49473bafe (patch)
tree10a419a35c25241b6eee147861326f59c3e7c692
parent73688fbe5327b1ae62bcac8fee103a895bdd5c5d (diff)
Handle rvalue references throughout
Move the reference type enumeration from class TypeInfo to a common header and use that in all classes representing a type. Task-number: PYSIDE-323 Change-Id: I8eecf76efd8b5daf0230161a224e16e218ebbf8d Reviewed-by: Christian Tismer <tismer@stackless.com> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r--ApiExtractor/abstractmetabuilder.cpp14
-rw-r--r--ApiExtractor/abstractmetalang.cpp48
-rw-r--r--ApiExtractor/abstractmetalang.h18
-rw-r--r--ApiExtractor/parser/codemodel.cpp4
-rw-r--r--ApiExtractor/parser/codemodel.h7
-rw-r--r--ApiExtractor/parser/codemodel_enums.h38
-rw-r--r--ApiExtractor/parser/compiler_utils.cpp2
-rw-r--r--ApiExtractor/qtdocparser.cpp6
-rw-r--r--ApiExtractor/tests/testabstractmetatype.cpp4
-rw-r--r--ApiExtractor/tests/testcontainer.cpp2
-rw-r--r--ApiExtractor/typeparser.cpp28
-rw-r--r--ApiExtractor/typeparser.h8
-rw-r--r--generator/generator.cpp24
-rw-r--r--generator/shiboken2/cppgenerator.cpp12
-rw-r--r--generator/shiboken2/shibokengenerator.cpp43
15 files changed, 178 insertions, 80 deletions
diff --git a/ApiExtractor/abstractmetabuilder.cpp b/ApiExtractor/abstractmetabuilder.cpp
index 2ce8e057a..14e6b3641 100644
--- a/ApiExtractor/abstractmetabuilder.cpp
+++ b/ApiExtractor/abstractmetabuilder.cpp
@@ -1505,7 +1505,7 @@ static bool _compareAbstractMetaTypes(const AbstractMetaType* type, const Abstra
return false;
return type->typeEntry() == other->typeEntry()
&& type->isConstant() == other->isConstant()
- && type->isReference() == other->isReference()
+ && type->referenceType() == other->referenceType()
&& type->indirections() == other->indirections();
}
@@ -1621,7 +1621,7 @@ void AbstractMetaBuilderPrivate::traverseFunctions(ScopeModelItem scopeItem,
if (metaFunction->isConstructor() && metaFunction->arguments().size() == 1) {
const AbstractMetaType* argType = metaFunction->arguments().first()->type();
isCopyCtor = argType->isConstant()
- && argType->isReference()
+ && argType->referenceType() == LValueReference
&& argType->typeEntry()->name() == metaFunction->name();
}
@@ -2235,7 +2235,8 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateType(double vr,
AbstractMetaType *metaType = q->createMetaType();
metaType->setTypeEntry(type);
metaType->setIndirections(typeInfo.indirections);
- metaType->setReference(typeInfo.isReference);
+ if (typeInfo.isReference)
+ metaType->setReferenceType(LValueReference);
metaType->setConstant(typeInfo.isConstant);
if (isTemplate) {
foreach (const QString& templateArg, templateArgs) {
@@ -2445,15 +2446,14 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateType(const TypeInfo &_typ
AbstractMetaType *metaType = q->createMetaType();
metaType->setTypeEntry(type);
metaType->setIndirections(typeInfo.indirections);
- metaType->setReference(typeInfo.is_reference);
+ metaType->setReferenceType(typeInfo.referenceType);
metaType->setConstant(typeInfo.is_constant);
metaType->setOriginalTypeDescription(_typei.toString());
foreach (const TypeParser::Info &ta, typeInfo.template_instantiations) {
TypeInfo info;
info.setConstant(ta.is_constant);
- if (ta.is_reference)
- info.setReferenceType(TypeInfo::LValueReference);
+ info.setReferenceType(ta.referenceType);
info.setIndirections(ta.indirections);
info.setFunctionPointer(false);
@@ -2808,7 +2808,7 @@ bool AbstractMetaBuilderPrivate::inheritTemplate(AbstractMetaClass *subclass,
AbstractMetaType *temporaryType = q->createMetaType();
temporaryType->setTypeEntry(t);
temporaryType->setConstant(i.is_constant);
- temporaryType->setReference(i.is_reference);
+ temporaryType->setReferenceType(i.referenceType);
temporaryType->setIndirections(i.indirections);
temporaryType->decideUsagePattern();
templateTypes << temporaryType;
diff --git a/ApiExtractor/abstractmetalang.cpp b/ApiExtractor/abstractmetalang.cpp
index 8ecd8371c..3e7ff3f60 100644
--- a/ApiExtractor/abstractmetalang.cpp
+++ b/ApiExtractor/abstractmetalang.cpp
@@ -95,10 +95,10 @@ AbstractMetaType::AbstractMetaType()
m_originalTemplateType(0),
m_pattern(InvalidPattern),
m_constant(false),
- m_reference(false),
m_cppInstantiation(true),
m_indirections(0),
- m_reserved(0)
+ m_reserved(0),
+ m_referenceType(NoReference)
{
}
@@ -132,7 +132,7 @@ AbstractMetaType *AbstractMetaType::copy() const
cpy->setTypeUsagePattern(typeUsagePattern());
cpy->setConstant(isConstant());
- cpy->setReference(isReference());
+ cpy->setReferenceType(referenceType());
cpy->setIndirections(indirections());
cpy->setInstantiations(instantiations());
cpy->setArrayElementCount(arrayElementCount());
@@ -169,8 +169,16 @@ QString AbstractMetaType::cppSignature() const
m_cachedCppSignature += QLatin1Char(' ');
if (indirections())
m_cachedCppSignature += QString(indirections(), QLatin1Char('*'));
- if (isReference())
+ switch (referenceType()) {
+ case NoReference:
+ break;
+ case LValueReference:
m_cachedCppSignature += QLatin1Char('&');
+ break;
+ case RValueReference:
+ m_cachedCppSignature += QLatin1String("&&");
+ break;
+ }
}
}
return m_cachedCppSignature;
@@ -181,7 +189,7 @@ void AbstractMetaType::decideUsagePattern()
const TypeEntry* type = typeEntry();
if (type->isPrimitive() && (!actualIndirections()
- || (isConstant() && isReference() && !indirections()))) {
+ || (isConstant() && m_referenceType == LValueReference && !indirections()))) {
setTypeUsagePattern(AbstractMetaType::PrimitivePattern);
} else if (type->isVoid()) {
@@ -192,30 +200,30 @@ void AbstractMetaType::decideUsagePattern()
} else if (type->isString()
&& indirections() == 0
- && (isConstant() == isReference()
+ && (isConstant() == (m_referenceType == LValueReference)
|| isConstant())) {
setTypeUsagePattern(AbstractMetaType::StringPattern);
} else if (type->isChar()
&& !indirections()
- && isConstant() == isReference()) {
+ && isConstant() == (m_referenceType == LValueReference)) {
setTypeUsagePattern(AbstractMetaType::CharPattern);
} else if (type->isJObjectWrapper()
&& !indirections()
- && isConstant() == isReference()) {
+ && isConstant() == (m_referenceType == LValueReference)) {
setTypeUsagePattern(AbstractMetaType::JObjectWrapperPattern);
} else if (type->isVariant()
&& !indirections()
- && isConstant() == isReference()) {
+ && isConstant() == (m_referenceType == LValueReference)) {
setTypeUsagePattern(AbstractMetaType::VariantPattern);
} else if (type->isEnum() && !actualIndirections()) {
setTypeUsagePattern(AbstractMetaType::EnumPattern);
} else if (type->isObject() && indirections() == 0) {
- if (isReference()) {
+ if (m_referenceType == LValueReference) {
if (((ComplexTypeEntry*) type)->isQObject())
setTypeUsagePattern(AbstractMetaType::QObjectPattern);
else
@@ -232,8 +240,8 @@ void AbstractMetaType::decideUsagePattern()
setTypeUsagePattern(AbstractMetaType::ObjectPattern);
// const-references to pointers can be passed as pointers
- if (isReference() && isConstant()) {
- setReference(false);
+ if (referenceType() == LValueReference && isConstant()) {
+ setReferenceType(NoReference);
setConstant(false);
}
@@ -244,7 +252,7 @@ void AbstractMetaType::decideUsagePattern()
} else if (type->isFlags()
&& !indirections()
- && (isConstant() == isReference())) {
+ && (isConstant() == (m_referenceType == LValueReference))) {
setTypeUsagePattern(AbstractMetaType::FlagsPattern);
} else if (type->isArray()) {
@@ -1119,7 +1127,7 @@ bool AbstractMetaFunction::isCopyConstructor() const
const AbstractMetaType* type = arguments().first()->type();
return type->typeEntry() == ownerClass()->typeEntry() &&
- type->isConstant() && type->isReference();
+ type->isConstant() && type->referenceType() == LValueReference;
}
QString AbstractMetaFunction::modifiedName() const
@@ -2058,7 +2066,7 @@ void AbstractMetaClass::addDefaultCopyConstructor(bool isPrivate)
AbstractMetaType* argType = new AbstractMetaType;
argType->setTypeEntry(typeEntry());
- argType->setReference(true);
+ argType->setReferenceType(LValueReference);
argType->setConstant(true);
argType->setTypeUsagePattern(AbstractMetaType::ValuePattern);
@@ -2598,8 +2606,16 @@ QString AbstractMetaType::minimalSignature() const
for (int j = 0; j < indirections(); ++j)
minimalSignature += QLatin1Char('*');
- if (isReference())
+ switch (referenceType()) {
+ case NoReference:
+ break;
+ case LValueReference:
minimalSignature += QLatin1Char('&');
+ break;
+ case RValueReference:
+ minimalSignature += QLatin1String("&&");
+ break;
+ }
return minimalSignature;
}
diff --git a/ApiExtractor/abstractmetalang.h b/ApiExtractor/abstractmetalang.h
index 673e9c9b2..dc38e7009 100644
--- a/ApiExtractor/abstractmetalang.h
+++ b/ApiExtractor/abstractmetalang.h
@@ -33,6 +33,8 @@
#include "typesystem_enums.h"
#include "typesystem_typedefs.h"
+#include "parser/codemodel_enums.h"
+
#include <QtCore/qobjectdefs.h>
#include <QtCore/QStringList>
@@ -502,14 +504,8 @@ public:
m_constant = constant;
}
- bool isReference() const
- {
- return m_reference;
- }
- void setReference(bool ref)
- {
- m_reference = ref;
- }
+ ReferenceType referenceType() const { return m_referenceType; }
+ void setReferenceType(ReferenceType ref) { m_referenceType = ref; }
/**
* Says if the type is to be implemented using target language
@@ -537,7 +533,7 @@ public:
int actualIndirections() const
{
- return m_indirections + (isReference() ? 1 : 0);
+ return m_indirections + (m_referenceType == LValueReference ? 1 : 0);
}
int indirections() const
{
@@ -616,10 +612,10 @@ private:
TypeUsagePattern m_pattern;
uint m_constant : 1;
- uint m_reference : 1;
uint m_cppInstantiation : 1;
int m_indirections : 4;
- uint m_reserved : 25; // unused
+ uint m_reserved : 26; // unused
+ ReferenceType m_referenceType;
AbstractMetaTypeList m_children;
Q_DISABLE_COPY(AbstractMetaType);
diff --git a/ApiExtractor/parser/codemodel.cpp b/ApiExtractor/parser/codemodel.cpp
index 36cd2c9b2..f803e9c7e 100644
--- a/ApiExtractor/parser/codemodel.cpp
+++ b/ApiExtractor/parser/codemodel.cpp
@@ -202,10 +202,10 @@ QString TypeInfo::toString() const
switch (referenceType()) {
case NoReference:
break;
- case TypeInfo::LValueReference:
+ case LValueReference:
tmp += QLatin1Char('&');
break;
- case TypeInfo::RValueReference:
+ case RValueReference:
tmp += QLatin1String("&&");
break;
}
diff --git a/ApiExtractor/parser/codemodel.h b/ApiExtractor/parser/codemodel.h
index 5df8efd93..83503492a 100644
--- a/ApiExtractor/parser/codemodel.h
+++ b/ApiExtractor/parser/codemodel.h
@@ -32,6 +32,7 @@
#define CODEMODEL_H
#include "codemodel_fwd.h"
+#include "codemodel_enums.h"
#include <QtCore/QHash>
#include <QtCore/QList>
@@ -94,12 +95,6 @@ QDebug operator<<(QDebug d, const CodeModel *m);
class TypeInfo
{
public:
- enum ReferenceType {
- NoReference,
- LValueReference,
- RValueReference
- };
-
TypeInfo() : flags(0), m_referenceType(NoReference) {}
QStringList qualifiedName() const
diff --git a/ApiExtractor/parser/codemodel_enums.h b/ApiExtractor/parser/codemodel_enums.h
new file mode 100644
index 000000000..aa8b051d8
--- /dev/null
+++ b/ApiExtractor/parser/codemodel_enums.h
@@ -0,0 +1,38 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of PySide2.
+**
+** $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$
+**
+****************************************************************************/
+
+#ifndef CODEMODEL_ENUMS_H
+#define CODEMODEL_ENUMS_H
+
+enum ReferenceType {
+ NoReference,
+ LValueReference,
+ RValueReference
+};
+
+#endif // CODEMODEL_ENUMS_H
diff --git a/ApiExtractor/parser/compiler_utils.cpp b/ApiExtractor/parser/compiler_utils.cpp
index 06100f91e..95a9db6c3 100644
--- a/ApiExtractor/parser/compiler_utils.cpp
+++ b/ApiExtractor/parser/compiler_utils.cpp
@@ -47,7 +47,7 @@ TypeInfo CompilerUtils::typeDescription(TypeSpecifierAST *type_specifier, Declar
typeInfo.setQualifiedName(type_cc.qualifiedName());
typeInfo.setConstant(type_cc.isConstant());
typeInfo.setVolatile(type_cc.isVolatile());
- typeInfo.setReferenceType(decl_cc.isReference() ? TypeInfo::LValueReference : TypeInfo::NoReference);
+ typeInfo.setReferenceType(decl_cc.isReference() ? LValueReference : NoReference);
typeInfo.setIndirections(decl_cc.indirection());
typeInfo.setArrayElements(decl_cc.arrayElements());
diff --git a/ApiExtractor/qtdocparser.cpp b/ApiExtractor/qtdocparser.cpp
index 0236c5ee3..f1421ff91 100644
--- a/ApiExtractor/qtdocparser.cpp
+++ b/ApiExtractor/qtdocparser.cpp
@@ -116,9 +116,11 @@ void QtDocParser::fillDocumentation(AbstractMetaClass* metaClass)
if (arg->type()->isConstant())
type.prepend(QLatin1String("const "));
- if (arg->type()->isReference()) {
+ if (arg->type()->referenceType() == LValueReference) {
type += QLatin1String(" &");
- } if (arg->type()->indirections()) {
+ } else if (arg->type()->referenceType() == RValueReference) {
+ type += QLatin1String(" &&");
+ } else if (arg->type()->indirections()) {
type += QLatin1Char(' ');
for (int j = 0, max = arg->type()->indirections(); j < max; ++j)
type += QLatin1Char('*');
diff --git a/ApiExtractor/tests/testabstractmetatype.cpp b/ApiExtractor/tests/testabstractmetatype.cpp
index 4519932d5..dfe13e037 100644
--- a/ApiExtractor/tests/testabstractmetatype.cpp
+++ b/ApiExtractor/tests/testabstractmetatype.cpp
@@ -54,7 +54,7 @@ void TestAbstractMetaType::testConstCharPtrType()
QVERIFY(!rtype->isPrimitive()); // const char* differs from char, so it's not considered a primitive type by apiextractor
QVERIFY(rtype->isNativePointer());
QVERIFY(!rtype->isQObject());
- QVERIFY(!rtype->isReference());
+ QCOMPARE(rtype->referenceType(), NoReference);
QVERIFY(!rtype->isValue());
QVERIFY(!rtype->isValuePointer());
}
@@ -123,7 +123,7 @@ void TestAbstractMetaType::testCharType()
QVERIFY(rtype->isPrimitive());
QVERIFY(!rtype->isNativePointer());
QVERIFY(!rtype->isQObject());
- QVERIFY(!rtype->isReference());
+ QCOMPARE(rtype->referenceType(), NoReference);
QVERIFY(!rtype->isValue());
QVERIFY(!rtype->isValuePointer());
}
diff --git a/ApiExtractor/tests/testcontainer.cpp b/ApiExtractor/tests/testcontainer.cpp
index e867fa9d4..47a298385 100644
--- a/ApiExtractor/tests/testcontainer.cpp
+++ b/ApiExtractor/tests/testcontainer.cpp
@@ -93,7 +93,7 @@ void TestContainer::testListOfValueType()
QCOMPARE(templateInstanceType->indirections(), 0);
QVERIFY(!templateInstanceType->typeEntry()->isObject());
QVERIFY(templateInstanceType->typeEntry()->isValue());
- QVERIFY(!templateInstanceType->isReference());
+ QCOMPARE(templateInstanceType->referenceType(), NoReference);
QVERIFY(!templateInstanceType->isObject());
QVERIFY(!templateInstanceType->isValuePointer());
QVERIFY(templateInstanceType->isValue());
diff --git a/ApiExtractor/typeparser.cpp b/ApiExtractor/typeparser.cpp
index adca5099e..67120a1ac 100644
--- a/ApiExtractor/typeparser.cpp
+++ b/ApiExtractor/typeparser.cpp
@@ -201,9 +201,22 @@ TypeParser::Info TypeParser::parse(const QString &str, QString *errorMessage)
break;
case Scanner::AmpersandToken:
- stack.top()->is_reference = true;
+ switch (stack.top()->referenceType) {
+ case NoReference:
+ stack.top()->referenceType = LValueReference;
+ break;
+ case LValueReference:
+ stack.top()->referenceType = RValueReference;
+ break;
+ case RValueReference:
+ const QString message = scanner.msgParseError(QStringLiteral("Too many '&' qualifiers"));
+ if (errorMessage)
+ *errorMessage = message;
+ else
+ qWarning().noquote().nospace() << message;
+ return invalidInfo();
+ }
break;
-
case Scanner::LessThanToken:
stack.top()->template_instantiations << Info();
stack.push(&stack.top()->template_instantiations.last());
@@ -291,8 +304,15 @@ QString TypeParser::Info::toString() const
for (int i = 0; i < arrays.size(); ++i)
s += QLatin1Char('[') + arrays.at(i) + QLatin1Char(']');
s += QString(indirections, QLatin1Char('*'));
- if (is_reference)
+ switch (referenceType) {
+ case NoReference:
+ break;
+ case LValueReference:
s += QLatin1Char('&');
-
+ break;
+ case RValueReference:
+ s += QLatin1String("&&");
+ break;
+ }
return s;
}
diff --git a/ApiExtractor/typeparser.h b/ApiExtractor/typeparser.h
index 9cc61dcd9..9ccd0992c 100644
--- a/ApiExtractor/typeparser.h
+++ b/ApiExtractor/typeparser.h
@@ -29,6 +29,8 @@
#ifndef TYPEPARSER_H
#define TYPEPARSER_H
+#include "parser/codemodel_enums.h"
+
#include <QtCore/QList>
#include <QtCore/QString>
#include <QtCore/QStringList>
@@ -38,14 +40,14 @@ class TypeParser
public:
struct Info
{
- Info() : is_reference(false), is_constant(false), is_busted(false), indirections(0) { }
+ Info() : referenceType(NoReference), is_constant(false), is_busted(false), indirections(0) { }
QStringList qualified_name;
QStringList arrays;
QList<Info> template_instantiations;
- uint is_reference : 1;
+ ReferenceType referenceType;
uint is_constant : 1;
uint is_busted : 1;
- uint indirections : 5;
+ uint indirections : 6;
QString toString() const;
QString instantiationName() const;
diff --git a/generator/generator.cpp b/generator/generator.cpp
index 0f2cf37b5..a6281ed4e 100644
--- a/generator/generator.cpp
+++ b/generator/generator.cpp
@@ -94,8 +94,16 @@ QString Generator::getSimplifiedContainerTypeName(const AbstractMetaType* type)
QString typeName = type->cppSignature();
if (type->isConstant())
typeName.remove(0, sizeof("const ") / sizeof(char) - 1);
- if (type->isReference())
+ switch (type->referenceType()) {
+ case NoReference:
+ break;
+ case LValueReference:
typeName.chop(1);
+ break;
+ case RValueReference:
+ typeName.chop(2);
+ break;
+ }
while (typeName.endsWith(QLatin1Char('*')) || typeName.endsWith(QLatin1Char(' ')))
typeName.chop(1);
return typeName;
@@ -483,8 +491,16 @@ QString Generator::getFullTypeNameWithoutModifiers(const AbstractMetaType* type)
QString typeName = type->cppSignature();
if (type->isConstant())
typeName.remove(0, sizeof("const ") / sizeof(char) - 1);
- if (type->isReference())
+ switch (type->referenceType()) {
+ case NoReference:
+ break;
+ case LValueReference:
typeName.chop(1);
+ break;
+ case RValueReference:
+ typeName.chop(2);
+ break;
+ }
while (typeName.endsWith(QLatin1Char('*')) || typeName.endsWith(QLatin1Char(' ')))
typeName.chop(1);
return QLatin1String("::") + typeName;
@@ -492,7 +508,7 @@ QString Generator::getFullTypeNameWithoutModifiers(const AbstractMetaType* type)
QString Generator::minimalConstructor(const AbstractMetaType* type) const
{
- if (!type || (type->isReference() && Generator::isObjectType(type)))
+ if (!type || (type->referenceType() == LValueReference && Generator::isObjectType(type)))
return QString();
if (type->isContainer()) {
@@ -701,7 +717,7 @@ QString Generator::translateType(const AbstractMetaType *cType,
copyType->setConstant(false);
if (options & Generator::ExcludeReference)
- copyType->setReference(false);
+ copyType->setReferenceType(NoReference);
s = copyType->cppSignature();
if (!copyType->typeEntry()->isVoid() && !copyType->typeEntry()->isCppPrimitive())
diff --git a/generator/shiboken2/cppgenerator.cpp b/generator/shiboken2/cppgenerator.cpp
index 1e44e7be4..b7dc8b9c3 100644
--- a/generator/shiboken2/cppgenerator.cpp
+++ b/generator/shiboken2/cppgenerator.cpp
@@ -684,7 +684,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream&s, const AbstractMetaFun
|| argType->isFlags()
|| argType->isEnum()
|| argType->isContainer()
- || arg->type()->isReference();
+ || arg->type()->referenceType() == LValueReference;
if (!convert && argType->isPrimitive()) {
if (argType->basicReferencedTypeEntry())
@@ -851,7 +851,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream&s, const AbstractMetaFun
s << '(' << typeCast << ')';
}
}
- if (func->type()->isReference() && !isPointer(func->type()))
+ if (func->type()->referenceType() == LValueReference && !isPointer(func->type()))
s << '*';
s << CPP_RETURN_VAR ";" << endl;
}
@@ -1118,7 +1118,7 @@ void CppGenerator::writeConverterFunctions(QTextStream& s, const AbstractMetaCla
}
if (isWrapperType(sourceType)) {
typeCheck += QLatin1String("pyIn)");
- toCppConv = (sourceType->isReference() || !isPointerToWrapperType(sourceType))
+ toCppConv = (sourceType->referenceType() == LValueReference || !isPointerToWrapperType(sourceType))
? QLatin1String("*") : QString();
toCppConv += cpythonWrapperCPtr(sourceType->typeEntry(), QLatin1String("pyIn"));
} else if (typeCheck.contains(QLatin1String("%in"))) {
@@ -2010,7 +2010,7 @@ void CppGenerator::writePythonToCppTypeConversion(QTextStream& s,
bool treatAsPointer = isValueTypeWithCopyConstructorOnly(type);
bool isPointerOrObjectType = (isObjectType(type) || isPointer(type)) && !isUserPrimitive(type) && !isCppPrimitive(type);
bool isNotContainerEnumOrFlags = !typeEntry->isContainer() && !typeEntry->isEnum() && !typeEntry->isFlags();
- bool mayHaveImplicitConversion = type->isReference()
+ bool mayHaveImplicitConversion = type->referenceType() == LValueReference
&& !isUserPrimitive(type)
&& !isCppPrimitive(type)
&& isNotContainerEnumOrFlags
@@ -2036,7 +2036,7 @@ void CppGenerator::writePythonToCppTypeConversion(QTextStream& s,
s << "* " << cppOut;
if (!defaultValue.isEmpty())
s << " = " << defaultValue;
- } else if (type->isReference() && !typeEntry->isPrimitive() && isNotContainerEnumOrFlags) {
+ } else if (type->referenceType() == LValueReference && !typeEntry->isPrimitive() && isNotContainerEnumOrFlags) {
s << "* " << cppOut << " = &" << cppOutAux;
} else {
s << ' ' << cppOut;
@@ -2836,7 +2836,7 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f
int idx = arg->argumentIndex() - removedArgs;
bool deRef = isValueTypeWithCopyConstructorOnly(arg->type())
|| isObjectTypeUsedAsValueType(arg->type())
- || (arg->type()->isReference() && isWrapperType(arg->type()) && !isPointer(arg->type()));
+ || (arg->type()->referenceType() == LValueReference && isWrapperType(arg->type()) && !isPointer(arg->type()));
QString argName = hasConversionRule
? arg->name() + QLatin1String(CONV_RULE_OUT_VAR_SUFFIX)
: QString::fromLatin1("%1" CPP_ARG "%2").arg(deRef ? QLatin1String("*") : QString()).arg(idx);
diff --git a/generator/shiboken2/shibokengenerator.cpp b/generator/shiboken2/shibokengenerator.cpp
index 5b2d75830..1d2052b34 100644
--- a/generator/shiboken2/shibokengenerator.cpp
+++ b/generator/shiboken2/shibokengenerator.cpp
@@ -445,8 +445,16 @@ QString ShibokenGenerator::guessScopeForDefaultValue(const AbstractMetaFunction*
QString typeName = translateTypeForWrapperMethod(arg->type(), func->implementingClass());
if (arg->type()->isConstant())
typeName.remove(0, sizeof("const ") / sizeof(char) - 1);
- if (arg->type()->isReference())
+ switch (arg->type()->referenceType()) {
+ case NoReference:
+ break;
+ case LValueReference:
typeName.chop(1);
+ break;
+ case RValueReference:
+ typeName.chop(2);
+ break;
+ }
prefix = typeName + QLatin1Char('(');
suffix = QLatin1Char(')');
}
@@ -623,7 +631,7 @@ QString ShibokenGenerator::getFormatUnitString(const AbstractMetaFunction* func,
|| arg->type()->isEnum()
|| arg->type()->isFlags()
|| arg->type()->isContainer()
- || arg->type()->isReference()) {
+ || arg->type()->referenceType() == LValueReference) {
result += QLatin1Char(objType);
} else if (arg->type()->isPrimitive()) {
const PrimitiveTypeEntry* ptype = (const PrimitiveTypeEntry*) arg->type()->typeEntry();
@@ -662,7 +670,7 @@ QString ShibokenGenerator::cpythonBaseName(const AbstractMetaClass* metaClass)
QString ShibokenGenerator::cpythonBaseName(const TypeEntry* type)
{
QString baseName;
- if (ShibokenGenerator::isWrapperType(type) || type->isNamespace()) { // && !type->isReference()) {
+ if (ShibokenGenerator::isWrapperType(type) || type->isNamespace()) { // && type->referenceType() == NoReference) {
baseName = QLatin1String("Sbk_") + type->name();
} else if (type->isPrimitive()) {
const PrimitiveTypeEntry* ptype = (const PrimitiveTypeEntry*) type;
@@ -935,7 +943,7 @@ bool ShibokenGenerator::isPointerToWrapperType(const AbstractMetaType* type)
bool ShibokenGenerator::isObjectTypeUsedAsValueType(const AbstractMetaType* type)
{
- return type->typeEntry()->isObject() && !type->isReference() && type->indirections() == 0;
+ return type->typeEntry()->isObject() && type->referenceType() == NoReference && type->indirections() == 0;
}
bool ShibokenGenerator::isValueTypeWithCopyConstructorOnly(const AbstractMetaClass* metaClass)
@@ -1008,7 +1016,7 @@ bool ShibokenGenerator::shouldDereferenceArgumentPointer(const AbstractMetaArgum
bool ShibokenGenerator::shouldDereferenceAbstractMetaTypePointer(const AbstractMetaType* metaType)
{
- return metaType->isReference() && isWrapperType(metaType) && !isPointer(metaType);
+ return metaType->referenceType() == LValueReference && isWrapperType(metaType) && !isPointer(metaType);
}
bool ShibokenGenerator::visibilityModifiedToPrivate(const AbstractMetaFunction* func)
@@ -1166,7 +1174,7 @@ QString ShibokenGenerator::cpythonIsConvertibleFunction(const AbstractMetaType*
QString isConv;
if (isPointer(metaType) || isValueTypeWithCopyConstructorOnly(metaType))
isConv = QLatin1String("isPythonToCppPointerConvertible");
- else if (metaType->isReference())
+ else if (metaType->referenceType() == LValueReference)
isConv = QLatin1String("isPythonToCppReferenceConvertible");
else
isConv = QLatin1String("isPythonToCppValueConvertible");
@@ -1204,7 +1212,7 @@ QString ShibokenGenerator::cpythonToPythonConversionFunction(const AbstractMetaT
{
if (isWrapperType(type)) {
QString conversion;
- if (type->isReference() && !(type->isValue() && type->isConstant()) && !isPointer(type))
+ if (type->referenceType() == LValueReference && !(type->isValue() && type->isConstant()) && !isPointer(type))
conversion = QLatin1String("reference");
else if (type->isValue())
conversion = QLatin1String("copy");
@@ -1543,7 +1551,7 @@ ShibokenGenerator::ArgumentVarReplacementList ShibokenGenerator::getArgumentRepl
? arg->name() + QLatin1String(CONV_RULE_OUT_VAR_SUFFIX)
: QLatin1String(CPP_ARG) + QString::number(argPos);
if (isWrapperType(type)) {
- if (type->isReference() && !isPointer(type))
+ if (type->referenceType() == LValueReference && !isPointer(type))
argValue.prepend(QLatin1Char('*'));
}
}
@@ -1734,9 +1742,9 @@ void ShibokenGenerator::writeCodeSnips(QTextStream& s,
}
if (isWrapperType(type)) {
QString replacement = pair.second;
- if (type->isReference() && !isPointer(type))
+ if (type->referenceType() == LValueReference && !isPointer(type))
replacement.remove(0, 1);
- if (type->isReference() || isPointer(type))
+ if (type->referenceType() == LValueReference || isPointer(type))
code.replace(QString::fromLatin1("%%1.").arg(idx), replacement + QLatin1String("->"));
}
code.replace(QRegExp(QString::fromLatin1("%%1\\b").arg(idx)), pair.second);
@@ -2152,8 +2160,13 @@ AbstractMetaType* ShibokenGenerator::buildAbstractMetaTypeFromString(QString typ
if (isConst)
typeString.remove(0, sizeof("const ") / sizeof(char) - 1);
- bool isReference = typeString.endsWith(QLatin1Char('&'));
- if (isReference) {
+ ReferenceType refType = NoReference;
+ if (typeString.endsWith(QLatin1String("&&"))) {
+ refType = RValueReference;
+ typeString.chop(2);
+ typeString = typeString.trimmed();
+ } else if (typeString.endsWith(QLatin1Char('&'))) {
+ refType = LValueReference;
typeString.chop(1);
typeString = typeString.trimmed();
}
@@ -2199,7 +2212,7 @@ AbstractMetaType* ShibokenGenerator::buildAbstractMetaTypeFromString(QString typ
metaType = new AbstractMetaType();
metaType->setTypeEntry(typeEntry);
metaType->setIndirections(indirections);
- metaType->setReference(isReference);
+ metaType->setReferenceType(refType);
metaType->setConstant(isConst);
metaType->setTypeUsagePattern(AbstractMetaType::ContainerPattern);
foreach (const QString& instantiation, instantiatedTypes) {
@@ -2222,7 +2235,7 @@ AbstractMetaType* ShibokenGenerator::buildAbstractMetaTypeFromTypeEntry(const Ty
AbstractMetaType* metaType = new AbstractMetaType;
metaType->setTypeEntry(typeEntry);
metaType->setIndirections(0);
- metaType->setReference(false);
+ metaType->setReferenceType(NoReference);
metaType->setConstant(false);
metaType->decideUsagePattern();
m_metaTypeFromStringCache.insert(typeName, metaType);
@@ -2509,7 +2522,7 @@ Generator::Options ShibokenGenerator::getConverterOptions(const AbstractMetaType
} else if (metaType->isContainer()
|| (type->isPrimitive() && !isCStr)
// const refs become just the value, but pure refs must remain pure.
- || (type->isValue() && metaType->isConstant() && metaType->isReference())) {
+ || (type->isValue() && metaType->isConstant() && metaType->referenceType() == LValueReference)) {
flags = ExcludeConst | ExcludeReference;
}
return flags;