Removed private header dependencies and introduced loading QML types from XML file.

This commit is contained in:
Erik Verbruggen
2010-03-01 13:01:05 +01:00
parent 079897f295
commit 13d7612f09
13 changed files with 3635 additions and 388 deletions

View File

@@ -26,17 +26,10 @@ SOURCES += \
$$PWD/qmljsdocument.cpp \
$$PWD/qmljsscanner.cpp \
$$PWD/qmljsinterpreter.cpp \
$$PWD/qmljsmetatypesystem.cpp \
$$PWD/qmljslink.cpp \
$$PWD/qmljscheck.cpp \
$$PWD/qmljsscopebuilder.cpp
contains(QT_CONFIG, declarative) {
QT += declarative
} else {
DEFINES += NO_DECLARATIVE_BACKEND
}
contains(QT, gui) {
SOURCES += $$PWD/qmljsindenter.cpp
HEADERS += $$PWD/qmljsindenter.h

View File

@@ -30,7 +30,6 @@
#include "parser/qmljsast_p.h"
#include "qmljsbind.h"
#include "qmljsdocument.h"
#include "qmljsmetatypesystem.h"
#include <QtCore/QDir>
#include <QtCore/QFileInfo>

View File

@@ -38,10 +38,6 @@
#include <QtGui/QColor>
#include <QtGui/QApplication>
#ifndef NO_DECLARATIVE_BACKEND
# include <QtDeclarative/private/qdeclarativestringconverters_p.h> // ### remove me
#endif
namespace QmlJS {
namespace Messages {
static const char *invalid_property_name = QT_TRANSLATE_NOOP("QmlJS::Check", "'%1' is not a valid property name");
@@ -122,7 +118,6 @@ public:
if (StringLiteral *stringLiteral = cast<StringLiteral *>(_ast)) {
const QString curveName = stringLiteral->value->asString();
// ### update when easing changes hit master
if (!EasingCurveNameValue::curveNames().contains(curveName)) {
_message.message = tr(Messages::unknown_easing_curve_name);
}
@@ -139,12 +134,23 @@ public:
if (StringLiteral *stringLiteral = cast<StringLiteral *>(_ast)) {
const QString colorString = stringLiteral->value->asString();
#ifndef NO_DECLARATIVE_BACKEND
bool ok = false;
QDeclarativeStringConverters::colorFromString(colorString, &ok);
bool ok = true;
if (colorString.size() == 9 && colorString.at(0) == QLatin1Char('#')) {
// #rgba
for (int i = 1; i < 9; ++i) {
const QChar c = colorString.at(i);
if (c >= QLatin1Char('0') && c <= QLatin1Char('9')
|| c >= QLatin1Char('a') && c <= QLatin1Char('f')
|| c >= QLatin1Char('A') && c <= QLatin1Char('F'))
continue;
ok = false;
break;
}
} else {
ok = QColor(colorString).isValid();
}
if (!ok)
_message.message = QCoreApplication::translate("QmlJS::Check", "not a valid color");
#endif
} else {
visit((StringValue *)0);
}

File diff suppressed because it is too large Load Diff

View File

@@ -32,9 +32,9 @@
#include <qmljs/qmljsdocument.h>
#include <qmljs/qmljs_global.h>
#include <qmljs/qmljsmetatypesystem.h>
#include <qmljs/parser/qmljsastfwd_p.h>
#include <QtCore/QFileInfoList>
#include <QtCore/QList>
#include <QtCore/QString>
#include <QtCore/QHash>
@@ -66,6 +66,10 @@ class AnchorLineValue;
typedef QList<const Value *> ValueList;
class FakeMetaObject;
class FakeMetaMethod;
class FakeMetaProperty;
////////////////////////////////////////////////////////////////////////////////
// Value visitor
////////////////////////////////////////////////////////////////////////////////
@@ -396,41 +400,32 @@ private:
QString _className;
};
#ifndef NO_DECLARATIVE_BACKEND
class QmlObjectValue: public ObjectValue
{
public:
QmlObjectValue(const QMetaObject *metaObject, const QString &qmlTypeName, int majorVersion, int minorVersion, Engine *engine);
static const int NoVersion;
public:
QmlObjectValue(const FakeMetaObject *metaObject, Engine *engine);
virtual ~QmlObjectValue();
virtual const Value *lookupMember(const QString &name, Context *context) const;
virtual void processMembers(MemberProcessor *processor) const;
const Value *propertyValue(const QMetaProperty &prop) const;
const Value *propertyValue(const FakeMetaProperty &prop) const;
QString qmlTypeName() const
{ return _qmlTypeName; }
int majorVersion() const
{ return _majorVersion; }
int minorVersion() const
{ return _minorVersion; }
QString packageName() const;
int majorVersion() const;
int minorVersion() const;
protected:
const Value *findOrCreateSignature(int index, const QMetaMethod &method, QString *methodName) const;
bool isDerivedFrom(const QMetaObject *base) const;
const Value *findOrCreateSignature(int index, const FakeMetaMethod &method, QString *methodName) const;
bool isDerivedFrom(const FakeMetaObject *base) const;
private:
const QMetaObject *_metaObject;
QString _qmlTypeName;
int _majorVersion;
int _minorVersion;
const FakeMetaObject *_metaObject;
mutable QHash<int, const Value *> _metaSignature;
};
#endif // !NO_DECLARATIVE_BACKEND
class QMLJS_EXPORT Activation
{
public:
@@ -518,6 +513,23 @@ private:
// typing environment
////////////////////////////////////////////////////////////////////////////////
class QMLJS_EXPORT MetaTypeSystem
{
static QList<const FakeMetaObject *> _metaObjects;
public:
/** \return an empty list when successful, error messages otherwise. */
static QStringList load(const QFileInfoList &xmlFiles);
void reload(Interpreter::Engine *interpreter);
QList<Interpreter::QmlObjectValue *> staticTypesForImport(const QString &prefix, int majorVersion, int minorVersion) const;
Interpreter::QmlObjectValue *staticTypeForImport(const QString &qualifiedName) const;
private:
QHash<QString, QList<QmlObjectValue *> > _importedTypes;
};
class ConvertToNumber: protected ValueVisitor // ECMAScript ToInt()
{
public:
@@ -633,9 +645,6 @@ public:
// QML objects
const ObjectValue *qmlKeysObject();
const Value *defaultValueForBuiltinType(const QString &typeName) const;
#ifndef NO_DECLARATIVE_BACKEND
QmlObjectValue *newQmlObject(const QString &name, const QString &prefix, int majorVersion, int minorVersion);
#endif
// global object
ObjectValue *globalObject() const;
@@ -703,9 +712,7 @@ private:
ObjectValue *_globalObject;
ObjectValue *_mathObject;
ObjectValue *_qtObject;
#ifndef NO_DECLARATIVE_BACKEND
ObjectValue *_qmlKeysObject;
#endif
NullValue _nullValue;
UndefinedValue _undefinedValue;

View File

@@ -254,8 +254,8 @@ void Link::importNonFile(Interpreter::ObjectValue *typeEnv, Document::Ptr doc, A
// try the metaobject system
if (import->importUri) {
const QString package = Bind::toString(import->importUri, '/');
int majorVersion = -1; // ### TODO: Check these magic version numbers
int minorVersion = -1; // ### TODO: Check these magic version numbers
int majorVersion = QmlObjectValue::NoVersion;
int minorVersion = QmlObjectValue::NoVersion;
if (import->versionToken.isValid()) {
const QString versionString = doc->source().mid(import->versionToken.offset, import->versionToken.length);
@@ -269,11 +269,10 @@ void Link::importNonFile(Interpreter::ObjectValue *typeEnv, Document::Ptr doc, A
minorVersion = versionString.mid(dotIdx + 1).toInt();
}
}
#ifndef NO_DECLARATIVE_BACKEND
foreach (QmlObjectValue *object, engine()->metaTypeSystem().staticTypesForImport(package, majorVersion, minorVersion)) {
namespaceObject->setProperty(object->qmlTypeName(), object);
namespaceObject->setProperty(object->className(), object);
}
#endif // NO_DECLARATIVE_BACKEND
}
}

View File

@@ -1,86 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "qmljsinterpreter.h"
#include "qmljsmetatypesystem.h"
#ifndef NO_DECLARATIVE_BACKEND
#include <QtDeclarative/private/qdeclarativemetatype_p.h>
#endif // NO_DECLARATIVE_BACKEND
using namespace QmlJS;
using namespace QmlJS::Interpreter;
void MetaTypeSystem::reload(Interpreter::Engine *interpreter)
{
_importedTypes.clear();
#ifndef NO_DECLARATIVE_BACKEND
foreach (QDeclarativeType *type, QDeclarativeMetaType::qmlTypes()) {
const QString fqType = type->qmlTypeName();
const int sepIdx = fqType.lastIndexOf(QLatin1Char('/'));
QString typeName;
QString package;
if (sepIdx == -1) {
typeName = fqType;
} else {
typeName = fqType.mid(sepIdx + 1);
package = fqType.left(sepIdx);
}
_importedTypes[package].append(interpreter->newQmlObject(typeName, package, type->majorVersion(), type->minorVersion()));
}
}
QList<QmlObjectValue *> MetaTypeSystem::staticTypesForImport(const QString &prefix, int majorVersion, int minorVersion) const
{
QMap<QString, QmlObjectValue *> objectValuesByName;
foreach (QmlObjectValue *qmlObjectValue, _importedTypes.value(prefix)) {
if (qmlObjectValue->majorVersion() < majorVersion ||
(qmlObjectValue->majorVersion() == majorVersion && qmlObjectValue->minorVersion() <= minorVersion)) {
// we got a candidate.
const QString typeName = qmlObjectValue->qmlTypeName();
QmlObjectValue *previousCandidate = objectValuesByName.value(typeName, 0);
if (previousCandidate) {
// check if our new candidate is newer than the one we found previously
if (qmlObjectValue->majorVersion() > previousCandidate->majorVersion() ||
(qmlObjectValue->majorVersion() == previousCandidate->majorVersion() && qmlObjectValue->minorVersion() > previousCandidate->minorVersion())) {
// the new candidate has a higher version no. than the one we found previously, so replace it
objectValuesByName.insert(typeName, qmlObjectValue);
}
} else {
objectValuesByName.insert(typeName, qmlObjectValue);
}
}
}
return objectValuesByName.values();
#endif // NO_DECLARATIVE_BACKEND
}

View File

@@ -1,58 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef QMLJSMETATYPESYSTEM_H
#define QMLJSMETATYPESYSTEM_H
#include <QtCore/QHash>
#include <QtCore/QString>
namespace QmlJS {
namespace Interpreter {
class Engine;
class QmlObjectValue;
} // namespace Interpreter
class MetaTypeSystem
{
public:
void reload(Interpreter::Engine *interpreter);
#ifndef NO_DECLARATIVE_BACKEND
QList<Interpreter::QmlObjectValue *> staticTypesForImport(const QString &prefix, int majorVersion, int minorVersion) const;
#endif // NO_DECLARATIVE_BACKEND
private:
QHash<QString, QList<Interpreter::QmlObjectValue *> > _importedTypes;
};
} // namespace QmlJS
#endif // QMLJSMETATYPESYSTEM_H

View File

@@ -73,13 +73,12 @@ void ScopeBuilder::setQmlScopeObject(Node *node)
return; // Probably syntax errors, where we're working with a "recovered" AST.
}
#ifndef NO_DECLARATIVE_BACKEND
// check if the object has a Qt.ListElement ancestor
const ObjectValue *prototype = scopeObject->prototype(_context);
while (prototype) {
if (const QmlObjectValue *qmlMetaObject = dynamic_cast<const QmlObjectValue *>(prototype)) {
// ### Also check for Qt package. Involves changes in QmlObjectValue.
if (qmlMetaObject->qmlTypeName() == QLatin1String("ListElement")) {
if (qmlMetaObject->className() == QLatin1String("ListElement")
&& qmlMetaObject->packageName() == QLatin1String("Qt")) {
scopeChain.qmlScopeObjects.clear();
break;
}
@@ -91,8 +90,8 @@ void ScopeBuilder::setQmlScopeObject(Node *node)
prototype = scopeObject->prototype(_context);
while (prototype) {
if (const QmlObjectValue *qmlMetaObject = dynamic_cast<const QmlObjectValue *>(prototype)) {
// ### Also check for Qt package. Involves changes in QmlObjectValue.
if (qmlMetaObject->qmlTypeName() == QLatin1String("PropertyChanges"))
if (qmlMetaObject->className() == QLatin1String("PropertyChanges")
&& qmlMetaObject->packageName() == QLatin1String("Qt"))
break;
}
prototype = prototype->prototype(_context);
@@ -126,5 +125,4 @@ void ScopeBuilder::setQmlScopeObject(Node *node)
}
}
}
#endif
}