LanguageUtils: Add FakeMetaObject and ComponentVersion.

This commit is contained in:
Christian Kamm
2010-12-03 11:17:25 +01:00
parent 87c8cbf44c
commit 5de7be5f91
14 changed files with 439 additions and 275 deletions

View File

@@ -22,7 +22,6 @@ HEADERS += \
$$PWD/qmljslookupcontext.h \
$$PWD/qmljslineinfo.h \
$$PWD/qmljscompletioncontextfinder.h \
$$PWD/qmljscomponentversion.h \
$$PWD/qmljsmodelmanagerinterface.h \
$$PWD/qmljsicontextpane.h \
$$PWD/qmljspropertyreader.h \
@@ -42,7 +41,6 @@ SOURCES += \
$$PWD/qmljslookupcontext.cpp \
$$PWD/qmljslineinfo.cpp \
$$PWD/qmljscompletioncontextfinder.cpp \
$$PWD/qmljscomponentversion.cpp \
$$PWD/qmljsmodelmanagerinterface.cpp \
$$PWD/qmljspropertyreader.cpp \
$$PWD/qmljsrewriter.cpp \

View File

@@ -36,10 +36,13 @@
#include "qmljscheck.h"
#include "qmljsdocument.h"
#include <languageutils/componentversion.h>
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
#include <QtCore/QDebug>
using namespace LanguageUtils;
using namespace QmlJS;
using namespace QmlJS::AST;
using namespace QmlJS::Interpreter;

View File

@@ -36,7 +36,6 @@
#include <qmljs/parser/qmljsastvisitor_p.h>
#include <qmljs/qmljsinterpreter.h>
#include <qmljs/qmljscomponentversion.h>
#include <QtCore/QHash>
#include <QtCore/QStringList>

View File

@@ -1,83 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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.
**
** 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "qmljscomponentversion.h"
using namespace QmlJS;
const int ComponentVersion::NoVersion = -1;
ComponentVersion::ComponentVersion()
: _major(NoVersion), _minor(NoVersion)
{
}
ComponentVersion::ComponentVersion(int major, int minor)
: _major(major), _minor(minor)
{
}
ComponentVersion::~ComponentVersion()
{
}
bool ComponentVersion::isValid() const
{
return _major >= 0 && _minor >= 0;
}
namespace QmlJS {
bool operator<(const ComponentVersion &lhs, const ComponentVersion &rhs)
{
return lhs.majorVersion() < rhs.majorVersion()
|| (lhs.majorVersion() == rhs.majorVersion() && lhs.minorVersion() < rhs.minorVersion());
}
bool operator<=(const ComponentVersion &lhs, const ComponentVersion &rhs)
{
return lhs.majorVersion() < rhs.majorVersion()
|| (lhs.majorVersion() == rhs.majorVersion() && lhs.minorVersion() <= rhs.minorVersion());
}
bool operator==(const ComponentVersion &lhs, const ComponentVersion &rhs)
{
return lhs.majorVersion() == rhs.majorVersion() && lhs.minorVersion() == rhs.minorVersion();
}
bool operator!=(const ComponentVersion &lhs, const ComponentVersion &rhs)
{
return !(lhs == rhs);
}
}

View File

@@ -1,68 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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.
**
** 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.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#ifndef QMLJSCOMPONENTVERSION_H
#define QMLJSCOMPONENTVERSION_H
#include "qmljs_global.h"
namespace QmlJS {
class QMLJS_EXPORT ComponentVersion
{
int _major;
int _minor;
public:
static const int NoVersion;
ComponentVersion();
ComponentVersion(int major, int minor);
~ComponentVersion();
int majorVersion() const
{ return _major; }
int minorVersion() const
{ return _minor; }
bool isValid() const;
};
bool operator<(const ComponentVersion &lhs, const ComponentVersion &rhs);
bool operator<=(const ComponentVersion &lhs, const ComponentVersion &rhs);
bool operator==(const ComponentVersion &lhs, const ComponentVersion &rhs);
bool operator!=(const ComponentVersion &lhs, const ComponentVersion &rhs);
} // namespace QmlJS
#endif // QMLJSCOMPONENTVERSION_H

View File

@@ -45,15 +45,15 @@
QT_QML_BEGIN_NAMESPACE
namespace LanguageUtils {
class FakeMetaObject;
}
namespace QmlJS {
class Bind;
class Snapshot;
namespace Interpreter {
class FakeMetaObject;
}
class QMLJS_EXPORT Document
{
public:
@@ -134,7 +134,7 @@ private:
bool _valid;
QList<QmlDirParser::Component> _components;
QList<QmlDirParser::Plugin> _plugins;
typedef QList<const Interpreter::FakeMetaObject *> FakeMetaObjectList;
typedef QList<const LanguageUtils::FakeMetaObject *> FakeMetaObjectList;
FakeMetaObjectList _metaObjects;
DumpStatus _dumpStatus;

View File

@@ -38,6 +38,8 @@
#include "qmljsscopebuilder.h"
#include "parser/qmljsast_p.h"
#include <languageutils/fakemetaobject.h>
#include <QtCore/QFile>
#include <QtCore/QDir>
#include <QtCore/QString>
@@ -48,6 +50,7 @@
#include <QtCore/QProcess>
#include <QtCore/QDebug>
using namespace LanguageUtils;
using namespace QmlJS::Interpreter;
using namespace QmlJS::AST;
@@ -103,210 +106,6 @@ public:
}
};
} // end of anonymous namespace
namespace QmlJS {
namespace Interpreter {
class FakeMetaEnum {
QString m_name;
QStringList m_keys;
QList<int> m_values;
public:
FakeMetaEnum(const QString &name)
: m_name(name)
{}
QString name() const
{ return m_name; }
void addKey(const QString &key, int value)
{ m_keys.append(key); m_values.append(value); }
QString key(int index) const
{ return m_keys.at(index); }
int keyCount() const
{ return m_keys.size(); }
QStringList keys() const
{ return m_keys; }
};
class FakeMetaMethod {
public:
enum {
Signal,
Slot,
Method
};
enum {
Private,
Protected,
Public
};
public:
FakeMetaMethod(const QString &name, const QString &returnType = QString())
: m_name(name), m_returnType(returnType), m_methodTy(Method), m_methodAccess(Public)
{}
QString methodName() const
{ return m_name; }
QStringList parameterNames() const
{ return m_paramNames; }
QStringList parameterTypes() const
{ return m_paramTypes; }
void addParameter(const QString &name, const QString &type)
{ m_paramNames.append(name); m_paramTypes.append(type); }
int methodType() const
{ return m_methodTy; }
void setMethodType(int methodType)
{ m_methodTy = methodType; }
int access() const
{ return m_methodAccess; }
private:
QString m_name;
QString m_returnType;
QStringList m_paramNames;
QStringList m_paramTypes;
int m_methodTy;
int m_methodAccess;
};
class FakeMetaProperty {
QString m_propertyName;
QString m_type;
bool m_isList;
bool m_isWritable;
bool m_isPointer;
public:
FakeMetaProperty(const QString &name, const QString &type, bool isList, bool isWritable, bool isPointer)
: m_propertyName(name), m_type(type), m_isList(isList), m_isWritable(isWritable), m_isPointer(isPointer)
{}
QString name() const
{ return m_propertyName; }
QString typeName() const
{ return m_type; }
bool isList() const
{ return m_isList; }
bool isWritable() const
{ return m_isWritable; }
bool isPointer() const
{ return m_isPointer; }
};
class FakeMetaObject {
Q_DISABLE_COPY(FakeMetaObject)
public:
class Export {
public:
QString package;
QString type;
QmlJS::ComponentVersion version;
QString packageNameVersion;
};
private:
QList<Export> m_exports;
const FakeMetaObject *m_super;
QString m_superName;
QList<FakeMetaEnum> m_enums;
QHash<QString, int> m_enumNameToIndex;
QList<FakeMetaProperty> m_props;
QHash<QString, int> m_propNameToIdx;
QList<FakeMetaMethod> m_methods;
QString m_defaultPropertyName;
public:
FakeMetaObject()
: m_super(0)
{
}
void addExport(const QString &name, const QString &package, QmlJS::ComponentVersion version)
{
Export exp;
exp.type = name;
exp.package = package;
exp.version = version;
exp.packageNameVersion = QString::fromLatin1("%1.%2 %3.%4").arg(
package, name,
QString::number(version.majorVersion()),
QString::number(version.minorVersion()));
m_exports.append(exp);
}
QList<Export> exports() const
{ return m_exports; }
void setSuperclassName(const QString &superclass)
{ m_superName = superclass; }
QString superclassName() const
{ return m_superName; }
void setSuperclass(FakeMetaObject *superClass)
{ m_super = superClass; }
const FakeMetaObject *superClass() const
{ return m_super; }
void addEnum(const FakeMetaEnum &fakeEnum)
{ m_enumNameToIndex.insert(fakeEnum.name(), m_enums.size()); m_enums.append(fakeEnum); }
int enumeratorCount() const
{ return m_enums.size(); }
int enumeratorOffset() const
{ return 0; }
FakeMetaEnum enumerator(int index) const
{ return m_enums.at(index); }
int enumeratorIndex(const QString &name) const
{ return m_enumNameToIndex.value(name, -1); }
void addProperty(const FakeMetaProperty &property)
{ m_propNameToIdx.insert(property.name(), m_props.size()); m_props.append(property); }
int propertyCount() const
{ return m_props.size(); }
int propertyOffset() const
{ return 0; }
FakeMetaProperty property(int index) const
{ return m_props.at(index); }
int propertyIndex(const QString &name) const
{ return m_propNameToIdx.value(name, -1); }
void addMethod(const FakeMetaMethod &method)
{ m_methods.append(method); }
int methodCount() const
{ return m_methods.size(); }
int methodOffset() const
{ return 0; }
FakeMetaMethod method(int index) const
{ return m_methods.at(index); }
QString defaultPropertyName() const
{ return m_defaultPropertyName; }
void setDefaultPropertyName(const QString defaultPropertyName)
{ m_defaultPropertyName = defaultPropertyName; }
};
} // end of Interpreter namespace
} // end of QmlJS namespace
namespace {
class MetaFunction: public FunctionValue
{
FakeMetaMethod _method;
@@ -423,7 +222,7 @@ private:
bool doInsert = true;
QString name, defaultPropertyName;
QmlJS::ComponentVersion version;
ComponentVersion version;
QString extends;
QString id;
foreach (const QXmlStreamAttribute &attr, _xml.attributes()) {
@@ -469,7 +268,7 @@ private:
unexpectedElement(_xml.name(), tag);
}
metaObject->addExport(id, QString(), QmlJS::ComponentVersion());
metaObject->addExport(id, QString(), ComponentVersion());
if (doInsert) {
_objects->insert(id, metaObject);
@@ -738,7 +537,7 @@ private:
if (_xml.name() == childTag) {
QString type;
QString package;
QmlJS::ComponentVersion version;
ComponentVersion version;
foreach (const QXmlStreamAttribute &attr, _xml.attributes()) {
if (attr.name() == QLatin1String("module")) {
package = attr.value().toString();
@@ -754,7 +553,7 @@ private:
invalidAttr(versionStr, QLatin1String("version"), childTag);
continue;
}
version = QmlJS::ComponentVersion(major, QmlJS::ComponentVersion::NoVersion);
version = ComponentVersion(major, ComponentVersion::NoVersion);
} else {
bool ok = false;
const int major = versionStr.left(dotIdx).toInt(&ok);
@@ -767,7 +566,7 @@ private:
invalidAttr(versionStr, QLatin1String("version"), childTag);
continue;
}
version = QmlJS::ComponentVersion(major, minor);
version = ComponentVersion(major, minor);
}
} else {
ignoreAttr(attr);
@@ -789,7 +588,7 @@ private:
} // end of anonymous namespace
QmlObjectValue::QmlObjectValue(const FakeMetaObject *metaObject, const QString &className,
const QString &packageName, const QmlJS::ComponentVersion version, Engine *engine)
const QString &packageName, const ComponentVersion version, Engine *engine)
: ObjectValue(engine),
_metaObject(metaObject),
_packageName(packageName),
@@ -927,7 +726,7 @@ QString QmlObjectValue::nameInPackage(const QString &packageName) const
return QString();
}
QmlJS::ComponentVersion QmlObjectValue::version() const
ComponentVersion QmlObjectValue::version() const
{ return _componentVersion; }
QString QmlObjectValue::defaultPropertyName() const
@@ -2255,7 +2054,7 @@ void CppQmlTypes::load(Engine *engine, const QList<const FakeMetaObject *> &obje
}
}
QList<QmlObjectValue *> CppQmlTypes::typesForImport(const QString &packageName, QmlJS::ComponentVersion version) const
QList<QmlObjectValue *> CppQmlTypes::typesForImport(const QString &packageName, ComponentVersion version) const
{
QMap<QString, QmlObjectValue *> objectValuesByName;
@@ -2280,7 +2079,7 @@ QList<QmlObjectValue *> CppQmlTypes::typesForImport(const QString &packageName,
}
QmlObjectValue *CppQmlTypes::typeForImport(const QString &qualifiedName,
QmlJS::ComponentVersion version) const
ComponentVersion version) const
{
QString name = qualifiedName;
QString packageName;
@@ -2317,7 +2116,7 @@ bool CppQmlTypes::hasPackage(const QString &package) const
return _typesByPackage.contains(package);
}
QString CppQmlTypes::qualifiedName(const QString &package, const QString &type, QmlJS::ComponentVersion version)
QString CppQmlTypes::qualifiedName(const QString &package, const QString &type, ComponentVersion version)
{
return QString("%1.%2 %3.%4").arg(
package, type,
@@ -2330,7 +2129,7 @@ QmlObjectValue *CppQmlTypes::typeByQualifiedName(const QString &name) const
return _typesByFullyQualifiedName.value(name);
}
QmlObjectValue *CppQmlTypes::typeByQualifiedName(const QString &package, const QString &type, QmlJS::ComponentVersion version) const
QmlObjectValue *CppQmlTypes::typeByQualifiedName(const QString &package, const QString &type, ComponentVersion version) const
{
return typeByQualifiedName(qualifiedName(package, type, version));
}
@@ -2353,7 +2152,7 @@ QmlObjectValue *CppQmlTypes::getOrCreate(const QString &package, const QString &
if (!value) {
*created = true;
value = new QmlObjectValue(
metaObject, typeName, package, QmlJS::ComponentVersion(), engine);
metaObject, typeName, package, ComponentVersion(), engine);
_typesByFullyQualifiedName[qName] = value;
} else {
*created = false;
@@ -3484,7 +3283,7 @@ ImportInfo::ImportInfo()
}
ImportInfo::ImportInfo(Type type, const QString &name,
QmlJS::ComponentVersion version, UiImport *ast)
ComponentVersion version, UiImport *ast)
: _type(type)
, _name(name)
, _version(version)
@@ -3514,7 +3313,7 @@ QString ImportInfo::id() const
return QString();
}
QmlJS::ComponentVersion ImportInfo::version() const
ComponentVersion ImportInfo::version() const
{
return _version;
}

View File

@@ -34,9 +34,9 @@
#ifndef QMLJS_INTERPRETER_H
#define QMLJS_INTERPRETER_H
#include <languageutils/componentversion.h>
#include <qmljs/qmljsdocument.h>
#include <qmljs/qmljs_global.h>
#include <qmljs/qmljscomponentversion.h>
#include <qmljs/parser/qmljsastfwd_p.h>
#include <QtCore/QFileInfoList>
@@ -46,6 +46,13 @@
#include <QtCore/QSet>
#include <QtCore/QMutex>
namespace LanguageUtils {
class FakeMetaObject;
class FakeMetaMethod;
class FakeMetaProperty;
class FakeMetaEnum;
}
namespace QmlJS {
class NameId;
@@ -75,11 +82,6 @@ class TypeEnvironment;
typedef QList<const Value *> ValueList;
class FakeMetaObject;
class FakeMetaMethod;
class FakeMetaProperty;
class FakeMetaEnum;
////////////////////////////////////////////////////////////////////////////////
// Value visitor
////////////////////////////////////////////////////////////////////////////////
@@ -450,16 +452,17 @@ private:
class QMLJS_EXPORT QmlObjectValue: public ObjectValue
{
public:
QmlObjectValue(const FakeMetaObject *metaObject, const QString &className,
const QString &packageName, const ComponentVersion version, Engine *engine);
QmlObjectValue(const LanguageUtils::FakeMetaObject *metaObject, const QString &className,
const QString &packageName, const LanguageUtils::ComponentVersion version,
Engine *engine);
virtual ~QmlObjectValue();
virtual void processMembers(MemberProcessor *processor) const;
const Value *propertyValue(const FakeMetaProperty &prop) const;
const Value *propertyValue(const LanguageUtils::FakeMetaProperty &prop) const;
QString packageName() const;
QString nameInPackage(const QString &packageName) const;
ComponentVersion version() const;
LanguageUtils::ComponentVersion version() const;
QString defaultPropertyName() const;
QString propertyType(const QString &propertyName) const;
bool isListProperty(const QString &name) const;
@@ -473,27 +476,28 @@ public:
bool hasChildInPackage() const;
protected:
const Value *findOrCreateSignature(int index, const FakeMetaMethod &method, QString *methodName) const;
bool isDerivedFrom(const FakeMetaObject *base) const;
const Value *findOrCreateSignature(int index, const LanguageUtils::FakeMetaMethod &method,
QString *methodName) const;
bool isDerivedFrom(const LanguageUtils::FakeMetaObject *base) const;
private:
const FakeMetaObject *_metaObject;
const LanguageUtils::FakeMetaObject *_metaObject;
const QString _packageName;
const ComponentVersion _componentVersion;
const LanguageUtils::ComponentVersion _componentVersion;
mutable QHash<int, const Value *> _metaSignature;
};
class QMLJS_EXPORT QmlEnumValue: public NumberValue
{
public:
QmlEnumValue(const FakeMetaEnum &metaEnum, Engine *engine);
QmlEnumValue(const LanguageUtils::FakeMetaEnum &metaEnum, Engine *engine);
virtual ~QmlEnumValue();
QString name() const;
QStringList keys() const;
private:
FakeMetaEnum *_metaEnum;
LanguageUtils::FakeMetaEnum *_metaEnum;
};
class QMLJS_EXPORT Activation
@@ -588,34 +592,38 @@ class QMLJS_EXPORT CppQmlTypesLoader
public:
/** \return an empty list when successful, error messages otherwise. */
static QStringList load(const QFileInfoList &xmlFiles);
static QList<const FakeMetaObject *> builtinObjects;
static QList<const LanguageUtils::FakeMetaObject *> builtinObjects;
// parses the xml string and fills the newObjects map
static QString parseQmlTypeXml(const QByteArray &xml, QMap<QString, FakeMetaObject *> *newObjects);
static QString parseQmlTypeXml(const QByteArray &xml,
QMap<QString, LanguageUtils::FakeMetaObject *> *newObjects);
private:
static void setSuperClasses(QMap<QString, FakeMetaObject *> *newObjects);
static void setSuperClasses(QMap<QString, LanguageUtils::FakeMetaObject *> *newObjects);
};
class QMLJS_EXPORT CppQmlTypes
{
public:
void load(Interpreter::Engine *interpreter, const QList<const FakeMetaObject *> &objects);
void load(Interpreter::Engine *interpreter, const QList<const LanguageUtils::FakeMetaObject *> &objects);
QList<Interpreter::QmlObjectValue *> typesForImport(const QString &prefix, ComponentVersion version) const;
QList<Interpreter::QmlObjectValue *> typesForImport(const QString &prefix, LanguageUtils::ComponentVersion version) const;
Interpreter::QmlObjectValue *typeForImport(const QString &qualifiedName,
ComponentVersion version = ComponentVersion()) const;
LanguageUtils::ComponentVersion version = LanguageUtils::ComponentVersion()) const;
bool hasPackage(const QString &package) const;
QHash<QString, QmlObjectValue *> types() const
{ return _typesByFullyQualifiedName; }
static QString qualifiedName(const QString &package, const QString &type, ComponentVersion version);
static QString qualifiedName(const QString &package, const QString &type, LanguageUtils::ComponentVersion version);
QmlObjectValue *typeByQualifiedName(const QString &name) const;
QmlObjectValue *typeByQualifiedName(const QString &package, const QString &type, ComponentVersion version) const;
QmlObjectValue *typeByQualifiedName(const QString &package, const QString &type,
LanguageUtils::ComponentVersion version) const;
private:
QmlObjectValue *getOrCreate(const QString &package, const QString &cppName, const FakeMetaObject *metaObject, Engine *engine, bool *created);
QmlObjectValue *getOrCreate(const QString &package, const QString &cppName,
const LanguageUtils::FakeMetaObject *metaObject,
Engine *engine, bool *created);
QHash<QString, QList<QmlObjectValue *> > _typesByPackage;
@@ -969,7 +977,7 @@ public:
ImportInfo();
ImportInfo(Type type, const QString &name,
ComponentVersion version = ComponentVersion(),
LanguageUtils::ComponentVersion version = LanguageUtils::ComponentVersion(),
AST::UiImport *ast = 0);
bool isValid() const;
@@ -982,13 +990,13 @@ public:
// null if the import has no 'as', otherwise the target id
QString id() const;
ComponentVersion version() const;
LanguageUtils::ComponentVersion version() const;
AST::UiImport *ast() const;
private:
Type _type;
QString _name;
ComponentVersion _version;
LanguageUtils::ComponentVersion _version;
AST::UiImport *_ast;
};

View File

@@ -40,10 +40,13 @@
#include "qmljsscopebuilder.h"
#include "qmljsmodelmanagerinterface.h"
#include <languageutils/componentversion.h>
#include <QtCore/QFileInfo>
#include <QtCore/QDir>
#include <QtCore/QDebug>
using namespace LanguageUtils;
using namespace QmlJS;
using namespace QmlJS::Interpreter;
using namespace QmlJS::AST;