Mercurial > projects > qtd
annotate generator/generatorsetd.cpp @ 331:1defd6a98364 signals
Make static constructors shared. Requires new dmd. Remove irrelevant junk
author | eldar1@eldar1-laptop |
---|---|
date | Fri, 22 Jan 2010 23:59:07 +0000 |
parents | ae06da58ec25 |
children | b5773ccab07d |
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"; | |
220 | |
221 for (int i=0; i<generators.size(); ++i) { | |
222 Generator *generator = generators.at(i); | |
223 ReportHandler::setContext(contexts.at(i)); | |
224 | |
225 generator->setOutputDirectory(outDir); | |
226 generator->setClasses(builder.classes()); | |
227 if (printStdout) | |
228 generator->printClasses(); | |
229 else | |
230 generator->generate(); | |
231 } | |
232 | |
233 QString res; | |
234 res = QString("Classes in typesystem: %1\n" | |
235 "Generated:\n" | |
236 " - d.........: %2 (%3)\n" | |
237 " - cpp-impl..: %4 (%5)\n" | |
238 " - cpp-h.....: %6 (%7)\n" | |
239 " - meta-info.: %8 (%9)\n" | |
240 " - pri.......: %10 (%11)\n" | |
241 ) | |
242 .arg(builder.classes().size()) | |
243 .arg(d_generator ? d_generator->numGenerated() : 0) | |
244 .arg(d_generator ? d_generator->numGeneratedAndWritten() : 0) | |
245 .arg(cpp_impl_generator ? cpp_impl_generator->numGenerated() : 0) | |
246 .arg(cpp_impl_generator ? cpp_impl_generator->numGeneratedAndWritten() : 0) | |
247 .arg(cpp_header_generator ? cpp_header_generator->numGenerated() : 0) | |
248 .arg(cpp_header_generator ? cpp_header_generator->numGeneratedAndWritten() : 0) | |
249 .arg(metainfo ? metainfo->numGenerated() : 0) | |
250 .arg(metainfo ? metainfo->numGeneratedAndWritten() : 0) | |
251 .arg(priGenerator->numGenerated()) | |
252 .arg(priGenerator->numGeneratedAndWritten()); | |
253 | |
254 return res; | |
255 } | |
256 | |
257 void dumpMetaDAttributes(const AbstractMetaAttributes *attr) | |
258 { | |
259 if (attr->isNative()) printf(" native"); | |
260 if (attr->isAbstract()) printf(" abstract"); | |
261 if (attr->isFinalInTargetLang()) printf(" final(d)"); | |
262 if (attr->isFinalInCpp()) printf(" final(cpp)"); | |
263 if (attr->isStatic()) printf(" static"); | |
264 if (attr->isPrivate()) printf(" private"); | |
265 if (attr->isProtected()) printf(" protected"); | |
266 if (attr->isPublic()) printf(" public"); | |
267 if (attr->isFriendly()) printf(" friendly"); | |
268 } | |
269 | |
270 void dumpMetaDType(const AbstractMetaType *type) | |
271 { | |
272 if (!type) { | |
273 printf("[void]"); | |
274 } else { | |
275 printf("[type: %s", qPrintable(type->typeEntry()->qualifiedCppName())); | |
276 if (type->isReference()) printf(" &"); | |
277 int indirections = type->indirections(); | |
278 if (indirections) printf(" %s", qPrintable(QString(indirections, '*'))); | |
279 | |
280 printf(", %s", qPrintable(type->typeEntry()->qualifiedTargetLangName())); | |
281 | |
282 if (type->isPrimitive()) printf(" primitive"); | |
283 if (type->isEnum()) printf(" enum"); | |
284 if (type->isQObject()) printf(" q_obj"); | |
285 if (type->isNativePointer()) printf(" n_ptr"); | |
286 if (type->isTargetLangString()) printf(" d_string"); | |
287 if (type->isConstant()) printf(" const"); | |
288 printf("]"); | |
289 } | |
290 } | |
291 | |
292 void dumpMetaDArgument(const AbstractMetaArgument *arg) | |
293 { | |
294 printf(" "); | |
295 dumpMetaDType(arg->type()); | |
296 printf(" %s", qPrintable(arg->argumentName())); | |
297 if (!arg->defaultValueExpression().isEmpty()) | |
298 printf(" = %s", qPrintable(arg->defaultValueExpression())); | |
299 printf("\n"); | |
300 } | |
301 | |
302 void dumpMetaDFunction(const AbstractMetaFunction *func) | |
303 { | |
304 printf(" %s() - ", qPrintable(func->name())); | |
305 dumpMetaDType(func->type()); | |
306 dumpMetaDAttributes(func); | |
307 if (func->isConstant()) printf(" const"); | |
308 printf("\n arguments:\n"); | |
309 foreach (AbstractMetaArgument *arg, func->arguments()) | |
310 dumpMetaDArgument(arg); | |
311 } | |
312 | |
313 void dumpMetaDClass(const AbstractMetaClass *cls) | |
314 { | |
315 printf("\nclass: %s, package: %s\n", qPrintable(cls->name()), qPrintable(cls->package())); | |
316 if (cls->hasVirtualFunctions()) | |
317 printf(" shell based\n"); | |
318 printf(" baseclass: %s %s\n", qPrintable(cls->baseClassName()), cls->isQObject() ? "'QObject-type'" : "'not a QObject-type'"); | |
319 printf(" interfaces:"); | |
320 foreach (AbstractMetaClass *iface, cls->interfaces()) | |
321 printf(" %s", qPrintable(iface->name())); | |
322 printf("\n"); | |
323 printf(" attributes:"); | |
324 dumpMetaDAttributes(cls); | |
325 | |
326 printf("\n functions:\n"); | |
327 foreach (const AbstractMetaFunction *func, cls->functions()) | |
328 dumpMetaDFunction(func); | |
329 | |
330 // printf("\n fields:\n"); | |
331 // foreach (const AbstractMetaField *field, cls->fields()) | |
332 // dumpMetaJavaField(field); | |
333 | |
334 // printf("\n enums:\n"); | |
335 // foreach (const AbstractMetaEnum *e, cls->enums()) | |
336 // dumpMetaJavaEnum(e); | |
337 } | |
338 | |
339 void dumpMetaDTree(const AbstractMetaClassList &classes) | |
340 { | |
341 foreach (AbstractMetaClass *cls, classes) { | |
342 dumpMetaDClass(cls); | |
343 } | |
344 } | |
345 |