1
|
1 /****************************************************************************
|
|
2 **
|
|
3 ** Copyright (C) 1992-2008 Nokia. All rights reserved.
|
|
4 **
|
|
5 ** This file is part of Qt Jambi.
|
|
6 **
|
|
7 ** * Commercial Usage
|
|
8 * Licensees holding valid Qt Commercial licenses may use this file in
|
|
9 * accordance with the Qt Commercial License Agreement provided with the
|
|
10 * Software or, alternatively, in accordance with the terms contained in
|
|
11 * a written agreement between you and Nokia.
|
|
12 *
|
|
13 *
|
|
14 * GNU General Public License Usage
|
|
15 * Alternatively, this file may be used under the terms of the GNU
|
|
16 * General Public License versions 2.0 or 3.0 as published by the Free
|
|
17 * Software Foundation and appearing in the file LICENSE.GPL included in
|
|
18 * the packaging of this file. Please review the following information
|
|
19 * to ensure GNU General Public Licensing requirements will be met:
|
|
20 * http://www.fsf.org/licensing/licenses/info/GPLv2.html and
|
|
21 * http://www.gnu.org/copyleft/gpl.html. In addition, as a special
|
|
22 * exception, Nokia gives you certain additional rights. These rights
|
|
23 * are described in the Nokia Qt GPL Exception version 1.2, included in
|
|
24 * the file GPL_EXCEPTION.txt in this package.
|
|
25 *
|
|
26 * Qt for Windows(R) Licensees
|
|
27 * As a special exception, Nokia, as the sole copyright holder for Qt
|
|
28 * Designer, grants users of the Qt/Eclipse Integration plug-in the
|
|
29 * right for the Qt/Eclipse Integration to link to functionality
|
|
30 * provided by Qt Designer and its related libraries.
|
|
31 *
|
|
32 *
|
|
33 * If you are unsure which license is appropriate for your use, please
|
|
34 * contact the sales department at qt-sales@nokia.com.
|
|
35
|
|
36 **
|
|
37 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|
38 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
39 **
|
|
40 ****************************************************************************/
|
|
41
|
|
42 #include "main.h"
|
|
43 #include "asttoxml.h"
|
|
44 #include "reporthandler.h"
|
|
45 #include "typesystem.h"
|
|
46 #include "generatorset.h"
|
|
47 #include "fileout.h"
|
|
48 #include "binder.h"
|
|
49
|
|
50 #include "abstractmetalang.h"
|
|
51
|
|
52 #include <QDir>
|
|
53
|
|
54 bool cpp_shared;
|
|
55 bool dPhobos = false;
|
|
56 int dVersion = 1;
|
|
57
|
|
58 void ReportHandler_message_handler(const std::string &str)
|
|
59 {
|
|
60 ReportHandler::warning(QString::fromStdString(str));
|
|
61 }
|
|
62
|
|
63
|
|
64 void displayHelp(GeneratorSet *generatorSet);
|
|
65
|
|
66 #include <QDebug>
|
|
67 int main(int argc, char *argv[])
|
|
68 {
|
|
69 GeneratorSet *gs = GeneratorSet::getInstance();
|
|
70
|
|
71 QString default_file = "qtjambi_masterinclude.h";
|
|
72 QString default_system = "build_all.txt";
|
|
73
|
|
74 QString fileName;
|
|
75 QString typesystemFileName;
|
|
76 QString pp_file = ".preprocessed.tmp";
|
|
77 QStringList rebuild_classes;
|
4
|
78 QString source_dir;
|
1
|
79
|
|
80 QMap<QString, QString> args;
|
|
81
|
|
82 int argNum = 0;
|
|
83 for (int i=1; i<argc; ++i) {
|
|
84 QString arg(argv[i]);
|
|
85 arg = arg.trimmed();
|
|
86 if( arg.startsWith("--") ) {
|
|
87 int split = arg.indexOf("=");
|
|
88 if( split > 0 )
|
|
89 args[arg.mid(2).left(split-2)] = arg.mid(split + 1).trimmed();
|
|
90 else
|
|
91 args[arg.mid(2)] = QString();
|
|
92 } else if( arg.startsWith("-")) {
|
|
93 args[arg.mid(1)] = QString();
|
|
94 } else {
|
|
95 argNum++;
|
|
96 args[QString("arg-%1").arg(argNum)] = arg;
|
|
97 }
|
|
98 }
|
|
99
|
|
100 if (args.contains("no-suppress-warnings")) {
|
|
101 TypeDatabase *db = TypeDatabase::instance();
|
|
102 db->setSuppressWarnings(false);
|
|
103 }
|
|
104
|
|
105 if (args.contains("include-eclipse-warnings")) {
|
|
106 TypeDatabase *db = TypeDatabase::instance();
|
|
107 db->setIncludeEclipseWarnings(true);
|
|
108 }
|
|
109
|
|
110 if (args.contains("debug-level")) {
|
|
111 QString level = args.value("debug-level");
|
|
112 if (level == "sparse")
|
|
113 ReportHandler::setDebugLevel(ReportHandler::SparseDebug);
|
|
114 else if (level == "medium")
|
|
115 ReportHandler::setDebugLevel(ReportHandler::MediumDebug);
|
|
116 else if (level == "full")
|
|
117 ReportHandler::setDebugLevel(ReportHandler::FullDebug);
|
|
118 }
|
|
119
|
|
120 if (args.contains("dummy")) {
|
|
121 FileOut::dummy = true;
|
|
122 }
|
|
123
|
|
124 if (args.contains("diff")) {
|
|
125 FileOut::diff = true;
|
|
126 }
|
|
127
|
|
128 if (args.contains("rebuild-only")) {
|
|
129 QStringList classes = args.value("rebuild-only").split(",", QString::SkipEmptyParts);
|
|
130 TypeDatabase::instance()->setRebuildClasses(classes);
|
|
131 }
|
|
132
|
|
133 if (args.contains("d-target"))
|
|
134 {
|
|
135 QString dTarget = args.value("d-target");
|
|
136 if (dTarget == "d1-tango")
|
|
137 dVersion = 1;
|
|
138 /*
|
|
139 else if (dtarget == "d2-tango")
|
|
140 qFatal("Tango D2 target is not supported");
|
|
141 */
|
|
142 else if (dTarget == "d2-phobos")
|
|
143 {
|
|
144 dVersion = 2;
|
|
145 dPhobos = true;
|
|
146 }
|
|
147 else
|
|
148 {
|
|
149 fprintf(stderr, "D target '%s' is not recognized", qPrintable(dTarget));
|
|
150 return 1;
|
|
151 }
|
|
152 }
|
|
153
|
4
|
154 source_dir = args.value("source-directory");
|
1
|
155 fileName = args.value("arg-1");
|
4
|
156 if (!source_dir.isEmpty())
|
|
157 {
|
|
158 fileName = source_dir + "/" + fileName;
|
|
159 }
|
1
|
160
|
|
161 typesystemFileName = args.value("arg-2");
|
|
162 if (args.contains("arg-3"))
|
|
163 displayHelp(gs);
|
|
164
|
|
165 if (fileName.isEmpty())
|
|
166 fileName = default_file;
|
|
167
|
|
168 if (typesystemFileName.isEmpty())
|
|
169 typesystemFileName = default_system;
|
|
170
|
|
171 if (fileName.isEmpty() || typesystemFileName.isEmpty() )
|
|
172 displayHelp(gs);
|
|
173
|
|
174 if (!gs->readParameters(args))
|
|
175 displayHelp(gs);
|
|
176
|
|
177 cpp_shared = args.contains("cpp_shared");
|
|
178
|
|
179 printf("Running the QtD Generator. Please wait while source files are being generated...\n");
|
|
180
|
4
|
181 if (!TypeDatabase::instance()->parseFile(typesystemFileName, source_dir))
|
1
|
182 qFatal("Cannot parse file: '%s'", qPrintable(typesystemFileName));
|
|
183
|
4
|
184 if (!Preprocess::preprocess(fileName, pp_file, args.value("include-paths"), source_dir, args.value("qt-include-directory"))) {
|
1
|
185 fprintf(stderr, "Preprocessor failed on file: '%s'\n", qPrintable(fileName));
|
|
186 return 1;
|
|
187 }
|
|
188
|
|
189 if (args.contains("ast-to-xml")) {
|
|
190 astToXML(pp_file);
|
|
191 return 0;
|
|
192 }
|
|
193
|
|
194 ArgumentReplace::init(); // replacer for arguments which are D keywords such as "version"
|
|
195
|
|
196 Binder::installMessageHandler(ReportHandler_message_handler);
|
|
197 gs->buildModel(pp_file);
|
|
198 if (args.contains("dump-object-tree")) {
|
|
199 gs->dumpObjectTree();
|
|
200 return 0;
|
|
201 }
|
|
202 printf("%s\n", qPrintable(gs->generate()));
|
|
203
|
|
204 printf("Done, %d warnings (%d known issues)\n", ReportHandler::warningCount(),
|
|
205 ReportHandler::suppressedCount());
|
|
206 }
|
|
207
|
|
208
|
|
209 void displayHelp(GeneratorSet* generatorSet) {
|
|
210 #if defined(Q_OS_WIN32)
|
|
211 char path_splitter = ';';
|
|
212 #else
|
|
213 char path_splitter = ':';
|
|
214 #endif
|
|
215 printf("Usage:\n generator [options] header-file typesystem-file\n\n");
|
|
216 printf("Available options:\n\n");
|
|
217 printf("General:\n");
|
|
218 printf(
|
|
219 " --cpp-shared \n"
|
4
|
220 " --qt-include-directory \n"
|
|
221 " --qt-directory \n"
|
|
222 " --source-directory \n"
|
1
|
223 " --debug-level=[sparse|medium|full] \n"
|
4
|
224 " --d-target=[d1-tango|d2-phobos] \n"
|
1
|
225 " --dump-object-tree \n"
|
|
226 " --help, -h or -? \n"
|
|
227 " --no-suppress-warnings \n"
|
|
228 " --include-eclipse-warnings \n"
|
|
229 " --output-directory=[dir] \n"
|
|
230 " --include-paths=<path>[%c<path>%c...] \n"
|
|
231 " --print-stdout \n"
|
|
232 ,
|
|
233 path_splitter, path_splitter);
|
|
234
|
|
235 printf("%s", qPrintable( generatorSet->usage()));
|
|
236 exit(0);
|
|
237 }
|