Mercurial > projects > qtd
comparison generator/generatorsetd.cpp @ 1:e78566595089
initial import
author | mandel |
---|---|
date | Mon, 11 May 2009 16:01:50 +0000 |
parents | |
children | 136c9ee83ee5 |
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 "generatorsetd.h" | |
43 #include "reporthandler.h" | |
44 | |
45 #include "dgenerator.h" | |
46 #include "cppheadergenerator.h" | |
47 #include "cppimplgenerator.h" | |
48 #include "metainfogenerator.h" | |
49 #include "classlistgenerator.h" | |
50 #include "containergenerator.h" | |
51 #include "qdocgenerator.h" | |
52 #include "uiconverter.h" | |
53 #include "jumptable.h" | |
54 | |
55 #include <QFileInfo> | |
56 | |
57 GeneratorSet *GeneratorSet::getInstance() { | |
58 return new GeneratorSetD(); | |
59 } | |
60 | |
61 void dumpMetaDTree(const AbstractMetaClassList &classes); | |
62 | |
63 GeneratorSetD::GeneratorSetD() : | |
64 no_d(false), | |
65 no_cpp_h(false), | |
66 no_cpp_impl(false), | |
67 no_metainfo(false), | |
68 build_class_list(false), | |
69 build_qdoc_japi(false), | |
70 docs_enabled(false), | |
71 do_ui_convert(false), | |
72 native_jump_table(false), | |
73 doc_dir("../../main/doc/jdoc") | |
74 {} | |
75 | |
76 QString GeneratorSetD::usage() { | |
77 QString usage = | |
78 " --no-d \n" | |
79 " --no-metainfo \n" | |
80 " --no-cpp-h \n" | |
81 " --no-cpp-impl \n" | |
82 " --convert-to-jui=[.ui-file name] \n" | |
83 " --custom-widgets=[file names] \n"; | |
84 | |
85 return usage; | |
86 } | |
87 | |
88 bool GeneratorSetD::readParameters(const QMap<QString, QString> args) { | |
89 no_d = args.contains("no-d"); | |
90 no_cpp_h = args.contains("no-cpp-h"); | |
91 no_cpp_impl = args.contains("no-cpp-impl"); | |
92 no_metainfo = args.contains("no-metainfo"); | |
93 build_class_list = args.contains("build-class-list"); | |
94 native_jump_table = args.contains("native-jump-table"); | |
95 | |
96 if (args.contains("build-qdoc-japi")) { | |
97 no_d = true; | |
98 no_cpp_h = true; | |
99 no_cpp_impl = true; | |
100 no_metainfo = true; | |
101 build_qdoc_japi = true; | |
102 } | |
103 | |
104 if (args.contains("jdoc-dir")) { | |
105 doc_dir = args.value("jdoc-dir"); | |
106 } | |
107 | |
108 docs_enabled = args.contains("jdoc-enabled"); | |
109 | |
110 if (args.contains("custom-widgets")) | |
111 custom_widgets = args.value("custom-widgets"); | |
112 | |
113 if (args.contains("convert-to-jui")) { | |
114 ui_file_name = args.value("convert-to-jui"); | |
115 do_ui_convert = true; | |
116 | |
117 if (!QFileInfo(ui_file_name).exists()) { | |
118 printf(".ui file '%s' does not exist\n", qPrintable(ui_file_name)); | |
119 return false; | |
120 } | |
121 } | |
122 return GeneratorSet::readParameters(args); | |
123 } | |
124 | |
125 void GeneratorSetD::buildModel(const QString pp_file) { | |
126 // Building the code inforamation... | |
127 builder.setFileName(pp_file); | |
128 builder.build(); | |
129 } | |
130 | |
131 void GeneratorSetD::dumpObjectTree() { | |
132 dumpMetaDTree(builder.classes()); | |
133 } | |
134 | |
135 QString GeneratorSetD::generate() { | |
136 | |
137 // Ui conversion... | |
138 if (do_ui_convert) { | |
139 UiConverter converter; | |
140 converter.setClasses(builder.classes()); | |
141 converter.convertToJui(ui_file_name, custom_widgets); | |
142 return 0; | |
143 } else if (!custom_widgets.isEmpty()) { | |
144 fprintf(stderr, "NOTE: The --custom-widgets option only has an effect when used with --convert-to-jui"); | |
145 } | |
146 | |
147 // Code generation | |
148 QList<Generator *> generators; | |
149 PriGenerator *priGenerator = new PriGenerator; | |
150 ContainerGenerator *cointainerGenerator = new ContainerGenerator; | |
151 DGenerator *d_generator = 0; | |
152 CppHeaderGenerator *cpp_header_generator = 0; | |
153 CppImplGenerator *cpp_impl_generator = 0; | |
154 MetaInfoGenerator *metainfo = 0; | |
155 JumpTablePreprocessor *jumpTablePreprocessor = 0; | |
156 JumpTableGenerator *jumpTableGenerator = 0; | |
157 | |
158 QStringList contexts; | |
159 if (build_qdoc_japi) { | |
160 generators << new QDocGenerator; | |
161 contexts << "QDocGenerator"; | |
162 } | |
163 | |
164 if (native_jump_table) { | |
165 jumpTablePreprocessor = new JumpTablePreprocessor(); | |
166 generators << jumpTablePreprocessor; | |
167 contexts << "JumpTablePreprocessor"; | |
168 } | |
169 | |
170 if (!no_d) { | |
171 d_generator = new DGenerator; | |
172 d_generator->setDocumentationDirectory(doc_dir); | |
173 d_generator->setDocumentationEnabled(docs_enabled); | |
174 d_generator->setNativeJumpTable(native_jump_table); | |
175 generators << d_generator; | |
176 | |
177 contexts << "JavaGenerator"; | |
178 } | |
179 | |
180 if (!no_cpp_h) { | |
181 cpp_header_generator = new CppHeaderGenerator(priGenerator); | |
182 generators << cpp_header_generator; | |
183 contexts << "CppHeaderGenerator"; | |
184 } | |
185 | |
186 if (!no_cpp_impl) { | |
187 cpp_impl_generator = new CppImplGenerator(priGenerator); | |
188 cpp_impl_generator->setNativeJumpTable(native_jump_table); | |
189 generators << cpp_impl_generator; | |
190 contexts << "CppImplGenerator"; | |
191 } | |
192 | |
193 if (native_jump_table) { | |
194 jumpTableGenerator = new JumpTableGenerator(jumpTablePreprocessor, priGenerator); | |
195 generators << jumpTableGenerator; | |
196 contexts << "JumpTableGenerator"; | |
197 } | |
198 | |
199 if (!no_metainfo) { | |
200 metainfo = new MetaInfoGenerator(priGenerator); | |
201 generators << metainfo; | |
202 contexts << "MetaInfoGenerator"; | |
203 } | |
204 | |
205 if (build_class_list) { | |
206 generators << new ClassListGenerator; | |
207 contexts << "ClassListGenerator"; | |
208 } | |
209 | |
210 generators << priGenerator; | |
211 contexts << "PriGenerator"; | |
212 | |
213 generators << cointainerGenerator; | |
214 contexts << "cointainerGenerator"; | |
215 | |
216 for (int i=0; i<generators.size(); ++i) { | |
217 Generator *generator = generators.at(i); | |
218 ReportHandler::setContext(contexts.at(i)); | |
219 | |
220 generator->setOutputDirectory(outDir); | |
221 generator->setClasses(builder.classes()); | |
222 if (printStdout) | |
223 generator->printClasses(); | |
224 else | |
225 generator->generate(); | |
226 } | |
227 | |
228 QString res; | |
229 res = QString("Classes in typesystem: %1\n" | |
230 "Generated:\n" | |
231 " - d.........: %2 (%3)\n" | |
232 " - cpp-impl..: %4 (%5)\n" | |
233 " - cpp-h.....: %6 (%7)\n" | |
234 " - meta-info.: %8 (%9)\n" | |
235 " - pri.......: %10 (%11)\n" | |
236 ) | |
237 .arg(builder.classes().size()) | |
238 .arg(d_generator ? d_generator->numGenerated() : 0) | |
239 .arg(d_generator ? d_generator->numGeneratedAndWritten() : 0) | |
240 .arg(cpp_impl_generator ? cpp_impl_generator->numGenerated() : 0) | |
241 .arg(cpp_impl_generator ? cpp_impl_generator->numGeneratedAndWritten() : 0) | |
242 .arg(cpp_header_generator ? cpp_header_generator->numGenerated() : 0) | |
243 .arg(cpp_header_generator ? cpp_header_generator->numGeneratedAndWritten() : 0) | |
244 .arg(metainfo ? metainfo->numGenerated() : 0) | |
245 .arg(metainfo ? metainfo->numGeneratedAndWritten() : 0) | |
246 .arg(priGenerator->numGenerated()) | |
247 .arg(priGenerator->numGeneratedAndWritten()); | |
248 | |
249 return res; | |
250 } | |
251 | |
252 void dumpMetaDAttributes(const AbstractMetaAttributes *attr) | |
253 { | |
254 if (attr->isNative()) printf(" native"); | |
255 if (attr->isAbstract()) printf(" abstract"); | |
256 if (attr->isFinalInTargetLang()) printf(" final(d)"); | |
257 if (attr->isFinalInCpp()) printf(" final(cpp)"); | |
258 if (attr->isStatic()) printf(" static"); | |
259 if (attr->isPrivate()) printf(" private"); | |
260 if (attr->isProtected()) printf(" protected"); | |
261 if (attr->isPublic()) printf(" public"); | |
262 if (attr->isFriendly()) printf(" friendly"); | |
263 } | |
264 | |
265 void dumpMetaDType(const AbstractMetaType *type) | |
266 { | |
267 if (!type) { | |
268 printf("[void]"); | |
269 } else { | |
270 printf("[type: %s", qPrintable(type->typeEntry()->qualifiedCppName())); | |
271 if (type->isReference()) printf(" &"); | |
272 int indirections = type->indirections(); | |
273 if (indirections) printf(" %s", qPrintable(QString(indirections, '*'))); | |
274 | |
275 printf(", %s", qPrintable(type->typeEntry()->qualifiedTargetLangName())); | |
276 | |
277 if (type->isPrimitive()) printf(" primitive"); | |
278 if (type->isEnum()) printf(" enum"); | |
279 if (type->isQObject()) printf(" q_obj"); | |
280 if (type->isNativePointer()) printf(" n_ptr"); | |
281 if (type->isTargetLangString()) printf(" d_string"); | |
282 if (type->isConstant()) printf(" const"); | |
283 printf("]"); | |
284 } | |
285 } | |
286 | |
287 void dumpMetaDArgument(const AbstractMetaArgument *arg) | |
288 { | |
289 printf(" "); | |
290 dumpMetaDType(arg->type()); | |
291 printf(" %s", qPrintable(arg->argumentName())); | |
292 if (!arg->defaultValueExpression().isEmpty()) | |
293 printf(" = %s", qPrintable(arg->defaultValueExpression())); | |
294 printf("\n"); | |
295 } | |
296 | |
297 void dumpMetaDFunction(const AbstractMetaFunction *func) | |
298 { | |
299 printf(" %s() - ", qPrintable(func->name())); | |
300 dumpMetaDType(func->type()); | |
301 dumpMetaDAttributes(func); | |
302 if (func->isConstant()) printf(" const"); | |
303 printf("\n arguments:\n"); | |
304 foreach (AbstractMetaArgument *arg, func->arguments()) | |
305 dumpMetaDArgument(arg); | |
306 } | |
307 | |
308 void dumpMetaDClass(const AbstractMetaClass *cls) | |
309 { | |
310 printf("\nclass: %s, package: %s\n", qPrintable(cls->name()), qPrintable(cls->package())); | |
311 if (cls->hasVirtualFunctions()) | |
312 printf(" shell based\n"); | |
313 printf(" baseclass: %s %s\n", qPrintable(cls->baseClassName()), cls->isQObject() ? "'QObject-type'" : "'not a QObject-type'"); | |
314 printf(" interfaces:"); | |
315 foreach (AbstractMetaClass *iface, cls->interfaces()) | |
316 printf(" %s", qPrintable(iface->name())); | |
317 printf("\n"); | |
318 printf(" attributes:"); | |
319 dumpMetaDAttributes(cls); | |
320 | |
321 printf("\n functions:\n"); | |
322 foreach (const AbstractMetaFunction *func, cls->functions()) | |
323 dumpMetaDFunction(func); | |
324 | |
325 // printf("\n fields:\n"); | |
326 // foreach (const AbstractMetaField *field, cls->fields()) | |
327 // dumpMetaJavaField(field); | |
328 | |
329 // printf("\n enums:\n"); | |
330 // foreach (const AbstractMetaEnum *e, cls->enums()) | |
331 // dumpMetaJavaEnum(e); | |
332 } | |
333 | |
334 void dumpMetaDTree(const AbstractMetaClassList &classes) | |
335 { | |
336 foreach (AbstractMetaClass *cls, classes) { | |
337 dumpMetaDClass(cls); | |
338 } | |
339 } | |
340 |