#include "private/qdeclarativecompiler_p.h"
-#include "private/qdeclarativeparser_p.h"
-#include "private/qdeclarativescriptparser_p.h"
#include "qdeclarativepropertyvaluesource.h"
#include "qdeclarativecomponent.h"
#include "private/qmetaobjectbuilder_p.h"
#include "private/qdeclarativerewrite_p.h"
#include "qdeclarativescriptstring.h"
#include "private/qdeclarativeglobal_p.h"
-#include "private/qdeclarativescriptparser_p.h"
#include "private/qdeclarativebinding_p.h"
#include "private/qdeclarativev4compiler_p.h"
#include "private/qdeclarativeutils_p.h"
DEFINE_BOOL_CONFIG_OPTION(compilerDump, QML_COMPILER_DUMP);
DEFINE_BOOL_CONFIG_OPTION(compilerStatDump, QML_COMPILER_STATS);
-using namespace QDeclarativeParser;
+using namespace QDeclarativeScript;
using namespace QDeclarativeCompilerTypes;
static QString id_string(QLatin1String("id"));
This test corresponds to action taken by genLiteralAssignment(). Any change
made here, must have a corresponding action in genLiteralAssigment().
*/
-bool QDeclarativeCompiler::testLiteralAssignment(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Value *v)
+bool QDeclarativeCompiler::testLiteralAssignment(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Value *v)
{
- const QDeclarativeParser::Variant &value = v->value;
+ const QDeclarativeScript::Variant &value = v->value;
if (!prop->core.isWritable())
COMPILE_EXCEPTION(v, tr("Invalid property assignment: \"%1\" is a read-only property").arg(prop->name().toString()));
if (enumValue == -1)
COMPILE_EXCEPTION(v, tr("Invalid property assignment: unknown enumeration"));
- v->value = QDeclarativeParser::Variant((double)enumValue);
+ v->value = QDeclarativeScript::Variant((double)enumValue);
return true;
}
Any literal assignment that is approved in testLiteralAssignment() must have
a corresponding action in this method.
*/
-void QDeclarativeCompiler::genLiteralAssignment(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Value *v)
+void QDeclarativeCompiler::genLiteralAssignment(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Value *v)
{
QDeclarativeInstruction instr;
// Compile types
const QList<QDeclarativeTypeData::TypeReference> &resolvedTypes = unit->resolvedTypes();
- QList<QDeclarativeScriptParser::TypeReference *> referencedTypes = unit->parser().referencedTypes();
+ QList<QDeclarativeScript::TypeReference *> referencedTypes = unit->parser().referencedTypes();
for (int ii = 0; ii < resolvedTypes.count(); ++ii) {
QDeclarativeCompiledData::TypeReference ref;
const QDeclarativeTypeData::TypeReference &tref = resolvedTypes.at(ii);
- QDeclarativeScriptParser::TypeReference *parserRef = referencedTypes.at(ii);
+ QDeclarativeScript::TypeReference *parserRef = referencedTypes.at(ii);
if (tref.type) {
ref.type = tref.type;
out->types << ref;
}
- QDeclarativeParser::Object *root = unit->parser().tree();
+ QDeclarativeScript::Object *root = unit->parser().tree();
Q_ASSERT(root);
this->engine = engine;
return !isError();
}
-void QDeclarativeCompiler::compileTree(QDeclarativeParser::Object *tree)
+void QDeclarativeCompiler::compileTree(QDeclarativeScript::Object *tree)
{
compileState = pool->New<ComponentCompileState>();
return false;
}
-bool QDeclarativeCompiler::buildObject(QDeclarativeParser::Object *obj, const BindingContext &ctxt)
+bool QDeclarativeCompiler::buildObject(QDeclarativeScript::Object *obj, const BindingContext &ctxt)
{
if (componentStats)
componentStats->componentStat.objects++;
return true;
}
-void QDeclarativeCompiler::genObject(QDeclarativeParser::Object *obj)
+void QDeclarativeCompiler::genObject(QDeclarativeScript::Object *obj)
{
QDeclarativeCompiledData::TypeReference &tr = output->types[obj->type];
if (tr.type && obj->metatype == &QDeclarativeComponent::staticMetaObject) {
genObjectBody(obj);
}
-void QDeclarativeCompiler::genObjectBody(QDeclarativeParser::Object *obj)
+void QDeclarativeCompiler::genObjectBody(QDeclarativeScript::Object *obj)
{
for (Property *prop = obj->scriptStringProperties.first(); prop; prop = Object::PropertyList::next(prop)) {
Q_ASSERT(prop->scriptStringScope != -1);
for (Property *prop = obj->signalProperties.first(); prop; prop = Object::PropertyList::next(prop)) {
- QDeclarativeParser::Value *v = prop->values.first();
+ QDeclarativeScript::Value *v = prop->values.first();
if (v->type == Value::SignalObject) {
}
}
-void QDeclarativeCompiler::genValueTypeProperty(QDeclarativeParser::Object *obj,QDeclarativeParser::Property *prop)
+void QDeclarativeCompiler::genValueTypeProperty(QDeclarativeScript::Object *obj,QDeclarativeScript::Property *prop)
{
QDeclarativeInstruction fetch;
fetch.setType(QDeclarativeInstruction::FetchValueType);
output->addInstruction(pop);
}
-void QDeclarativeCompiler::genComponent(QDeclarativeParser::Object *obj)
+void QDeclarativeCompiler::genComponent(QDeclarativeScript::Object *obj)
{
- QDeclarativeParser::Object *root = obj->defaultProperty->values.first()->object;
+ QDeclarativeScript::Object *root = obj->defaultProperty->values.first()->object;
Q_ASSERT(root);
QDeclarativeInstruction create;
}
}
-bool QDeclarativeCompiler::buildComponent(QDeclarativeParser::Object *obj,
+bool QDeclarativeCompiler::buildComponent(QDeclarativeScript::Object *obj,
const BindingContext &ctxt)
{
// The special "Component" element can only have the id property and a
if (!obj->dynamicSlots.isEmpty())
COMPILE_EXCEPTION(obj, tr("Component objects cannot declare new functions."));
- QDeclarativeParser::Object *root = 0;
+ QDeclarativeScript::Object *root = 0;
if (obj->defaultProperty && !obj->defaultProperty->values.isEmpty())
root = obj->defaultProperty->values.first()->object;
return true;
}
-bool QDeclarativeCompiler::buildComponentFromRoot(QDeclarativeParser::Object *obj,
+bool QDeclarativeCompiler::buildComponentFromRoot(QDeclarativeScript::Object *obj,
const BindingContext &ctxt)
{
ComponentCompileState *oldComponentCompileState = compileState;
// Build a sub-object. A sub-object is one that was not created directly by
// QML - such as a grouped property object, or an attached object. Sub-object's
// can't have an id, involve a custom parser, have attached properties etc.
-bool QDeclarativeCompiler::buildSubObject(QDeclarativeParser::Object *obj, const BindingContext &ctxt)
+bool QDeclarativeCompiler::buildSubObject(QDeclarativeScript::Object *obj, const BindingContext &ctxt)
{
Q_ASSERT(obj->metatype);
Q_ASSERT(!obj->defaultProperty);
return output->types.count() - 1;
}
-bool QDeclarativeCompiler::buildSignal(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj,
+bool QDeclarativeCompiler::buildSignal(QDeclarativeScript::Property *prop, QDeclarativeScript::Object *obj,
const BindingContext &ctxt)
{
Q_ASSERT(obj->metaObject());
/*!
Returns true if (value) property \a prop exists on obj, false otherwise.
*/
-bool QDeclarativeCompiler::doesPropertyExist(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj)
+bool QDeclarativeCompiler::doesPropertyExist(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj)
{
if (prop->name().isEmpty())
return false;
return property(obj, prop->name()) != 0;
}
-bool QDeclarativeCompiler::buildProperty(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj,
+bool QDeclarativeCompiler::buildProperty(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj,
const BindingContext &ctxt)
{
if (prop->isEmpty())
}
bool QDeclarativeCompiler::buildPropertyInNamespace(QDeclarativeImportedNamespace *ns,
- QDeclarativeParser::Property *nsProp,
- QDeclarativeParser::Object *obj,
+ QDeclarativeScript::Property *nsProp,
+ QDeclarativeScript::Object *obj,
const BindingContext &ctxt)
{
if (!nsProp->value)
return true;
}
-void QDeclarativeCompiler::genValueProperty(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj)
+void QDeclarativeCompiler::genValueProperty(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj)
{
if (prop->core.isQList()) {
genListProperty(prop, obj);
}
}
-void QDeclarativeCompiler::genListProperty(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj)
+void QDeclarativeCompiler::genListProperty(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj)
{
int listType = enginePrivate->listType(prop->type);
output->addInstruction(pop);
}
-void QDeclarativeCompiler::genPropertyAssignment(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj,
- QDeclarativeParser::Property *valueTypeProperty)
+void QDeclarativeCompiler::genPropertyAssignment(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj,
+ QDeclarativeScript::Property *valueTypeProperty)
{
for (Value *v = prop->values.first(); v; v = Property::ValueList::next(v)) {
}
}
-bool QDeclarativeCompiler::buildIdProperty(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj)
+bool QDeclarativeCompiler::buildIdProperty(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj)
{
if (prop->value ||
prop->values.isMany() ||
prop->values.first()->object)
COMPILE_EXCEPTION(prop, tr("Invalid use of id property"));
- QDeclarativeParser::Value *idValue = prop->values.first();
+ QDeclarativeScript::Value *idValue = prop->values.first();
QString val = idValue->primitive();
COMPILE_CHECK(checkValidId(idValue, val));
return true;
}
-void QDeclarativeCompiler::addId(const QString &id, QDeclarativeParser::Object *obj)
+void QDeclarativeCompiler::addId(const QString &id, QDeclarativeScript::Object *obj)
{
Q_ASSERT(!compileState->ids.value(id));
Q_ASSERT(obj->id == id);
}
QDeclarativeCompilerTypes::ComponentCompileState *
-QDeclarativeCompiler::componentState(QDeclarativeParser::Object *obj)
+QDeclarativeCompiler::componentState(QDeclarativeScript::Object *obj)
{
Q_ASSERT(obj->componentCompileState);
return obj->componentCompileState;
// GridView.row: 10
// }
// GridView is an attached property object.
-bool QDeclarativeCompiler::buildAttachedProperty(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj,
+bool QDeclarativeCompiler::buildAttachedProperty(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj,
const BindingContext &ctxt)
{
Q_ASSERT(prop->value);
// font.family: "Helvetica"
// }
// font is a nested property. pointSize and family are not.
-bool QDeclarativeCompiler::buildGroupedProperty(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj,
+bool QDeclarativeCompiler::buildGroupedProperty(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj,
const BindingContext &ctxt)
{
Q_ASSERT(prop->type != 0);
}
bool QDeclarativeCompiler::buildValueTypeProperty(QObject *type,
- QDeclarativeParser::Object *obj,
- QDeclarativeParser::Object *baseObj,
+ QDeclarativeScript::Object *obj,
+ QDeclarativeScript::Object *baseObj,
const BindingContext &ctxt)
{
if (obj->defaultProperty)
if (prop->values.isMany()) {
COMPILE_EXCEPTION(prop, tr("Single property assignment expected"));
} else if (!prop->values.isEmpty()) {
- QDeclarativeParser::Value *value = prop->values.first();
+ QDeclarativeScript::Value *value = prop->values.first();
if (value->object) {
COMPILE_EXCEPTION(prop, tr("Unexpected object assignment"));
// Build assignments to QML lists. QML lists are properties of type
// QDeclarativeListProperty<T>. List properties can accept a list of
// objects, or a single binding.
-bool QDeclarativeCompiler::buildListProperty(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj,
+bool QDeclarativeCompiler::buildListProperty(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj,
const BindingContext &ctxt)
{
Q_ASSERT(prop->core.isQList());
}
// Compiles an assignment to a QDeclarativeScriptString property
-bool QDeclarativeCompiler::buildScriptStringProperty(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj,
+bool QDeclarativeCompiler::buildScriptStringProperty(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj,
const BindingContext &ctxt)
{
if (prop->values.isMany())
}
// Compile regular property assignments of the form "property: <value>"
-bool QDeclarativeCompiler::buildPropertyAssignment(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj,
+bool QDeclarativeCompiler::buildPropertyAssignment(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj,
const BindingContext &ctxt)
{
obj->addValueProperty(prop);
}
// Compile assigning a single object instance to a regular property
-bool QDeclarativeCompiler::buildPropertyObjectAssignment(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj,
- QDeclarativeParser::Value *v,
+bool QDeclarativeCompiler::buildPropertyObjectAssignment(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj,
+ QDeclarativeScript::Value *v,
const BindingContext &ctxt)
{
Q_ASSERT(prop->index != -1);
v->type = Value::CreatedObject;
} else if (propertyMetaObject == &QDeclarativeComponent::staticMetaObject) {
// Automatic "Component" insertion
- QDeclarativeParser::Object *root = v->object;
- QDeclarativeParser::Object *component = pool->New<Object>();
+ QDeclarativeScript::Object *root = v->object;
+ QDeclarativeScript::Object *component = pool->New<Object>();
component->type = componentTypeRef();
component->typeName = "Qt/Component";
component->metatype = &QDeclarativeComponent::staticMetaObject;
component->location = root->location;
- QDeclarativeParser::Value *componentValue = pool->New<Value>();
+ QDeclarativeScript::Value *componentValue = pool->New<Value>();
componentValue->object = root;
component->getDefaultProperty()->addValue(componentValue);
v->object = component;
// Item {
// NumberAnimation on x { }
// }
-bool QDeclarativeCompiler::buildPropertyOnAssignment(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj,
- QDeclarativeParser::Object *baseObj,
- QDeclarativeParser::Value *v,
+bool QDeclarativeCompiler::buildPropertyOnAssignment(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj,
+ QDeclarativeScript::Object *baseObj,
+ QDeclarativeScript::Value *v,
const BindingContext &ctxt)
{
Q_ASSERT(prop->index != -1);
}
// Compile assigning a literal or binding to a regular property
-bool QDeclarativeCompiler::buildPropertyLiteralAssignment(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj,
- QDeclarativeParser::Value *v,
+bool QDeclarativeCompiler::buildPropertyLiteralAssignment(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj,
+ QDeclarativeScript::Value *v,
const BindingContext &ctxt)
{
Q_ASSERT(prop->index != -1);
}
bool QDeclarativeCompiler::testQualifiedEnumAssignment(const QMetaProperty &prop,
- QDeclarativeParser::Object *obj,
- QDeclarativeParser::Value *v,
+ QDeclarativeScript::Object *obj,
+ QDeclarativeScript::Value *v,
bool *isAssignment)
{
*isAssignment = false;
return true;
v->type = Value::Literal;
- v->value = QDeclarativeParser::Variant((double)value);
+ v->value = QDeclarativeScript::Variant((double)value);
*isAssignment = true;
return true;
}
// Ensures that the dynamic meta specification on obj is valid
-bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj)
+bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeScript::Object *obj)
{
bool seenDefaultProperty = false;
// Check properties
int dpCount = obj->dynamicProperties.count();
for (Object::DynamicProperty *p = obj->dynamicProperties.first(); p; p = obj->dynamicProperties.next(p)) {
- const QDeclarativeParser::Object::DynamicProperty &prop = *p;
+ const QDeclarativeScript::Object::DynamicProperty &prop = *p;
if (prop.isDefaultProperty) {
if (seenDefaultProperty)
return true;
}
-bool QDeclarativeCompiler::mergeDynamicMetaProperties(QDeclarativeParser::Object *obj)
+bool QDeclarativeCompiler::mergeDynamicMetaProperties(QDeclarativeScript::Object *obj)
{
for (Object::DynamicProperty *p = obj->dynamicProperties.first(); p; p = obj->dynamicProperties.next(p)) {
Q_GLOBAL_STATIC(QAtomicInt, classIndexCounter)
-bool QDeclarativeCompiler::buildDynamicMeta(QDeclarativeParser::Object *obj, DynamicMetaMode mode)
+bool QDeclarativeCompiler::buildDynamicMeta(QDeclarativeScript::Object *obj, DynamicMetaMode mode)
{
Q_ASSERT(obj);
Q_ASSERT(obj->metatype);
return true;
}
-bool QDeclarativeCompiler::checkValidId(QDeclarativeParser::Value *v, const QString &val)
+bool QDeclarativeCompiler::checkValidId(QDeclarativeScript::Value *v, const QString &val)
{
if (val.isEmpty())
COMPILE_EXCEPTION(v, tr( "Invalid empty ID"));
bool QDeclarativeCompiler::compileAlias(QFastMetaBuilder &builder,
QByteArray &data,
- QDeclarativeParser::Object *obj,
+ QDeclarativeScript::Object *obj,
int propIndex, int aliasIndex,
Object::DynamicProperty &prop)
{
if (alias.count() < 1 || alias.count() > 3)
COMPILE_EXCEPTION(prop.defaultValue, tr("Invalid alias reference. An alias reference must be specified as <id>, <id>.<property> or <id>.<value property>.<property>"));
- QDeclarativeParser::Object *idObject = compileState->ids.value(alias.at(0));
+ QDeclarativeScript::Object *idObject = compileState->ids.value(alias.at(0));
if (!idObject)
COMPILE_EXCEPTION(prop.defaultValue, tr("Invalid alias reference. Unable to find id \"%1\"").arg(alias.at(0)));
return true;
}
-bool QDeclarativeCompiler::buildBinding(QDeclarativeParser::Value *value,
- QDeclarativeParser::Property *prop,
+bool QDeclarativeCompiler::buildBinding(QDeclarativeScript::Value *value,
+ QDeclarativeScript::Property *prop,
const BindingContext &ctxt)
{
Q_ASSERT(prop->index != -1);
return true;
}
-void QDeclarativeCompiler::genBindingAssignment(QDeclarativeParser::Value *binding,
- QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj,
- QDeclarativeParser::Property *valueTypeProperty)
+void QDeclarativeCompiler::genBindingAssignment(QDeclarativeScript::Value *binding,
+ QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj,
+ QDeclarativeScript::Property *valueTypeProperty)
{
Q_UNUSED(obj);
Q_ASSERT(binding->bindingReference);
return output->contextCaches.count() - 1;
}
-int QDeclarativeCompiler::genValueTypeData(QDeclarativeParser::Property *valueTypeProp,
- QDeclarativeParser::Property *prop)
+int QDeclarativeCompiler::genValueTypeData(QDeclarativeScript::Property *valueTypeProp,
+ QDeclarativeScript::Property *prop)
{
typedef QDeclarativePropertyPrivate QDPP;
QByteArray data = QDPP::saveValueType(prop->parent->metaObject(), prop->index,
return output->indexForByteArray(data);
}
-int QDeclarativeCompiler::genPropertyData(QDeclarativeParser::Property *prop)
+int QDeclarativeCompiler::genPropertyData(QDeclarativeScript::Property *prop)
{
typedef QDeclarativePropertyPrivate QDPP;
QByteArray data = QDPP::saveProperty(prop->parent->metaObject(), prop->index, engine);
QString functionArray(QLatin1String("["));
for (int ii = 0; ii < sharedBindings.count(); ++ii) {
BindingReference *reference = sharedBindings.at(ii);
- QDeclarativeParser::Value *value = reference->value;
+ QDeclarativeScript::Value *value = reference->value;
const QString &expression = reference->rewrittenExpression;
if (ii != 0) functionArray += QLatin1String(",");
Returns true if from can be assigned to a (QObject) property of type
to.
*/
-bool QDeclarativeCompiler::canCoerce(int to, QDeclarativeParser::Object *from)
+bool QDeclarativeCompiler::canCoerce(int to, QDeclarativeScript::Object *from)
{
const QMetaObject *toMo =
enginePrivate->rawMetaObjectForType(to);
/*!
Returns the element name, as written in the QML file, for o.
*/
-QString QDeclarativeCompiler::elementName(QDeclarativeParser::Object *o)
+QString QDeclarativeCompiler::elementName(QDeclarativeScript::Object *o)
{
Q_ASSERT(o);
if (o->type != -1) {
}
}
-QDeclarativeType *QDeclarativeCompiler::toQmlType(QDeclarativeParser::Object *from)
+QDeclarativeType *QDeclarativeCompiler::toQmlType(QDeclarativeScript::Object *from)
{
// ### Optimize
const QMetaObject *mo = from->metatype;
return type;
}
-QStringList QDeclarativeCompiler::deferredProperties(QDeclarativeParser::Object *obj)
+QStringList QDeclarativeCompiler::deferredProperties(QDeclarativeScript::Object *obj)
{
const QMetaObject *mo = obj->metatype;
}
QDeclarativePropertyCache::Data *
-QDeclarativeCompiler::property(QDeclarativeParser::Object *object, int index)
+QDeclarativeCompiler::property(QDeclarativeScript::Object *object, int index)
{
QDeclarativePropertyCache *cache = 0;
}
QDeclarativePropertyCache::Data *
-QDeclarativeCompiler::property(QDeclarativeParser::Object *object, const QHashedStringRef &name, bool *notInRevision)
+QDeclarativeCompiler::property(QDeclarativeScript::Object *object, const QHashedStringRef &name, bool *notInRevision)
{
if (notInRevision) *notInRevision = false;
// This code must match the semantics of QDeclarativePropertyPrivate::findSignalByName
QDeclarativePropertyCache::Data *
-QDeclarativeCompiler::signal(QDeclarativeParser::Object *object, const QHashedStringRef &name, bool *notInRevision)
+QDeclarativeCompiler::signal(QDeclarativeScript::Object *object, const QHashedStringRef &name, bool *notInRevision)
{
if (notInRevision) *notInRevision = false;
}
// This code must match the semantics of QDeclarativePropertyPrivate::findSignalByName
-int QDeclarativeCompiler::indexOfSignal(QDeclarativeParser::Object *object, const QString &name,
+int QDeclarativeCompiler::indexOfSignal(QDeclarativeScript::Object *object, const QString &name,
bool *notInRevision)
{
QDeclarativePropertyCache::Data *d = signal(object, QStringRef(&name), notInRevision);
return d?d->coreIndex:-1;
}
-int QDeclarativeCompiler::indexOfProperty(QDeclarativeParser::Object *object, const QString &name,
+int QDeclarativeCompiler::indexOfProperty(QDeclarativeScript::Object *object, const QString &name,
bool *notInRevision)
{
return indexOfProperty(object, QStringRef(&name), notInRevision);
}
-int QDeclarativeCompiler::indexOfProperty(QDeclarativeParser::Object *object, const QHashedStringRef &name,
+int QDeclarativeCompiler::indexOfProperty(QDeclarativeScript::Object *object, const QHashedStringRef &name,
bool *notInRevision)
{
QDeclarativePropertyCache::Data *d = property(object, name, notInRevision);
#include "qdeclarativeerror.h"
#include "private/qv8_p.h"
#include "private/qdeclarativeinstruction_p.h"
-#include "private/qdeclarativeparser_p.h"
+#include "private/qdeclarativescript_p.h"
#include "private/qdeclarativeengine_p.h"
#include "private/qbitfield_p.h"
#include "private/qdeclarativepropertycache_p.h"
{
BindingContext()
: stack(0), owner(0), object(0) {}
- BindingContext(QDeclarativeParser::Object *o)
+ BindingContext(QDeclarativeScript::Object *o)
: stack(0), owner(0), object(o) {}
BindingContext incr() const {
BindingContext rv(object);
bool isSubContext() const { return stack != 0; }
int stack;
int owner;
- QDeclarativeParser::Object *object;
+ QDeclarativeScript::Object *object;
};
struct BindingReference : public QDeclarativePool::Class
{
BindingReference() : nextReference(0) {}
- QDeclarativeParser::Variant expression;
- QDeclarativeParser::Property *property;
- QDeclarativeParser::Value *value;
+ QDeclarativeScript::Variant expression;
+ QDeclarativeScript::Property *property;
+ QDeclarativeScript::Value *value;
enum DataType { QtScript, V4, V8 };
DataType dataType;
BindingReference *nextReference;
};
- struct IdList : public QFieldList<QDeclarativeParser::Object,
- &QDeclarativeParser::Object::nextIdObject>
+ struct IdList : public QFieldList<QDeclarativeScript::Object,
+ &QDeclarativeScript::Object::nextIdObject>
{
- QDeclarativeParser::Object *value(const QString &id) const {
- for (QDeclarativeParser::Object *o = first(); o; o = next(o)) {
+ QDeclarativeScript::Object *value(const QString &id) const {
+ for (QDeclarativeScript::Object *o = first(); o; o = next(o)) {
if (o->id == id)
return o;
}
typedef QDeclarativeCompilerTypes::BindingReference B;
typedef QFieldList<B, &B::nextReference> BindingReferenceList;
BindingReferenceList bindings;
- typedef QDeclarativeParser::Object O;
+ typedef QDeclarativeScript::Object O;
typedef QFieldList<O, &O::nextAliasingObject> AliasingObjectsList;
AliasingObjectsList aliasingObjects;
- QDeclarativeParser::Object *root;
+ QDeclarativeScript::Object *root;
};
};
private:
static void reset(QDeclarativeCompiledData *);
- void compileTree(QDeclarativeParser::Object *tree);
+ void compileTree(QDeclarativeScript::Object *tree);
- bool buildObject(QDeclarativeParser::Object *obj, const QDeclarativeCompilerTypes::BindingContext &);
- bool buildComponent(QDeclarativeParser::Object *obj, const QDeclarativeCompilerTypes::BindingContext &);
- bool buildSubObject(QDeclarativeParser::Object *obj, const QDeclarativeCompilerTypes::BindingContext &);
- bool buildSignal(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj,
+ bool buildObject(QDeclarativeScript::Object *obj, const QDeclarativeCompilerTypes::BindingContext &);
+ bool buildComponent(QDeclarativeScript::Object *obj, const QDeclarativeCompilerTypes::BindingContext &);
+ bool buildSubObject(QDeclarativeScript::Object *obj, const QDeclarativeCompilerTypes::BindingContext &);
+ bool buildSignal(QDeclarativeScript::Property *prop, QDeclarativeScript::Object *obj,
const QDeclarativeCompilerTypes::BindingContext &);
- bool buildProperty(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj,
+ bool buildProperty(QDeclarativeScript::Property *prop, QDeclarativeScript::Object *obj,
const QDeclarativeCompilerTypes::BindingContext &);
bool buildPropertyInNamespace(QDeclarativeImportedNamespace *ns,
- QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj,
+ QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj,
const QDeclarativeCompilerTypes::BindingContext &);
- bool buildIdProperty(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj);
- bool buildAttachedProperty(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj,
+ bool buildIdProperty(QDeclarativeScript::Property *prop, QDeclarativeScript::Object *obj);
+ bool buildAttachedProperty(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj,
const QDeclarativeCompilerTypes::BindingContext &ctxt);
- bool buildGroupedProperty(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj,
+ bool buildGroupedProperty(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj,
const QDeclarativeCompilerTypes::BindingContext &ctxt);
bool buildValueTypeProperty(QObject *type,
- QDeclarativeParser::Object *obj,
- QDeclarativeParser::Object *baseObj,
+ QDeclarativeScript::Object *obj,
+ QDeclarativeScript::Object *baseObj,
const QDeclarativeCompilerTypes::BindingContext &ctxt);
- bool buildListProperty(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj,
+ bool buildListProperty(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj,
const QDeclarativeCompilerTypes::BindingContext &ctxt);
- bool buildScriptStringProperty(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj,
+ bool buildScriptStringProperty(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj,
const QDeclarativeCompilerTypes::BindingContext &ctxt);
- bool buildPropertyAssignment(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj,
+ bool buildPropertyAssignment(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj,
const QDeclarativeCompilerTypes::BindingContext &ctxt);
- bool buildPropertyObjectAssignment(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj,
- QDeclarativeParser::Value *value,
+ bool buildPropertyObjectAssignment(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj,
+ QDeclarativeScript::Value *value,
const QDeclarativeCompilerTypes::BindingContext &ctxt);
- bool buildPropertyOnAssignment(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj,
- QDeclarativeParser::Object *baseObj,
- QDeclarativeParser::Value *value,
+ bool buildPropertyOnAssignment(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj,
+ QDeclarativeScript::Object *baseObj,
+ QDeclarativeScript::Value *value,
const QDeclarativeCompilerTypes::BindingContext &ctxt);
- bool buildPropertyLiteralAssignment(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj,
- QDeclarativeParser::Value *value,
+ bool buildPropertyLiteralAssignment(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj,
+ QDeclarativeScript::Value *value,
const QDeclarativeCompilerTypes::BindingContext &ctxt);
- bool doesPropertyExist(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj);
- bool testLiteralAssignment(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Value *value);
+ bool doesPropertyExist(QDeclarativeScript::Property *prop, QDeclarativeScript::Object *obj);
+ bool testLiteralAssignment(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Value *value);
bool testQualifiedEnumAssignment(const QMetaProperty &prop,
- QDeclarativeParser::Object *obj,
- QDeclarativeParser::Value *value,
+ QDeclarativeScript::Object *obj,
+ QDeclarativeScript::Value *value,
bool *isAssignment);
enum DynamicMetaMode { IgnoreAliases, ResolveAliases, ForceCreation };
- bool mergeDynamicMetaProperties(QDeclarativeParser::Object *obj);
- bool buildDynamicMeta(QDeclarativeParser::Object *obj, DynamicMetaMode mode);
- bool checkDynamicMeta(QDeclarativeParser::Object *obj);
- bool buildBinding(QDeclarativeParser::Value *, QDeclarativeParser::Property *prop,
+ bool mergeDynamicMetaProperties(QDeclarativeScript::Object *obj);
+ bool buildDynamicMeta(QDeclarativeScript::Object *obj, DynamicMetaMode mode);
+ bool checkDynamicMeta(QDeclarativeScript::Object *obj);
+ bool buildBinding(QDeclarativeScript::Value *, QDeclarativeScript::Property *prop,
const QDeclarativeCompilerTypes::BindingContext &ctxt);
- bool buildComponentFromRoot(QDeclarativeParser::Object *obj, const QDeclarativeCompilerTypes::BindingContext &);
+ bool buildComponentFromRoot(QDeclarativeScript::Object *obj, const QDeclarativeCompilerTypes::BindingContext &);
bool compileAlias(QFastMetaBuilder &,
QByteArray &data,
- QDeclarativeParser::Object *obj,
+ QDeclarativeScript::Object *obj,
int propIndex, int aliasIndex,
- QDeclarativeParser::Object::DynamicProperty &);
+ QDeclarativeScript::Object::DynamicProperty &);
bool completeComponentBuild();
- bool checkValidId(QDeclarativeParser::Value *, const QString &);
-
-
- void genObject(QDeclarativeParser::Object *obj);
- void genObjectBody(QDeclarativeParser::Object *obj);
- void genValueTypeProperty(QDeclarativeParser::Object *obj,QDeclarativeParser::Property *);
- void genComponent(QDeclarativeParser::Object *obj);
- void genValueProperty(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj);
- void genListProperty(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj);
- void genPropertyAssignment(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj,
- QDeclarativeParser::Property *valueTypeProperty = 0);
- void genLiteralAssignment(QDeclarativeParser::Property *prop,
- QDeclarativeParser::Value *value);
- void genBindingAssignment(QDeclarativeParser::Value *binding,
- QDeclarativeParser::Property *prop,
- QDeclarativeParser::Object *obj,
- QDeclarativeParser::Property *valueTypeProperty = 0);
+ bool checkValidId(QDeclarativeScript::Value *, const QString &);
+
+
+ void genObject(QDeclarativeScript::Object *obj);
+ void genObjectBody(QDeclarativeScript::Object *obj);
+ void genValueTypeProperty(QDeclarativeScript::Object *obj,QDeclarativeScript::Property *);
+ void genComponent(QDeclarativeScript::Object *obj);
+ void genValueProperty(QDeclarativeScript::Property *prop, QDeclarativeScript::Object *obj);
+ void genListProperty(QDeclarativeScript::Property *prop, QDeclarativeScript::Object *obj);
+ void genPropertyAssignment(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj,
+ QDeclarativeScript::Property *valueTypeProperty = 0);
+ void genLiteralAssignment(QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Value *value);
+ void genBindingAssignment(QDeclarativeScript::Value *binding,
+ QDeclarativeScript::Property *prop,
+ QDeclarativeScript::Object *obj,
+ QDeclarativeScript::Property *valueTypeProperty = 0);
int genContextCache();
- int genValueTypeData(QDeclarativeParser::Property *prop, QDeclarativeParser::Property *valueTypeProp);
- int genPropertyData(QDeclarativeParser::Property *prop);
+ int genValueTypeData(QDeclarativeScript::Property *prop, QDeclarativeScript::Property *valueTypeProp);
+ int genPropertyData(QDeclarativeScript::Property *prop);
int componentTypeRef();
- static QDeclarativeType *toQmlType(QDeclarativeParser::Object *from);
- bool canCoerce(int to, QDeclarativeParser::Object *from);
+ static QDeclarativeType *toQmlType(QDeclarativeScript::Object *from);
+ bool canCoerce(int to, QDeclarativeScript::Object *from);
- QString elementName(QDeclarativeParser::Object *);
+ QString elementName(QDeclarativeScript::Object *);
- QStringList deferredProperties(QDeclarativeParser::Object *);
+ QStringList deferredProperties(QDeclarativeScript::Object *);
- QDeclarativePropertyCache::Data *property(QDeclarativeParser::Object *, int);
- QDeclarativePropertyCache::Data *property(QDeclarativeParser::Object *, const QHashedStringRef &,
+ QDeclarativePropertyCache::Data *property(QDeclarativeScript::Object *, int);
+ QDeclarativePropertyCache::Data *property(QDeclarativeScript::Object *, const QHashedStringRef &,
bool *notInRevision = 0);
- QDeclarativePropertyCache::Data *signal(QDeclarativeParser::Object *, const QHashedStringRef &,
+ QDeclarativePropertyCache::Data *signal(QDeclarativeScript::Object *, const QHashedStringRef &,
bool *notInRevision = 0);
- int indexOfProperty(QDeclarativeParser::Object *, const QHashedStringRef &, bool *notInRevision = 0);
- int indexOfProperty(QDeclarativeParser::Object *, const QString &, bool *notInRevision = 0);
- int indexOfSignal(QDeclarativeParser::Object *, const QString &, bool *notInRevision = 0);
+ int indexOfProperty(QDeclarativeScript::Object *, const QHashedStringRef &, bool *notInRevision = 0);
+ int indexOfProperty(QDeclarativeScript::Object *, const QString &, bool *notInRevision = 0);
+ int indexOfSignal(QDeclarativeScript::Object *, const QString &, bool *notInRevision = 0);
- void addId(const QString &, QDeclarativeParser::Object *);
+ void addId(const QString &, QDeclarativeScript::Object *);
void dumpStats();
QDeclarativePool *pool;
- QDeclarativeCompilerTypes::ComponentCompileState *componentState(QDeclarativeParser::Object *);
+ QDeclarativeCompilerTypes::ComponentCompileState *componentState(QDeclarativeScript::Object *);
void saveComponentState();
QList<QDeclarativeError> exceptions;
QDeclarativeCompiledData *output;
QDeclarativeEngine *engine;
QDeclarativeEnginePrivate *enginePrivate;
- QDeclarativeParser::Object *unitRoot;
+ QDeclarativeScript::Object *unitRoot;
QDeclarativeTypeData *unit;
int lineNumber;
int ids;
- QList<QDeclarativeParser::LocationSpan> scriptBindings;
- QList<QDeclarativeParser::LocationSpan> optimizedBindings;
+ QList<QDeclarativeScript::LocationSpan> scriptBindings;
+ QList<QDeclarativeScript::LocationSpan> optimizedBindings;
int objects;
};
struct ComponentStats : public QDeclarativePool::Class
#include "private/qdeclarativebinding_p.h"
#include "private/qdeclarativebinding_p_p.h"
#include "private/qdeclarativeglobal_p.h"
-#include "private/qdeclarativescriptparser_p.h"
+#include "private/qdeclarativescript_p.h"
#include "private/qdeclarativedebugtrace_p.h"
#include "private/qdeclarativeenginedebug_p.h"
#include "private/qdeclarativetypenamecache_p.h"
#include "private/qdeclarativenotifier_p.h"
#include "qdeclarativelist.h"
-#include "private/qdeclarativeparser_p.h"
+#include "private/qdeclarativescript_p.h"
#include <QtCore/qhash.h>
#include <QtDeclarative/qjsvalue.h>
#include "private/qdeclarativecustomparser_p.h"
#include "private/qdeclarativecustomparser_p_p.h"
-#include "private/qdeclarativeparser_p.h"
#include "private/qdeclarativecompiler_p.h"
#include <QtCore/qdebug.h>
QT_BEGIN_NAMESPACE
-using namespace QDeclarativeParser;
+using namespace QDeclarativeScript;
/*!
\class QDeclarativeCustomParser
*/
QDeclarativeCustomParserNode
-QDeclarativeCustomParserNodePrivate::fromObject(QDeclarativeParser::Object *root)
+QDeclarativeCustomParserNodePrivate::fromObject(QDeclarativeScript::Object *root)
{
QDeclarativeCustomParserNode rootNode;
rootNode.d->name = root->typeName;
}
QDeclarativeCustomParserProperty
-QDeclarativeCustomParserNodePrivate::fromProperty(QDeclarativeParser::Property *p)
+QDeclarativeCustomParserNodePrivate::fromProperty(QDeclarativeScript::Property *p)
{
QDeclarativeCustomParserProperty prop;
prop.d->name = p->name().toUtf8();
for (int ii = 0; ii < props.count(); ++ii)
prop.d->values << QVariant::fromValue(props.at(ii));
} else {
- for (QDeclarativeParser::Value *v = p->values.first(); v; v = p->values.next(v)) {
- v->type = QDeclarativeParser::Value::Literal;
+ for (QDeclarativeScript::Value *v = p->values.first(); v; v = p->values.next(v)) {
+ v->type = QDeclarativeScript::Value::Literal;
if(v->object) {
QDeclarativeCustomParserNode node = fromObject(v->object);
return d->properties;
}
-QDeclarativeParser::Location QDeclarativeCustomParserNode::location() const
+QDeclarativeScript::Location QDeclarativeCustomParserNode::location() const
{
return d->location;
}
return d->isList;
}
-QDeclarativeParser::Location QDeclarativeCustomParserProperty::location() const
+QDeclarativeScript::Location QDeclarativeCustomParserProperty::location() const
{
return d->location;
}
#include "private/qdeclarativemetatype_p.h"
#include "qdeclarativeerror.h"
-#include "private/qdeclarativeparser_p.h"
+#include "private/qdeclarativescript_p.h"
#include "private/qdeclarativebinding_p.h"
#include <QtCore/qbytearray.h>
~QDeclarativeCustomParserProperty();
QByteArray name() const;
- QDeclarativeParser::Location location() const;
+ QDeclarativeScript::Location location() const;
bool isList() const;
- // Will be one of QDeclarativeParser::Variant, QDeclarativeCustomParserProperty or
+ // Will be one of QDeclarativeScript::Variant, QDeclarativeCustomParserProperty or
// QDeclarativeCustomParserNode
QList<QVariant> assignedValues() const;
~QDeclarativeCustomParserNode();
QByteArray name() const;
- QDeclarativeParser::Location location() const;
+ QDeclarativeScript::Location location() const;
QList<QDeclarativeCustomParserProperty> properties() const;
private:
QList<QDeclarativeError> exceptions;
QDeclarativeCompiler *compiler;
- QDeclarativeParser::Object *object;
+ QDeclarativeScript::Object *object;
Flags m_flags;
friend class QDeclarativeCompiler;
};
#include "private/qdeclarativecustomparser_p.h"
-#include "private/qdeclarativeparser_p.h"
+#include "private/qdeclarativescript_p.h"
#include <QtCore/qglobal.h>
public:
QByteArray name;
QList<QDeclarativeCustomParserProperty> properties;
- QDeclarativeParser::Location location;
+ QDeclarativeScript::Location location;
- static QDeclarativeCustomParserNode fromObject(QDeclarativeParser::Object *);
- static QDeclarativeCustomParserProperty fromProperty(QDeclarativeParser::Property *);
+ static QDeclarativeCustomParserNode fromObject(QDeclarativeScript::Object *);
+ static QDeclarativeCustomParserProperty fromProperty(QDeclarativeScript::Property *);
};
class QDeclarativeCustomParserPropertyPrivate
QByteArray name;
bool isList;
- QDeclarativeParser::Location location;
+ QDeclarativeScript::Location location;
QList<QVariant> values;
};
QString resolvedUri(const QString &dir_arg, QDeclarativeImportDatabase *database);
bool add(const QDeclarativeDirComponents &qmldircomponentsnetwork,
const QString& uri_arg, const QString& prefix,
- int vmaj, int vmin, QDeclarativeScriptParser::Import::Type importType,
+ int vmaj, int vmin, QDeclarativeScript::Import::Type importType,
QDeclarativeImportDatabase *database, QList<QDeclarativeError> *errors);
bool find(const QString& type, int *vmajor, int *vminor,
QDeclarativeType** type_return, QString* url_return, QList<QDeclarativeError> *errors);
bool QDeclarativeImportsPrivate::add(const QDeclarativeDirComponents &qmldircomponentsnetwork,
const QString& uri_arg, const QString& prefix, int vmaj, int vmin,
- QDeclarativeScriptParser::Import::Type importType,
+ QDeclarativeScript::Import::Type importType,
QDeclarativeImportDatabase *database, QList<QDeclarativeError> *errors)
{
static QLatin1String Slash_qmldir("/qmldir");
}
QString url = uri;
bool versionFound = false;
- if (importType == QDeclarativeScriptParser::Import::Library) {
+ if (importType == QDeclarativeScript::Import::Library) {
Q_ASSERT(vmaj >= 0 && vmin >= 0); // Versions are always specified for libraries
return false;
}
} else {
- if (importType == QDeclarativeScriptParser::Import::File && qmldircomponents.isEmpty()) {
+ if (importType == QDeclarativeScript::Import::File && qmldircomponents.isEmpty()) {
QString importUrl = resolveLocalUrl(base, uri + Slash_qmldir);
QString localFileOrQrc = QDeclarativeEnginePrivate::urlToLocalFileOrQrc(importUrl);
if (!localFileOrQrc.isEmpty()) {
data.url = url;
data.majversion = vmaj;
data.minversion = vmin;
- data.isLibrary = importType == QDeclarativeScriptParser::Import::Library;
+ data.isLibrary = importType == QDeclarativeScript::Import::Library;
data.qmlDirComponents = qmldircomponents;
s->imports.prepend(data);
*/
bool QDeclarativeImports::addImport(QDeclarativeImportDatabase *importDb,
const QString& uri, const QString& prefix, int vmaj, int vmin,
- QDeclarativeScriptParser::Import::Type importType,
+ QDeclarativeScript::Import::Type importType,
const QDeclarativeDirComponents &qmldircomponentsnetwork,
QList<QDeclarativeError> *errors)
{
if (qmlImportTrace())
qDebug().nospace() << "QDeclarativeImports(" << qPrintable(baseUrl().toString()) << ")" << "::addImport: "
<< uri << " " << vmaj << '.' << vmin << " "
- << (importType==QDeclarativeScriptParser::Import::Library? "Library" : "File")
+ << (importType==QDeclarativeScript::Import::Library? "Library" : "File")
<< " as " << prefix;
return d->add(qmldircomponentsnetwork, uri, prefix, vmaj, vmin, importType, importDb, errors);
#include <QtCore/qurl.h>
#include <QtCore/qcoreapplication.h>
#include <QtCore/qset.h>
+#include <QtCore/qstringlist.h>
#include <private/qdeclarativedirparser_p.h>
-#include <private/qdeclarativescriptparser_p.h>
+#include <private/qdeclarativescript_p.h>
#include <private/qdeclarativemetatype_p.h>
//
bool addImport(QDeclarativeImportDatabase *,
const QString& uri, const QString& prefix, int vmaj, int vmin,
- QDeclarativeScriptParser::Import::Type importType,
+ QDeclarativeScript::Import::Type importType,
const QDeclarativeDirComponents &qmldircomponentsnetwork,
QList<QDeclarativeError> *errors);
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtDeclarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** GNU Lesser General Public License Usage
-** This file may be used under the terms of the GNU Lesser General Public
-** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this
-** file. Please review the following information to ensure the GNU Lesser
-** General Public License version 2.1 requirements will be met:
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU General
-** Public License version 3.0 as published by the Free Software Foundation
-** and appearing in the file LICENSE.GPL included in the packaging of this
-** file. Please review the following information to ensure the GNU General
-** Public License version 3.0 requirements will be met:
-** http://www.gnu.org/copyleft/gpl.html.
-**
-** Other Usage
-** Alternatively, this file may be used in accordance with the terms and
-** conditions contained in a signed written agreement between you and Nokia.
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "private/qdeclarativeparser_p.h"
-
-#include "qdeclarativepropertyvaluesource.h"
-#include "private/qdeclarativevme_p.h"
-#include "qdeclarative.h"
-#include "private/qdeclarativecomponent_p.h"
-#include "qdeclarativecomponent.h"
-#include "private/qmetaobjectbuilder_p.h"
-#include "private/qdeclarativevmemetaobject_p.h"
-#include "private/qdeclarativecompiler_p.h"
-#include "parser/qdeclarativejsast_p.h"
-#include "parser/qdeclarativejsengine_p.h"
-
-#include <QStack>
-#include <QColor>
-#include <QPointF>
-#include <QSizeF>
-#include <QRectF>
-#include <QStringBuilder>
-#include <QtDebug>
-
-QT_BEGIN_NAMESPACE
-
-using namespace QDeclarativeJS;
-using namespace QDeclarativeParser;
-
-QDeclarativeParser::Object::Object()
-: type(-1), idIndex(-1), metatype(0), synthCache(0), defaultProperty(0), parserStatusCast(-1),
- componentCompileState(0), nextAliasingObject(0), nextIdObject(0)
-{
-}
-
-QDeclarativeParser::Object::~Object()
-{
- if (synthCache) synthCache->release();
-}
-
-void Object::setBindingBit(int b)
-{
- while (bindingBitmask.size() < 4 * (1 + b / 32))
- bindingBitmask.append(char(0));
-
- quint32 *bits = (quint32 *)bindingBitmask.data();
- bits[b / 32] |= (1 << (b % 32));
-}
-
-const QMetaObject *Object::metaObject() const
-{
- if (!metadata.isEmpty() && metatype)
- return &extObject;
- else
- return metatype;
-}
-
-QDeclarativeParser::Property *Object::getDefaultProperty()
-{
- if (!defaultProperty) {
- defaultProperty = pool()->New<Property>();
- defaultProperty->parent = this;
- }
- return defaultProperty;
-}
-
-void QDeclarativeParser::Object::addValueProperty(Property *p)
-{
- valueProperties.append(p);
-}
-
-void QDeclarativeParser::Object::addSignalProperty(Property *p)
-{
- signalProperties.append(p);
-}
-
-void QDeclarativeParser::Object::addAttachedProperty(Property *p)
-{
- attachedProperties.append(p);
-}
-
-void QDeclarativeParser::Object::addGroupedProperty(Property *p)
-{
- groupedProperties.append(p);
-}
-
-void QDeclarativeParser::Object::addValueTypeProperty(Property *p)
-{
- valueTypeProperties.append(p);
-}
-
-void QDeclarativeParser::Object::addScriptStringProperty(Property *p)
-{
- scriptStringProperties.append(p);
-}
-
-// This lookup is optimized for missing, and having to create a new property.
-Property *QDeclarativeParser::Object::getProperty(const QHashedStringRef &name, bool create)
-{
- if (create) {
- quint32 h = name.hash();
- if (propertiesHashField.testAndSet(h)) {
- for (Property *p = properties.first(); p; p = properties.next(p)) {
- if (p->name() == name)
- return p;
- }
- }
-
- Property *property = pool()->New<Property>();
- property->parent = this;
- property->_name = name;
- property->isDefault = false;
- properties.prepend(property);
- return property;
- } else {
- for (Property *p = properties.first(); p; p = properties.next(p)) {
- if (p->name() == name)
- return p;
- }
- }
-}
-
-Property *QDeclarativeParser::Object::getProperty(const QStringRef &name, bool create)
-{
- return getProperty(QHashedStringRef(name), create);
-}
-
-Property *QDeclarativeParser::Object::getProperty(const QString &name, bool create)
-{
- for (Property *p = properties.first(); p; p = properties.next(p)) {
- if (p->name() == name)
- return p;
- }
-
- if (create) {
- Property *property = pool()->New<Property>();
- property->parent = this;
- property->_name = QStringRef(pool()->NewString(name));
- propertiesHashField.testAndSet(property->_name.hash());
- property->isDefault = false;
- properties.prepend(property);
- return property;
- } else {
- return 0;
- }
-}
-
-QDeclarativeParser::Object::DynamicProperty::DynamicProperty()
-: isDefaultProperty(false), type(Variant), defaultValue(0), nextProperty(0),
- resolvedCustomTypeName(0)
-{
-}
-
-QDeclarativeParser::Object::DynamicSignal::DynamicSignal()
-: nextSignal(0)
-{
-}
-
-// Returns length in utf8 bytes
-int QDeclarativeParser::Object::DynamicSignal::parameterTypesLength() const
-{
- int rv = 0;
- for (int ii = 0; ii < parameterTypes.count(); ++ii)
- rv += parameterTypes.at(ii).length();
- return rv;
-}
-
-// Returns length in utf8 bytes
-int QDeclarativeParser::Object::DynamicSignal::parameterNamesLength() const
-{
- int rv = 0;
- for (int ii = 0; ii < parameterNames.count(); ++ii)
- rv += parameterNames.at(ii).utf8length();
- return rv;
-}
-
-QDeclarativeParser::Object::DynamicSlot::DynamicSlot()
-: nextSlot(0)
-{
-}
-
-int QDeclarativeParser::Object::DynamicSlot::parameterNamesLength() const
-{
- int rv = 0;
- for (int ii = 0; ii < parameterNames.count(); ++ii)
- rv += parameterNames.at(ii).length();
- return rv;
-}
-
-QDeclarativeParser::Property::Property()
-: parent(0), type(0), index(-1), value(0), isDefault(true), isDeferred(false),
- isValueTypeSubProperty(false), isAlias(false), scriptStringScope(-1), nextMainProperty(0),
- nextProperty(0)
-{
-}
-
-QDeclarativeParser::Object *QDeclarativeParser::Property::getValue(const LocationSpan &l)
-{
- if (!value) { value = pool()->New<Object>(); value->location = l; }
- return value;
-}
-
-void QDeclarativeParser::Property::addValue(Value *v)
-{
- values.append(v);
-}
-
-void QDeclarativeParser::Property::addOnValue(Value *v)
-{
- onValues.append(v);
-}
-
-bool QDeclarativeParser::Property::isEmpty() const
-{
- return !value && values.isEmpty() && onValues.isEmpty();
-}
-
-QDeclarativeParser::Value::Value()
-: type(Unknown), object(0), bindingReference(0), signalExpressionContextStack(0), nextValue(0)
-{
-}
-
-QDeclarativeParser::Variant::Variant()
-: t(Invalid)
-{
-}
-
-QDeclarativeParser::Variant::Variant(const Variant &o)
-: t(o.t), d(o.d), asWritten(o.asWritten)
-{
-}
-
-QDeclarativeParser::Variant::Variant(bool v)
-: t(Boolean), b(v)
-{
-}
-
-QDeclarativeParser::Variant::Variant(double v, const QStringRef &asWritten)
-: t(Number), d(v), asWritten(asWritten)
-{
-}
-
-QDeclarativeParser::Variant::Variant(QDeclarativeJS::AST::StringLiteral *v)
-: t(String), l(v)
-{
-}
-
-QDeclarativeParser::Variant::Variant(const QStringRef &asWritten, QDeclarativeJS::AST::Node *n)
-: t(Script), n(n), asWritten(asWritten)
-{
-}
-
-QDeclarativeParser::Variant &QDeclarativeParser::Variant::operator=(const Variant &o)
-{
- t = o.t;
- d = o.d;
- asWritten = o.asWritten;
- return *this;
-}
-
-QDeclarativeParser::Variant::Type QDeclarativeParser::Variant::type() const
-{
- return t;
-}
-
-bool QDeclarativeParser::Variant::asBoolean() const
-{
- return b;
-}
-
-QString QDeclarativeParser::Variant::asString() const
-{
- if (t == String) {
- // XXX aakenned
- return l->value.toString();
- } else {
- return asWritten.toString();
- }
-}
-
-double QDeclarativeParser::Variant::asNumber() const
-{
- return d;
-}
-
-//reverse of Lexer::singleEscape()
-QString escapedString(const QString &string)
-{
- QString tmp = QLatin1String("\"");
- for (int i = 0; i < string.length(); ++i) {
- const QChar &c = string.at(i);
- switch(c.unicode()) {
- case 0x08:
- tmp += QLatin1String("\\b");
- break;
- case 0x09:
- tmp += QLatin1String("\\t");
- break;
- case 0x0A:
- tmp += QLatin1String("\\n");
- break;
- case 0x0B:
- tmp += QLatin1String("\\v");
- break;
- case 0x0C:
- tmp += QLatin1String("\\f");
- break;
- case 0x0D:
- tmp += QLatin1String("\\r");
- break;
- case 0x22:
- tmp += QLatin1String("\\\"");
- break;
- case 0x27:
- tmp += QLatin1String("\\\'");
- break;
- case 0x5C:
- tmp += QLatin1String("\\\\");
- break;
- default:
- tmp += c;
- break;
- }
- }
- tmp += QLatin1Char('\"');
- return tmp;
-}
-
-QString QDeclarativeParser::Variant::asScript() const
-{
- switch(type()) {
- default:
- case Invalid:
- return QString();
- case Boolean:
- return b?QLatin1String("true"):QLatin1String("false");
- case Number:
- if (asWritten.isEmpty())
- return QString::number(d);
- else
- return asWritten.toString();
- case String:
- return escapedString(asString());
- case Script:
- if (AST::IdentifierExpression *i = AST::cast<AST::IdentifierExpression *>(n)) {
- // XXX aakenned
- return i->name.toString();
- } else
- return asWritten.toString();
- }
-}
-
-QDeclarativeJS::AST::Node *QDeclarativeParser::Variant::asAST() const
-{
- if (type() == Script)
- return n;
- else
- return 0;
-}
-
-bool QDeclarativeParser::Variant::isStringList() const
-{
- if (isString())
- return true;
-
- if (type() != Script || !n)
- return false;
-
- AST::ArrayLiteral *array = AST::cast<AST::ArrayLiteral *>(n);
- if (!array)
- return false;
-
- AST::ElementList *elements = array->elements;
-
- while (elements) {
-
- if (!AST::cast<AST::StringLiteral *>(elements->expression))
- return false;
-
- elements = elements->next;
- }
-
- return true;
-}
-
-QStringList QDeclarativeParser::Variant::asStringList() const
-{
- QStringList rv;
- if (isString()) {
- rv << asString();
- return rv;
- }
-
- AST::ArrayLiteral *array = AST::cast<AST::ArrayLiteral *>(n);
- if (!array)
- return rv;
-
- AST::ElementList *elements = array->elements;
- while (elements) {
-
- AST::StringLiteral *string = AST::cast<AST::StringLiteral *>(elements->expression);
- if (!string)
- return QStringList();
- rv.append(string->value.toString());
-
- elements = elements->next;
- }
-
- return rv;
-}
-
-QT_END_NAMESPACE
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtDeclarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** GNU Lesser General Public License Usage
-** This file may be used under the terms of the GNU Lesser General Public
-** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this
-** file. Please review the following information to ensure the GNU Lesser
-** General Public License version 2.1 requirements will be met:
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU General
-** Public License version 3.0 as published by the Free Software Foundation
-** and appearing in the file LICENSE.GPL included in the packaging of this
-** file. Please review the following information to ensure the GNU General
-** Public License version 3.0 requirements will be met:
-** http://www.gnu.org/copyleft/gpl.html.
-**
-** Other Usage
-** Alternatively, this file may be used in accordance with the terms and
-** conditions contained in a signed written agreement between you and Nokia.
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QDECLARATIVEPARSER_P_H
-#define QDECLARATIVEPARSER_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qdeclarative.h"
-
-#include <QtCore/qbytearray.h>
-#include <QtCore/qlist.h>
-#include <QtCore/qurl.h>
-#include <QtCore/qstring.h>
-#include <QtCore/qstringlist.h>
-
-#include <private/qobject_p.h>
-#include <private/qdeclarativerefcount_p.h>
-#include <private/qdeclarativeglobal_p.h>
-#include <private/qdeclarativepool_p.h>
-#include <private/qfieldlist_p.h>
-#include <private/qdeclarativepropertycache_p.h>
-#include <private/qfastmetabuilder_p.h>
-#include <private/qhashedstring_p.h>
-#include <private/qhashfield_p.h>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-class QDeclarativePropertyCache;
-namespace QDeclarativeJS { namespace AST { class Node; class StringLiteral; } }
-namespace QDeclarativeCompilerTypes { class BindingReference; class ComponentCompileState; }
-
-/*
- XXX
-
- These types are created (and owned) by the QDeclarativeScriptParser and consumed by the
- QDeclarativeCompiler. During the compilation phase the compiler will update some of
- the fields for its own use.
-
- The types are part of the generic sounding "QDeclarativeParser" namespace for legacy
- reasons (there used to be more in this namespace) and will be cleaned up and
- migrated into a more appropriate location eventually.
-*/
-namespace QDeclarativeParser
-{
- struct Location
- {
- Location() : line(-1), column(-1) {}
- int line;
- int column;
-
- inline bool operator<(const Location &other) {
- return line < other.line ||
- (line == other.line && column < other.column);
- }
- };
-
- struct LocationRange
- {
- LocationRange() : offset(0), length(0) {}
- quint32 offset;
- quint32 length;
- };
-
- struct LocationSpan
- {
- Location start;
- Location end;
- LocationRange range;
-
- bool operator<(LocationSpan &o) const {
- return (start.line < o.start.line) ||
- (start.line == o.start.line && start.column < o.start.column);
- }
- };
-
- class Object;
- class Property;
- class Q_DECLARATIVE_EXPORT Variant
- {
- public:
- enum Type {
- Invalid,
- Boolean,
- Number,
- String,
- Script
- };
-
- Variant();
- Variant(const Variant &);
- explicit Variant(bool);
- explicit Variant(double, const QStringRef &asWritten = QStringRef());
- explicit Variant(QDeclarativeJS::AST::StringLiteral *);
- explicit Variant(const QStringRef &asWritten, QDeclarativeJS::AST::Node *);
- Variant &operator=(const Variant &);
-
- Type type() const;
-
- bool isBoolean() const { return type() == Boolean; }
- bool isNumber() const { return type() == Number; }
- bool isString() const { return type() == String; }
- bool isScript() const { return type() == Script; }
- bool isStringList() const;
-
- bool asBoolean() const;
- QString asString() const;
- double asNumber() const;
- QString asScript() const;
- QDeclarativeJS::AST::Node *asAST() const;
- QStringList asStringList() const;
-
- private:
- Type t;
- union {
- bool b;
- double d;
- QDeclarativeJS::AST::StringLiteral *l;
- QDeclarativeJS::AST::Node *n;
- };
- QStringRef asWritten;
- };
-
- class Value : public QDeclarativePool::POD
- {
- public:
- Value();
-
- enum Type {
- // The type of this value assignment is not yet known
- Unknown,
- // This is used as a literal property assignment
- Literal,
- // This is used as a property binding assignment
- PropertyBinding,
- // This is used as a QDeclarativePropertyValueSource assignment
- ValueSource,
- // This is used as a QDeclarativePropertyValueInterceptor assignment
- ValueInterceptor,
- // This is used as a property QObject assignment
- CreatedObject,
- // This is used as a signal object assignment
- SignalObject,
- // This is used as a signal expression assignment
- SignalExpression,
- // This is used as an id assignment only
- Id
- };
- Type type;
-
- // ### Temporary (for id only)
- QString primitive() const { return value.isString() ? value.asString() : value.asScript(); }
-
- // Primitive value
- Variant value;
- // Object value
- Object *object;
-
- LocationSpan location;
-
- // Used by compiler
- QDeclarativeCompilerTypes::BindingReference *bindingReference;
- int signalExpressionContextStack;
-
- // Used in Property::ValueList lists
- Value *nextValue;
- };
-
- class Property : public QDeclarativePool::POD
- {
- public:
- Property();
-
- // The Object to which this property is attached
- Object *parent;
-
- Object *getValue(const LocationSpan &);
- void addValue(Value *v);
- void addOnValue(Value *v);
-
- // The QVariant::Type of the property, or 0 (QVariant::Invalid) if
- // unknown.
- int type;
- // The metaobject index of this property, or -1 if unknown.
- int index;
- // The core data in the case of a regular property.
- // XXX This has to be a value now as the synthCache may change during
- // compilation which invalidates pointers. We should fix this.
- QDeclarativePropertyCache::Data core;
-
- // Returns true if this is an empty property - both value and values
- // are unset.
- bool isEmpty() const;
-
- typedef QFieldList<Value, &Value::nextValue> ValueList;
- // The list of values assigned to this property. Content in values
- // and value are mutually exclusive
- ValueList values;
- // The list of values assigned to this property using the "on" syntax
- ValueList onValues;
- // The accessed property. This is used to represent dot properties.
- // Content in value and values are mutually exclusive.
- Object *value;
- // The property name
- const QHashedStringRef &name() const { return _name; }
- void setName(const QString &n) { _name = QHashedStringRef(pool()->NewString(n)); }
- void setName(const QHashedStringRef &n) { _name = n; }
- // True if this property was accessed as the default property.
- bool isDefault;
- // True if the setting of this property will be deferred. Set by the
- // QDeclarativeCompiler
- bool isDeferred;
- // True if this property is a value-type pseudo-property
- bool isValueTypeSubProperty;
- // True if this property is a property alias. Set by the
- // QDeclarativeCompiler
- bool isAlias;
-
- // Used for scriptStringProperties
- int scriptStringScope;
-
- LocationSpan location;
- LocationRange listValueRange;
-
- // Used in Object::MainPropertyList
- Property *nextMainProperty;
-
- // Used in Object::PropertyList lists
- Property *nextProperty;
-
- private:
- friend class Object;
- QHashedStringRef _name;
- };
-
- class Object : public QDeclarativePool::Class
- {
- public:
- Object();
- virtual ~Object();
-
- // Type of the object. The integer is an index into the
- // QDeclarativeCompiledData::types array, or -1 if the object is a property
- // group.
- int type;
-
- // The fully-qualified name of this type
- QByteArray typeName;
- // The id assigned to the object (if any). Set by the QDeclarativeCompiler
- QString id;
- // The id index assigned to the object (if any). Set by the QDeclarativeCompiler
- int idIndex;
- // Custom parsed data
- QByteArray custom;
- // Bit mask of the properties assigned bindings
- QByteArray bindingBitmask;
- void setBindingBit(int);
- // Returns the metaobject for this type, or 0 if not available.
- // Internally selectd between the metatype and extObject variables
- const QMetaObject *metaObject() const;
-
- // The compile time metaobject for this type
- const QMetaObject *metatype;
- // The synthesized metaobject, if QML added signals or properties to
- // this type. Otherwise null
- QAbstractDynamicMetaObject extObject;
- QByteArray metadata; // Generated by compiler
- QByteArray synthdata; // Generated by compiler
- QDeclarativePropertyCache *synthCache; // Generated by compiler
-
- Property *getDefaultProperty();
- // name ptr must be guarenteed to remain valid
- Property *getProperty(const QHashedStringRef &name, bool create=true);
- Property *getProperty(const QStringRef &name, bool create=true);
- Property *getProperty(const QString &name, bool create=true);
-
- Property *defaultProperty;
-
- typedef QFieldList<Property, &Property::nextMainProperty> MainPropertyList;
- MainPropertyList properties;
- QHashField propertiesHashField;
-
- // Output of the compilation phase (these properties continue to exist
- // in either the defaultProperty or properties members too)
- void addValueProperty(Property *);
- void addSignalProperty(Property *);
- void addAttachedProperty(Property *);
- void addGroupedProperty(Property *);
- void addValueTypeProperty(Property *);
- void addScriptStringProperty(Property *);
-
- typedef QFieldList<Property, &Property::nextProperty> PropertyList;
- PropertyList valueProperties;
- PropertyList signalProperties;
- PropertyList attachedProperties;
- PropertyList groupedProperties;
- PropertyList valueTypeProperties;
- PropertyList scriptStringProperties;
-
- // Script blocks that were nested under this object
- struct ScriptBlock {
- enum Pragma {
- None = 0x00000000,
- Shared = 0x00000001
- };
- Q_DECLARE_FLAGS(Pragmas, Pragma)
-
- QString code;
- QString file;
- Pragmas pragmas;
- };
-
- // The bytes to cast instances by to get to the QDeclarativeParserStatus
- // interface. -1 indicates the type doesn't support this interface.
- // Set by the QDeclarativeCompiler.
- int parserStatusCast;
-
- LocationSpan location;
-
- struct DynamicProperty : public QDeclarativePool::POD
- {
- DynamicProperty();
-
- enum Type { Variant, Int, Bool, Real, String, Url, Color, Time,
- Date, DateTime, Alias, Custom, CustomList };
-
- bool isDefaultProperty;
- Type type;
-
- QHashedStringRef customType;
- QHashedStringRef name;
- QDeclarativeParser::Property *defaultValue;
- LocationSpan location;
-
- // Used by Object::DynamicPropertyList
- DynamicProperty *nextProperty;
-
- // Used by the compiler
- QByteArray *resolvedCustomTypeName;
- QFastMetaBuilder::StringRef typeRef;
- QFastMetaBuilder::StringRef nameRef;
- QFastMetaBuilder::StringRef changedSignatureRef;
- };
-
- struct DynamicSignal : public QDeclarativePool::POD
- {
- DynamicSignal();
-
- QHashedStringRef name;
- QDeclarativePool::List<QHashedCStringRef> parameterTypes;
- QDeclarativePool::List<QHashedStringRef> parameterNames;
-
- int parameterTypesLength() const;
- int parameterNamesLength() const;
-
- // Used by Object::DynamicSignalList
- DynamicSignal *nextSignal;
-
- // Used by the compiler
- QFastMetaBuilder::StringRef signatureRef;
- QFastMetaBuilder::StringRef parameterNamesRef;
- };
-
- struct DynamicSlot : public QDeclarativePool::Class
- {
- DynamicSlot();
-
- QHashedStringRef name;
- QString body;
- QList<QByteArray> parameterNames;
- LocationSpan location;
-
- int parameterNamesLength() const;
-
- // Used by Object::DynamicSlotList
- DynamicSlot *nextSlot;
-
- // Used by the compiler
- QFastMetaBuilder::StringRef signatureRef;
- QFastMetaBuilder::StringRef parameterNamesRef;
- };
-
- // The list of dynamic properties
- typedef QFieldList<DynamicProperty, &DynamicProperty::nextProperty> DynamicPropertyList;
- DynamicPropertyList dynamicProperties;
- // The list of dynamic signals
- typedef QFieldList<DynamicSignal, &DynamicSignal::nextSignal> DynamicSignalList;
- DynamicSignalList dynamicSignals;
- // The list of dynamic slots
- typedef QFieldList<DynamicSlot, &DynamicSlot::nextSlot> DynamicSlotList;
- DynamicSlotList dynamicSlots;
-
- // Used by compiler
- QDeclarativeCompilerTypes::ComponentCompileState *componentCompileState;
-
- // Used by ComponentCompileState::AliasingObjectsList
- Object *nextAliasingObject;
- // Used by ComponentComppileState::IdList
- Object *nextIdObject;
- };
-
-}
-
-Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeParser::Object::ScriptBlock::Pragmas);
-
-QT_END_NAMESPACE
-
-Q_DECLARE_METATYPE(QDeclarativeParser::Variant)
-
-QT_END_HEADER
-
-#endif // QDECLARATIVEPARSER_P_H
**
****************************************************************************/
-#include "private/qdeclarativescriptparser_p.h"
+#include "private/qdeclarativescript_p.h"
-#include "private/qdeclarativeparser_p.h"
#include "parser/qdeclarativejsengine_p.h"
#include "parser/qdeclarativejsparser_p.h"
#include "parser/qdeclarativejslexer_p.h"
QT_BEGIN_NAMESPACE
using namespace QDeclarativeJS;
-using namespace QDeclarativeParser;
+using namespace QDeclarativeScript;
+
+//
+// Parser IR classes
+//
+QDeclarativeScript::Object::Object()
+: type(-1), idIndex(-1), metatype(0), synthCache(0), defaultProperty(0), parserStatusCast(-1),
+ componentCompileState(0), nextAliasingObject(0), nextIdObject(0)
+{
+}
+
+QDeclarativeScript::Object::~Object()
+{
+ if (synthCache) synthCache->release();
+}
+
+void Object::setBindingBit(int b)
+{
+ while (bindingBitmask.size() < 4 * (1 + b / 32))
+ bindingBitmask.append(char(0));
+
+ quint32 *bits = (quint32 *)bindingBitmask.data();
+ bits[b / 32] |= (1 << (b % 32));
+}
+
+const QMetaObject *Object::metaObject() const
+{
+ if (!metadata.isEmpty() && metatype)
+ return &extObject;
+ else
+ return metatype;
+}
+
+QDeclarativeScript::Property *Object::getDefaultProperty()
+{
+ if (!defaultProperty) {
+ defaultProperty = pool()->New<Property>();
+ defaultProperty->parent = this;
+ }
+ return defaultProperty;
+}
+
+void QDeclarativeScript::Object::addValueProperty(Property *p)
+{
+ valueProperties.append(p);
+}
+
+void QDeclarativeScript::Object::addSignalProperty(Property *p)
+{
+ signalProperties.append(p);
+}
+
+void QDeclarativeScript::Object::addAttachedProperty(Property *p)
+{
+ attachedProperties.append(p);
+}
+
+void QDeclarativeScript::Object::addGroupedProperty(Property *p)
+{
+ groupedProperties.append(p);
+}
+
+void QDeclarativeScript::Object::addValueTypeProperty(Property *p)
+{
+ valueTypeProperties.append(p);
+}
+
+void QDeclarativeScript::Object::addScriptStringProperty(Property *p)
+{
+ scriptStringProperties.append(p);
+}
+
+// This lookup is optimized for missing, and having to create a new property.
+Property *QDeclarativeScript::Object::getProperty(const QHashedStringRef &name, bool create)
+{
+ if (create) {
+ quint32 h = name.hash();
+ if (propertiesHashField.testAndSet(h)) {
+ for (Property *p = properties.first(); p; p = properties.next(p)) {
+ if (p->name() == name)
+ return p;
+ }
+ }
+
+ Property *property = pool()->New<Property>();
+ property->parent = this;
+ property->_name = name;
+ property->isDefault = false;
+ properties.prepend(property);
+ return property;
+ } else {
+ for (Property *p = properties.first(); p; p = properties.next(p)) {
+ if (p->name() == name)
+ return p;
+ }
+ }
+
+ return 0;
+}
+
+Property *QDeclarativeScript::Object::getProperty(const QStringRef &name, bool create)
+{
+ return getProperty(QHashedStringRef(name), create);
+}
+
+Property *QDeclarativeScript::Object::getProperty(const QString &name, bool create)
+{
+ for (Property *p = properties.first(); p; p = properties.next(p)) {
+ if (p->name() == name)
+ return p;
+ }
+
+ if (create) {
+ Property *property = pool()->New<Property>();
+ property->parent = this;
+ property->_name = QStringRef(pool()->NewString(name));
+ propertiesHashField.testAndSet(property->_name.hash());
+ property->isDefault = false;
+ properties.prepend(property);
+ return property;
+ } else {
+ return 0;
+ }
+}
+
+QDeclarativeScript::Object::DynamicProperty::DynamicProperty()
+: isDefaultProperty(false), type(Variant), defaultValue(0), nextProperty(0),
+ resolvedCustomTypeName(0)
+{
+}
+
+QDeclarativeScript::Object::DynamicSignal::DynamicSignal()
+: nextSignal(0)
+{
+}
+
+// Returns length in utf8 bytes
+int QDeclarativeScript::Object::DynamicSignal::parameterTypesLength() const
+{
+ int rv = 0;
+ for (int ii = 0; ii < parameterTypes.count(); ++ii)
+ rv += parameterTypes.at(ii).length();
+ return rv;
+}
+
+// Returns length in utf8 bytes
+int QDeclarativeScript::Object::DynamicSignal::parameterNamesLength() const
+{
+ int rv = 0;
+ for (int ii = 0; ii < parameterNames.count(); ++ii)
+ rv += parameterNames.at(ii).utf8length();
+ return rv;
+}
+
+QDeclarativeScript::Object::DynamicSlot::DynamicSlot()
+: nextSlot(0)
+{
+}
+
+int QDeclarativeScript::Object::DynamicSlot::parameterNamesLength() const
+{
+ int rv = 0;
+ for (int ii = 0; ii < parameterNames.count(); ++ii)
+ rv += parameterNames.at(ii).length();
+ return rv;
+}
+
+QDeclarativeScript::Property::Property()
+: parent(0), type(0), index(-1), value(0), isDefault(true), isDeferred(false),
+ isValueTypeSubProperty(false), isAlias(false), scriptStringScope(-1),
+ nextMainProperty(0), nextProperty(0)
+{
+}
+
+QDeclarativeScript::Object *QDeclarativeScript::Property::getValue(const LocationSpan &l)
+{
+ if (!value) { value = pool()->New<Object>(); value->location = l; }
+ return value;
+}
+
+void QDeclarativeScript::Property::addValue(Value *v)
+{
+ values.append(v);
+}
+
+void QDeclarativeScript::Property::addOnValue(Value *v)
+{
+ onValues.append(v);
+}
+
+bool QDeclarativeScript::Property::isEmpty() const
+{
+ return !value && values.isEmpty() && onValues.isEmpty();
+}
+
+QDeclarativeScript::Value::Value()
+: type(Unknown), object(0), bindingReference(0), signalExpressionContextStack(0), nextValue(0)
+{
+}
+
+QDeclarativeScript::Variant::Variant()
+: t(Invalid)
+{
+}
+
+QDeclarativeScript::Variant::Variant(const Variant &o)
+: t(o.t), d(o.d), asWritten(o.asWritten)
+{
+}
+
+QDeclarativeScript::Variant::Variant(bool v)
+: t(Boolean), b(v)
+{
+}
+
+QDeclarativeScript::Variant::Variant(double v, const QStringRef &asWritten)
+: t(Number), d(v), asWritten(asWritten)
+{
+}
+
+QDeclarativeScript::Variant::Variant(QDeclarativeJS::AST::StringLiteral *v)
+: t(String), l(v)
+{
+}
+
+QDeclarativeScript::Variant::Variant(const QStringRef &asWritten, QDeclarativeJS::AST::Node *n)
+: t(Script), n(n), asWritten(asWritten)
+{
+}
+
+QDeclarativeScript::Variant &QDeclarativeScript::Variant::operator=(const Variant &o)
+{
+ t = o.t;
+ d = o.d;
+ asWritten = o.asWritten;
+ return *this;
+}
+
+QDeclarativeScript::Variant::Type QDeclarativeScript::Variant::type() const
+{
+ return t;
+}
+
+bool QDeclarativeScript::Variant::asBoolean() const
+{
+ return b;
+}
+
+QString QDeclarativeScript::Variant::asString() const
+{
+ if (t == String) {
+ // XXX aakenned
+ return l->value.toString();
+ } else {
+ return asWritten.toString();
+ }
+}
+
+double QDeclarativeScript::Variant::asNumber() const
+{
+ return d;
+}
+
+//reverse of Lexer::singleEscape()
+QString escapedString(const QString &string)
+{
+ QString tmp = QLatin1String("\"");
+ for (int i = 0; i < string.length(); ++i) {
+ const QChar &c = string.at(i);
+ switch(c.unicode()) {
+ case 0x08:
+ tmp += QLatin1String("\\b");
+ break;
+ case 0x09:
+ tmp += QLatin1String("\\t");
+ break;
+ case 0x0A:
+ tmp += QLatin1String("\\n");
+ break;
+ case 0x0B:
+ tmp += QLatin1String("\\v");
+ break;
+ case 0x0C:
+ tmp += QLatin1String("\\f");
+ break;
+ case 0x0D:
+ tmp += QLatin1String("\\r");
+ break;
+ case 0x22:
+ tmp += QLatin1String("\\\"");
+ break;
+ case 0x27:
+ tmp += QLatin1String("\\\'");
+ break;
+ case 0x5C:
+ tmp += QLatin1String("\\\\");
+ break;
+ default:
+ tmp += c;
+ break;
+ }
+ }
+ tmp += QLatin1Char('\"');
+ return tmp;
+}
+
+QString QDeclarativeScript::Variant::asScript() const
+{
+ switch(type()) {
+ default:
+ case Invalid:
+ return QString();
+ case Boolean:
+ return b?QLatin1String("true"):QLatin1String("false");
+ case Number:
+ if (asWritten.isEmpty())
+ return QString::number(d);
+ else
+ return asWritten.toString();
+ case String:
+ return escapedString(asString());
+ case Script:
+ if (AST::IdentifierExpression *i = AST::cast<AST::IdentifierExpression *>(n)) {
+ // XXX aakenned
+ return i->name.toString();
+ } else
+ return asWritten.toString();
+ }
+}
+
+QDeclarativeJS::AST::Node *QDeclarativeScript::Variant::asAST() const
+{
+ if (type() == Script)
+ return n;
+ else
+ return 0;
+}
+
+bool QDeclarativeScript::Variant::isStringList() const
+{
+ if (isString())
+ return true;
+
+ if (type() != Script || !n)
+ return false;
+
+ AST::ArrayLiteral *array = AST::cast<AST::ArrayLiteral *>(n);
+ if (!array)
+ return false;
+
+ AST::ElementList *elements = array->elements;
+
+ while (elements) {
+
+ if (!AST::cast<AST::StringLiteral *>(elements->expression))
+ return false;
+
+ elements = elements->next;
+ }
+
+ return true;
+}
-void QDeclarativeScriptParser::Import::extractVersion(int *maj, int *min) const
+QStringList QDeclarativeScript::Variant::asStringList() const
+{
+ QStringList rv;
+ if (isString()) {
+ rv << asString();
+ return rv;
+ }
+
+ AST::ArrayLiteral *array = AST::cast<AST::ArrayLiteral *>(n);
+ if (!array)
+ return rv;
+
+ AST::ElementList *elements = array->elements;
+ while (elements) {
+
+ AST::StringLiteral *string = AST::cast<AST::StringLiteral *>(elements->expression);
+ if (!string)
+ return QStringList();
+ rv.append(string->value.toString());
+
+ elements = elements->next;
+ }
+
+ return rv;
+}
+
+//
+// Actual parser classes
+//
+void QDeclarativeScript::Import::extractVersion(int *maj, int *min) const
{
*maj = -1; *min = -1;
{
struct State {
State() : object(0), property(0) {}
- State(QDeclarativeParser::Object *o) : object(o), property(0) {}
- State(QDeclarativeParser::Object *o, Property *p) : object(o), property(p) {}
+ State(QDeclarativeScript::Object *o) : object(o), property(0) {}
+ State(QDeclarativeScript::Object *o, Property *p) : object(o), property(p) {}
- QDeclarativeParser::Object *object;
+ QDeclarativeScript::Object *object;
Property *property;
};
struct StateStack : public QStack<State>
{
- void pushObject(QDeclarativeParser::Object *obj)
+ void pushObject(QDeclarativeScript::Object *obj)
{
push(State(obj));
}
};
public:
- ProcessAST(QDeclarativeScriptParser *parser);
+ ProcessAST(QDeclarativeScript::Parser *parser);
virtual ~ProcessAST();
void operator()(const QString &code, AST::Node *node);
protected:
- QDeclarativeParser::Object *defineObjectBinding(AST::UiQualifiedId *propertyName, bool onAssignment,
+ QDeclarativeScript::Object *defineObjectBinding(AST::UiQualifiedId *propertyName, bool onAssignment,
const QString &objectType,
AST::SourceLocation typeLocation,
LocationSpan location,
AST::UiObjectInitializer *initializer = 0);
- QDeclarativeParser::Variant getVariant(AST::Statement *stmt);
- QDeclarativeParser::Variant getVariant(AST::ExpressionNode *expr);
+ QDeclarativeScript::Variant getVariant(AST::Statement *stmt);
+ QDeclarativeScript::Variant getVariant(AST::ExpressionNode *expr);
LocationSpan location(AST::SourceLocation start, AST::SourceLocation end);
LocationSpan location(AST::UiQualifiedId *);
QString asString(AST::UiQualifiedId *node) const;
const State state() const;
- QDeclarativeParser::Object *currentObject() const;
+ QDeclarativeScript::Object *currentObject() const;
Property *currentProperty() const;
QString qualifiedNameId() const;
}
private:
- QDeclarativeScriptParser *_parser;
+ QDeclarativeScript::Parser *_parser;
StateStack _stateStack;
QStringList _scope;
const QString *_contents;
};
-ProcessAST::ProcessAST(QDeclarativeScriptParser *parser)
+ProcessAST::ProcessAST(QDeclarativeScript::Parser *parser)
: _parser(parser)
{
}
return _stateStack.back();
}
-QDeclarativeParser::Object *ProcessAST::currentObject() const
+QDeclarativeScript::Object *ProcessAST::currentObject() const
{
return state().object;
}
return s;
}
-QDeclarativeParser::Object *
+QDeclarativeScript::Object *
ProcessAST::defineObjectBinding(AST::UiQualifiedId *propertyName,
bool onAssignment,
const QString &objectType,
if (lastTypeDot >= 0)
resolvableObjectType.replace(QLatin1Char('.'),QLatin1Char('/'));
- QDeclarativeParser::Object *obj = _parser->_pool.New<QDeclarativeParser::Object>();
+ QDeclarativeScript::Object *obj = _parser->_pool.New<QDeclarativeScript::Object>();
- QDeclarativeScriptParser::TypeReference *typeRef = _parser->findOrCreateType(resolvableObjectType);
+ QDeclarativeScript::TypeReference *typeRef = _parser->findOrCreateType(resolvableObjectType);
obj->type = typeRef->id;
typeRef->refObjects.append(obj);
if (propertyCount) {
Property *prop = currentProperty();
- QDeclarativeParser::Value *v = _parser->_pool.New<QDeclarativeParser::Value>();
+ QDeclarativeScript::Value *v = _parser->_pool.New<QDeclarativeScript::Value>();
v->object = obj;
v->location = obj->location;
if (onAssignment)
_parser->setTree(obj);
} else {
const State state = _stateStack.top();
- QDeclarativeParser::Value *v = _parser->_pool.New<QDeclarativeParser::Value>();
+ QDeclarativeScript::Value *v = _parser->_pool.New<QDeclarativeScript::Value>();
v->object = obj;
v->location = obj->location;
if (state.property) {
bool ProcessAST::visit(AST::UiImport *node)
{
QString uri;
- QDeclarativeScriptParser::Import import;
+ QDeclarativeScript::Import import;
if (!node->fileName.isNull()) {
uri = node->fileName.toString();
if (uri.endsWith(QLatin1String(".js"))) {
- import.type = QDeclarativeScriptParser::Import::Script;
+ import.type = QDeclarativeScript::Import::Script;
} else {
- import.type = QDeclarativeScriptParser::Import::File;
+ import.type = QDeclarativeScript::Import::File;
}
} else {
- import.type = QDeclarativeScriptParser::Import::Library;
+ import.type = QDeclarativeScript::Import::Library;
uri = asString(node->importUri);
}
}
// Check for script qualifier clashes
- bool isScript = import.type == QDeclarativeScriptParser::Import::Script;
+ bool isScript = import.type == QDeclarativeScript::Import::Script;
for (int ii = 0; ii < _parser->_imports.count(); ++ii) {
- const QDeclarativeScriptParser::Import &other = _parser->_imports.at(ii);
- bool otherIsScript = other.type == QDeclarativeScriptParser::Import::Script;
+ const QDeclarativeScript::Import &other = _parser->_imports.at(ii);
+ bool otherIsScript = other.type == QDeclarativeScript::Import::Script;
if ((isScript || otherIsScript) && import.qualifier == other.qualifier) {
QDeclarativeError error;
}
}
- } else if (import.type == QDeclarativeScriptParser::Import::Script) {
+ } else if (import.type == QDeclarativeScript::Import::Script) {
QDeclarativeError error;
error.setDescription(QCoreApplication::translate("QDeclarativeParser","Script import requires a qualifier"));
error.setLine(node->fileNameToken.startLine);
if (node->versionToken.isValid()) {
import.version = textAt(node->versionToken);
- } else if (import.type == QDeclarativeScriptParser::Import::Library) {
+ } else if (import.type == QDeclarativeScript::Import::Library) {
QDeclarativeError error;
error.setDescription(QCoreApplication::translate("QDeclarativeParser","Library import requires a version"));
error.setLine(node->importIdToken.startLine);
bool typeFound = false;
Object::DynamicProperty::Type type;
- if (memberType.length() == strlen("alias") &&
+ if ((unsigned)memberType.length() == strlen("alias") &&
QHashedString::compare(memberType.constData(), "alias", strlen("alias"))) {
type = Object::DynamicProperty::Alias;
typeFound = true;
if (typeModifier.isEmpty()) {
type = Object::DynamicProperty::Custom;
- } else if(typeModifier.length() == strlen("list") &&
+ } else if((unsigned)typeModifier.length() == strlen("list") &&
QHashedString::compare(typeModifier.constData(), "list", strlen("list"))) {
type = Object::DynamicProperty::CustomList;
} else {
property->isDefaultProperty = node->isDefaultMember;
property->type = type;
if (type >= Object::DynamicProperty::Custom) {
- QDeclarativeScriptParser::TypeReference *typeRef =
+ QDeclarativeScript::TypeReference *typeRef =
_parser->findOrCreateType(memberType.toString());
typeRef->refObjects.append(_stateStack.top().object);
property->customType = memberType;
property->defaultValue->location =
location(node->statement->firstSourceLocation(),
node->statement->lastSourceLocation());
- QDeclarativeParser::Value *value = _parser->_pool.New<QDeclarativeParser::Value>();
+ QDeclarativeScript::Value *value = _parser->_pool.New<QDeclarativeScript::Value>();
value->location = location(node->statement->firstSourceLocation(),
node->statement->lastSourceLocation());
value->value = getVariant(node->statement);
return false;
}
-QDeclarativeParser::Variant ProcessAST::getVariant(AST::Statement *stmt)
+QDeclarativeScript::Variant ProcessAST::getVariant(AST::Statement *stmt)
{
if (stmt) {
if (AST::ExpressionStatement *exprStmt = AST::cast<AST::ExpressionStatement *>(stmt))
return getVariant(exprStmt->expression);
- return QDeclarativeParser::Variant(asStringRef(stmt), stmt);
+ return QDeclarativeScript::Variant(asStringRef(stmt), stmt);
}
- return QDeclarativeParser::Variant();
+ return QDeclarativeScript::Variant();
}
-QDeclarativeParser::Variant ProcessAST::getVariant(AST::ExpressionNode *expr)
+QDeclarativeScript::Variant ProcessAST::getVariant(AST::ExpressionNode *expr)
{
if (AST::StringLiteral *lit = AST::cast<AST::StringLiteral *>(expr)) {
- return QDeclarativeParser::Variant(lit);
+ return QDeclarativeScript::Variant(lit);
} else if (expr->kind == AST::Node::Kind_TrueLiteral) {
- return QDeclarativeParser::Variant(true);
+ return QDeclarativeScript::Variant(true);
} else if (expr->kind == AST::Node::Kind_FalseLiteral) {
- return QDeclarativeParser::Variant(false);
+ return QDeclarativeScript::Variant(false);
} else if (AST::NumericLiteral *lit = AST::cast<AST::NumericLiteral *>(expr)) {
- return QDeclarativeParser::Variant(lit->value, asStringRef(expr));
+ return QDeclarativeScript::Variant(lit->value, asStringRef(expr));
} else {
if (AST::UnaryMinusExpression *unaryMinus = AST::cast<AST::UnaryMinusExpression *>(expr)) {
if (AST::NumericLiteral *lit = AST::cast<AST::NumericLiteral *>(unaryMinus->expression)) {
- return QDeclarativeParser::Variant(-lit->value, asStringRef(expr));
+ return QDeclarativeScript::Variant(-lit->value, asStringRef(expr));
}
}
- return QDeclarativeParser::Variant(asStringRef(expr), expr);
+ return QDeclarativeScript::Variant(asStringRef(expr), expr);
}
}
return 0;
}
- QDeclarativeParser::Variant primitive;
+ QDeclarativeScript::Variant primitive;
if (AST::ExpressionStatement *stmt = AST::cast<AST::ExpressionStatement *>(node->statement)) {
primitive = getVariant(stmt->expression);
} else { // do binding
- primitive = QDeclarativeParser::Variant(asStringRef(node->statement), node->statement);
+ primitive = QDeclarativeScript::Variant(asStringRef(node->statement), node->statement);
}
prop->location.range.length = prop->location.range.offset + prop->location.range.length - node->qualifiedId->identifierToken.offset;
prop->location.range.offset = node->qualifiedId->identifierToken.offset;
- QDeclarativeParser::Value *v = _parser->_pool.New<QDeclarativeParser::Value>();
+ QDeclarativeScript::Value *v = _parser->_pool.New<QDeclarativeScript::Value>();
v->value = primitive;
v->location = location(node->statement->firstSourceLocation(),
node->statement->lastSourceLocation());
bool ProcessAST::visit(AST::UiSourceElement *node)
{
- QDeclarativeParser::Object *obj = currentObject();
+ QDeclarativeScript::Object *obj = currentObject();
if (AST::FunctionDeclaration *funDecl = AST::cast<AST::FunctionDeclaration *>(node->sourceElement)) {
} // end of anonymous namespace
-QDeclarativeScriptParser::QDeclarativeScriptParser()
+QDeclarativeScript::Parser::Parser()
: root(0), data(0)
{
}
-QDeclarativeScriptParser::~QDeclarativeScriptParser()
+QDeclarativeScript::Parser::~Parser()
{
clear();
}
-class QDeclarativeScriptParserJsASTData
+namespace QDeclarativeScript {
+class ParserJsASTData
{
public:
- QDeclarativeScriptParserJsASTData(const QString &filename)
- : filename(filename) {}
+ ParserJsASTData(const QString &filename)
+ : filename(filename) {}
QString filename;
Engine engine;
};
+}
-bool QDeclarativeScriptParser::parse(const QByteArray &qmldata, const QUrl &url)
+bool QDeclarativeScript::Parser::parse(const QByteArray &qmldata, const QUrl &url)
{
clear();
#endif
QString *code = _pool.NewString(stream.readAll());
- data = new QDeclarativeScriptParserJsASTData(fileName);
+ data = new QDeclarativeScript::ParserJsASTData(fileName);
Lexer lexer(&data->engine);
lexer.setCode(*code, /*line = */ 1);
- Parser parser(&data->engine);
+ QDeclarativeJS::Parser parser(&data->engine);
if (! parser.parse() || !_errors.isEmpty()) {
return _errors.isEmpty();
}
-QList<QDeclarativeScriptParser::TypeReference*> QDeclarativeScriptParser::referencedTypes() const
+QList<QDeclarativeScript::TypeReference*> QDeclarativeScript::Parser::referencedTypes() const
{
return _refTypes;
}
-QDeclarativeParser::Object *QDeclarativeScriptParser::tree() const
+QDeclarativeScript::Object *QDeclarativeScript::Parser::tree() const
{
return root;
}
-QList<QDeclarativeScriptParser::Import> QDeclarativeScriptParser::imports() const
+QList<QDeclarativeScript::Import> QDeclarativeScript::Parser::imports() const
{
return _imports;
}
-QList<QDeclarativeError> QDeclarativeScriptParser::errors() const
+QList<QDeclarativeError> QDeclarativeScript::Parser::errors() const
{
return _errors;
}
*data++ = space;
}
-static QDeclarativeParser::LocationSpan
+static QDeclarativeScript::LocationSpan
locationFromLexer(const QDeclarativeJS::Lexer &lex, int startLine, int startColumn, int startOffset)
{
- QDeclarativeParser::LocationSpan l;
+ QDeclarativeScript::LocationSpan l;
l.start.line = startLine; l.start.column = startColumn;
l.end.line = lex.tokenEndLine(); l.end.column = lex.tokenEndColumn();
are:
library
*/
-QDeclarativeParser::Object::ScriptBlock::Pragmas QDeclarativeScriptParser::extractPragmas(QString &script)
+QDeclarativeScript::Object::ScriptBlock::Pragmas QDeclarativeScript::Parser::extractPragmas(QString &script)
{
- QDeclarativeParser::Object::ScriptBlock::Pragmas rv = QDeclarativeParser::Object::ScriptBlock::None;
+ QDeclarativeScript::Object::ScriptBlock::Pragmas rv = QDeclarativeScript::Object::ScriptBlock::None;
const QString pragma(QLatin1String("pragma"));
const QString library(QLatin1String("library"));
return rv;
if (pragmaValue == library) {
- rv |= QDeclarativeParser::Object::ScriptBlock::Shared;
+ rv |= QDeclarativeScript::Object::ScriptBlock::Shared;
replaceWithSpace(script, startOffset, endOffset - startOffset);
} else {
return rv;
return false;
}
-QDeclarativeScriptParser::JavaScriptMetaData QDeclarativeScriptParser::extractMetaData(QString &script)
+QDeclarativeScript::Parser::JavaScriptMetaData QDeclarativeScript::Parser::extractMetaData(QString &script)
{
JavaScriptMetaData rv;
- QDeclarativeParser::Object::ScriptBlock::Pragmas &pragmas = rv.pragmas;
+ QDeclarativeScript::Object::ScriptBlock::Pragmas &pragmas = rv.pragmas;
const QString pragma(QLatin1String("pragma"));
const QString js(QLatin1String(".js"));
if (!importId.at(0).isUpper())
return rv;
- QDeclarativeParser::LocationSpan location =
+ QDeclarativeScript::LocationSpan location =
locationFromLexer(l, startLine, startColumn, startOffset);
token = l.lex();
if (!importId.at(0).isUpper())
return rv;
- QDeclarativeParser::LocationSpan location =
+ QDeclarativeScript::LocationSpan location =
locationFromLexer(l, startLine, startColumn, startOffset);
token = l.lex();
int endOffset = l.tokenLength() + l.tokenOffset();
if (pragmaValue == library) {
- pragmas |= QDeclarativeParser::Object::ScriptBlock::Shared;
+ pragmas |= QDeclarativeScript::Object::ScriptBlock::Shared;
replaceWithSpace(script, startOffset, endOffset - startOffset);
} else {
return rv;
return rv;
}
-void QDeclarativeScriptParser::clear()
+void QDeclarativeScript::Parser::clear()
{
_imports.clear();
qDeleteAll(_refTypes);
_pool.clear();
}
-QDeclarativeScriptParser::TypeReference *QDeclarativeScriptParser::findOrCreateType(const QString &name)
+QDeclarativeScript::TypeReference *QDeclarativeScript::Parser::findOrCreateType(const QString &name)
{
TypeReference *type = 0;
int i = 0;
return type;
}
-void QDeclarativeScriptParser::setTree(QDeclarativeParser::Object *tree)
+void QDeclarativeScript::Parser::setTree(QDeclarativeScript::Object *tree)
{
Q_ASSERT(! root);
--- /dev/null
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef QDECLARATIVESCRIPT_P_H
+#define QDECLARATIVESCRIPT_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtDeclarative/qdeclarativeerror.h>
+
+#include <private/qfieldlist_p.h>
+#include <private/qhashfield_p.h>
+#include <private/qfastmetabuilder_p.h>
+#include <private/qdeclarativepool_p.h>
+#include <private/qdeclarativepropertycache_p.h>
+
+#include <QtCore/QList>
+#include <QtCore/QUrl>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Declarative)
+
+class QByteArray;
+class QDeclarativePropertyCache;
+namespace QDeclarativeJS { namespace AST { class Node; class StringLiteral; } }
+namespace QDeclarativeCompilerTypes { class BindingReference; class ComponentCompileState; }
+
+namespace QDeclarativeScript {
+
+struct Location
+{
+ Location() : line(-1), column(-1) {}
+ int line;
+ int column;
+
+ inline bool operator<(const Location &other) {
+ return line < other.line ||
+ (line == other.line && column < other.column);
+ }
+};
+
+struct LocationRange
+{
+ LocationRange() : offset(0), length(0) {}
+ quint32 offset;
+ quint32 length;
+};
+
+struct LocationSpan
+{
+ Location start;
+ Location end;
+ LocationRange range;
+
+ bool operator<(LocationSpan &o) const {
+ return (start.line < o.start.line) ||
+ (start.line == o.start.line && start.column < o.start.column);
+ }
+};
+
+class Import
+{
+public:
+ Import() : type(Library) {}
+
+ enum Type { Library, File, Script };
+ Type type;
+
+ QString uri;
+ QString qualifier;
+ QString version;
+
+ void extractVersion(int *maj, int *min) const;
+
+ QDeclarativeScript::LocationSpan location;
+};
+
+class Object;
+class TypeReference
+{
+public:
+ TypeReference(int typeId, const QString &typeName) : id(typeId), name(typeName) {}
+
+ int id;
+ // type as it has been referenced in Qml
+ QString name;
+ // objects in parse tree referencing the type
+ QList<QDeclarativeScript::Object*> refObjects;
+};
+
+class Object;
+class Property;
+
+class Q_DECLARATIVE_EXPORT Variant
+{
+public:
+ enum Type {
+ Invalid,
+ Boolean,
+ Number,
+ String,
+ Script
+ };
+
+ Variant();
+ Variant(const Variant &);
+ explicit Variant(bool);
+ explicit Variant(double, const QStringRef &asWritten = QStringRef());
+ explicit Variant(QDeclarativeJS::AST::StringLiteral *);
+ explicit Variant(const QStringRef &asWritten, QDeclarativeJS::AST::Node *);
+ Variant &operator=(const Variant &);
+
+ Type type() const;
+
+ bool isBoolean() const { return type() == Boolean; }
+ bool isNumber() const { return type() == Number; }
+ bool isString() const { return type() == String; }
+ bool isScript() const { return type() == Script; }
+ bool isStringList() const;
+
+ bool asBoolean() const;
+ QString asString() const;
+ double asNumber() const;
+ QString asScript() const;
+ QDeclarativeJS::AST::Node *asAST() const;
+ QStringList asStringList() const;
+
+private:
+ Type t;
+ union {
+ bool b;
+ double d;
+ QDeclarativeJS::AST::StringLiteral *l;
+ QDeclarativeJS::AST::Node *n;
+ };
+ QStringRef asWritten;
+};
+
+class Value : public QDeclarativePool::POD
+{
+public:
+ Value();
+
+ enum Type {
+ // The type of this value assignment is not yet known
+ Unknown,
+ // This is used as a literal property assignment
+ Literal,
+ // This is used as a property binding assignment
+ PropertyBinding,
+ // This is used as a QDeclarativePropertyValueSource assignment
+ ValueSource,
+ // This is used as a QDeclarativePropertyValueInterceptor assignment
+ ValueInterceptor,
+ // This is used as a property QObject assignment
+ CreatedObject,
+ // This is used as a signal object assignment
+ SignalObject,
+ // This is used as a signal expression assignment
+ SignalExpression,
+ // This is used as an id assignment only
+ Id
+ };
+ Type type;
+
+ // ### Temporary (for id only)
+ QString primitive() const { return value.isString() ? value.asString() : value.asScript(); }
+
+ // Primitive value
+ Variant value;
+ // Object value
+ Object *object;
+
+ LocationSpan location;
+
+ // Used by compiler
+ QDeclarativeCompilerTypes::BindingReference *bindingReference;
+ int signalExpressionContextStack;
+
+ // Used in Property::ValueList lists
+ Value *nextValue;
+};
+
+class Property : public QDeclarativePool::POD
+{
+public:
+ Property();
+
+ // The Object to which this property is attached
+ Object *parent;
+
+ Object *getValue(const LocationSpan &);
+ void addValue(Value *v);
+ void addOnValue(Value *v);
+
+ // The QVariant::Type of the property, or 0 (QVariant::Invalid) if
+ // unknown.
+ int type;
+ // The metaobject index of this property, or -1 if unknown.
+ int index;
+ // The core data in the case of a regular property.
+ // XXX This has to be a value now as the synthCache may change during
+ // compilation which invalidates pointers. We should fix this.
+ QDeclarativePropertyCache::Data core;
+
+ // Returns true if this is an empty property - both value and values
+ // are unset.
+ bool isEmpty() const;
+
+ typedef QFieldList<Value, &Value::nextValue> ValueList;
+ // The list of values assigned to this property. Content in values
+ // and value are mutually exclusive
+ ValueList values;
+ // The list of values assigned to this property using the "on" syntax
+ ValueList onValues;
+ // The accessed property. This is used to represent dot properties.
+ // Content in value and values are mutually exclusive.
+ Object *value;
+ // The property name
+ const QHashedStringRef &name() const { return _name; }
+ void setName(const QString &n) { _name = QHashedStringRef(pool()->NewString(n)); }
+ void setName(const QHashedStringRef &n) { _name = n; }
+ // True if this property was accessed as the default property.
+ bool isDefault;
+ // True if the setting of this property will be deferred. Set by the
+ // QDeclarativeCompiler
+ bool isDeferred;
+ // True if this property is a value-type pseudo-property
+ bool isValueTypeSubProperty;
+ // True if this property is a property alias. Set by the
+ // QDeclarativeCompiler
+ bool isAlias;
+
+ // Used for scriptStringProperties
+ int scriptStringScope;
+
+ LocationSpan location;
+ LocationRange listValueRange;
+
+ // Used in Object::MainPropertyList
+ Property *nextMainProperty;
+
+ // Used in Object::PropertyList lists
+ Property *nextProperty;
+
+private:
+ friend class Object;
+ QHashedStringRef _name;
+};
+
+class Object : public QDeclarativePool::Class
+{
+public:
+ Object();
+ virtual ~Object();
+
+ // Type of the object. The integer is an index into the
+ // QDeclarativeCompiledData::types array, or -1 if the object is a property
+ // group.
+ int type;
+
+ // The fully-qualified name of this type
+ QByteArray typeName;
+ // The id assigned to the object (if any). Set by the QDeclarativeCompiler
+ QString id;
+ // The id index assigned to the object (if any). Set by the QDeclarativeCompiler
+ int idIndex;
+ // Custom parsed data
+ QByteArray custom;
+ // Bit mask of the properties assigned bindings
+ QByteArray bindingBitmask;
+ void setBindingBit(int);
+ // Returns the metaobject for this type, or 0 if not available.
+ // Internally selectd between the metatype and extObject variables
+ const QMetaObject *metaObject() const;
+
+ // The compile time metaobject for this type
+ const QMetaObject *metatype;
+ // The synthesized metaobject, if QML added signals or properties to
+ // this type. Otherwise null
+ QAbstractDynamicMetaObject extObject;
+ QByteArray metadata; // Generated by compiler
+ QByteArray synthdata; // Generated by compiler
+ QDeclarativePropertyCache *synthCache; // Generated by compiler
+
+ Property *getDefaultProperty();
+ // name ptr must be guarenteed to remain valid
+ Property *getProperty(const QHashedStringRef &name, bool create=true);
+ Property *getProperty(const QStringRef &name, bool create=true);
+ Property *getProperty(const QString &name, bool create=true);
+
+ Property *defaultProperty;
+
+ typedef QFieldList<Property, &Property::nextMainProperty> MainPropertyList;
+ MainPropertyList properties;
+ QHashField propertiesHashField;
+
+ // Output of the compilation phase (these properties continue to exist
+ // in either the defaultProperty or properties members too)
+ void addValueProperty(Property *);
+ void addSignalProperty(Property *);
+ void addAttachedProperty(Property *);
+ void addGroupedProperty(Property *);
+ void addValueTypeProperty(Property *);
+ void addScriptStringProperty(Property *);
+
+ typedef QFieldList<Property, &Property::nextProperty> PropertyList;
+ PropertyList valueProperties;
+ PropertyList signalProperties;
+ PropertyList attachedProperties;
+ PropertyList groupedProperties;
+ PropertyList valueTypeProperties;
+ PropertyList scriptStringProperties;
+
+ // Script blocks that were nested under this object
+ struct ScriptBlock {
+ enum Pragma {
+ None = 0x00000000,
+ Shared = 0x00000001
+ };
+ Q_DECLARE_FLAGS(Pragmas, Pragma)
+
+ QString code;
+ QString file;
+ Pragmas pragmas;
+ };
+
+ // The bytes to cast instances by to get to the QDeclarativeParserStatus
+ // interface. -1 indicates the type doesn't support this interface.
+ // Set by the QDeclarativeCompiler.
+ int parserStatusCast;
+
+ LocationSpan location;
+
+ struct DynamicProperty : public QDeclarativePool::POD
+ {
+ DynamicProperty();
+
+ enum Type { Variant, Int, Bool, Real, String, Url, Color, Time,
+ Date, DateTime, Alias, Custom, CustomList };
+
+ bool isDefaultProperty;
+ Type type;
+
+ QHashedStringRef customType;
+ QHashedStringRef name;
+ QDeclarativeScript::Property *defaultValue;
+ LocationSpan location;
+
+ // Used by Object::DynamicPropertyList
+ DynamicProperty *nextProperty;
+
+ // Used by the compiler
+ QByteArray *resolvedCustomTypeName;
+ QFastMetaBuilder::StringRef typeRef;
+ QFastMetaBuilder::StringRef nameRef;
+ QFastMetaBuilder::StringRef changedSignatureRef;
+ };
+
+ struct DynamicSignal : public QDeclarativePool::POD
+ {
+ DynamicSignal();
+
+ QHashedStringRef name;
+ QDeclarativePool::List<QHashedCStringRef> parameterTypes;
+ QDeclarativePool::List<QHashedStringRef> parameterNames;
+
+ int parameterTypesLength() const;
+ int parameterNamesLength() const;
+
+ // Used by Object::DynamicSignalList
+ DynamicSignal *nextSignal;
+
+ // Used by the compiler
+ QFastMetaBuilder::StringRef signatureRef;
+ QFastMetaBuilder::StringRef parameterNamesRef;
+ LocationSpan location;
+ };
+
+ struct DynamicSlot : public QDeclarativePool::Class
+ {
+ DynamicSlot();
+
+ QHashedStringRef name;
+ QString body;
+ QList<QByteArray> parameterNames;
+ LocationSpan location;
+
+ int parameterNamesLength() const;
+
+ // Used by Object::DynamicSlotList
+ DynamicSlot *nextSlot;
+
+ // Used by the compiler
+ QFastMetaBuilder::StringRef signatureRef;
+ QFastMetaBuilder::StringRef parameterNamesRef;
+ };
+
+ // The list of dynamic properties
+ typedef QFieldList<DynamicProperty, &DynamicProperty::nextProperty> DynamicPropertyList;
+ DynamicPropertyList dynamicProperties;
+ // The list of dynamic signals
+ typedef QFieldList<DynamicSignal, &DynamicSignal::nextSignal> DynamicSignalList;
+ DynamicSignalList dynamicSignals;
+ // The list of dynamic slots
+ typedef QFieldList<DynamicSlot, &DynamicSlot::nextSlot> DynamicSlotList;
+ DynamicSlotList dynamicSlots;
+
+ // Used by compiler
+ QDeclarativeCompilerTypes::ComponentCompileState *componentCompileState;
+
+ // Used by ComponentCompileState::AliasingObjectsList
+ Object *nextAliasingObject;
+ // Used by ComponentComppileState::IdList
+ Object *nextIdObject;
+};
+
+class ParserJsASTData;
+class Q_AUTOTEST_EXPORT Parser
+{
+public:
+ Parser();
+ ~Parser();
+
+ bool parse(const QByteArray &data, const QUrl &url = QUrl());
+
+ QList<TypeReference*> referencedTypes() const;
+
+ QDeclarativeScript::Object *tree() const;
+ QList<Import> imports() const;
+
+ void clear();
+
+ QList<QDeclarativeError> errors() const;
+
+ class JavaScriptMetaData {
+ public:
+ JavaScriptMetaData()
+ : pragmas(QDeclarativeScript::Object::ScriptBlock::None) {}
+
+ QDeclarativeScript::Object::ScriptBlock::Pragmas pragmas;
+ QList<Import> imports;
+ };
+
+ static QDeclarativeScript::Object::ScriptBlock::Pragmas extractPragmas(QString &);
+ static JavaScriptMetaData extractMetaData(QString &);
+
+
+// ### private:
+ TypeReference *findOrCreateType(const QString &name);
+ void setTree(QDeclarativeScript::Object *tree);
+
+ void setScriptFile(const QString &filename) {_scriptFile = filename; }
+ QString scriptFile() const { return _scriptFile; }
+
+// ### private:
+ QList<QDeclarativeError> _errors;
+
+ QDeclarativePool _pool;
+ QDeclarativeScript::Object *root;
+ QList<Import> _imports;
+ QList<TypeReference*> _refTypes;
+ QString _scriptFile;
+ ParserJsASTData *data;
+};
+
+}
+
+Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeScript::Object::ScriptBlock::Pragmas);
+
+QT_END_NAMESPACE
+
+Q_DECLARE_METATYPE(QDeclarativeScript::Variant)
+
+QT_END_HEADER
+
+#endif // QDECLARATIVESCRIPT_P_H
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtDeclarative module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** GNU Lesser General Public License Usage
-** This file may be used under the terms of the GNU Lesser General Public
-** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this
-** file. Please review the following information to ensure the GNU Lesser
-** General Public License version 2.1 requirements will be met:
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU General
-** Public License version 3.0 as published by the Free Software Foundation
-** and appearing in the file LICENSE.GPL included in the packaging of this
-** file. Please review the following information to ensure the GNU General
-** Public License version 3.0 requirements will be met:
-** http://www.gnu.org/copyleft/gpl.html.
-**
-** Other Usage
-** Alternatively, this file may be used in accordance with the terms and
-** conditions contained in a signed written agreement between you and Nokia.
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-#ifndef QDECLARATIVESCRIPTPARSER_P_H
-#define QDECLARATIVESCRIPTPARSER_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qdeclarativeerror.h"
-
-#include <private/qdeclarativeparser_p.h>
-#include <private/qdeclarativepool_p.h>
-
-#include <QtCore/QList>
-#include <QtCore/QUrl>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Declarative)
-
-class QByteArray;
-
-class QDeclarativeScriptParserJsASTData;
-class Q_AUTOTEST_EXPORT QDeclarativeScriptParser
-{
-public:
- class Import
- {
- public:
- Import() : type(Library) {}
-
- enum Type { Library, File, Script };
- Type type;
-
- QString uri;
- QString qualifier;
- QString version;
-
- void extractVersion(int *maj, int *min) const;
-
- QDeclarativeParser::LocationSpan location;
- };
-
- class TypeReference
- {
- public:
- TypeReference(int typeId, const QString &typeName) : id(typeId), name(typeName) {}
-
- int id;
- // type as it has been referenced in Qml
- QString name;
- // objects in parse tree referencing the type
- QList<QDeclarativeParser::Object*> refObjects;
- };
-
- QDeclarativeScriptParser();
- ~QDeclarativeScriptParser();
-
- bool parse(const QByteArray &data, const QUrl &url = QUrl());
-
- QList<TypeReference*> referencedTypes() const;
-
- QDeclarativeParser::Object *tree() const;
- QList<Import> imports() const;
-
- void clear();
-
- QList<QDeclarativeError> errors() const;
-
- class JavaScriptMetaData {
- public:
- JavaScriptMetaData()
- : pragmas(QDeclarativeParser::Object::ScriptBlock::None) {}
-
- QDeclarativeParser::Object::ScriptBlock::Pragmas pragmas;
- QList<Import> imports;
- };
-
- static QDeclarativeParser::Object::ScriptBlock::Pragmas extractPragmas(QString &);
- static JavaScriptMetaData extractMetaData(QString &);
-
-
-// ### private:
- TypeReference *findOrCreateType(const QString &name);
- void setTree(QDeclarativeParser::Object *tree);
-
- void setScriptFile(const QString &filename) {_scriptFile = filename; }
- QString scriptFile() const { return _scriptFile; }
-
-// ### private:
- QList<QDeclarativeError> _errors;
-
- QDeclarativePool _pool;
- QDeclarativeParser::Object *root;
- QList<Import> _imports;
- QList<TypeReference*> _refTypes;
- QString _scriptFile;
- QDeclarativeScriptParserJsASTData *data;
-};
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif // QDECLARATIVESCRIPTPARSER_P_H
return m_imports;
}
-const QDeclarativeScriptParser &QDeclarativeTypeData::parser() const
+const QDeclarativeScript::Parser &QDeclarativeTypeData::parser() const
{
return scriptParser;
}
m_imports.setBaseUrl(finalUrl());
- foreach (const QDeclarativeScriptParser::Import &import, scriptParser.imports()) {
- if (import.type == QDeclarativeScriptParser::Import::File && import.qualifier.isEmpty()) {
+ foreach (const QDeclarativeScript::Import &import, scriptParser.imports()) {
+ if (import.type == QDeclarativeScript::Import::File && import.qualifier.isEmpty()) {
QUrl importUrl = finalUrl().resolved(QUrl(import.uri + QLatin1String("/qmldir")));
if (QDeclarativeEnginePrivate::urlToLocalFileOrQrc(importUrl).isEmpty()) {
QDeclarativeQmldirData *data = typeLoader()->getQmldir(importUrl);
addDependency(data);
m_qmldirs << data;
}
- } else if (import.type == QDeclarativeScriptParser::Import::Script) {
+ } else if (import.type == QDeclarativeScript::Import::Script) {
QUrl scriptUrl = finalUrl().resolved(QUrl(import.uri));
QDeclarativeScriptBlob *blob = typeLoader()->getScript(scriptUrl);
addDependency(blob);
QList<QDeclarativeError> errors;
if (QDeclarativeQmldirData *qmldir = qmldirForUrl(finalUrl().resolved(QUrl(QLatin1String("./qmldir"))))) {
m_imports.addImport(importDatabase, QLatin1String("."),
- QString(), -1, -1, QDeclarativeScriptParser::Import::File,
+ QString(), -1, -1, QDeclarativeScript::Import::File,
qmldir->dirComponents(), &errors);
} else {
m_imports.addImport(importDatabase, QLatin1String("."),
- QString(), -1, -1, QDeclarativeScriptParser::Import::File,
+ QString(), -1, -1, QDeclarativeScript::Import::File,
QDeclarativeDirComponents(), &errors);
}
return;
}
- foreach (const QDeclarativeScriptParser::Import &import, scriptParser.imports()) {
+ foreach (const QDeclarativeScript::Import &import, scriptParser.imports()) {
QDeclarativeDirComponents qmldircomponentsnetwork;
- if (import.type == QDeclarativeScriptParser::Import::Script)
+ if (import.type == QDeclarativeScript::Import::Script)
continue;
- if (import.type == QDeclarativeScriptParser::Import::File && import.qualifier.isEmpty()) {
+ if (import.type == QDeclarativeScript::Import::File && import.qualifier.isEmpty()) {
QUrl qmldirUrl = finalUrl().resolved(QUrl(import.uri + QLatin1String("/qmldir")));
if (QDeclarativeQmldirData *qmldir = qmldirForUrl(qmldirUrl))
qmldircomponentsnetwork = qmldir->dirComponents();
}
}
- foreach (QDeclarativeScriptParser::TypeReference *parserRef, scriptParser.referencedTypes()) {
+ foreach (QDeclarativeScript::TypeReference *parserRef, scriptParser.referencedTypes()) {
TypeReference ref;
QString url;
}
if (!parserRef->refObjects.isEmpty()) {
- QDeclarativeParser::Object *obj = parserRef->refObjects.first();
+ QDeclarativeScript::Object *obj = parserRef->refObjects.first();
error.setLine(obj->location.start.line);
error.setColumn(obj->location.start.column);
}
}
QDeclarativeScriptData::QDeclarativeScriptData(QDeclarativeEngine *engine)
-: QDeclarativeCleanup(engine), importCache(0), pragmas(QDeclarativeParser::Object::ScriptBlock::None),
+: QDeclarativeCleanup(engine), importCache(0), pragmas(QDeclarativeScript::Object::ScriptBlock::None),
m_loaded(false)
{
}
}
QDeclarativeScriptBlob::QDeclarativeScriptBlob(const QUrl &url, QDeclarativeTypeLoader *loader)
-: QDeclarativeDataBlob(url, JavaScriptFile), m_pragmas(QDeclarativeParser::Object::ScriptBlock::None),
+: QDeclarativeDataBlob(url, JavaScriptFile), m_pragmas(QDeclarativeScript::Object::ScriptBlock::None),
m_imports(loader), m_scriptData(0), m_typeLoader(loader)
{
}
}
}
-QDeclarativeParser::Object::ScriptBlock::Pragmas QDeclarativeScriptBlob::pragmas() const
+QDeclarativeScript::Object::ScriptBlock::Pragmas QDeclarativeScriptBlob::pragmas() const
{
return m_pragmas;
}
m_source = QString::fromUtf8(data);
- QDeclarativeScriptParser::JavaScriptMetaData metadata =
- QDeclarativeScriptParser::extractMetaData(m_source);
+ QDeclarativeScript::Parser::JavaScriptMetaData metadata =
+ QDeclarativeScript::Parser::extractMetaData(m_source);
m_imports.setBaseUrl(finalUrl());
m_pragmas = metadata.pragmas;
- foreach (const QDeclarativeScriptParser::Import &import, metadata.imports) {
- Q_ASSERT(import.type != QDeclarativeScriptParser::Import::File);
+ foreach (const QDeclarativeScript::Import &import, metadata.imports) {
+ Q_ASSERT(import.type != QDeclarativeScript::Import::File);
- if (import.type == QDeclarativeScriptParser::Import::Script) {
+ if (import.type == QDeclarativeScript::Import::Script) {
QUrl scriptUrl = finalUrl().resolved(QUrl(import.uri));
QDeclarativeScriptBlob *blob = typeLoader()->getScript(scriptUrl);
addDependency(blob);
blob->addref();
m_scripts << ref;
} else {
- Q_ASSERT(import.type == QDeclarativeScriptParser::Import::Library);
+ Q_ASSERT(import.type == QDeclarativeScript::Import::Library);
int vmaj = -1;
int vmin = -1;
import.extractVersion(&vmaj, &vmin);
#include <QtDeclarative/qdeclarativeerror.h>
#include <QtDeclarative/qdeclarativeengine.h>
#include <private/qdeclarativecleanup_p.h>
-#include <private/qdeclarativescriptparser_p.h>
+#include <private/qdeclarativescript_p.h>
#include <private/qdeclarativedirparser_p.h>
#include <private/qdeclarativeimport_p.h>
#include "private/qhashedstring_p.h"
{
TypeReference() : type(0), majorVersion(0), minorVersion(0), typeData(0) {}
- QDeclarativeParser::Location location;
+ QDeclarativeScript::Location location;
QDeclarativeType *type;
int majorVersion;
int minorVersion;
{
ScriptReference() : script(0) {}
- QDeclarativeParser::Location location;
+ QDeclarativeScript::Location location;
QString qualifier;
QDeclarativeScriptBlob *script;
};
QDeclarativeTypeLoader *typeLoader() const;
const QDeclarativeImports &imports() const;
- const QDeclarativeScriptParser &parser() const;
+ const QDeclarativeScript::Parser &parser() const;
const QList<TypeReference> &resolvedTypes() const;
const QList<ScriptReference> &resolvedScripts() const;
QDeclarativeQmldirData *qmldirForUrl(const QUrl &);
- QDeclarativeScriptParser scriptParser;
+ QDeclarativeScript::Parser scriptParser;
QDeclarativeImports m_imports;
QList<ScriptReference> m_scripts;
QUrl url;
QDeclarativeTypeNameCache *importCache;
QList<QDeclarativeScriptBlob *> scripts;
- QDeclarativeParser::Object::ScriptBlock::Pragmas pragmas;
+ QDeclarativeScript::Object::ScriptBlock::Pragmas pragmas;
protected:
virtual void clear(); // From QDeclarativeCleanup
{
ScriptReference() : script(0) {}
- QDeclarativeParser::Location location;
+ QDeclarativeScript::Location location;
QString qualifier;
QDeclarativeScriptBlob *script;
};
- QDeclarativeParser::Object::ScriptBlock::Pragmas pragmas() const;
+ QDeclarativeScript::Object::ScriptBlock::Pragmas pragmas() const;
QString scriptSource() const;
QDeclarativeTypeLoader *typeLoader() const;
virtual void done();
private:
- QDeclarativeParser::Object::ScriptBlock::Pragmas m_pragmas;
+ QDeclarativeScript::Object::ScriptBlock::Pragmas m_pragmas;
QString m_source;
QDeclarativeImports m_imports;
QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(parentCtxt->engine);
QV8Engine *v8engine = ep->v8engine();
- bool shared = script->pragmas & QDeclarativeParser::Object::ScriptBlock::Shared;
+ bool shared = script->pragmas & QDeclarativeScript::Object::ScriptBlock::Shared;
QDeclarativeContextData *effectiveCtxt = parentCtxt;
if (shared)
if (f.open(QIODevice::ReadOnly)) {
QByteArray data = f.readAll();
QString sourceCode = QString::fromUtf8(data);
- QDeclarativeScriptParser::extractPragmas(sourceCode);
+ QDeclarativeScript::Parser::extractPragmas(sourceCode);
v8::HandleScope handle_scope;
v8::Context::Scope scope(workerEngine->context());
INCLUDEPATH += $$PWD
SOURCES += \
- $$PWD/qdeclarativeparser.cpp \
$$PWD/qdeclarativeinstruction.cpp \
$$PWD/qdeclarativevmemetaobject.cpp \
$$PWD/qdeclarativeengine.cpp \
$$PWD/qdeclarativetypeloader.cpp \
$$PWD/qdeclarativeinfo.cpp \
$$PWD/qdeclarativeerror.cpp \
- $$PWD/qdeclarativescriptparser.cpp \
+ $$PWD/qdeclarativescript.cpp \
$$PWD/qdeclarativeenginedebug.cpp \
$$PWD/qdeclarativerewrite.cpp \
$$PWD/qdeclarativevaluetype.cpp \
$$PWD/qdeclarativelist.cpp \
HEADERS += \
- $$PWD/qdeclarativeparser_p.h \
$$PWD/qdeclarativeglobal_p.h \
$$PWD/qdeclarativeinstruction_p.h \
$$PWD/qdeclarativevmemetaobject_p.h \
$$PWD/qdeclarativelist_p.h \
$$PWD/qdeclarativedata_p.h \
$$PWD/qdeclarativeerror.h \
- $$PWD/qdeclarativescriptparser_p.h \
+ $$PWD/qdeclarativescript_p.h \
$$PWD/qdeclarativeenginedebug_p.h \
$$PWD/qdeclarativerewrite_p.h \
$$PWD/qdeclarativevaluetype_p.h \
struct Expression
{
Expression(const QDeclarativeImports &imp) : imports(imp) {}
- QDeclarativeParser::Object *component;
- QDeclarativeParser::Object *context;
- QDeclarativeParser::Property *property;
- QDeclarativeParser::Variant expression;
+ QDeclarativeScript::Object *component;
+ QDeclarativeScript::Object *context;
+ QDeclarativeScript::Property *property;
+ QDeclarativeScript::Variant expression;
QDeclarativeCompilerTypes::IdList *ids;
QDeclarativeTypeNameCache *importCache;
QDeclarativeImports imports;
#include "qdeclarativev4instruction_p.h"
#include "qdeclarativev4ir_p.h"
-#include <private/qdeclarativeparser_p.h>
+#include <private/qdeclarativescript_p.h>
#include <private/qdeclarativeimport_p.h>
#include <private/qdeclarativeengine_p.h>
return name;
}
-Name *BasicBlock::ID_OBJECT(const QString &id, const QDeclarativeParser::Object *object, quint32 line, quint32 column)
+Name *BasicBlock::ID_OBJECT(const QString &id, const QDeclarativeScript::Object *object, quint32 line, quint32 column)
{
Name *name = function->pool->New<Name>();
name->init(/*base = */ 0, IR::ObjectType,
#include <private/qdeclarativejsast_p.h>
#include <private/qdeclarativejsengine_p.h>
-#include <private/qdeclarativeparser_p.h>
+#include <private/qdeclarativescript_p.h>
#include <private/qdeclarativeimport_p.h>
#include <private/qdeclarativeengine_p.h>
#include <private/qdeclarativev4compiler_p.h>
void *ptr;
const QMetaObject *meta;
const QDeclarativeType *declarativeType;
- const QDeclarativeParser::Object *idObject;
+ const QDeclarativeScript::Object *idObject;
};
int index;
Storage storage;
Name *SYMBOL(Type type, const QString &id, const QMetaObject *meta, int index, Name::Storage storage, quint32 line, quint32 column);
Name *SYMBOL(Name *base, Type type, const QString &id, const QMetaObject *meta, int index, quint32 line, quint32 column);
Name *SYMBOL(Name *base, Type type, const QString &id, const QMetaObject *meta, int index, Name::Storage storage, quint32 line, quint32 column);
- Name *ID_OBJECT(const QString &id, const QDeclarativeParser::Object *object, quint32 line, quint32 column);
+ Name *ID_OBJECT(const QString &id, const QDeclarativeScript::Object *object, quint32 line, quint32 column);
Name *ATTACH_TYPE(const QString &id, const QDeclarativeType *attachType, Name::Storage storage, quint32 line, quint32 column);
Expr *UNOP(AluOp op, Expr *expr);
} else if (m_engine->v8engine()->illegalNames().contains(name) ) {
if (qmlVerboseCompiler()) qWarning() << "*** illegal symbol:" << name;
return false;
- } else if (const QDeclarativeParser::Object *obj = m_expression->ids->value(name)) {
+ } else if (const QDeclarativeScript::Object *obj = m_expression->ids->value(name)) {
IR::Name *code = _block->ID_OBJECT(name, obj, line, column);
if (obj == m_expression->component)
code->storage = IR::Name::RootStorage;
break;
case IR::Name::IdObject: {
- const QDeclarativeParser::Object *idObject = baseName->idObject;
+ const QDeclarativeScript::Object *idObject = baseName->idObject;
QDeclarativePropertyCache *cache =
idObject->synthCache?idObject->synthCache:m_engine->cache(idObject->metaObject());
QByteArray data = m_reply->readAll();
QString code = QString::fromUtf8(data);
- QDeclarativeScriptParser::extractPragmas(code);
+ QDeclarativeScript::Parser::extractPragmas(code);
QDeclarativeContextData *importContext = new QDeclarativeContextData;
importContext->isInternal = true;
if (f.open(QIODevice::ReadOnly)) {
QByteArray data = f.readAll();
QString code = QString::fromUtf8(data);
- QDeclarativeScriptParser::extractPragmas(code);
+ QDeclarativeScript::Parser::extractPragmas(code);
QDeclarativeContextData *importContext = new QDeclarativeContextData;
importContext->isInternal = true;
error(props.at(ii), QDeclarativeConnections::tr("Connections: syntax error"));
return QByteArray();
} else {
- QDeclarativeParser::Variant v = qvariant_cast<QDeclarativeParser::Variant>(value);
+ QDeclarativeScript::Variant v = qvariant_cast<QDeclarativeScript::Variant>(value);
if (v.isScript()) {
ds << propName;
ds << v.asScript();
#include "parser/qdeclarativejsengine_p.h"
#include <qdeclarativecustomparser_p.h>
-#include <qdeclarativeparser_p.h>
+#include <qdeclarativescript_p.h>
#include <qdeclarativeengine_p.h>
#include <qdeclarativecontext.h>
#include <qdeclarativeinfo.h>
} else {
- QDeclarativeParser::Variant variant =
- qvariant_cast<QDeclarativeParser::Variant>(value);
+ QDeclarativeScript::Variant variant =
+ qvariant_cast<QDeclarativeScript::Variant>(value);
int ref = data.count();
d += char(variant.asBoolean());
} else if (variant.isScript()) {
if (definesEmptyList(variant.asScript())) {
- d[0] = char(QDeclarativeParser::Variant::Invalid); // marks empty list
+ d[0] = char(QDeclarativeScript::Variant::Invalid); // marks empty list
} else {
QByteArray script = variant.asScript().toUtf8();
int v = evaluateEnum(script);
}
if (literal) {
- d[0] = char(QDeclarativeParser::Variant::String);
+ d[0] = char(QDeclarativeScript::Variant::String);
d += literal->value.toUtf8();
} else {
error(prop, QDeclarativeListModel::tr("ListElement: cannot use script for property value"));
return false;
}
} else {
- d[0] = char(QDeclarativeParser::Variant::Number);
+ d[0] = char(QDeclarativeScript::Variant::Number);
d += QByteArray::number(v);
}
}
case ListInstruction::Value:
{
ModelNode *n = nodes.top();
- switch (QDeclarativeParser::Variant::Type(data[instr.dataIdx])) {
- case QDeclarativeParser::Variant::Invalid:
+ switch (QDeclarativeScript::Variant::Type(data[instr.dataIdx])) {
+ case QDeclarativeScript::Variant::Invalid:
n->isArray = true;
break;
- case QDeclarativeParser::Variant::Boolean:
+ case QDeclarativeScript::Variant::Boolean:
n->values.append(bool(data[1 + instr.dataIdx]));
break;
- case QDeclarativeParser::Variant::Number:
+ case QDeclarativeScript::Variant::Number:
n->values.append(QByteArray(data + 1 + instr.dataIdx).toDouble());
break;
- case QDeclarativeParser::Variant::String:
+ case QDeclarativeScript::Variant::String:
n->values.append(QString::fromUtf8(data + 1 + instr.dataIdx));
break;
default:
#include <qdeclarativeinfo.h>
#include <qdeclarativecustomparser_p.h>
-#include <qdeclarativeparser_p.h>
+#include <qdeclarativescript_p.h>
#include <qdeclarativeexpression.h>
#include <qdeclarativebinding_p.h>
#include <qdeclarativecontext.h>
ds << data.count();
for(int ii = 0; ii < data.count(); ++ii) {
- QDeclarativeParser::Variant v = qvariant_cast<QDeclarativeParser::Variant>(data.at(ii).second);
+ QDeclarativeScript::Variant v = qvariant_cast<QDeclarativeScript::Variant>(data.at(ii).second);
QVariant var;
bool isScript = v.isScript();
QDeclarativeBinding::Identifier id = 0;
switch(v.type()) {
- case QDeclarativeParser::Variant::Boolean:
+ case QDeclarativeScript::Variant::Boolean:
var = QVariant(v.asBoolean());
break;
- case QDeclarativeParser::Variant::Number:
+ case QDeclarativeScript::Variant::Number:
var = QVariant(v.asNumber());
break;
- case QDeclarativeParser::Variant::String:
+ case QDeclarativeScript::Variant::String:
var = QVariant(v.asString());
break;
- case QDeclarativeParser::Variant::Invalid:
- case QDeclarativeParser::Variant::Script:
+ case QDeclarativeScript::Variant::Invalid:
+ case QDeclarativeScript::Variant::Script:
var = QVariant(v.asScript());
{
// Pre-rewrite the expression
#include <qdeclarativeinfo.h>
#include <private/qdeclarativeproperty_p.h>
+#include <private/qdeclarativescript_p.h>
#include <QtQuick1/private/qdeclarativeitem_p.h>
#include <QtCore/qdebug.h>
error(props.at(ii), QDeclarativeGestureArea::tr("GestureArea: syntax error"));
return QByteArray();
} else {
- QDeclarativeParser::Variant v = qvariant_cast<QDeclarativeParser::Variant>(value);
+ QDeclarativeScript::Variant v = qvariant_cast<QDeclarativeScript::Variant>(value);
if (v.isScript()) {
ds << propName;
ds << int(type);
error(props.at(ii), QDeclarative1Connections::tr("Connections: syntax error"));
return QByteArray();
} else {
- QDeclarativeParser::Variant v = qvariant_cast<QDeclarativeParser::Variant>(value);
+ QDeclarativeScript::Variant v = qvariant_cast<QDeclarativeScript::Variant>(value);
if (v.isScript()) {
ds << propName;
ds << v.asScript();
#include "QtQuick1/private/qdeclarativeopenmetaobject_p.h"
#include <QtDeclarative/private/qdeclarativecustomparser_p.h>
-#include <QtDeclarative/private/qdeclarativeparser_p.h>
+#include <QtDeclarative/private/qdeclarativescript_p.h>
#include <QtDeclarative/private/qdeclarativeengine_p.h>
#include <QtDeclarative/qdeclarativecontext.h>
#include <QtDeclarative/qdeclarativeinfo.h>
#include <QtDeclarative/qdeclarativeinfo.h>
#include <QtDeclarative/private/qdeclarativecustomparser_p.h>
-#include <QtDeclarative/private/qdeclarativeparser_p.h>
+#include <QtDeclarative/private/qdeclarativescript_p.h>
#include <QtDeclarative/qdeclarativeexpression.h>
#include <QtDeclarative/private/qdeclarativebinding_p.h>
#include <QtDeclarative/qdeclarativecontext.h>
ds << data.count();
for(int ii = 0; ii < data.count(); ++ii) {
- QDeclarativeParser::Variant v = qvariant_cast<QDeclarativeParser::Variant>(data.at(ii).second);
+ QDeclarativeScript::Variant v = qvariant_cast<QDeclarativeScript::Variant>(data.at(ii).second);
QVariant var;
bool isScript = v.isScript();
QDeclarativeBinding::Identifier id = 0;
switch(v.type()) {
- case QDeclarativeParser::Variant::Boolean:
+ case QDeclarativeScript::Variant::Boolean:
var = QVariant(v.asBoolean());
break;
- case QDeclarativeParser::Variant::Number:
+ case QDeclarativeScript::Variant::Number:
var = QVariant(v.asNumber());
break;
- case QDeclarativeParser::Variant::String:
+ case QDeclarativeScript::Variant::String:
var = QVariant(v.asString());
break;
- case QDeclarativeParser::Variant::Invalid:
- case QDeclarativeParser::Variant::Script:
+ case QDeclarativeScript::Variant::Invalid:
+ case QDeclarativeScript::Variant::Script:
var = QVariant(v.asScript());
{
// Pre-rewrite the expression
#include <QtDeclarative/private/qdeclarativejsmemorypool_p.h>
#include <QtDeclarative/private/qdeclarativejsparser_p.h>
#include <QtDeclarative/private/qdeclarativejslexer_p.h>
-#include <QtDeclarative/private/qdeclarativescriptparser_p.h>
+#include <QtDeclarative/private/qdeclarativescript_p.h>
#include <QFile>
#include <QDebug>
QUrl url = QUrl::fromLocalFile(file);
QBENCHMARK {
- QDeclarativeScriptParser parser;
+ QDeclarativeScript::Parser parser;
parser.parse(data, url);
parser.tree();
}