comparison generator/main.cpp @ 1:e78566595089

initial import
author mandel
date Mon, 11 May 2009 16:01:50 +0000
parents
children 0a29ce1ae854
comparison
equal deleted inserted replaced
0:36fb74dc547d 1:e78566595089
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;
78
79 QMap<QString, QString> args;
80
81 int argNum = 0;
82 for (int i=1; i<argc; ++i) {
83 QString arg(argv[i]);
84 arg = arg.trimmed();
85 if( arg.startsWith("--") ) {
86 int split = arg.indexOf("=");
87 if( split > 0 )
88 args[arg.mid(2).left(split-2)] = arg.mid(split + 1).trimmed();
89 else
90 args[arg.mid(2)] = QString();
91 } else if( arg.startsWith("-")) {
92 args[arg.mid(1)] = QString();
93 } else {
94 argNum++;
95 args[QString("arg-%1").arg(argNum)] = arg;
96 }
97 }
98
99 if (args.contains("no-suppress-warnings")) {
100 TypeDatabase *db = TypeDatabase::instance();
101 db->setSuppressWarnings(false);
102 }
103
104 if (args.contains("include-eclipse-warnings")) {
105 TypeDatabase *db = TypeDatabase::instance();
106 db->setIncludeEclipseWarnings(true);
107 }
108
109 if (args.contains("debug-level")) {
110 QString level = args.value("debug-level");
111 if (level == "sparse")
112 ReportHandler::setDebugLevel(ReportHandler::SparseDebug);
113 else if (level == "medium")
114 ReportHandler::setDebugLevel(ReportHandler::MediumDebug);
115 else if (level == "full")
116 ReportHandler::setDebugLevel(ReportHandler::FullDebug);
117 }
118
119 if (args.contains("dummy")) {
120 FileOut::dummy = true;
121 }
122
123 if (args.contains("diff")) {
124 FileOut::diff = true;
125 }
126
127 if (args.contains("rebuild-only")) {
128 QStringList classes = args.value("rebuild-only").split(",", QString::SkipEmptyParts);
129 TypeDatabase::instance()->setRebuildClasses(classes);
130 }
131
132 if (args.contains("d-target"))
133 {
134 QString dTarget = args.value("d-target");
135 if (dTarget == "d1-tango")
136 dVersion = 1;
137 /*
138 else if (dtarget == "d2-tango")
139 qFatal("Tango D2 target is not supported");
140 */
141 else if (dTarget == "d2-phobos")
142 {
143 dVersion = 2;
144 dPhobos = true;
145 }
146 else
147 {
148 fprintf(stderr, "D target '%s' is not recognized", qPrintable(dTarget));
149 return 1;
150 }
151 }
152
153 fileName = args.value("arg-1");
154
155 typesystemFileName = args.value("arg-2");
156 if (args.contains("arg-3"))
157 displayHelp(gs);
158
159 if (fileName.isEmpty())
160 fileName = default_file;
161
162 if (typesystemFileName.isEmpty())
163 typesystemFileName = default_system;
164
165 if (fileName.isEmpty() || typesystemFileName.isEmpty() )
166 displayHelp(gs);
167
168 if (!gs->readParameters(args))
169 displayHelp(gs);
170
171 cpp_shared = args.contains("cpp_shared");
172
173 printf("Running the QtD Generator. Please wait while source files are being generated...\n");
174
175 if (!TypeDatabase::instance()->parseFile(typesystemFileName))
176 qFatal("Cannot parse file: '%s'", qPrintable(typesystemFileName));
177
178
179 if (!Preprocess::preprocess(fileName, pp_file, args.value("include-paths"))) {
180 fprintf(stderr, "Preprocessor failed on file: '%s'\n", qPrintable(fileName));
181 return 1;
182 }
183
184 if (args.contains("ast-to-xml")) {
185 astToXML(pp_file);
186 return 0;
187 }
188
189 ArgumentReplace::init(); // replacer for arguments which are D keywords such as "version"
190
191 Binder::installMessageHandler(ReportHandler_message_handler);
192 gs->buildModel(pp_file);
193 if (args.contains("dump-object-tree")) {
194 gs->dumpObjectTree();
195 return 0;
196 }
197 printf("%s\n", qPrintable(gs->generate()));
198
199 printf("Done, %d warnings (%d known issues)\n", ReportHandler::warningCount(),
200 ReportHandler::suppressedCount());
201 }
202
203
204 void displayHelp(GeneratorSet* generatorSet) {
205 #if defined(Q_OS_WIN32)
206 char path_splitter = ';';
207 #else
208 char path_splitter = ':';
209 #endif
210 printf("Usage:\n generator [options] header-file typesystem-file\n\n");
211 printf("Available options:\n\n");
212 printf("General:\n");
213 printf(
214 " --cpp-shared \n"
215 " --debug-level=[sparse|medium|full] \n"
216 " --d-target=[d1-tango|d2-phobos] \n"
217 " --dump-object-tree \n"
218 " --help, -h or -? \n"
219 " --no-suppress-warnings \n"
220 " --include-eclipse-warnings \n"
221 " --output-directory=[dir] \n"
222 " --include-paths=<path>[%c<path>%c...] \n"
223 " --print-stdout \n"
224 ,
225 path_splitter, path_splitter);
226
227 printf("%s", qPrintable( generatorSet->usage()));
228 exit(0);
229 }