tools/porting/src/preprocessorcontrol.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the qt3to4 porting application of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    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 &currentFile,
       
    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