diff options
author | Joerg Bornemann <joerg.bornemann@digia.com> | 2014-02-27 17:35:52 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@digia.com> | 2014-02-28 12:42:44 +0100 |
commit | 85b234c3a0a4d1c40dd509f8a1a24907eea7d2ba (patch) | |
tree | f547648f13239d9fea0eccfe12fd840a55dde0d3 /src | |
parent | 08a4a71c7ced7b799e4b706377a39a5146431c38 (diff) |
give FileContext and ResolvedFileContext a common base
Change-Id: I76f0e5e0b9f99a6f33c3381436ee6c4879e36a68
Reviewed-by: Christian Kandeler <christian.kandeler@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/corelib/buildgraph/buildgraph.cpp | 4 | ||||
-rw-r--r-- | src/lib/corelib/corelib.qbs | 2 | ||||
-rw-r--r-- | src/lib/corelib/language/filecontext.cpp | 6 | ||||
-rw-r--r-- | src/lib/corelib/language/filecontext.h | 29 | ||||
-rw-r--r-- | src/lib/corelib/language/filecontextbase.cpp | 50 | ||||
-rw-r--r-- | src/lib/corelib/language/filecontextbase.h | 96 | ||||
-rw-r--r-- | src/lib/corelib/language/forward_decls.h | 4 | ||||
-rw-r--r-- | src/lib/corelib/language/language.cpp | 4 | ||||
-rw-r--r-- | src/lib/corelib/language/language.pri | 2 | ||||
-rw-r--r-- | src/lib/corelib/language/projectresolver.cpp | 8 | ||||
-rw-r--r-- | src/lib/corelib/language/resolvedfilecontext.cpp | 23 | ||||
-rw-r--r-- | src/lib/corelib/language/resolvedfilecontext.h | 11 |
12 files changed, 183 insertions, 56 deletions
diff --git a/src/lib/corelib/buildgraph/buildgraph.cpp b/src/lib/corelib/buildgraph/buildgraph.cpp index 35b67e736..6a115383c 100644 --- a/src/lib/corelib/buildgraph/buildgraph.cpp +++ b/src/lib/corelib/buildgraph/buildgraph.cpp @@ -165,8 +165,8 @@ static void setupProductScriptValue(ScriptEngine *engine, QScriptValue &productS void setupScriptEngineForFile(ScriptEngine *engine, const ResolvedFileContextConstPtr &fileContext, QScriptValue targetObject) { - engine->import(fileContext->jsImports, targetObject, targetObject); - JsExtensions::setupExtensions(fileContext->jsExtensions, targetObject); + engine->import(fileContext->jsImports(), targetObject, targetObject); + JsExtensions::setupExtensions(fileContext->jsExtensions(), targetObject); } void setupScriptEngineForProduct(ScriptEngine *engine, const ResolvedProductConstPtr &product, diff --git a/src/lib/corelib/corelib.qbs b/src/lib/corelib/corelib.qbs index 3ac288a6a..74db39d5d 100644 --- a/src/lib/corelib/corelib.qbs +++ b/src/lib/corelib/corelib.qbs @@ -178,6 +178,8 @@ QbsLibrary { "evaluatorscriptclass.h", "filecontext.cpp", "filecontext.h", + "filecontextbase.cpp", + "filecontextbase.h", "filetags.cpp", "filetags.h", "functiondeclaration.h", diff --git a/src/lib/corelib/language/filecontext.cpp b/src/lib/corelib/language/filecontext.cpp index 570b40c66..2300f8c7e 100644 --- a/src/lib/corelib/language/filecontext.cpp +++ b/src/lib/corelib/language/filecontext.cpp @@ -28,7 +28,6 @@ ****************************************************************************/ #include "filecontext.h" -#include <tools/fileinfo.h> namespace qbs { namespace Internal { @@ -43,10 +42,5 @@ FileContextPtr FileContext::create() return FileContextPtr(new FileContext); } -QString FileContext::dirPath() const -{ - return FileInfo::path(m_filePath); -} - } // namespace Internal } // namespace qbs diff --git a/src/lib/corelib/language/filecontext.h b/src/lib/corelib/language/filecontext.h index 75f93f04c..812cd2fe2 100644 --- a/src/lib/corelib/language/filecontext.h +++ b/src/lib/corelib/language/filecontext.h @@ -30,15 +30,13 @@ #ifndef QBS_FILECONTEXT_H #define QBS_FILECONTEXT_H +#include "filecontextbase.h" #include "item.h" -#include "jsimports.h" - -#include <QStringList> namespace qbs { namespace Internal { -class FileContext +class FileContext : public FileContextBase { friend class ItemReaderASTVisitor; @@ -47,35 +45,12 @@ class FileContext public: static FileContextPtr create(); - QString filePath() const; - QString dirPath() const; - JsImports jsImports() const; - QStringList jsExtensions() const; - Item *idScope() const; private: - QString m_filePath; - JsImports m_jsImports; - QStringList m_jsExtensions; Item *m_idScope; }; -inline QString FileContext::filePath() const -{ - return m_filePath; -} - -inline JsImports FileContext::jsImports() const -{ - return m_jsImports; -} - -inline QStringList FileContext::jsExtensions() const -{ - return m_jsExtensions; -} - inline Item *FileContext::idScope() const { return m_idScope; diff --git a/src/lib/corelib/language/filecontextbase.cpp b/src/lib/corelib/language/filecontextbase.cpp new file mode 100644 index 000000000..c6e77b1bc --- /dev/null +++ b/src/lib/corelib/language/filecontextbase.cpp @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** 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 "filecontextbase.h" + +#include <tools/fileinfo.h> + +namespace qbs { +namespace Internal { + +QString FileContextBase::dirPath() const +{ + return FileInfo::path(m_filePath); +} + +FileContextBase::FileContextBase(const FileContextBase &other) + : m_filePath(other.m_filePath) + , m_jsImports(other.m_jsImports) + , m_jsExtensions(other.m_jsExtensions) +{ +} + +} // namespace Internal +} // namespace qbs diff --git a/src/lib/corelib/language/filecontextbase.h b/src/lib/corelib/language/filecontextbase.h new file mode 100644 index 000000000..3a465ffaa --- /dev/null +++ b/src/lib/corelib/language/filecontextbase.h @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** 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_FILECONTEXTBASE_H +#define QBS_FILECONTEXTBASE_H + +#include "jsimports.h" + +namespace qbs { +namespace Internal { + +class FileContextBase +{ + friend class ItemReaderASTVisitor; + +public: + void setFilePath(const QString &filePath); + QString filePath() const; + + void setJsImports(const JsImports &jsImports); + JsImports jsImports() const; + + void setJsExtensions(const QStringList &extensions); + QStringList jsExtensions() const; + + QString dirPath() const; + +protected: + FileContextBase() {} + FileContextBase(const FileContextBase &other); + + QString m_filePath; + JsImports m_jsImports; + QStringList m_jsExtensions; +}; + +inline void FileContextBase::setFilePath(const QString &filePath) +{ + m_filePath = filePath; +} + +inline QString FileContextBase::filePath() const +{ + return m_filePath; +} + +inline void FileContextBase::setJsImports(const JsImports &jsImports) +{ + m_jsImports = jsImports; +} + +inline JsImports FileContextBase::jsImports() const +{ + return m_jsImports; +} + +inline void FileContextBase::setJsExtensions(const QStringList &extensions) +{ + m_jsExtensions = extensions; +} + +inline QStringList FileContextBase::jsExtensions() const +{ + return m_jsExtensions; +} + +} // namespace Internal +} // namespace qbs + +#endif // QBS_FILECONTEXTBASE_H diff --git a/src/lib/corelib/language/forward_decls.h b/src/lib/corelib/language/forward_decls.h index dc7c572df..0bbd33326 100644 --- a/src/lib/corelib/language/forward_decls.h +++ b/src/lib/corelib/language/forward_decls.h @@ -58,6 +58,10 @@ class FileContext; typedef QSharedPointer<FileContext> FileContextPtr; typedef QSharedPointer<const FileContext> FileContextConstPtr; +class FileContextBase; +typedef QSharedPointer<FileContextBase> FileContextBasePtr; +typedef QSharedPointer<const FileContextBase> FileContextBaseConstPtr; + class PropertyMapInternal; typedef QSharedPointer<PropertyMapInternal> PropertyMapPtr; typedef QSharedPointer<const PropertyMapInternal> PropertyMapConstPtr; diff --git a/src/lib/corelib/language/language.cpp b/src/lib/corelib/language/language.cpp index 8c57bb378..4b4d094f6 100644 --- a/src/lib/corelib/language/language.cpp +++ b/src/lib/corelib/language/language.cpp @@ -606,8 +606,8 @@ static QProcessEnvironment getProcessEnvironment(ScriptEngine *engine, EnvType e } // handle imports - engine->import(setupScript->fileContext->jsImports, scope, scope); - JsExtensions::setupExtensions(setupScript->fileContext->jsExtensions, scope); + engine->import(setupScript->fileContext->jsImports(), scope, scope); + JsExtensions::setupExtensions(setupScript->fileContext->jsExtensions(), scope); // expose properties of direct module dependencies QScriptValue scriptValue; diff --git a/src/lib/corelib/language/language.pri b/src/lib/corelib/language/language.pri index c4309d585..9a68d241d 100644 --- a/src/lib/corelib/language/language.pri +++ b/src/lib/corelib/language/language.pri @@ -7,6 +7,7 @@ HEADERS += \ $$PWD/evaluator.h \ $$PWD/evaluatorscriptclass.h \ $$PWD/filecontext.h \ + $$PWD/filecontextbase.h \ $$PWD/filetags.h \ $$PWD/forward_decls.h \ $$PWD/functiondeclaration.h \ @@ -40,6 +41,7 @@ SOURCES += \ $$PWD/evaluator.cpp \ $$PWD/evaluatorscriptclass.cpp \ $$PWD/filecontext.cpp \ + $$PWD/filecontextbase.cpp \ $$PWD/filetags.cpp \ $$PWD/identifiersearch.cpp \ $$PWD/importversion.cpp \ diff --git a/src/lib/corelib/language/projectresolver.cpp b/src/lib/corelib/language/projectresolver.cpp index c40a52672..869b8c63e 100644 --- a/src/lib/corelib/language/projectresolver.cpp +++ b/src/lib/corelib/language/projectresolver.cpp @@ -562,12 +562,8 @@ ScriptFunctionPtr ProjectResolver::scriptFunctionValue(Item *item, const QString ResolvedFileContextPtr ProjectResolver::resolvedFileContext(const FileContextConstPtr &ctx) const { ResolvedFileContextPtr &result = m_fileContextMap[ctx]; - if (!result) { - result = ResolvedFileContext::create(); - result->filePath = ctx->filePath(); - result->jsExtensions = ctx->jsExtensions(); - result->jsImports = ctx->jsImports(); - } + if (!result) + result = ResolvedFileContext::create(*ctx); return result; } diff --git a/src/lib/corelib/language/resolvedfilecontext.cpp b/src/lib/corelib/language/resolvedfilecontext.cpp index 0ac48e69b..bf36b4e79 100644 --- a/src/lib/corelib/language/resolvedfilecontext.cpp +++ b/src/lib/corelib/language/resolvedfilecontext.cpp @@ -50,18 +50,23 @@ static inline QDataStream& operator<<(QDataStream &stream, const JsImport &jsImp << jsImport.location; } +ResolvedFileContext::ResolvedFileContext(const FileContextBase &ctx) + : FileContextBase(ctx) +{ +} + void ResolvedFileContext::load(PersistentPool &pool) { - filePath = pool.idLoadString(); - jsExtensions = pool.idLoadStringList(); - pool.stream() >> jsImports; + m_filePath = pool.idLoadString(); + m_jsExtensions = pool.idLoadStringList(); + pool.stream() >> m_jsImports; } void ResolvedFileContext::store(PersistentPool &pool) const { - pool.storeString(filePath); - pool.storeStringList(jsExtensions); - pool.stream() << jsImports; + pool.storeString(m_filePath); + pool.storeStringList(m_jsExtensions); + pool.stream() << m_jsImports; } bool operator==(const ResolvedFileContext &a, const ResolvedFileContext &b) @@ -70,9 +75,9 @@ bool operator==(const ResolvedFileContext &a, const ResolvedFileContext &b) return true; if (!!&a != !!&b) return false; - return a.filePath == b.filePath - && a.jsExtensions == b.jsExtensions - && a.jsImports == b.jsImports; + return a.filePath() == b.filePath() + && a.jsExtensions() == b.jsExtensions() + && a.jsImports() == b.jsImports(); } } // namespace Internal diff --git a/src/lib/corelib/language/resolvedfilecontext.h b/src/lib/corelib/language/resolvedfilecontext.h index 66266181e..db5df5089 100644 --- a/src/lib/corelib/language/resolvedfilecontext.h +++ b/src/lib/corelib/language/resolvedfilecontext.h @@ -31,13 +31,14 @@ #define QBS_RESOLVEDFILECONTEXT_H #include "forward_decls.h" +#include "filecontextbase.h" #include "jsimports.h" #include <tools/persistentobject.h> namespace qbs { namespace Internal { -class ResolvedFileContext : public PersistentObject +class ResolvedFileContext : public FileContextBase, public PersistentObject { public: static ResolvedFileContextPtr create() @@ -45,12 +46,14 @@ public: return ResolvedFileContextPtr(new ResolvedFileContext); } - QString filePath; - QStringList jsExtensions; - JsImports jsImports; + static ResolvedFileContextPtr create(const FileContextBase &baseContext) + { + return ResolvedFileContextPtr(new ResolvedFileContext(baseContext)); + } private: ResolvedFileContext() {} + ResolvedFileContext(const FileContextBase &ctx); void load(PersistentPool &pool); void store(PersistentPool &pool) const; |