aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/corelib/language
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@digia.com>2014-07-18 17:22:26 +0200
committerJoerg Bornemann <joerg.bornemann@digia.com>2014-07-21 17:15:12 +0200
commit434ee46f8121d8a16a4e94dd6fedace56f799adf (patch)
tree8cbddc76ef8beaa8fb71643d9257007ec30c69e4 /src/lib/corelib/language
parent6baa546e2e3403ab51cf46baeefbe0658b0f45ca (diff)
add a simple Version class
This class replaces the Version struct in setup-qt and the ImportVersion class of the loader. Change-Id: Ic65eaf62de44ce0c082fe805431463defce1fe3b Reviewed-by: Christian Kandeler <christian.kandeler@digia.com>
Diffstat (limited to 'src/lib/corelib/language')
-rw-r--r--src/lib/corelib/language/importversion.cpp77
-rw-r--r--src/lib/corelib/language/importversion.h58
-rw-r--r--src/lib/corelib/language/itemreaderastvisitor.cpp22
-rw-r--r--src/lib/corelib/language/itemreaderastvisitor.h8
-rw-r--r--src/lib/corelib/language/language.pri2
5 files changed, 25 insertions, 142 deletions
diff --git a/src/lib/corelib/language/importversion.cpp b/src/lib/corelib/language/importversion.cpp
deleted file mode 100644
index 848775016..000000000
--- a/src/lib/corelib/language/importversion.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the Qt Build Suite.
-**
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** 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, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-****************************************************************************/
-
-#include "importversion.h"
-#include <logging/translator.h>
-#include <tools/error.h>
-#include <QStringList>
-
-namespace qbs {
-namespace Internal {
-
-ImportVersion::ImportVersion()
- : m_major(0), m_minor(0)
-{
-}
-
-ImportVersion ImportVersion::fromString(const QString &str, const CodeLocation &location)
-{
- QStringList lst = str.split(QLatin1Char('.'));
- if (Q_UNLIKELY(lst.count() < 1 || lst.count() > 2))
- throw ErrorInfo(Tr::tr("Wrong number of components in import version."), location);
- ImportVersion v;
- int *parts[] = {&v.m_major, &v.m_minor, 0};
- for (int i = 0; i < lst.count(); ++i) {
- if (!parts[i])
- break;
- bool ok;
- *parts[i] = lst.at(i).toInt(&ok);
- if (Q_UNLIKELY(!ok))
- throw ErrorInfo(Tr::tr("Cannot parse import version."), location);
- }
- return v;
-}
-
-bool ImportVersion::operator <(const ImportVersion &rhs) const
-{
- return m_major < rhs.m_major || (m_major == rhs.m_major && m_minor < rhs.m_minor);
-}
-
-bool ImportVersion::operator ==(const ImportVersion &rhs) const
-{
- return m_major == rhs.m_major && m_minor == rhs.m_minor;
-}
-
-bool ImportVersion::operator !=(const ImportVersion &rhs) const
-{
- return !operator ==(rhs);
-}
-
-} // namespace Internal
-} // namespace qbs
diff --git a/src/lib/corelib/language/importversion.h b/src/lib/corelib/language/importversion.h
deleted file mode 100644
index 034258793..000000000
--- a/src/lib/corelib/language/importversion.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the Qt Build Suite.
-**
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** 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, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-****************************************************************************/
-
-#ifndef QBS_IMPORTVERSION_H
-#define QBS_IMPORTVERSION_H
-
-#include <tools/codelocation.h>
-
-namespace qbs {
-namespace Internal {
-
-class ImportVersion
-{
-public:
- ImportVersion();
-
- static ImportVersion fromString(const QString &str,
- const CodeLocation &location = CodeLocation());
-
- bool operator <(const ImportVersion &rhs) const;
- bool operator ==(const ImportVersion &rhs) const;
- bool operator !=(const ImportVersion &rhs) const;
-
-private:
- int m_major;
- int m_minor;
-};
-
-} // namespace Internal
-} // namespace qbs
-
-#endif // QBS_IMPORTVERSION_H
diff --git a/src/lib/corelib/language/itemreaderastvisitor.cpp b/src/lib/corelib/language/itemreaderastvisitor.cpp
index dce00cdfe..690a944db 100644
--- a/src/lib/corelib/language/itemreaderastvisitor.cpp
+++ b/src/lib/corelib/language/itemreaderastvisitor.cpp
@@ -52,7 +52,7 @@ namespace Internal {
ItemReaderASTVisitor::ItemReaderASTVisitor(ItemReader *reader, ItemReaderResult *result)
: m_reader(reader)
, m_readerResult(result)
- , m_languageVersion(ImportVersion::fromString(reader->builtins()->languageVersion()))
+ , m_languageVersion(readImportVersion(reader->builtins()->languageVersion()))
, m_file(FileContext::create())
, m_item(0)
, m_sourceValue(0)
@@ -424,6 +424,22 @@ bool ItemReaderASTVisitor::visit(AST::FunctionDeclaration *ast)
return false;
}
+Version ItemReaderASTVisitor::readImportVersion(const QString &str, const CodeLocation &location)
+{
+ QStringList lst = str.split(QLatin1Char('.'));
+ if (Q_UNLIKELY(lst.count() < 1 || lst.count() > 2))
+ throw ErrorInfo(Tr::tr("Wrong number of components in import version."), location);
+ Version v;
+ int *parts[] = {&v.majorVersionRef(), &v.minorVersionRef(), 0};
+ for (int i = 0; i < lst.count(); ++i) {
+ bool ok;
+ *parts[i] = lst.at(i).toInt(&ok);
+ if (Q_UNLIKELY(!ok))
+ throw ErrorInfo(Tr::tr("Cannot parse import version."), location);
+ }
+ return v;
+}
+
bool ItemReaderASTVisitor::visitStatement(AST::Statement *statement)
{
QBS_CHECK(statement);
@@ -482,8 +498,8 @@ void ItemReaderASTVisitor::checkImportVersion(const AST::SourceLocation &version
if (!versionToken.length)
return;
const QString importVersionString = m_file->content().mid(versionToken.offset, versionToken.length);
- const ImportVersion importVersion
- = ImportVersion::fromString(importVersionString, toCodeLocation(versionToken));
+ const Version importVersion = readImportVersion(importVersionString,
+ toCodeLocation(versionToken));
if (Q_UNLIKELY(importVersion != m_languageVersion))
throw ErrorInfo(Tr::tr("Incompatible qbs version %1. This is qbs %2.").arg(
importVersionString, m_reader->builtins()->languageVersion()),
diff --git a/src/lib/corelib/language/itemreaderastvisitor.h b/src/lib/corelib/language/itemreaderastvisitor.h
index 5d12aac35..b92de888e 100644
--- a/src/lib/corelib/language/itemreaderastvisitor.h
+++ b/src/lib/corelib/language/itemreaderastvisitor.h
@@ -30,10 +30,12 @@
#ifndef QBS_ITEMREADERASTVISITOR_H
#define QBS_ITEMREADERASTVISITOR_H
-#include "importversion.h"
#include "item.h"
#include "filecontext.h"
+
#include <parser/qmljsastvisitor_p.h>
+#include <tools/version.h>
+
#include <QHash>
namespace qbs {
@@ -59,6 +61,8 @@ public:
bool visit(QbsQmlJS::AST::FunctionDeclaration *ast);
private:
+ static Version readImportVersion(const QString &str,
+ const CodeLocation &location = CodeLocation());
bool visitStatement(QbsQmlJS::AST::Statement *statement);
CodeLocation toCodeLocation(const QbsQmlJS::AST::SourceLocation &location) const;
void checkDuplicateBinding(Item *item, const QStringList &bindingName,
@@ -77,7 +81,7 @@ private:
ItemReader *m_reader;
ItemReaderResult *m_readerResult;
- const ImportVersion m_languageVersion;
+ const Version m_languageVersion;
FileContextPtr m_file;
QHash<QStringList, QString> m_typeNameToFile;
Item *m_item;
diff --git a/src/lib/corelib/language/language.pri b/src/lib/corelib/language/language.pri
index 9a68d241d..83829d61a 100644
--- a/src/lib/corelib/language/language.pri
+++ b/src/lib/corelib/language/language.pri
@@ -12,7 +12,6 @@ HEADERS += \
$$PWD/forward_decls.h \
$$PWD/functiondeclaration.h \
$$PWD/identifiersearch.h \
- $$PWD/importversion.h \
$$PWD/item.h \
$$PWD/itemdeclaration.h \
$$PWD/itemobserver.h \
@@ -44,7 +43,6 @@ SOURCES += \
$$PWD/filecontextbase.cpp \
$$PWD/filetags.cpp \
$$PWD/identifiersearch.cpp \
- $$PWD/importversion.cpp \
$$PWD/item.cpp \
$$PWD/itemdeclaration.cpp \
$$PWD/itempool.cpp \