tools/porting/src/preprocessorcontrol.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the qt3to4 porting application of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ****************************************************************************/
00023 
00024 #ifndef PREPROCESSORCONTROL_H
00025 #define PREPROCESSORCONTROL_H
00026 
00027 #include "tokenengine.h"
00028 #include "tokenizer.h"
00029 #include "rpplexer.h"
00030 #include "rpptreeevaluator.h"
00031 #include "rpp.h"
00032 #include <QString>
00033 #include <QStringList>
00034 #include <QHash>
00035 
00036 class IncludeFiles
00037 {
00038 public:
00039     IncludeFiles(const QString &basePath, const QStringList &searchPaths);
00040     QString quoteLookup(const QString &currentFile,
00041                         const QString &includeFile)const;
00042     QString angleBracketLookup(const QString &includeFile) const;
00043     QString resolve(const QString &filename) const;
00044 private:
00045     QString searchIncludePaths(const QString &includeFile)const;
00046     QStringList m_searchPaths;
00047     QString m_basePath;
00048 };
00049 
00050 class PreprocessorCache: public QObject
00051 {
00052 Q_OBJECT
00053 public:
00054     PreprocessorCache();
00055     TokenEngine::TokenContainer sourceTokens(const QString &filename);
00056     Rpp::Source *sourceTree(const QString &filename);
00057     bool containsSourceTokens(const QString &filename);
00058     bool containsSourceTree(const QString &filename);
00059 signals:
00060     void error(QString type, QString text);
00061     void readFile(QByteArray &contents, QString filename);
00062 private:
00063     QByteArray readFile(const QString & filename) const;
00064     Tokenizer m_tokenizer;
00065     Rpp::RppLexer m_lexer;
00066     Rpp::Preprocessor m_preprocessor;
00067     TypedPool<Rpp::Item> m_memoryPool;
00068     QHash<QString, Rpp::Source *> m_sourceTrees;
00069     QHash<QString, TokenEngine::TokenContainer> m_sourceTokens;
00070 };
00071 
00072 class PreprocessorController: public QObject
00073 {
00074 Q_OBJECT
00075 public:
00076     PreprocessorController(IncludeFiles includefiles,
00077                            PreprocessorCache &preprocessorCache,
00078                            QStringList preLoadFilesFilenames = QStringList());
00079 
00080     TokenEngine::TokenSectionSequence evaluate(const QString &filename, Rpp::DefineMap *activedefinitions);
00081 public slots:
00082     void includeSlot(::Rpp::Source *&includee, const ::Rpp::Source *includer,
00083          const QString &filename, ::Rpp::RppTreeEvaluator::IncludeType includeType);
00084     void readFile(QByteArray &contents, QString filename);
00085 signals:
00086     void error(QString type, QString text);
00087 private:
00088     IncludeFiles m_includeFiles;
00089     Rpp::RppTreeEvaluator m_rppTreeEvaluator;
00090     PreprocessorCache &m_preprocessorCache;
00091     QHash<QString, QByteArray> m_preLoadFiles;
00092 };
00093 
00094 Rpp::DefineMap *defaultMacros(PreprocessorCache &preprocessorCache);
00095 
00096 class StandardOutErrorHandler : public QObject
00097 {
00098 Q_OBJECT
00099 public slots:
00100     void error(QString type, QString text);
00101 };
00102 
00103 class RppPreprocessor
00104 {
00105 public:
00106     RppPreprocessor(QString basePath, QStringList includePaths, QStringList preLoadFilesFilename = QStringList());
00107     ~RppPreprocessor();
00108     TokenEngine::TokenSectionSequence evaluate(const QString &filename);
00109 private:
00110     IncludeFiles m_includeFiles;
00111     PreprocessorCache m_cache;
00112     Rpp::DefineMap *m_activeDefinitions;
00113     PreprocessorController m_controller;
00114     StandardOutErrorHandler m_errorHandler;
00115 };
00116 
00117 #endif

Generated on Thu Mar 15 12:02:43 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1