|
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 FILEPORTER_H |
|
43 #define FILEPORTER_H |
|
44 |
|
45 #include "portingrules.h" |
|
46 #include "replacetoken.h" |
|
47 #include "filewriter.h" |
|
48 #include "preprocessorcontrol.h" |
|
49 #include <QString> |
|
50 #include <QSet> |
|
51 #include <QMap> |
|
52 |
|
53 QT_BEGIN_NAMESPACE |
|
54 |
|
55 class FilePorter |
|
56 { |
|
57 public: |
|
58 FilePorter(PreprocessorCache &preprocessorCache); |
|
59 void port(QString fileName); |
|
60 QSet<QByteArray> usedQtModules(); |
|
61 private: |
|
62 QByteArray loadFile(const QString &fileName); |
|
63 QByteArray includeAnalyse(QByteArray fileContents); |
|
64 TextReplacements includeDirectiveReplacements(); |
|
65 |
|
66 PreprocessorCache &preprocessorCache; |
|
67 const QList<TokenReplacement*> tokenReplacementRules; |
|
68 const QHash<QByteArray, QByteArray> headerReplacements; |
|
69 |
|
70 ReplaceToken replaceToken; |
|
71 Tokenizer tokenizer; //used by includeAnalyse |
|
72 |
|
73 QSet<QByteArray> qt4HeaderNames; |
|
74 QSet<QByteArray> m_usedQtModules; |
|
75 }; |
|
76 |
|
77 class PreprocessReplace : public Rpp::RppTreeWalker |
|
78 { |
|
79 public: |
|
80 PreprocessReplace(const Rpp::Source *source, const QHash<QByteArray, QByteArray> &headerReplacements); |
|
81 TextReplacements getReplacements(); |
|
82 private: |
|
83 void evaluateIncludeDirective(const Rpp::IncludeDirective *directive); |
|
84 void evaluateText(const Rpp::Text *textLine); |
|
85 const QHash<QByteArray, QByteArray> headerReplacements; |
|
86 TextReplacements replacements; |
|
87 |
|
88 }; |
|
89 |
|
90 class IncludeDirectiveAnalyzer : public Rpp::RppTreeWalker |
|
91 { |
|
92 public: |
|
93 IncludeDirectiveAnalyzer(const TokenEngine::TokenContainer &fileContents); |
|
94 int insertPos(); |
|
95 QSet<QByteArray> includedHeaders(); |
|
96 QSet<QByteArray> usedClasses(); |
|
97 private: |
|
98 void evaluateIncludeDirective(const Rpp::IncludeDirective *directive); |
|
99 void evaluateIfSection(const Rpp::IfSection *ifSection); |
|
100 void evaluateText(const Rpp::Text *textLine); |
|
101 |
|
102 int insertTokenIndex; |
|
103 bool foundInsertPos; |
|
104 bool foundQtHeader; |
|
105 int ifSectionCount; |
|
106 |
|
107 const TokenEngine::TokenContainer &fileContents; |
|
108 Rpp::Source *source; |
|
109 TypedPool<Rpp::Item> mempool; |
|
110 QSet<QByteArray> m_includedHeaders; |
|
111 QSet<QByteArray> m_usedClasses; |
|
112 }; |
|
113 |
|
114 QT_END_NAMESPACE |
|
115 |
|
116 #endif |