diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2013-09-12 16:53:32 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-20 14:26:05 +0200 |
commit | 3ec5aae38e77d370d1a23efe4b924ee4762a2238 (patch) | |
tree | bff7f62c5daa35a2e045d87a0ea882d211d05c4e /src/qml/compiler | |
parent | 6042327dee1f8dd912a86be16f4044d259c9b3e4 (diff) |
[new compiler] Add support for id properties
Change-Id: Idb4a0ad06f6cbe5d040da075a8f43d067a27ebc4
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/compiler')
-rw-r--r-- | src/qml/compiler/qqmlcodegenerator.cpp | 45 | ||||
-rw-r--r-- | src/qml/compiler/qqmlcodegenerator_p.h | 2 |
2 files changed, 47 insertions, 0 deletions
diff --git a/src/qml/compiler/qqmlcodegenerator.cpp b/src/qml/compiler/qqmlcodegenerator.cpp index b875067620..2bd00f2a1f 100644 --- a/src/qml/compiler/qqmlcodegenerator.cpp +++ b/src/qml/compiler/qqmlcodegenerator.cpp @@ -705,6 +705,12 @@ void QQmlCodeGenerator::appendBinding(const AST::SourceLocation &nameLocation, i { if (!sanityCheckPropertyName(nameLocation, propertyNameIndex)) return; + + if (stringAt(propertyNameIndex) == QStringLiteral("id")) { + setId(value); + return; + } + Binding *binding = New<Binding>(); binding->propertyNameIndex = propertyNameIndex; setBindingValue(binding, value); @@ -722,6 +728,45 @@ void QQmlCodeGenerator::appendBinding(const AST::SourceLocation &nameLocation, i _object->bindings->append(binding); } +bool QQmlCodeGenerator::setId(AST::Statement *value) +{ + AST::SourceLocation loc = value->firstSourceLocation(); + QStringRef str; + + if (AST::ExpressionStatement *stmt = AST::cast<AST::ExpressionStatement *>(value)) + if (AST::StringLiteral *lit = AST::cast<AST::StringLiteral *>(stmt->expression)) + str = lit->value; + + if (str.isEmpty()) + str = asStringRef(value); + + if (str.isEmpty()) + COMPILE_EXCEPTION(loc, tr( "Invalid empty ID")); + + QChar ch = str.at(0); + if (ch.isLetter() && !ch.isLower()) + COMPILE_EXCEPTION(loc, tr( "IDs cannot start with an uppercase letter")); + + QChar u(QLatin1Char('_')); + if (!ch.isLetter() && ch != u) + COMPILE_EXCEPTION(loc, tr( "IDs must start with a letter or underscore")); + + for (int ii = 1; ii < str.count(); ++ii) { + ch = str.at(ii); + if (!ch.isLetterOrNumber() && ch != u) + COMPILE_EXCEPTION(loc, tr( "IDs must contain only letters, numbers, and underscores")); + } + +#if 0 // ### + if (enginePrivate->v8engine()->illegalNames().contains(str)) + COMPILE_EXCEPTION(v, tr( "ID illegally masks global JavaScript property")); +#endif + + _object->idIndex = registerString(str.toString()); + + return true; +} + AST::UiQualifiedId *QQmlCodeGenerator::resolveQualifiedId(AST::UiQualifiedId *name, QmlObject **object) { *object = _object; diff --git a/src/qml/compiler/qqmlcodegenerator_p.h b/src/qml/compiler/qqmlcodegenerator_p.h index 5344dc1535..3e14a32bce 100644 --- a/src/qml/compiler/qqmlcodegenerator_p.h +++ b/src/qml/compiler/qqmlcodegenerator_p.h @@ -220,6 +220,8 @@ public: void appendBinding(const AST::SourceLocation &nameLocation, int propertyNameIndex, AST::Statement *value); void appendBinding(const AST::SourceLocation &nameLocation, int propertyNameIndex, int objectIndex); + bool setId(AST::Statement *value); + // resolves qualified name (font.pixelSize for example) and returns the last name along // with the object any right-hand-side of a binding should apply to. AST::UiQualifiedId *resolveQualifiedId(AST::UiQualifiedId *name, QmlObject **object); |