aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2014-02-03 13:30:06 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-04 18:28:25 +0100
commite5bd40742ab8d0b4ffc9307eb46bc41456fe394a (patch)
treec14979f7f451e90988714450607234059fa5d022
parent48144d3b29a1204bf1820d782228fbd9e25f318e (diff)
[new compiler] Cleanup empty string handling
Ensure that the empty string always has index 0, that simplifies the code in a few places and makes it easier to check for the empty string in other places where there's no access to the string pool itself. Change-Id: Icd204aec478e8350ef3fee75d89bda1f88cffe26 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
-rw-r--r--src/qml/compiler/qqmlcodegenerator.cpp23
-rw-r--r--src/qml/compiler/qqmlcodegenerator_p.h7
-rw-r--r--src/qml/compiler/qqmltypecompiler.cpp17
-rw-r--r--src/qml/compiler/qv4compiler.cpp2
4 files changed, 23 insertions, 26 deletions
diff --git a/src/qml/compiler/qqmlcodegenerator.cpp b/src/qml/compiler/qqmlcodegenerator.cpp
index 04c4e5f598..ccf7e47e26 100644
--- a/src/qml/compiler/qqmlcodegenerator.cpp
+++ b/src/qml/compiler/qqmlcodegenerator.cpp
@@ -54,6 +54,8 @@
QT_USE_NAMESPACE
+static const quint32 emptyStringIndex = 0;
+
DEFINE_BOOL_CONFIG_OPTION(lookupHints, QML_LOOKUP_HINTS);
using namespace QtQml;
@@ -156,9 +158,10 @@ void QmlObject::appendFunction(Function *f)
target->functions->append(f);
}
-QString QmlObject::appendBinding(Binding *b, bool isListBinding, bool bindToDefaultProperty)
+QString QmlObject::appendBinding(Binding *b, bool isListBinding)
{
- if (!isListBinding && !bindToDefaultProperty
+ const bool bindingToDefaultProperty = (b->propertyNameIndex == 0);
+ if (!isListBinding && !bindingToDefaultProperty
&& b->type != QV4::CompiledData::Binding::Type_GroupProperty
&& b->type != QV4::CompiledData::Binding::Type_AttachedProperty
&& !(b->flags & QV4::CompiledData::Binding::IsOnAssignment)) {
@@ -231,7 +234,7 @@ bool QQmlCodeGenerator::generateFromQml(const QString &code, const QUrl &url, co
this->pool = output->jsParserEngine.pool();
this->jsGenerator = &output->jsGenerator;
- emptyStringIndex = registerString(QString());
+ Q_ASSERT(registerString(QString()) == emptyStringIndex);
sourceCode = code;
@@ -950,15 +953,13 @@ void QQmlCodeGenerator::appendBinding(const AST::SourceLocation &nameLocation, q
return;
}
- const bool bindingToDefaultProperty = (propertyNameIndex == emptyStringIndex);
-
Binding *binding = New<Binding>();
binding->propertyNameIndex = propertyNameIndex;
binding->location.line = nameLocation.startLine;
binding->location.column = nameLocation.startColumn;
binding->flags = 0;
setBindingValue(binding, value);
- QString error = bindingsTarget()->appendBinding(binding, /*isListBinding*/false, bindingToDefaultProperty);
+ QString error = bindingsTarget()->appendBinding(binding, /*isListBinding*/false);
if (!error.isEmpty()) {
recordError(nameLocation, error);
}
@@ -971,8 +972,6 @@ void QQmlCodeGenerator::appendBinding(const AST::SourceLocation &nameLocation, q
return;
}
- const bool bindingToDefaultProperty = (propertyNameIndex == emptyStringIndex);
-
Binding *binding = New<Binding>();
binding->propertyNameIndex = propertyNameIndex;
binding->location.line = nameLocation.startLine;
@@ -987,7 +986,7 @@ void QQmlCodeGenerator::appendBinding(const AST::SourceLocation &nameLocation, q
binding->flags |= QV4::CompiledData::Binding::InitializerForReadOnlyDeclaration;
// No type name on the initializer means it must be a group property
- if (stringAt(_objects.at(objectIndex)->inheritedTypeNameIndex).isEmpty())
+ if (_objects.at(objectIndex)->inheritedTypeNameIndex == emptyStringIndex)
binding->type = QV4::CompiledData::Binding::Type_GroupProperty;
else
binding->type = QV4::CompiledData::Binding::Type_Object;
@@ -998,7 +997,7 @@ void QQmlCodeGenerator::appendBinding(const AST::SourceLocation &nameLocation, q
binding->flags |= QV4::CompiledData::Binding::IsListItem;
binding->value.objectIndex = objectIndex;
- QString error = bindingsTarget()->appendBinding(binding, isListItem, bindingToDefaultProperty);
+ QString error = bindingsTarget()->appendBinding(binding, isListItem);
if (!error.isEmpty()) {
recordError(nameLocation, error);
}
@@ -1100,7 +1099,7 @@ bool QQmlCodeGenerator::resolveQualifiedId(AST::UiQualifiedId **nameToResolve, Q
int objIndex = defineQMLObject(0, AST::SourceLocation(), 0, 0);
binding->value.objectIndex = objIndex;
- QString error = (*object)->appendBinding(binding, /*isListBinding*/false, /*bindingToDefaultProperty*/false);
+ QString error = (*object)->appendBinding(binding, /*isListBinding*/false);
if (!error.isEmpty()) {
recordError(qualifiedIdElement->identifierToken, error);
return false;
@@ -1128,7 +1127,7 @@ void QQmlCodeGenerator::recordError(const AST::SourceLocation &location, const Q
void QQmlCodeGenerator::collectTypeReferences()
{
foreach (QmlObject *obj, _objects) {
- if (!stringAt(obj->inheritedTypeNameIndex).isEmpty()) {
+ if (obj->inheritedTypeNameIndex != emptyStringIndex) {
QV4::CompiledData::TypeReference &r = _typeReferences.add(obj->inheritedTypeNameIndex, obj->location);
r.needsCreation = true;
}
diff --git a/src/qml/compiler/qqmlcodegenerator_p.h b/src/qml/compiler/qqmlcodegenerator_p.h
index 5475d7f57a..ed94a99726 100644
--- a/src/qml/compiler/qqmlcodegenerator_p.h
+++ b/src/qml/compiler/qqmlcodegenerator_p.h
@@ -161,7 +161,7 @@ struct QmlObject
{
Q_DECLARE_TR_FUNCTIONS(QmlObject)
public:
- int inheritedTypeNameIndex;
+ quint32 inheritedTypeNameIndex;
quint32 idIndex;
int indexOfDefaultProperty;
@@ -191,7 +191,7 @@ public:
QString appendProperty(QmlProperty *prop, const QString &propertyName, bool isDefaultProperty, const AST::SourceLocation &defaultToken, AST::SourceLocation *errorLocation);
void appendFunction(Function *f);
- QString appendBinding(Binding *b, bool isListBinding, bool bindToDefaultProperty);
+ QString appendBinding(Binding *b, bool isListBinding);
private:
PoolList<QmlProperty> *properties;
@@ -305,7 +305,7 @@ public:
static QQmlScript::LocationSpan location(AST::SourceLocation start, AST::SourceLocation end);
- int registerString(const QString &str) const { return jsGenerator->registerString(str); }
+ quint32 registerString(const QString &str) const { return jsGenerator->registerString(str); }
template <typename _Tp> _Tp *New() { return pool->New<_Tp>(); }
QString stringAt(int index) const { return jsGenerator->strings.at(index); }
@@ -330,7 +330,6 @@ public:
QString sourceCode;
QUrl url;
QV4::Compiler::JSUnitGenerator *jsGenerator;
- quint32 emptyStringIndex;
};
struct Q_QML_EXPORT QmlUnitGenerator
diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp
index 41dcd669a3..6197ddf5d0 100644
--- a/src/qml/compiler/qqmltypecompiler.cpp
+++ b/src/qml/compiler/qqmltypecompiler.cpp
@@ -397,7 +397,7 @@ bool QQmlPropertyCacheCreator::buildMetaObjectRecursively(int objectIndex, int r
Q_ASSERT(referencingObjectIndex >= 0);
QQmlPropertyCache *parentCache = propertyCaches.at(referencingObjectIndex);
Q_ASSERT(parentCache);
- Q_ASSERT(!stringAt(instantiatingBinding->propertyNameIndex).isEmpty());
+ Q_ASSERT(instantiatingBinding->propertyNameIndex != 0);
bool notInRevision = false;
instantiatingProperty = PropertyResolver(parentCache).property(stringAt(instantiatingBinding->propertyNameIndex), &notInRevision);
@@ -434,8 +434,7 @@ bool QQmlPropertyCacheCreator::buildMetaObjectRecursively(int objectIndex, int r
}
}
- QString typeName = stringAt(obj->inheritedTypeNameIndex);
- if (!typeName.isEmpty()) {
+ if (obj->inheritedTypeNameIndex != 0) {
QQmlCompiledData::TypeReference *typeRef = resolvedTypes->value(obj->inheritedTypeNameIndex);
Q_ASSERT(typeRef);
baseTypeCache = typeRef->createPropertyCache(QQmlEnginePrivate::get(enginePrivate));
@@ -1004,10 +1003,9 @@ void QQmlComponentAndAliasResolver::findAndRegisterImplicitComponents(const QtQm
continue;
QQmlPropertyData *pd = 0;
- QString propertyName = stringAt(binding->propertyNameIndex);
- if (!propertyName.isEmpty()) {
+ if (binding->propertyNameIndex != 0) {
bool notInRevision = false;
- pd = propertyResolver.property(propertyName, &notInRevision);
+ pd = propertyResolver.property(stringAt(binding->propertyNameIndex), &notInRevision);
} else {
pd = defaultProperty;
}
@@ -1045,7 +1043,7 @@ void QQmlComponentAndAliasResolver::findAndRegisterImplicitComponents(const QtQm
QtQml::Binding *syntheticBinding = pool->New<QtQml::Binding>();
*syntheticBinding = *binding;
syntheticBinding->type = QV4::CompiledData::Binding::Type_Object;
- QString error = syntheticComponent->appendBinding(syntheticBinding, /*isListBinding*/false, /*bindingToDefaultProperty*/false);
+ QString error = syntheticComponent->appendBinding(syntheticBinding, /*isListBinding*/false);
Q_ASSERT(error.isEmpty());
Q_UNUSED(error);
@@ -1065,7 +1063,7 @@ bool QQmlComponentAndAliasResolver::resolve()
const int objCountWithoutSynthesizedComponents = qmlObjects->count();
for (int i = 0; i < objCountWithoutSynthesizedComponents; ++i) {
const QtQml::QmlObject *obj = qmlObjects->at(i);
- if (stringAt(obj->inheritedTypeNameIndex).isEmpty())
+ if (obj->inheritedTypeNameIndex == 0)
continue;
QQmlCompiledData::TypeReference *tref = resolvedTypes->value(obj->inheritedTypeNameIndex);
@@ -1131,8 +1129,7 @@ bool QQmlComponentAndAliasResolver::collectIdsAndAliases(int objectIndex)
{
const QtQml::QmlObject *obj = qmlObjects->at(objectIndex);
- QString id = stringAt(obj->idIndex);
- if (!id.isEmpty()) {
+ if (obj->idIndex != 0) {
if (_idToObjectIndex.contains(obj->idIndex)) {
recordError(obj->locationOfIdProperty, tr("id is not unique"));
return false;
diff --git a/src/qml/compiler/qv4compiler.cpp b/src/qml/compiler/qv4compiler.cpp
index 7fb10d5f42..bc47b815f2 100644
--- a/src/qml/compiler/qv4compiler.cpp
+++ b/src/qml/compiler/qv4compiler.cpp
@@ -53,6 +53,8 @@ QV4::Compiler::JSUnitGenerator::JSUnitGenerator(QQmlJS::V4IR::Module *module, in
if (headerSize == -1)
headerSize = sizeof(QV4::CompiledData::Unit);
this->headerSize = headerSize;
+ // Make sure the empty string always gets index 0
+ registerString(QString());
}
int QV4::Compiler::JSUnitGenerator::registerString(const QString &str)