Commit 0d5d6344 authored by Christian Kamm's avatar Christian Kamm
Browse files

QmlJS: Collect import version numbers in Bind.

parent 1cf95867
......@@ -53,17 +53,17 @@ Bind::~Bind()
{
}
QStringList Bind::fileImports() const
QList<Bind::ImportInfo> Bind::fileImports() const
{
return _fileImports;
}
QStringList Bind::directoryImports() const
QList<Bind::ImportInfo> Bind::directoryImports() const
{
return _directoryImports;
}
QStringList Bind::libraryImports() const
QList<Bind::ImportInfo> Bind::libraryImports() const
{
return _libraryImports;
}
......@@ -185,14 +185,30 @@ bool Bind::visit(AST::Program *)
bool Bind::visit(UiImport *ast)
{
ImportInfo info;
info.majorVersion = QmlObjectValue::NoVersion;
info.minorVersion = QmlObjectValue::NoVersion;
if (ast->versionToken.isValid()) {
const QString versionString = _doc->source().mid(ast->versionToken.offset, ast->versionToken.length);
const int dotIdx = versionString.indexOf(QLatin1Char('.'));
if (dotIdx != -1) {
info.majorVersion = versionString.left(dotIdx).toInt();
info.minorVersion = versionString.mid(dotIdx + 1).toInt();
}
}
if (ast->importUri) {
_libraryImports += toString(ast->importUri, QLatin1Char('/'));
info.name = toString(ast->importUri, QLatin1Char('/'));
_libraryImports += info;
} else if (ast->fileName) {
const QFileInfo importFileInfo(_doc->path() + QLatin1Char('/') + ast->fileName->asString());
info.name = importFileInfo.absoluteFilePath();
if (importFileInfo.isFile())
_fileImports += importFileInfo.absoluteFilePath();
_fileImports += info;
else if (importFileInfo.isDir())
_directoryImports += importFileInfo.absoluteFilePath();
_directoryImports += info;
//else
// error: file or directory does not exist
}
......
......@@ -50,9 +50,15 @@ public:
Bind(Document *doc);
virtual ~Bind();
QStringList fileImports() const;
QStringList directoryImports() const;
QStringList libraryImports() const;
struct ImportInfo {
QString name;
int majorVersion;
int minorVersion;
};
QList<ImportInfo> fileImports() const;
QList<ImportInfo> directoryImports() const;
QList<ImportInfo> libraryImports() const;
Interpreter::ObjectValue *currentObjectValue() const;
Interpreter::ObjectValue *idEnvironment() const;
......@@ -105,9 +111,9 @@ private:
QHash<AST::FunctionDeclaration *, Interpreter::ObjectValue *> _functionScopes;
QStringList _includedScripts;
QStringList _fileImports;
QStringList _directoryImports;
QStringList _libraryImports;
QList<ImportInfo> _fileImports;
QList<ImportInfo> _directoryImports;
QList<ImportInfo> _libraryImports;
};
} // end of namespace Qml
......
......@@ -65,8 +65,8 @@ void Link::initializeScopeChain()
} else {
// add scope chains for all components that import this file
foreach (Document::Ptr otherDoc, _snapshot) {
foreach (const QString &fileImport, otherDoc->bind()->fileImports()) {
if (_doc->fileName() == fileImport) {
foreach (const Bind::ImportInfo &fileImport, otherDoc->bind()->fileImports()) {
if (_doc->fileName() == fileImport.name) {
ScopeChain::QmlComponentChain *component = new ScopeChain::QmlComponentChain;
componentScopes.insert(otherDoc.data(), component);
scopeChain.qmlComponentScope.instantiatingComponents += component;
......
......@@ -236,15 +236,15 @@ static void findNewFileImports(const Document::Ptr &doc, const Snapshot &snapsho
QStringList *importedFiles, QSet<QString> *scannedPaths)
{
// scan files and directories that are explicitly imported
foreach (const QString &fileImport, doc->bind()->fileImports()) {
if (! snapshot.document(fileImport))
*importedFiles += fileImport;
foreach (const Bind::ImportInfo &fileImport, doc->bind()->fileImports()) {
if (! snapshot.document(fileImport.name))
*importedFiles += fileImport.name;
}
foreach (const QString &directoryImport, doc->bind()->directoryImports()) {
if (snapshot.documentsInDirectory(directoryImport).isEmpty()) {
if (! scannedPaths->contains(directoryImport)) {
*importedFiles += qmlFilesInDirectory(directoryImport);
scannedPaths->insert(directoryImport);
foreach (const Bind::ImportInfo &directoryImport, doc->bind()->directoryImports()) {
if (snapshot.documentsInDirectory(directoryImport.name).isEmpty()) {
if (! scannedPaths->contains(directoryImport.name)) {
*importedFiles += qmlFilesInDirectory(directoryImport.name);
scannedPaths->insert(directoryImport.name);
}
}
}
......@@ -256,10 +256,10 @@ static void findNewLibraryImports(const Document::Ptr &doc, const Snapshot &snap
{
// scan library imports
const QStringList importPaths = modelManager->importPaths();
foreach (const QString &libraryImport, doc->bind()->libraryImports()) {
foreach (const Bind::ImportInfo &libraryImport, doc->bind()->libraryImports()) {
foreach (const QString &importPath, importPaths) {
QDir dir(importPath);
dir.cd(libraryImport);
dir.cd(libraryImport.name);
const QString targetPath = dir.absolutePath();
// if we know there is a library, done
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment