| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information ([email protected])
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the qt3to4 porting application of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef PREPROCESSORCONTROL_H
|
|---|
| 43 | #define PREPROCESSORCONTROL_H
|
|---|
| 44 |
|
|---|
| 45 | #include "tokenengine.h"
|
|---|
| 46 | #include "tokenizer.h"
|
|---|
| 47 | #include "rpplexer.h"
|
|---|
| 48 | #include "rpptreeevaluator.h"
|
|---|
| 49 | #include "rpp.h"
|
|---|
| 50 | #include <QString>
|
|---|
| 51 | #include <QStringList>
|
|---|
| 52 | #include <QHash>
|
|---|
| 53 |
|
|---|
| 54 | QT_BEGIN_NAMESPACE
|
|---|
| 55 |
|
|---|
| 56 | class IncludeFiles
|
|---|
| 57 | {
|
|---|
| 58 | public:
|
|---|
| 59 | IncludeFiles(const QString &basePath, const QStringList &searchPaths);
|
|---|
| 60 | QString quoteLookup(const QString ¤tFile,
|
|---|
| 61 | const QString &includeFile)const;
|
|---|
| 62 | QString angleBracketLookup(const QString &includeFile) const;
|
|---|
| 63 | QString resolve(const QString &filename) const;
|
|---|
| 64 | private:
|
|---|
| 65 | QString searchIncludePaths(const QString &includeFile)const;
|
|---|
| 66 | QStringList m_searchPaths;
|
|---|
| 67 | QString m_basePath;
|
|---|
| 68 | };
|
|---|
| 69 |
|
|---|
| 70 | class PreprocessorCache: public QObject
|
|---|
| 71 | {
|
|---|
| 72 | Q_OBJECT
|
|---|
| 73 | public:
|
|---|
| 74 | PreprocessorCache();
|
|---|
| 75 | TokenEngine::TokenContainer sourceTokens(const QString &filename);
|
|---|
| 76 | Rpp::Source *sourceTree(const QString &filename);
|
|---|
| 77 | bool containsSourceTokens(const QString &filename);
|
|---|
| 78 | bool containsSourceTree(const QString &filename);
|
|---|
| 79 | signals:
|
|---|
| 80 | void error(QString type, QString text);
|
|---|
| 81 | void readFile(QByteArray &contents, QString filename);
|
|---|
| 82 | private:
|
|---|
| 83 | QByteArray readFile(const QString & filename) const;
|
|---|
| 84 | Tokenizer m_tokenizer;
|
|---|
| 85 | Rpp::RppLexer m_lexer;
|
|---|
| 86 | Rpp::Preprocessor m_preprocessor;
|
|---|
| 87 | TypedPool<Rpp::Item> m_memoryPool;
|
|---|
| 88 | QHash<QString, Rpp::Source *> m_sourceTrees;
|
|---|
| 89 | QHash<QString, TokenEngine::TokenContainer> m_sourceTokens;
|
|---|
| 90 | };
|
|---|
| 91 |
|
|---|
| 92 | class PreprocessorController: public QObject
|
|---|
| 93 | {
|
|---|
| 94 | Q_OBJECT
|
|---|
| 95 | public:
|
|---|
| 96 | PreprocessorController(IncludeFiles includefiles,
|
|---|
| 97 | PreprocessorCache &preprocessorCache,
|
|---|
| 98 | QStringList preLoadFilesFilenames = QStringList());
|
|---|
| 99 |
|
|---|
| 100 | TokenEngine::TokenSectionSequence evaluate(const QString &filename, Rpp::DefineMap *activedefinitions);
|
|---|
| 101 | public slots:
|
|---|
| 102 | void includeSlot(Rpp::Source *&includee, const Rpp::Source *includer,
|
|---|
| 103 | const QString &filename, Rpp::RppTreeEvaluator::IncludeType includeType);
|
|---|
| 104 | void readFile(QByteArray &contents, QString filename);
|
|---|
| 105 | signals:
|
|---|
| 106 | void error(QString type, QString text);
|
|---|
| 107 | private:
|
|---|
| 108 | IncludeFiles m_includeFiles;
|
|---|
| 109 | Rpp::RppTreeEvaluator m_rppTreeEvaluator;
|
|---|
| 110 | PreprocessorCache &m_preprocessorCache;
|
|---|
| 111 | QHash<QString, QByteArray> m_preLoadFiles;
|
|---|
| 112 | };
|
|---|
| 113 |
|
|---|
| 114 | Rpp::DefineMap *defaultMacros(PreprocessorCache &preprocessorCache);
|
|---|
| 115 |
|
|---|
| 116 | class StandardOutErrorHandler : public QObject
|
|---|
| 117 | {
|
|---|
| 118 | Q_OBJECT
|
|---|
| 119 | public slots:
|
|---|
| 120 | void error(QString type, QString text);
|
|---|
| 121 | };
|
|---|
| 122 |
|
|---|
| 123 | class RppPreprocessor
|
|---|
| 124 | {
|
|---|
| 125 | public:
|
|---|
| 126 | RppPreprocessor(QString basePath, QStringList includePaths, QStringList preLoadFilesFilename = QStringList());
|
|---|
| 127 | ~RppPreprocessor();
|
|---|
| 128 | TokenEngine::TokenSectionSequence evaluate(const QString &filename);
|
|---|
| 129 | private:
|
|---|
| 130 | IncludeFiles m_includeFiles;
|
|---|
| 131 | PreprocessorCache m_cache;
|
|---|
| 132 | Rpp::DefineMap *m_activeDefinitions;
|
|---|
| 133 | PreprocessorController m_controller;
|
|---|
| 134 | StandardOutErrorHandler m_errorHandler;
|
|---|
| 135 | };
|
|---|
| 136 |
|
|---|
| 137 | QT_END_NAMESPACE
|
|---|
| 138 |
|
|---|
| 139 | #endif
|
|---|