diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2014-01-17 15:56:14 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-20 15:10:03 +0100 |
commit | 9d8e0365eb05f7a13a23fdd10e1c30a3c19a2064 (patch) | |
tree | 017ffc9c7c24b91919d59453b691b2505d19eaf0 /src/qml/compiler | |
parent | ae0a2ea25714af603babe5aa0de364d1ebae1170 (diff) |
[new compiler] Fix duplicate property/signal name detection for group objects
For a rectangle like this:
color: "blue"
border.color: "red"
we must not issue a duplicate property error for "color" because they
are in different objects. This patch fixes that by moving the sets for
checking the presence of these into the object itself, so that the qSwap
on _object also transitions to the correct property/signal name set.
Change-Id: I9ac0e5877eb9f60b618b031f99290707de28112d
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/compiler')
-rw-r--r-- | src/qml/compiler/qqmlcodegenerator.cpp | 14 | ||||
-rw-r--r-- | src/qml/compiler/qqmlcodegenerator_p.h | 6 |
2 files changed, 9 insertions, 11 deletions
diff --git a/src/qml/compiler/qqmlcodegenerator.cpp b/src/qml/compiler/qqmlcodegenerator.cpp index 629671399d..54ee0c98bd 100644 --- a/src/qml/compiler/qqmlcodegenerator.cpp +++ b/src/qml/compiler/qqmlcodegenerator.cpp @@ -303,7 +303,7 @@ bool QQmlCodeGenerator::sanityCheckFunctionNames() if (functionNames.contains(name)) COMPILE_EXCEPTION(function->identifierToken, tr("Duplicate method name")); functionNames.insert(name); - if (_signalNames.contains(name)) + if (_object->signalNames.contains(name)) COMPILE_EXCEPTION(function->identifierToken, tr("Duplicate method name")); if (name.at(0).isUpper()) @@ -327,16 +327,12 @@ int QQmlCodeGenerator::defineQMLObject(AST::UiQualifiedId *qualifiedTypeNameId, _object->init(pool, registerString(asString(qualifiedTypeNameId)), emptyStringIndex, loc); QSet<QString> propertyNames; - qSwap(_propertyNames, propertyNames); QSet<QString> signalNames; - qSwap(_signalNames, signalNames); accept(initializer); sanityCheckFunctionNames(); - qSwap(_propertyNames, propertyNames); - qSwap(_signalNames, signalNames); qSwap(_object, obj); return objectIndex; } @@ -586,9 +582,9 @@ bool QQmlCodeGenerator::visit(AST::UiPublicMember *node) p = p->next; } - if (_signalNames.contains(signalName)) + if (_object->signalNames.contains(signalName)) COMPILE_EXCEPTION(node->identifierToken, tr("Duplicate signal name")); - _signalNames.insert(signalName); + _object->signalNames.insert(signalName); if (signalName.at(0).isUpper()) COMPILE_EXCEPTION(node->identifierToken, tr("Signal names cannot begin with an upper case letter")); @@ -992,10 +988,10 @@ bool QQmlCodeGenerator::sanityCheckPropertyName(const AST::SourceLocation &nameL // List items are implement by multiple bindings to the same name, so allow duplicates. if (!isListItemOnOrAssignment) { - if (_propertyNames.contains(name)) + if (_object->propertyNames.contains(name)) COMPILE_EXCEPTION(nameLocation, tr("Duplicate property name")); - _propertyNames.insert(name); + _object->propertyNames.insert(name); } if (name.at(0).isUpper()) diff --git a/src/qml/compiler/qqmlcodegenerator_p.h b/src/qml/compiler/qqmlcodegenerator_p.h index 0b70701515..c296a3e624 100644 --- a/src/qml/compiler/qqmlcodegenerator_p.h +++ b/src/qml/compiler/qqmlcodegenerator_p.h @@ -155,6 +155,10 @@ struct QmlObject PoolList<Binding> *bindings; PoolList<Function> *functions; + // caches to quickly find duplicates + QSet<QString> propertyNames; + QSet<QString> signalNames; + void init(QQmlJS::MemoryPool *pool, int typeNameIndex, int id, const AST::SourceLocation &location = AST::SourceLocation()); void dump(DebugStream &out); @@ -295,8 +299,6 @@ public: QV4::CompiledData::TypeReferenceMap _typeReferences; QmlObject *_object; - QSet<QString> _propertyNames; - QSet<QString> _signalNames; QQmlJS::MemoryPool *pool; QString sourceCode; |