Mercurial > projects > qtd
annotate generator/generatorsetd.cpp @ 262:90131f64c9c9 lifetime
looks like enabling/disabling GC is enough
author | maxter |
---|---|
date | Tue, 22 Sep 2009 15:19:04 +0000 |
parents | b5773ccab07d |
children |
rev | line source |
---|---|
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 "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; | |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
110
diff
changeset
|
150 ContainerGenerator *cointainerGenerator; |
1 | 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 | |
110 | 158 ClassFromEntry::construct(builder.classes()); |
159 | |
1 | 160 QStringList contexts; |
161 if (build_qdoc_japi) { | |
162 generators << new QDocGenerator; | |
163 contexts << "QDocGenerator"; | |
164 } | |
165 | |
166 if (native_jump_table) { | |
167 jumpTablePreprocessor = new JumpTablePreprocessor(); | |
168 generators << jumpTablePreprocessor; | |
169 contexts << "JumpTablePreprocessor"; | |
170 } | |
171 | |
172 if (!no_d) { | |
173 d_generator = new DGenerator; | |
174 d_generator->setDocumentationDirectory(doc_dir); | |
175 d_generator->setDocumentationEnabled(docs_enabled); | |
176 d_generator->setNativeJumpTable(native_jump_table); | |
177 generators << d_generator; | |
178 | |
179 contexts << "JavaGenerator"; | |
180 } | |
181 | |
182 if (!no_cpp_h) { | |
183 cpp_header_generator = new CppHeaderGenerator(priGenerator); | |
184 generators << cpp_header_generator; | |
185 contexts << "CppHeaderGenerator"; | |
186 } | |
187 | |
188 if (!no_cpp_impl) { | |
189 cpp_impl_generator = new CppImplGenerator(priGenerator); | |
190 cpp_impl_generator->setNativeJumpTable(native_jump_table); | |
191 generators << cpp_impl_generator; | |
192 contexts << "CppImplGenerator"; | |
193 } | |
194 | |
195 if (native_jump_table) { | |
196 jumpTableGenerator = new JumpTableGenerator(jumpTablePreprocessor, priGenerator); | |
197 generators << jumpTableGenerator; | |
198 contexts << "JumpTableGenerator"; | |
199 } | |
200 | |
201 if (!no_metainfo) { | |
202 metainfo = new MetaInfoGenerator(priGenerator); | |
203 generators << metainfo; | |
204 contexts << "MetaInfoGenerator"; | |
205 } | |
206 | |
207 if (build_class_list) { | |
208 generators << new ClassListGenerator; | |
209 contexts << "ClassListGenerator"; | |
210 } | |
211 | |
167
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
110
diff
changeset
|
212 cointainerGenerator = new ContainerGenerator(cpp_impl_generator); |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
110
diff
changeset
|
213 |
ae06da58ec25
fixed hacky conversion of arguments when emmitting a signal
eldar
parents:
110
diff
changeset
|
214 |
1 | 215 generators << priGenerator; |
216 contexts << "PriGenerator"; | |
217 | |
218 generators << cointainerGenerator; | |
219 contexts << "cointainerGenerator"; | |
260 | 220 |
221 // qtd | |
222 // code for including classses in 1 module for avoiding circular imports | |
223 foreach (AbstractMetaClass *cls, builder.classes()) { | |
224 ComplexTypeEntry *ctype = const_cast<ComplexTypeEntry*>(cls->typeEntry()); | |
225 | |
226 if (!cls->isInterface() && cls->isAbstract()) | |
227 ctype->setAbstract(true); | |
228 | |
229 ctype->setIsPolymorphic(cls->isPolymorphic()); | |
230 | |
231 | |
232 foreach(QString child, ctype->includedClasses) { | |
233 ComplexTypeEntry *ctype_child = TypeDatabase::instance()->findComplexType(child); | |
234 ctype_child->addedTo = cls->name(); | |
235 } | |
236 | |
237 foreach (AbstractMetaFunction *function, cls->functions()) | |
238 function->checkStoreResult(); | |
239 } | |
1 | 240 |
241 for (int i=0; i<generators.size(); ++i) { | |
242 Generator *generator = generators.at(i); | |
243 ReportHandler::setContext(contexts.at(i)); | |
244 | |
245 generator->setOutputDirectory(outDir); | |
246 generator->setClasses(builder.classes()); | |
247 if (printStdout) | |
248 generator->printClasses(); | |
249 else | |
250 generator->generate(); | |
251 } | |
252 | |
253 QString res; | |
254 res = QString("Classes in typesystem: %1\n" | |
255 "Generated:\n" | |
256 " - d.........: %2 (%3)\n" | |
257 " - cpp-impl..: %4 (%5)\n" | |
258 " - cpp-h.....: %6 (%7)\n" | |
259 " - meta-info.: %8 (%9)\n" | |
260 " - pri.......: %10 (%11)\n" | |
261 ) | |
262 .arg(builder.classes().size()) | |
263 .arg(d_generator ? d_generator->numGenerated() : 0) | |
264 .arg(d_generator ? d_generator->numGeneratedAndWritten() : 0) | |
265 .arg(cpp_impl_generator ? cpp_impl_generator->numGenerated() : 0) | |
266 .arg(cpp_impl_generator ? cpp_impl_generator->numGeneratedAndWritten() : 0) | |
267 .arg(cpp_header_generator ? cpp_header_generator->numGenerated() : 0) | |
268 .arg(cpp_header_generator ? cpp_header_generator->numGeneratedAndWritten() : 0) | |
269 .arg(metainfo ? metainfo->numGenerated() : 0) | |
270 .arg(metainfo ? metainfo->numGeneratedAndWritten() : 0) | |
271 .arg(priGenerator->numGenerated()) | |
272 .arg(priGenerator->numGeneratedAndWritten()); | |
273 | |
274 return res; | |
275 } | |
276 | |
277 void dumpMetaDAttributes(const AbstractMetaAttributes *attr) | |
278 { | |
279 if (attr->isNative()) printf(" native"); | |
280 if (attr->isAbstract()) printf(" abstract"); | |
281 if (attr->isFinalInTargetLang()) printf(" final(d)"); | |
282 if (attr->isFinalInCpp()) printf(" final(cpp)"); | |
283 if (attr->isStatic()) printf(" static"); | |
284 if (attr->isPrivate()) printf(" private"); | |
285 if (attr->isProtected()) printf(" protected"); | |
286 if (attr->isPublic()) printf(" public"); | |
287 if (attr->isFriendly()) printf(" friendly"); | |
288 } | |
289 | |
290 void dumpMetaDType(const AbstractMetaType *type) | |
291 { | |
292 if (!type) { | |
293 printf("[void]"); | |
294 } else { | |
295 printf("[type: %s", qPrintable(type->typeEntry()->qualifiedCppName())); | |
296 if (type->isReference()) printf(" &"); | |
297 int indirections = type->indirections(); | |
298 if (indirections) printf(" %s", qPrintable(QString(indirections, '*'))); | |
299 | |
300 printf(", %s", qPrintable(type->typeEntry()->qualifiedTargetLangName())); | |
301 | |
302 if (type->isPrimitive()) printf(" primitive"); | |
303 if (type->isEnum()) printf(" enum"); | |
304 if (type->isQObject()) printf(" q_obj"); | |
305 if (type->isNativePointer()) printf(" n_ptr"); | |
306 if (type->isTargetLangString()) printf(" d_string"); | |
307 if (type->isConstant()) printf(" const"); | |
308 printf("]"); | |
309 } | |
310 } | |
311 | |
312 void dumpMetaDArgument(const AbstractMetaArgument *arg) | |
313 { | |
314 printf(" "); | |
315 dumpMetaDType(arg->type()); | |
316 printf(" %s", qPrintable(arg->argumentName())); | |
317 if (!arg->defaultValueExpression().isEmpty()) | |
318 printf(" = %s", qPrintable(arg->defaultValueExpression())); | |
319 printf("\n"); | |
320 } | |
321 | |
322 void dumpMetaDFunction(const AbstractMetaFunction *func) | |
323 { | |
324 printf(" %s() - ", qPrintable(func->name())); | |
325 dumpMetaDType(func->type()); | |
326 dumpMetaDAttributes(func); | |
327 if (func->isConstant()) printf(" const"); | |
328 printf("\n arguments:\n"); | |
329 foreach (AbstractMetaArgument *arg, func->arguments()) | |
330 dumpMetaDArgument(arg); | |
331 } | |
332 | |
333 void dumpMetaDClass(const AbstractMetaClass *cls) | |
334 { | |
335 printf("\nclass: %s, package: %s\n", qPrintable(cls->name()), qPrintable(cls->package())); | |
336 if (cls->hasVirtualFunctions()) | |
337 printf(" shell based\n"); | |
338 printf(" baseclass: %s %s\n", qPrintable(cls->baseClassName()), cls->isQObject() ? "'QObject-type'" : "'not a QObject-type'"); | |
339 printf(" interfaces:"); | |
340 foreach (AbstractMetaClass *iface, cls->interfaces()) | |
341 printf(" %s", qPrintable(iface->name())); | |
342 printf("\n"); | |
343 printf(" attributes:"); | |
344 dumpMetaDAttributes(cls); | |
345 | |
346 printf("\n functions:\n"); | |
347 foreach (const AbstractMetaFunction *func, cls->functions()) | |
348 dumpMetaDFunction(func); | |
349 | |
350 // printf("\n fields:\n"); | |
351 // foreach (const AbstractMetaField *field, cls->fields()) | |
352 // dumpMetaJavaField(field); | |
353 | |
354 // printf("\n enums:\n"); | |
355 // foreach (const AbstractMetaEnum *e, cls->enums()) | |
356 // dumpMetaJavaEnum(e); | |
357 } | |
358 | |
359 void dumpMetaDTree(const AbstractMetaClassList &classes) | |
360 { | |
361 foreach (AbstractMetaClass *cls, classes) { | |
362 dumpMetaDClass(cls); | |
363 } | |
364 } | |
365 |