00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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 ¤tFile,
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