Skip to content

Commit 8355416

Browse files
committed
Improve parsing of Q_PROPERTY types starting with "const"
1 parent 2b5c50f commit 8355416

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

generator/abstractmetabuilder.cpp

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,11 +2256,33 @@ void AbstractMetaBuilder::parseQ_Property(AbstractMetaClass *meta_class, const Q
22562256
QStringList qualifiedScopeName = currentScope()->qualifiedName();
22572257
bool ok = false;
22582258
AbstractMetaType *type = 0;
2259-
QString scope;
2259+
int pIndex = 0;
2260+
QString typeName = l.value(pIndex++);
2261+
bool isConst = false;
2262+
if (typeName == "const") {
2263+
// use the next part as the type name
2264+
typeName = l.value(pIndex++);
2265+
isConst = true;
2266+
}
2267+
QString propertyName = l.value(pIndex++);
2268+
QString modifiers;
2269+
while (typeName.endsWith("*") || typeName.endsWith("&")) {
2270+
modifiers.insert(0, typeName.at(typeName.length() - 1));
2271+
typeName.chop(1);
2272+
}
2273+
while (propertyName.startsWith("*") || propertyName.startsWith("&")) {
2274+
modifiers.append(propertyName.at(0));
2275+
propertyName.remove(0, 1);
2276+
if (propertyName.isEmpty() && pIndex < l.size()) {
2277+
propertyName = l.value(pIndex++);
2278+
}
2279+
}
22602280
for (int j=qualifiedScopeName.size(); j>=0; --j) {
2261-
scope = j > 0 ? QStringList(qualifiedScopeName.mid(0, j)).join("::") + "::" : QString();
2281+
QStringList scope(qualifiedScopeName.mid(0, j));
22622282
TypeInfo info;
2263-
info.setQualifiedName((scope + l.at(0)).split("::"));
2283+
info.setIndirections(modifiers.count('*'));
2284+
info.setReference(modifiers.contains('&')); // r-value reference seems improbable for a property...
2285+
info.setQualifiedName(scope + QStringList(typeName));
22642286

22652287
type = translateType(info, &ok);
22662288
if (type != 0 && ok) {
@@ -2269,18 +2291,16 @@ void AbstractMetaBuilder::parseQ_Property(AbstractMetaClass *meta_class, const Q
22692291
}
22702292

22712293
if (type == 0 || !ok) {
2272-
ReportHandler::warning(QString("Unable to decide type of property: '%1' in class '%2'")
2273-
.arg(l.at(0)).arg(meta_class->name()));
2294+
ReportHandler::warning(QString("Unable to decide type '%1' of property '%2' in class '%3'")
2295+
.arg(typeName).arg(propertyName).arg(meta_class->name()));
22742296
continue;
22752297
}
22762298

2277-
QString typeName = scope + l.at(0);
2278-
22792299
QPropertySpec *spec = new QPropertySpec(type->typeEntry());
2280-
spec->setName(l.at(1));
2300+
spec->setName(propertyName);
22812301
spec->setIndex(i);
22822302

2283-
for (int pos=2; pos+1<l.size(); pos+=2) {
2303+
for (int pos=pIndex; pos+1<l.size(); pos+=2) {
22842304
if (l.at(pos) == QLatin1String("READ"))
22852305
spec->setRead(l.at(pos+1));
22862306
else if (l.at(pos) == QLatin1String("WRITE"))

0 commit comments

Comments
 (0)