summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qdeclarativecompiler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/qml/qdeclarativecompiler.cpp')
-rw-r--r--src/declarative/qml/qdeclarativecompiler.cpp249
1 files changed, 143 insertions, 106 deletions
diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp
index f4ccce1..fad7779 100644
--- a/src/declarative/qml/qdeclarativecompiler.cpp
+++ b/src/declarative/qml/qdeclarativecompiler.cpp
@@ -146,7 +146,7 @@ bool QDeclarativeCompiler::isSignalPropertyName(const QByteArray &name)
For example:
\code
- COMPILE_EXCEPTION(property, QCoreApplication::translate("QDeclarativeCompiler","Error for property \"%1\"").arg(QString::fromUtf8(property->name)));
+ COMPILE_EXCEPTION(property, tr("Error for property \"%1\"").arg(QString::fromUtf8(property->name)));
\endcode
*/
#define COMPILE_EXCEPTION(token, desc) \
@@ -184,7 +184,7 @@ bool QDeclarativeCompiler::testLiteralAssignment(const QMetaProperty &prop,
QString string = v->value.asScript();
if (!prop.isWritable())
- COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop.name())));
+ COMPILE_EXCEPTION(v, tr("Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop.name())));
if (prop.isEnumType()) {
int value;
@@ -193,7 +193,7 @@ bool QDeclarativeCompiler::testLiteralAssignment(const QMetaProperty &prop,
} else
value = prop.enumerator().keyToValue(string.toUtf8().constData());
if (value == -1)
- COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Invalid property assignment: unknown enumeration"));
+ COMPILE_EXCEPTION(v, tr("Invalid property assignment: unknown enumeration"));
return true;
}
int type = prop.userType();
@@ -201,65 +201,65 @@ bool QDeclarativeCompiler::testLiteralAssignment(const QMetaProperty &prop,
case -1:
break;
case QVariant::String:
- if (!v->value.isString()) COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Invalid property assignment: string expected"));
+ if (!v->value.isString()) COMPILE_EXCEPTION(v, tr("Invalid property assignment: string expected"));
break;
case QVariant::Url:
- if (!v->value.isString()) COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Invalid property assignment: url expected"));
+ if (!v->value.isString()) COMPILE_EXCEPTION(v, tr("Invalid property assignment: url expected"));
break;
case QVariant::UInt:
{
bool ok;
string.toUInt(&ok);
- if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Invalid property assignment: unsigned int expected"));
+ if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: unsigned int expected"));
}
break;
case QVariant::Int:
{
bool ok;
string.toInt(&ok);
- if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Invalid property assignment: int expected"));
+ if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: int expected"));
}
break;
case QMetaType::Float:
{
bool ok;
string.toFloat(&ok);
- if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Invalid property assignment: float expected"));
+ if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: float expected"));
}
break;
case QVariant::Double:
{
bool ok;
string.toDouble(&ok);
- if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Invalid property assignment: double expected"));
+ if (!v->value.isNumber() || !ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: double expected"));
}
break;
case QVariant::Color:
{
bool ok;
QDeclarativeStringConverters::colorFromString(string, &ok);
- if (!ok) COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Invalid property assignment: color expected"));
+ if (!ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: color expected"));
}
break;
case QVariant::Date:
{
bool ok;
QDeclarativeStringConverters::dateFromString(string, &ok);
- if (!ok) COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Invalid property assignment: date expected"));
+ if (!ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: date expected"));
}
break;
case QVariant::Time:
{
bool ok;
QDeclarativeStringConverters::timeFromString(string, &ok);
- if (!ok) COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Invalid property assignment: time expected"));
+ if (!ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: time expected"));
}
break;
case QVariant::DateTime:
{
bool ok;
QDeclarativeStringConverters::dateTimeFromString(string, &ok);
- if (!ok) COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Invalid property assignment: datetime expected"));
+ if (!ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: datetime expected"));
}
break;
case QVariant::Point:
@@ -267,7 +267,7 @@ bool QDeclarativeCompiler::testLiteralAssignment(const QMetaProperty &prop,
{
bool ok;
QPointF point = QDeclarativeStringConverters::pointFFromString(string, &ok);
- if (!ok) COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Invalid property assignment: point expected"));
+ if (!ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: point expected"));
}
break;
case QVariant::Size:
@@ -275,7 +275,7 @@ bool QDeclarativeCompiler::testLiteralAssignment(const QMetaProperty &prop,
{
bool ok;
QSizeF size = QDeclarativeStringConverters::sizeFFromString(string, &ok);
- if (!ok) COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Invalid property assignment: size expected"));
+ if (!ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: size expected"));
}
break;
case QVariant::Rect:
@@ -283,19 +283,19 @@ bool QDeclarativeCompiler::testLiteralAssignment(const QMetaProperty &prop,
{
bool ok;
QRectF rect = QDeclarativeStringConverters::rectFFromString(string, &ok);
- if (!ok) COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Invalid property assignment: rect expected"));
+ if (!ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: rect expected"));
}
break;
case QVariant::Bool:
{
- if (!v->value.isBoolean()) COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Invalid property assignment: boolean expected"));
+ if (!v->value.isBoolean()) COMPILE_EXCEPTION(v, tr("Invalid property assignment: boolean expected"));
}
break;
case QVariant::Vector3D:
{
bool ok;
QDeclarativeStringConverters::vector3DFromString(string, &ok);
- if (!ok) COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Invalid property assignment: 3D vector expected"));
+ if (!ok) COMPILE_EXCEPTION(v, tr("Invalid property assignment: 3D vector expected"));
}
break;
default:
@@ -304,7 +304,7 @@ bool QDeclarativeCompiler::testLiteralAssignment(const QMetaProperty &prop,
QDeclarativeMetaType::StringConverter converter =
QDeclarativeMetaType::customStringConverter(t);
if (!converter)
- COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Invalid property assignment: unsupported type \"%1\"").arg(QString::fromLatin1(QVariant::typeToName(prop.type()))));
+ COMPILE_EXCEPTION(v, tr("Invalid property assignment: unsupported type \"%1\"").arg(QString::fromLatin1(QVariant::typeToName(prop.type()))));
}
break;
}
@@ -342,9 +342,22 @@ void QDeclarativeCompiler::genLiteralAssignment(const QMetaProperty &prop,
switch(type) {
case -1:
{
- instr.type = QDeclarativeInstruction::StoreVariant;
- instr.storeString.propertyIndex = prop.propertyIndex();
- instr.storeString.value = output->indexForString(string);
+ if (v->value.isNumber()) {
+ double n = v->value.asNumber();
+ if (double(int(n)) == n) {
+ instr.type = QDeclarativeInstruction::StoreVariantInteger;
+ instr.storeInteger.propertyIndex = prop.propertyIndex();
+ instr.storeInteger.value = int(n);
+ } else {
+ instr.type = QDeclarativeInstruction::StoreVariantDouble;
+ instr.storeDouble.propertyIndex = prop.propertyIndex();
+ instr.storeDouble.value = n;
+ }
+ } else {
+ instr.type = QDeclarativeInstruction::StoreVariant;
+ instr.storeString.propertyIndex = prop.propertyIndex();
+ instr.storeString.value = output->indexForString(string);
+ }
}
break;
case QVariant::String:
@@ -560,7 +573,7 @@ bool QDeclarativeCompiler::compile(QDeclarativeEngine *engine,
if (tref.type) {
ref.type = tref.type;
if (!ref.type->isCreatable())
- COMPILE_EXCEPTION(parserRef->refObjects.first(), QCoreApplication::translate("QDeclarativeCompiler", "Element is not creatable."));
+ COMPILE_EXCEPTION(parserRef->refObjects.first(), tr( "Element is not creatable."));
} else if (tref.unit) {
ref.component = tref.unit->toComponent(engine);
@@ -881,23 +894,38 @@ void QDeclarativeCompiler::genObject(QDeclarativeParser::Object *obj)
}
// Create the object
- QDeclarativeInstruction create;
- create.type = QDeclarativeInstruction::CreateObject;
- create.line = obj->location.start.line;
- create.create.column = obj->location.start.column;
- create.create.data = -1;
- if (!obj->custom.isEmpty())
- create.create.data = output->indexForByteArray(obj->custom);
- create.create.type = obj->type;
- if (!output->types.at(create.create.type).type &&
- !obj->bindingBitmask.isEmpty()) {
- Q_ASSERT(obj->bindingBitmask.size() % 4 == 0);
- create.create.bindingBits =
- output->indexForByteArray(obj->bindingBitmask);
+ if (obj->custom.isEmpty() && output->types.at(obj->type).type &&
+ !output->types.at(obj->type).type->isExtendedType() && obj != compileState.root) {
+
+ QDeclarativeInstruction create;
+ create.type = QDeclarativeInstruction::CreateSimpleObject;
+ create.line = obj->location.start.line;
+ create.createSimple.create = output->types.at(obj->type).type->createFunction();
+ create.createSimple.typeSize = output->types.at(obj->type).type->createSize();
+ create.createSimple.column = obj->location.start.column;
+ output->bytecode << create;
+
} else {
- create.create.bindingBits = -1;
+
+ QDeclarativeInstruction create;
+ create.type = QDeclarativeInstruction::CreateObject;
+ create.line = obj->location.start.line;
+ create.create.column = obj->location.start.column;
+ create.create.data = -1;
+ if (!obj->custom.isEmpty())
+ create.create.data = output->indexForByteArray(obj->custom);
+ create.create.type = obj->type;
+ if (!output->types.at(create.create.type).type &&
+ !obj->bindingBitmask.isEmpty()) {
+ Q_ASSERT(obj->bindingBitmask.size() % 4 == 0);
+ create.create.bindingBits =
+ output->indexForByteArray(obj->bindingBitmask);
+ } else {
+ create.create.bindingBits = -1;
+ }
+ output->bytecode << create;
+
}
- output->bytecode << create;
// Setup the synthesized meta object if necessary
if (!obj->metadata.isEmpty()) {
@@ -1148,23 +1176,23 @@ bool QDeclarativeCompiler::buildComponent(QDeclarativeParser::Object *obj,
Property *idProp = 0;
if (obj->properties.count() > 1 ||
(obj->properties.count() == 1 && obj->properties.begin().key() != "id"))
- COMPILE_EXCEPTION(*obj->properties.begin(), QCoreApplication::translate("QDeclarativeCompiler","Component elements may not contain properties other than id"));
+ COMPILE_EXCEPTION(*obj->properties.begin(), tr("Component elements may not contain properties other than id"));
if (!obj->scriptBlockObjects.isEmpty())
- COMPILE_EXCEPTION(obj->scriptBlockObjects.first(), QCoreApplication::translate("QDeclarativeCompiler","Component elements may not contain script blocks"));
+ COMPILE_EXCEPTION(obj->scriptBlockObjects.first(), tr("Component elements may not contain script blocks"));
if (obj->properties.count())
idProp = *obj->properties.begin();
if (idProp) {
if (idProp->value || idProp->values.count() > 1 || idProp->values.at(0)->object)
- COMPILE_EXCEPTION(idProp, QCoreApplication::translate("QDeclarativeCompiler","Invalid component id specification"));
+ COMPILE_EXCEPTION(idProp, tr("Invalid component id specification"));
COMPILE_CHECK(checkValidId(idProp->values.first(), idProp->values.first()->primitive()));
QString idVal = idProp->values.first()->primitive();
if (compileState.ids.contains(idVal))
- COMPILE_EXCEPTION(idProp, QCoreApplication::translate("QDeclarativeCompiler","id is not unique"));
+ COMPILE_EXCEPTION(idProp, tr("id is not unique"));
obj->id = idVal;
addId(idVal, obj);
@@ -1174,14 +1202,14 @@ bool QDeclarativeCompiler::buildComponent(QDeclarativeParser::Object *obj,
if (obj->defaultProperty &&
(obj->defaultProperty->value || obj->defaultProperty->values.count() > 1 ||
(obj->defaultProperty->values.count() == 1 && !obj->defaultProperty->values.first()->object)))
- COMPILE_EXCEPTION(obj, QCoreApplication::translate("QDeclarativeCompiler","Invalid component body specification"));
+ COMPILE_EXCEPTION(obj, tr("Invalid component body specification"));
Object *root = 0;
if (obj->defaultProperty && obj->defaultProperty->values.count())
root = obj->defaultProperty->values.first()->object;
if (!root)
- COMPILE_EXCEPTION(obj, QCoreApplication::translate("QDeclarativeCompiler","Cannot create empty component specification"));
+ COMPILE_EXCEPTION(obj, tr("Cannot create empty component specification"));
// Build the component tree
COMPILE_CHECK(buildComponentFromRoot(root, ctxt));
@@ -1200,11 +1228,11 @@ bool QDeclarativeCompiler::buildScript(QDeclarativeParser::Object *obj, QDeclara
Property *source = *script->properties.begin();
if (script->defaultProperty)
- COMPILE_EXCEPTION(source, QCoreApplication::translate("QDeclarativeCompiler","Invalid Script block. Specify either the source property or inline script"));
+ COMPILE_EXCEPTION(source, tr("Invalid Script block. Specify either the source property or inline script"));
if (source->value || source->values.count() != 1 ||
source->values.at(0)->object || !source->values.at(0)->value.isStringList())
- COMPILE_EXCEPTION(source, QCoreApplication::translate("QDeclarativeCompiler","Invalid Script source value"));
+ COMPILE_EXCEPTION(source, tr("Invalid Script source value"));
QStringList sources = source->values.at(0)->value.asStringList();
@@ -1229,7 +1257,7 @@ bool QDeclarativeCompiler::buildScript(QDeclarativeParser::Object *obj, QDeclara
}
} else if (!script->properties.isEmpty()) {
- COMPILE_EXCEPTION(*script->properties.begin(), QCoreApplication::translate("QDeclarativeCompiler","Properties cannot be set on Script block"));
+ COMPILE_EXCEPTION(*script->properties.begin(), tr("Properties cannot be set on Script block"));
} else if (script->defaultProperty) {
QString scriptCode;
@@ -1243,7 +1271,7 @@ bool QDeclarativeCompiler::buildScript(QDeclarativeParser::Object *obj, QDeclara
if (lineNumber == 1)
lineNumber = v->location.start.line;
if (v->object || !v->value.isString())
- COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Invalid Script block"));
+ COMPILE_EXCEPTION(v, tr("Invalid Script block"));
if (ii == 0) {
currentLocation = v->location.start;
@@ -1387,7 +1415,7 @@ bool QDeclarativeCompiler::buildSignal(QDeclarativeParser::Property *prop, QDecl
} else {
if (prop->value || prop->values.count() != 1)
- COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Incorrectly specified signal assignment"));
+ COMPILE_EXCEPTION(prop, tr("Incorrectly specified signal assignment"));
prop->index = sigIdx;
obj->addSignalProperty(prop);
@@ -1400,7 +1428,7 @@ bool QDeclarativeCompiler::buildSignal(QDeclarativeParser::Property *prop, QDecl
QString script = prop->values.at(0)->value.asScript().trimmed();
if (script.isEmpty())
- COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Empty signal assignment"));
+ COMPILE_EXCEPTION(prop, tr("Empty signal assignment"));
compileState.signalExpressions.insert(prop->values.at(0), ctxt);
}
@@ -1438,7 +1466,7 @@ bool QDeclarativeCompiler::buildProperty(QDeclarativeParser::Property *prop,
const BindingContext &ctxt)
{
if (prop->isEmpty())
- COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Empty property assignment"));
+ COMPILE_EXCEPTION(prop, tr("Empty property assignment"));
const QMetaObject *metaObject = obj->metaObject();
Q_ASSERT(metaObject);
@@ -1450,7 +1478,7 @@ bool QDeclarativeCompiler::buildProperty(QDeclarativeParser::Property *prop,
// Attached properties cannot be used on sub-objects. Sub-objects
// always exist in a binding sub-context, which is what we test
// for here.
- COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Attached properties cannot be used here"));
+ COMPILE_EXCEPTION(prop, tr("Attached properties cannot be used here"));
}
QDeclarativeType *type = 0;
@@ -1465,11 +1493,11 @@ bool QDeclarativeCompiler::buildProperty(QDeclarativeParser::Property *prop,
ctxt));
return true;
} else if (!type || !type->attachedPropertiesType()) {
- COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Non-existent attached object"));
+ COMPILE_EXCEPTION(prop, tr("Non-existent attached object"));
}
if (!prop->value)
- COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Invalid attached object assignment"));
+ COMPILE_EXCEPTION(prop, tr("Invalid attached object assignment"));
Q_ASSERT(type->attachedPropertiesFunction());
prop->index = type->index();
@@ -1522,9 +1550,9 @@ bool QDeclarativeCompiler::buildProperty(QDeclarativeParser::Property *prop,
} else if (prop->index == -1) {
if (prop->isDefault) {
- COMPILE_EXCEPTION(prop->values.first(), QCoreApplication::translate("QDeclarativeCompiler","Cannot assign to non-existent default property"));
+ COMPILE_EXCEPTION(prop->values.first(), tr("Cannot assign to non-existent default property"));
} else {
- COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Cannot assign to non-existent property \"%1\"").arg(QString::fromUtf8(prop->name)));
+ COMPILE_EXCEPTION(prop, tr("Cannot assign to non-existent property \"%1\"").arg(QString::fromUtf8(prop->name)));
}
} else if (prop->value) {
@@ -1555,12 +1583,12 @@ QDeclarativeCompiler::buildPropertyInNamespace(QDeclarativeEnginePrivate::Import
const BindingContext &ctxt)
{
if (!nsProp->value)
- COMPILE_EXCEPTION(nsProp, QCoreApplication::translate("QDeclarativeCompiler","Invalid use of namespace"));
+ COMPILE_EXCEPTION(nsProp, tr("Invalid use of namespace"));
foreach (Property *prop, nsProp->value->properties) {
if (!isAttachedPropertyName(prop->name))
- COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Not an attached property name"));
+ COMPILE_EXCEPTION(prop, tr("Not an attached property name"));
// Setup attached property data
@@ -1569,10 +1597,10 @@ QDeclarativeCompiler::buildPropertyInNamespace(QDeclarativeEnginePrivate::Import
&type, 0, 0, 0);
if (!type || !type->attachedPropertiesType())
- COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Non-existent attached object"));
+ COMPILE_EXCEPTION(prop, tr("Non-existent attached object"));
if (!prop->value)
- COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Invalid attached object assignment"));
+ COMPILE_EXCEPTION(prop, tr("Invalid attached object assignment"));
Q_ASSERT(type->attachedPropertiesFunction());
prop->index = type->index();
@@ -1743,7 +1771,7 @@ bool QDeclarativeCompiler::buildIdProperty(QDeclarativeParser::Property *prop,
if (prop->value ||
prop->values.count() > 1 ||
prop->values.at(0)->object)
- COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Invalid use of id property"));
+ COMPILE_EXCEPTION(prop, tr("Invalid use of id property"));
QDeclarativeParser::Value *idValue = prop->values.at(0);
QString val = idValue->primitive();
@@ -1751,7 +1779,7 @@ bool QDeclarativeCompiler::buildIdProperty(QDeclarativeParser::Property *prop,
COMPILE_CHECK(checkValidId(idValue, val));
if (compileState.ids.contains(val))
- COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","id is not unique"));
+ COMPILE_EXCEPTION(prop, tr("id is not unique"));
prop->values.at(0)->type = Value::Id;
@@ -1832,17 +1860,21 @@ bool QDeclarativeCompiler::buildGroupedProperty(QDeclarativeParser::Property *pr
if (prop->values.count()) {
if (prop->values.at(0)->location < prop->value->location) {
- COMPILE_EXCEPTION(prop->value, QCoreApplication::translate("QDeclarativeCompiler", "Property has already been assigned a value"));
+ COMPILE_EXCEPTION(prop->value, tr( "Property has already been assigned a value"));
} else {
- COMPILE_EXCEPTION(prop->values.at(0), QCoreApplication::translate("QDeclarativeCompiler", "Property has already been assigned a value"));
+ COMPILE_EXCEPTION(prop->values.at(0), tr( "Property has already been assigned a value"));
}
}
+ if (!obj->metaObject()->property(prop->index).isWritable()) {
+ COMPILE_EXCEPTION(prop, tr( "Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop->name)));
+ }
+
COMPILE_CHECK(buildValueTypeProperty(ep->valueTypes[prop->type],
prop->value, obj, ctxt.incr()));
obj->addValueTypeProperty(prop);
} else {
- COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Invalid grouped property access"));
+ COMPILE_EXCEPTION(prop, tr("Invalid grouped property access"));
}
} else {
@@ -1850,10 +1882,10 @@ bool QDeclarativeCompiler::buildGroupedProperty(QDeclarativeParser::Property *pr
prop->value->metatype =
QDeclarativeEnginePrivate::get(engine)->metaObjectForType(prop->type);
if (!prop->value->metatype)
- COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Invalid grouped property access"));
+ COMPILE_EXCEPTION(prop, tr("Invalid grouped property access"));
if (prop->values.count())
- COMPILE_EXCEPTION(prop->values.at(0), QCoreApplication::translate("QDeclarativeCompiler", "Cannot assign a value directly to a grouped property"));
+ COMPILE_EXCEPTION(prop->values.at(0), tr( "Cannot assign a value directly to a grouped property"));
obj->addGroupedProperty(prop);
@@ -1869,28 +1901,28 @@ bool QDeclarativeCompiler::buildValueTypeProperty(QObject *type,
const BindingContext &ctxt)
{
if (obj->defaultProperty)
- COMPILE_EXCEPTION(obj, QCoreApplication::translate("QDeclarativeCompiler","Invalid property use"));
+ COMPILE_EXCEPTION(obj, tr("Invalid property use"));
obj->metatype = type->metaObject();
foreach (Property *prop, obj->properties) {
int idx = type->metaObject()->indexOfProperty(prop->name.constData());
if (idx == -1)
- COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Cannot assign to non-existent property \"%1\"").arg(QString::fromUtf8(prop->name)));
+ COMPILE_EXCEPTION(prop, tr("Cannot assign to non-existent property \"%1\"").arg(QString::fromUtf8(prop->name)));
QMetaProperty p = type->metaObject()->property(idx);
prop->index = idx;
prop->type = p.userType();
prop->isValueTypeSubProperty = true;
if (prop->value)
- COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Property assignment expected"));
+ COMPILE_EXCEPTION(prop, tr("Property assignment expected"));
if (prop->values.count() > 1) {
- COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Single property assignment expected"));
+ COMPILE_EXCEPTION(prop, tr("Single property assignment expected"));
} else if (prop->values.count()) {
Value *value = prop->values.at(0);
if (value->object) {
- COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Unexpected object assignment"));
+ COMPILE_EXCEPTION(prop, tr("Unexpected object assignment"));
} else if (value->value.isScript()) {
// ### Check for writability
BindingReference reference;
@@ -1947,19 +1979,19 @@ bool QDeclarativeCompiler::buildListProperty(QDeclarativeParser::Property *prop,
// at runtime.
if (!listTypeIsInterface) {
if (!canCoerce(listType, v->object)) {
- COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Cannot assign object to list"));
+ COMPILE_EXCEPTION(v, tr("Cannot assign object to list"));
}
}
} else if (v->value.isScript()) {
if (assignedBinding)
- COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Can only assign one binding to lists"));
+ COMPILE_EXCEPTION(v, tr("Can only assign one binding to lists"));
assignedBinding = true;
COMPILE_CHECK(buildBinding(v, prop, ctxt));
v->type = Value::PropertyBinding;
} else {
- COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Cannot assign primitives to lists"));
+ COMPILE_EXCEPTION(v, tr("Cannot assign primitives to lists"));
}
}
@@ -1972,10 +2004,10 @@ bool QDeclarativeCompiler::buildScriptStringProperty(QDeclarativeParser::Propert
const BindingContext &ctxt)
{
if (prop->values.count() > 1)
- COMPILE_EXCEPTION(prop->values.at(1), QCoreApplication::translate("QDeclarativeCompiler", "Cannot assign multiple values to a script property"));
+ COMPILE_EXCEPTION(prop->values.at(1), tr( "Cannot assign multiple values to a script property"));
if (prop->values.at(0)->object || !prop->values.at(0)->value.isScript())
- COMPILE_EXCEPTION(prop->values.at(0), QCoreApplication::translate("QDeclarativeCompiler", "Invalid property assignment: script expected"));
+ COMPILE_EXCEPTION(prop->values.at(0), tr( "Invalid property assignment: script expected"));
obj->addScriptStringProperty(prop, ctxt.stack);
@@ -2022,7 +2054,7 @@ bool QDeclarativeCompiler::buildPropertyObjectAssignment(QDeclarativeParser::Pro
Q_ASSERT(v->object->type != -1);
if (!obj->metaObject()->property(prop->index).isWritable())
- COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop->name)));
+ COMPILE_EXCEPTION(v, tr("Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop->name)));
if (QDeclarativeMetaType::isInterface(prop->type)) {
@@ -2081,7 +2113,7 @@ bool QDeclarativeCompiler::buildPropertyObjectAssignment(QDeclarativeParser::Pro
v->object = component;
COMPILE_CHECK(buildPropertyObjectAssignment(prop, obj, v, ctxt));
} else {
- COMPILE_EXCEPTION(v->object, QCoreApplication::translate("QDeclarativeCompiler","Cannot assign object to property"));
+ COMPILE_EXCEPTION(v->object, tr("Cannot assign object to property"));
}
}
@@ -2104,7 +2136,7 @@ bool QDeclarativeCompiler::buildPropertyOnAssignment(QDeclarativeParser::Propert
Q_ASSERT(v->object->type != -1);
if (!obj->metaObject()->property(prop->index).isWritable())
- COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop->name)));
+ COMPILE_EXCEPTION(v, tr("Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop->name)));
// Normally buildObject() will set this up, but we need the static
@@ -2131,7 +2163,7 @@ bool QDeclarativeCompiler::buildPropertyOnAssignment(QDeclarativeParser::Propert
buildDynamicMeta(baseObj, ForceCreation);
v->type = isPropertyValue ? Value::ValueSource : Value::ValueInterceptor;
} else {
- COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","\"%1\" cannot operate on \"%2\"").arg(QString::fromUtf8(v->object->typeName)).arg(QString::fromUtf8(prop->name.constData())));
+ COMPILE_EXCEPTION(v, tr("\"%1\" cannot operate on \"%2\"").arg(QString::fromUtf8(v->object->typeName)).arg(QString::fromUtf8(prop->name.constData())));
}
return true;
@@ -2179,7 +2211,7 @@ bool QDeclarativeCompiler::testQualifiedEnumAssignment(const QMetaProperty &prop
return true;
if (!prop.isWritable())
- COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler","Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop.name())));
+ COMPILE_EXCEPTION(v, tr("Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop.name())));
QString string = v->value.asString();
if (!string.at(0).isUpper())
@@ -2248,32 +2280,32 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj)
if (prop.isDefaultProperty) {
if (seenDefaultProperty)
- COMPILE_EXCEPTION(&prop, QCoreApplication::translate("QDeclarativeCompiler","Duplicate default property"));
+ COMPILE_EXCEPTION(&prop, tr("Duplicate default property"));
seenDefaultProperty = true;
}
if (propNames.contains(prop.name))
- COMPILE_EXCEPTION(&prop, QCoreApplication::translate("QDeclarativeCompiler","Duplicate property name"));
+ COMPILE_EXCEPTION(&prop, tr("Duplicate property name"));
if (QString::fromUtf8(prop.name).at(0).isUpper())
- COMPILE_EXCEPTION(&prop, QCoreApplication::translate("QDeclarativeCompiler","Property names cannot begin with an upper case letter"));
+ COMPILE_EXCEPTION(&prop, tr("Property names cannot begin with an upper case letter"));
propNames.insert(prop.name);
}
for (int ii = 0; ii < obj->dynamicSignals.count(); ++ii) {
QByteArray name = obj->dynamicSignals.at(ii).name;
if (methodNames.contains(name))
- COMPILE_EXCEPTION(obj, QCoreApplication::translate("QDeclarativeCompiler","Duplicate signal name"));
+ COMPILE_EXCEPTION(obj, tr("Duplicate signal name"));
if (QString::fromUtf8(name).at(0).isUpper())
- COMPILE_EXCEPTION(obj, QCoreApplication::translate("QDeclarativeCompiler","Signal names cannot begin with an upper case letter"));
+ COMPILE_EXCEPTION(obj, tr("Signal names cannot begin with an upper case letter"));
methodNames.insert(name);
}
for (int ii = 0; ii < obj->dynamicSlots.count(); ++ii) {
QByteArray name = obj->dynamicSlots.at(ii).name;
if (methodNames.contains(name))
- COMPILE_EXCEPTION(obj, QCoreApplication::translate("QDeclarativeCompiler","Duplicate method name"));
+ COMPILE_EXCEPTION(obj, tr("Duplicate method name"));
if (QString::fromUtf8(name).at(0).isUpper())
- COMPILE_EXCEPTION(obj, QCoreApplication::translate("QDeclarativeCompiler","Method names cannot begin with an upper case letter"));
+ COMPILE_EXCEPTION(obj, tr("Method names cannot begin with an upper case letter"));
methodNames.insert(name);
}
@@ -2294,11 +2326,11 @@ bool QDeclarativeCompiler::mergeDynamicMetaProperties(QDeclarativeParser::Object
} else {
property = obj->getProperty(p.name);
if (!property->values.isEmpty())
- COMPILE_EXCEPTION(property, QCoreApplication::translate("QDeclarativeCompiler","Property value set multiple times"));
+ COMPILE_EXCEPTION(property, tr("Property value set multiple times"));
}
if (property->value)
- COMPILE_EXCEPTION(property, QCoreApplication::translate("QDeclarativeCompiler","Invalid property nesting"));
+ COMPILE_EXCEPTION(property, tr("Invalid property nesting"));
for (int ii = 0; ii < p.defaultValue->values.count(); ++ii) {
Value *v = p.defaultValue->values.at(ii);
@@ -2351,7 +2383,7 @@ bool QDeclarativeCompiler::buildDynamicMeta(QDeclarativeParser::Object *obj, Dyn
if (-1 != propIdx) {
QMetaProperty prop = obj->metaObject()->property(propIdx);
if (prop.isFinal())
- COMPILE_EXCEPTION(&p, QCoreApplication::translate("QDeclarativeCompiler","Cannot override FINAL property"));
+ COMPILE_EXCEPTION(&p, tr("Cannot override FINAL property"));
}
if (p.isDefaultProperty &&
@@ -2376,7 +2408,7 @@ bool QDeclarativeCompiler::buildDynamicMeta(QDeclarativeParser::Object *obj, Dyn
QDeclarativeEnginePrivate *priv = QDeclarativeEnginePrivate::get(engine);
if (!priv->resolveType(unit->imports, p.customType, &qmltype,
&url, 0, 0, 0))
- COMPILE_EXCEPTION(&p, QCoreApplication::translate("QDeclarativeCompiler","Invalid property type"));
+ COMPILE_EXCEPTION(&p, tr("Invalid property type"));
if (!qmltype) {
QDeclarativeCompositeTypeData *tdata = priv->typeManager.get(url);
@@ -2505,7 +2537,7 @@ bool QDeclarativeCompiler::buildDynamicMeta(QDeclarativeParser::Object *obj, Dyn
((QDeclarativeVMEMetaData *)dynamicData.data())->methodCount++;
QDeclarativeVMEMetaData::MethodData methodData =
- { s.parameterNames.count(), 0, funcScript.length(), 0 };
+ { s.parameterNames.count(), 0, funcScript.length(), s.location.start.line };
dynamicData.append((char *)&methodData, sizeof(methodData));
}
@@ -2535,24 +2567,24 @@ bool QDeclarativeCompiler::buildDynamicMeta(QDeclarativeParser::Object *obj, Dyn
bool QDeclarativeCompiler::checkValidId(QDeclarativeParser::Value *v, const QString &val)
{
if (val.isEmpty())
- COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler", "Invalid empty ID"));
+ COMPILE_EXCEPTION(v, tr( "Invalid empty ID"));
if (val.at(0).isLetter() && !val.at(0).isLower())
- COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler", "IDs cannot start with an uppercase letter"));
+ COMPILE_EXCEPTION(v, tr( "IDs cannot start with an uppercase letter"));
QChar u(QLatin1Char('_'));
for (int ii = 0; ii < val.count(); ++ii) {
if (ii == 0 && !val.at(ii).isLetter() && val.at(ii) != u) {
- COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler", "IDs must start with a letter or underscore"));
+ COMPILE_EXCEPTION(v, tr( "IDs must start with a letter or underscore"));
} else if (ii != 0 && !val.at(ii).isLetterOrNumber() && val.at(ii) != u) {
- COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler", "IDs must contain only letters, numbers, and underscores"));
+ COMPILE_EXCEPTION(v, tr( "IDs must contain only letters, numbers, and underscores"));
}
}
if (QDeclarativeEnginePrivate::get(engine)->globalClass->illegalNames().contains(val))
- COMPILE_EXCEPTION(v, QCoreApplication::translate("QDeclarativeCompiler", "ID illegally masks global JavaScript property"));
+ COMPILE_EXCEPTION(v, tr( "ID illegally masks global JavaScript property"));
return true;
}
@@ -2583,24 +2615,24 @@ bool QDeclarativeCompiler::compileAlias(QMetaObjectBuilder &builder,
const Object::DynamicProperty &prop)
{
if (!prop.defaultValue)
- COMPILE_EXCEPTION(obj, QCoreApplication::translate("QDeclarativeCompiler","No property alias location"));
+ COMPILE_EXCEPTION(obj, tr("No property alias location"));
if (prop.defaultValue->values.count() != 1 ||
prop.defaultValue->values.at(0)->object ||
!prop.defaultValue->values.at(0)->value.isScript())
- COMPILE_EXCEPTION(prop.defaultValue, QCoreApplication::translate("QDeclarativeCompiler","Invalid alias location"));
+ COMPILE_EXCEPTION(prop.defaultValue, tr("Invalid alias location"));
QDeclarativeJS::AST::Node *node = prop.defaultValue->values.at(0)->value.asAST();
if (!node)
- COMPILE_EXCEPTION(obj, QCoreApplication::translate("QDeclarativeCompiler","No property alias location")); // ### Can this happen?
+ COMPILE_EXCEPTION(obj, tr("No property alias location")); // ### Can this happen?
QStringList alias = astNodeToStringList(node);
if (alias.count() != 1 && alias.count() != 2)
- COMPILE_EXCEPTION(prop.defaultValue, QCoreApplication::translate("QDeclarativeCompiler","Invalid alias reference. An alias reference must be specified as <id> or <id>.<property>"));
+ COMPILE_EXCEPTION(prop.defaultValue, tr("Invalid alias reference. An alias reference must be specified as <id> or <id>.<property>"));
if (!compileState.ids.contains(alias.at(0)))
- COMPILE_EXCEPTION(prop.defaultValue, QCoreApplication::translate("QDeclarativeCompiler","Invalid alias reference. Unable to find id \"%1\"").arg(alias.at(0)));
+ COMPILE_EXCEPTION(prop.defaultValue, tr("Invalid alias reference. Unable to find id \"%1\"").arg(alias.at(0)));
Object *idObject = compileState.ids[alias.at(0)];
@@ -2613,7 +2645,7 @@ bool QDeclarativeCompiler::compileAlias(QMetaObjectBuilder &builder,
propIdx = idObject->metaObject()->indexOfProperty(alias.at(1).toUtf8().constData());
if (-1 == propIdx)
- COMPILE_EXCEPTION(prop.defaultValue, QCoreApplication::translate("QDeclarativeCompiler","Invalid alias location"));
+ COMPILE_EXCEPTION(prop.defaultValue, tr("Invalid alias location"));
QMetaProperty aliasProperty = idObject->metaObject()->property(propIdx);
writable = aliasProperty.isWritable();
@@ -2667,7 +2699,7 @@ bool QDeclarativeCompiler::buildBinding(QDeclarativeParser::Value *value,
QMetaProperty mp = prop->parent->metaObject()->property(prop->index);
if (!mp.isWritable() && !QDeclarativeMetaType::isList(prop->type))
- COMPILE_EXCEPTION(prop, QCoreApplication::translate("QDeclarativeCompiler","Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop->name)));
+ COMPILE_EXCEPTION(prop, tr("Invalid property assignment: \"%1\" is a read-only property").arg(QString::fromUtf8(prop->name)));
BindingReference reference;
reference.expression = value->value;
@@ -2944,4 +2976,9 @@ QStringList QDeclarativeCompiler::deferredProperties(QDeclarativeParser::Object
return rv;
}
+QString QDeclarativeCompiler::tr(const char *str)
+{
+ return QCoreApplication::translate("QDeclarativeCompiler", str);
+}
+
QT_END_NAMESPACE