From 9d8e0365eb05f7a13a23fdd10e1c30a3c19a2064 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 17 Jan 2014 15:56:14 +0100 Subject: [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 --- src/qml/compiler/qqmlcodegenerator.cpp | 14 +++++--------- src/qml/compiler/qqmlcodegenerator_p.h | 6 ++++-- 2 files changed, 9 insertions(+), 11 deletions(-) (limited to 'src') 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 propertyNames; - qSwap(_propertyNames, propertyNames); QSet 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 *bindings; PoolList *functions; + // caches to quickly find duplicates + QSet propertyNames; + QSet 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 _propertyNames; - QSet _signalNames; QQmlJS::MemoryPool *pool; QString sourceCode; -- cgit v1.2.3